[Rt-commit] rt branch, 4.4/remove-user-info, repushed

Craig Kaiser craig at bestpractical.com
Thu Sep 13 10:52:26 EDT 2018


The branch 4.4/remove-user-info was deleted and repushed:
       was c4120b9f32fcf5ec2b72a9808a29fd65d4b48f16
       now b90d7c4fce68928fa131b1f97d9e84bd7d0e5c74

-:  ------- > 1: 846aad444 Allow rt-setup-fulltext-index to prompt for dba password
-:  ------- > 2: 2626be861 Fix typo in POD
-:  ------- > 3: 03a365485 Improve message when applying/removing custom roles from queues
1: 8b6402eb0 ! 4: 1e38d70cb Add GenerateAnonymousName function for RT::User
    @@ -30,7 +30,7 @@
     +    my $name = '';
     +
     +    while ( $invalid ) {
    -+        my @Chars = ('a'..'z', 'A'..'Z', '1'..'9');
    ++        my @Chars = ('a'..'z', 'A'..'Z', '0'..'9');
     +        for (1..$length || 9) {
     +            $name .= $Chars[int rand @Chars];
     +        }
2: 1a5f99e25 ! 5: 814480b46 Create method AnonymizeUser in User.pm
    @@ -15,7 +15,7 @@
     +=head2 AnonymizeUser { clear_customfields }
     +
     +Remove all personal identifying information on the user record, but keep
    -+the user record alive. Additonally replace the username with an anonymous name.
    ++the user record alive. Additionally replace the username with an anonymous name.
     +Submit clear_customfields in a paramhash, if true all customfield values
     +applied to the user record will be cleared.
     +
    @@ -24,7 +24,7 @@
     +sub AnonymizeUser {
     +    my $self = shift;
     +    my %args = (
    -+        clear_customfields  => undef,
    ++        ClearCustomFields  => undef,
     +        @_,
     +    );
     +
    @@ -34,18 +34,20 @@
     +        PagerPhone RealName Signature SMIMECertificate State Timezone WorkPhone Zip
     +    );
     +
    ++    $RT::Handle->BeginTransaction();
     +    # Remove identifying user information from record
     +    foreach my $attr (@user_idenifying_info) {
    -+        if ( length $self->$attr or !defined $self->$attr) {
    ++        if ( defined $self->$attr && length $self->$attr) {
     +                my $method = 'Set' . $attr;
     +                my ($ret, $msg) = $self->$method('');
    ++                RT::Logger->error($msg) unless $ret;
     +                return ($ret, $msg) unless $ret;
     +        }
     +    }
     +
     +    # Do not do anything if password is already unset
     +    if ( $self->HasPassword ) {
    -+        my ($ret, $msg) = $self->SetPassword('*NO-PASSWORD*');
    ++        my ($ret, $msg) = $self->_Set(Field => 'Password', Value => '*NO-PASSWORD*' );
     +        RT::Logger->error($msg) unless $ret;
     +    }
     +
    @@ -54,16 +56,20 @@
     +    RT::Logger->error($msg) unless $ret;
     +
     +    # Remove user customfield values
    -+    if ( $args{'clear_customfields'} ) {
    ++    if ( $args{'ClearCustomFields'} ) {
     +        my $customfields = RT::CustomFields->new(RT->SystemUser);
     +        ($ret, $msg) = $customfields->LimitToLookupType('RT::User');
     +        RT::Logger->error($msg) unless $ret;
     +
     +        while (my $customfield = $customfields->Next) {
    -+            ($ret, $msg) = $self->AddCustomFieldValue(Field => $customfield->Name, Value => '');
    -+            RT::Logger->error($msg) unless $ret;
    ++            if ( $self->FirstCustomFieldValue( $customfield->Name ) ) {
    ++                ($ret, $msg) = $self->DeleteCustomFieldValue( Field => $customfield->Id, Value =>  $self->FirstCustomFieldValue( $customfield->Name ) );
    ++                RT::Logger->error($msg) unless $ret;
    ++                $RT::Handle->Rollback() unless $ret;
    ++            }
     +        }
     +    }
    ++    $RT::Handle->Commit();
     +
     +    return(1, 'User successfully anonymized');
     +}
3: 0b50f1b1a ! 6: 61a2dbd9e Create modal mason component
    @@ -54,7 +54,7 @@
     +%# those contributions and any derivatives thereof.
     +%#
     +%# END BPS TAGGED BLOCK }}}
    -+<div class="<% $Class %>" align="center">
    ++<div id="<% $ModalId %>" class="<% $Class %>" align="center">
     +    <form action="<% $Action %>" method="<% $Method %>" id="<% $ModalId %>" name="<% $Name %>" >
     +% foreach my $field (@{$Fields}) {
     +        <p><% $field->{'Label'} %>
    @@ -63,8 +63,8 @@
     +%   }
     +        </p>
     +% }
    -+        <a href="#" rel="modal:close" class="button"><&|/l&><% $Cancel %></&></a>
    -+        <button type="Submit" class="button"><&|/l&><% $Accept %></&></button>
    ++        <a href="#" rel="modal:close" class="button"><&|/l&><%$Cancel%></&></a>
    ++        <button type="Submit" class="button"><&|/l&><%$Accept%></&></button>
     +    </form>
     +</div>
     +
4: efb956161 < -:  ------- Add modal to modify page
5: fa4ffc8a8 ! 7: a35c9b423 Create portlet for removing user information
    @@ -7,21 +7,6 @@
         Anonymize user will call the 'AnonymizeUser' method to clear identifying
         information from the user record. 'Replace User' and 'Remove User' will
         link to the shredder page with a pre formatted search.
    -
    -diff --git a/share/html/Elements/Modal b/share/html/Elements/Modal
    ---- a/share/html/Elements/Modal
    -+++ b/share/html/Elements/Modal
    -@@
    - %   }
    -         </p>
    - % }
    --        <a href="#" rel="modal:close" class="button"><&|/l&><% $Cancel %></&></a>
    --        <button type="Submit" class="button"><&|/l&><% $Accept %></&></button>
    -+        <a href="#" rel="modal:close" class="button"><&|/l&>$Cancel</&></a>
    -+        <button type="Submit" class="button"><&|/l&>$Accept</&></button>
    -     </form>
    - </div>
    - 
     
     diff --git a/share/html/Elements/UserRelatedInfo b/share/html/Elements/UserRelatedInfo
     new file mode 100644
    @@ -87,10 +72,10 @@
     +        <td class="value"><a href="#user-info-modal" rel="modal:open" class="button value" name="anonymize_user"><&|/l&>Anonymize</&></a></td>
     +    </tr><tr>
     +        <td class="label"><&|/l&>Replace user links in DB with "Nobody" user</&>:</td>
    -+        <td class="value"><a href="/Admin/Tools/Shredder/index.html?Plugin=Users&Users%3Astatus=enabled&Users%3Aname=<% $UserObj->Name %>&Users%3Areplace_relations=Nobody&Search=Search" name="replace-user" class="button value"><&|/l&>Replace</&></a></td>
    ++        <td class="value"><a href="<%RT->Config->Get('WebPath')%>/Admin/Tools/Shredder/index.html?Plugin=Users&Users%3Astatus=enabled&Users%3Aname=<% $UserObj->Name %>&Users%3Areplace_relations=Nobody&Search=Search" name="replace-user" class="button value"><&|/l&>Replace</&></a></td>
     +    </tr><tr>
     +        <td class="label"><&|/l&>Remove all references to user and links to user</&>:</td>
    -+        <td class="value"><a href="/Admin/Tools/Shredder/index.html?Plugin=Users&Users%3Astatus=enabled&Users%3Aname=<% $UserObj->Name %>&Search=Search&remove_user" class="button value" name="remove-user"><&|/l&>Remove</&></a></td>
    ++        <td class="value"><a href="<%RT->Config->Get('WebPath')%>/Admin/Tools/Shredder/index.html?Plugin=Users&Users%3Astatus=enabled&Users%3Aname=<% $UserObj->Name %>&Search=Search&remove_user" class="button value" name="remove-user"><&|/l&>Remove</&></a></td>
     +    </tr>
     +</table>
     +
6: 1f19bb76d < -:  ------- Add remove user info portlet to user modify page
-:  ------- > 8: e4e88fe8f Add remove user info portlet to user modify page
7: c4120b9f3 ! 9: b90d7c4fc Create test for remove user information
    @@ -24,10 +24,10 @@
     +
     +# Anonymize User
     +{
    -+    my $root = RT::Test->load_or_create_user( Name => 'root' );
    -+    ok $root && $root->id;
    ++    my $user = RT::Test->load_or_create_user( Name => 'Test User' );
    ++    ok $user && $user->id;
     +
    -+    my $user_id = $root->id;
    ++    my $user_id = $user->id;
     +
     +    $agent->get_ok( $url . "Admin/Users/Modify.html?id=" . $user_id );
     +    $agent->follow_link_ok( { text => 'Anonymize' } );
    @@ -35,23 +35,26 @@
     +    $agent->submit_form_ok( { form_id => 'user-info-modal', },
     +        "Anonymize user" );
     +
    -+    is $root->ValidateEmail('root at example.com'), 1, 'User Email removed';
    ++    $user->Load($user_id);
    ++    is $user->EmailAddress, '', 'User Email removed';
     +
     +# UserId is still the same, but all other records should be anonimyzed for TestUser
    -+    my ( $ret, $msg ) = $root->Load($user_id);
    ++    my ( $ret, $msg ) = $user->Load($user_id);
     +    ok $ret;
     +
    -+    is $root->Name =~ /anon_/, 1, 'Username replaced with anon name';
    ++    is $user->Name =~ /anon_/, 1, 'Username replaced with anon name';
     +
     +    my @user_idenifying_info = qw (
     +        Address1 Address2 City Comments Country EmailAddress
     +        FreeformContactInfo Gecos HomePhone MobilePhone NickName Organization
     +        PagerPhone RealName Signature SMIMECertificate State Timezone WorkPhone Zip
     +        );
    ++    $user->Load($user_id);
     +
     +    # Ensure that all other user fields are blank
     +    foreach my $attr (@user_idenifying_info) {
    -+        is $root->$attr, '', 'Attribute ' . $attr . ' is blank';
    ++        my $check = grep { not defined $_ or $_ eq '' or $_ eq 0 } $user->$attr;
    ++        is $check, 1, 'Attribute ' . $attr . ' is blank';
     +    }
     +
     +    # Test that customfield values are removed with anonymize user action
    @@ -63,19 +66,19 @@
     +    );
     +    ok $ret, $msg;
     +
    -+    ( $ret, $msg ) = $customfield->AddToObject($root);
    ++    ( $ret, $msg ) = $customfield->AddToObject($user);
     +    ok( $ret, "Added CF to user object - " . $msg );
     +
    -+    ( $ret, $msg ) = $root->AddCustomFieldValue(
    ++    ( $ret, $msg ) = $user->AddCustomFieldValue(
     +        Field => 'TestCustomfield',
     +        Value => 'Testing'
     +    );
     +    ok $ret, $msg;
     +
    -+    is $root->FirstCustomFieldValue('TestCustomfield'), 'Testing',
    ++    is $user->FirstCustomFieldValue('TestCustomfield'), 'Testing',
     +        'Customfield exists and has value for user.';
     +
    -+    $agent->get_ok( $url . "Admin/Users/Modify.html?id=" . $root->id );
    ++    $agent->get_ok( $url . "Admin/Users/Modify.html?id=" . $user->id );
     +    $agent->follow_link_ok( { text => 'Anonymize' } );
     +
     +    $agent->submit_form_ok(
    @@ -85,21 +88,21 @@
     +        "Anonymize user and customfields"
     +    );
     +
    -+    is $root->FirstCustomFieldValue('TestCustomfield'), undef,
    ++    is $user->FirstCustomFieldValue('TestCustomfield'), undef,
     +        'Customfield value cleared';
     +}
     +
     +# Test replace user
     +{
    -+    my $root = RT::Test->load_or_create_user(
    -+        Name       => 'root',
    ++    my $user = RT::Test->load_or_create_user(
    ++        Name       => 'user',
     +        Password   => 'password',
     +        Privileged => 1
     +    );
    -+    ok $root && $root->id;
    ++    ok $user && $user->id;
     +
     +    ok( RT::Test->set_rights(
    -+            { Principal => $root, Right => [qw(SuperUser)] },
    ++            { Principal => $user, Right => [qw(SuperUser)] },
     +        ),
     +        'set rights'
     +      );
    @@ -107,32 +110,34 @@
     +    ok $agent->logout;
     +    ok $agent->login( 'root' => 'password' );
     +
    -+    $agent->get_ok( $url . "Admin/Users/Modify.html?id=" . $root->id );
    ++    $agent->get_ok( $url . "Admin/Users/Modify.html?id=" . $user->id );
     +    $agent->follow_link_ok( { text => 'Replace' } );
     +
     +    $agent->submit_form_ok(
     +        {   form_id => 'shredder-search-form',
    -+            fields  => { WipeoutObject => 'User:name' . $root->Name, },
    ++            fields  => { WipeoutObject => 'RT::User-' . $user->Name, },
     +            button  => 'Wipeout'
     +        },
     +        "Replace user"
     +    );
     +
    -+    is $root->ValidateName( $root->Name ), 1,
    ++    my ($ret, $msg) = $user->Load($user->Id);
    ++
    ++    is $ret, 0,
     +        'User successfully deleted with replace';
     +}
     +
     +# Test Remove user
     +{
    -+    my $root = RT::Test->load_or_create_user(
    -+        Name       => 'root',
    ++    my $user = RT::Test->load_or_create_user(
    ++        Name       => 'user',
     +        Password   => 'password',
     +        Privileged => 1
     +    );
    -+    ok $root && $root->id;
    ++    ok $user && $user->id;
     +
     +    ok( RT::Test->set_rights(
    -+            { Principal => $root, Right => [qw(SuperUser)] },
    ++            { Principal => $user, Right => [qw(SuperUser)] },
     +        ),
     +        'set rights'
     +      );
    @@ -140,18 +145,20 @@
     +    $agent->logout;
     +    $agent->login( 'root' => 'password' );
     +
    -+    $agent->get_ok( $url . "Admin/Users/Modify.html?id=" . $root->id );
    ++    $agent->get_ok( $url . "Admin/Users/Modify.html?id=" . $user->id );
     +    $agent->follow_link_ok( { text => 'Remove' } );
     +
     +    $agent->submit_form_ok(
     +        {   form_id => 'shredder-search-form',
    -+            fields  => { WipeoutObject => 'User:name-' . $root->Name, },
    ++            fields  => { WipeoutObject => 'RT::User-' . $user->Name, },
     +            button  => 'Wipeout'
     +        },
     +        "Remove user"
     +    );
     +
    -+    is $root->ValidateName( $root->Name ), 1,
    ++    my ($ret, $msg) = $user->Load($user->Id);
    ++
    ++    is $ret, 0,
     +        'User successfully deleted with remove';
     +}
     +



More information about the rt-commit mailing list