[Rt-commit] rt branch, 4.4/remove-user-info, created. rt-4.4.3-94-gd6cf3a6db

Craig Kaiser craig at bestpractical.com
Fri Dec 14 08:56:04 EST 2018


The branch, 4.4/remove-user-info has been created
        at  d6cf3a6db74949bb1ccca6a4053dae97dd59b103 (commit)

- Log -----------------------------------------------------------------
commit 9df047a66f611136287d548beac7a89e7f98db46
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Thu Dec 13 09:10:47 2018 -0500

    Move User related info portlet into side column

diff --git a/share/html/Admin/Users/Modify.html b/share/html/Admin/Users/Modify.html
index d5e331c29..9281661d4 100644
--- a/share/html/Admin/Users/Modify.html
+++ b/share/html/Admin/Users/Modify.html
@@ -125,6 +125,13 @@
 
 <& /Elements/EditCustomFields, Object => $UserObj, Grouping => 'Access control' &>
 
+</&>
+<table width="100%" border="0">
+    <tr><td valign="top" class="boxcontainer">
+            <&| /Widgets/TitleBox, title => loc('Comments about this user'), class => 'user-info-comments' &>
+        <textarea class="comments" name="Comments" cols="80" rows="5" wrap="virtual"><%$UserObj->Comments//$ARGS{Comments}//''%></textarea>
+    </td></tr>
+</table>
 </&>
 % $m->callback( %ARGS, CallbackName => 'LeftColumnBottom', UserObj => $UserObj );
 </td>
@@ -203,6 +210,7 @@
 
 </table>
 </&>
+<& /User/Elements/BasicUserData, UserObj => $UserObj &>
 <br />
 
 <& /Elements/EditCustomFieldCustomGroupings, Object => $UserObj &>
@@ -211,9 +219,6 @@
 </td></tr>
 <tr>
 <td colspan="2">
-<&| /Widgets/TitleBox, title => loc('Comments about this user'), class => 'user-info-comments' &>
-<textarea class="comments" name="Comments" cols="80" rows="5" wrap="virtual"><%$UserObj->Comments//$ARGS{Comments}//''%></textarea>
-</&>
 %if (!$Create && $UserObj->Privileged) {
 <br />
 <&| /Widgets/TitleBox, title => loc('Signature'), class => 'user-info-signature' &>
@@ -232,7 +237,6 @@
 % }
 </form>
 
-<& /User/Elements/RelatedData, UserObj => $UserObj &>
 <%INIT>
 
 my $UserObj = RT::User->new($session{'CurrentUser'});
diff --git a/share/html/Prefs/AboutMe.html b/share/html/Prefs/AboutMe.html
index e2e046711..4aef37295 100644
--- a/share/html/Prefs/AboutMe.html
+++ b/share/html/Prefs/AboutMe.html
@@ -56,7 +56,7 @@
 
 </form>
 
-<& /User/Elements/RelatedData,
+<& /User/Elements/BasicUserData,
     UserObj           => $UserObj,
     UserDataButton    => loc( 'Download My Data' ),
     UserTicketsButton => loc( 'Download My Tickets' ),
diff --git a/share/html/SelfService/Prefs.html b/share/html/SelfService/Prefs.html
index 19644c981..3105f5e32 100644
--- a/share/html/SelfService/Prefs.html
+++ b/share/html/SelfService/Prefs.html
@@ -94,7 +94,7 @@
 % }
 
 % if( RT->Config->Get('SelfServiceDownloadUserData') ) {
-<& /SelfService/User/Elements/RelatedData, UserObj => $user &>
+<& /SelfService/User/Elements/BasicUserData, UserObj => $user &>
 % }
 
 <%INIT>
diff --git a/share/html/SelfService/User/Elements/RelatedData b/share/html/SelfService/User/Elements/RelatedData
index 4ad2469cd..4e9087176 100644
--- a/share/html/SelfService/User/Elements/RelatedData
+++ b/share/html/SelfService/User/Elements/RelatedData
@@ -51,9 +51,9 @@
 &>
 
 <div>
-    <a href="/SelfService/User/RelatedData.tsv?Type=User&id=<% $UserObj->id %>" class="button"><% $UserDataButton %></a>
+    <a href="/SelfService/User/BasicUserData.tsv?Type=User&id=<% $UserObj->id %>" class="button"><% $UserDataButton %></a>
     <a href="/SelfService/Search/Results.tsv?Query=Requestor.id=<% $UserObj->id %>&Format=<% $Format | un %>" class="button"><% $UserTicketsButton %></a>
-    <a href="/SelfService/User/RelatedData.tsv?Type=Transaction&id=<% $UserObj->id %>" class="button"><% $UserTxnButton %></a>
+    <a href="/SelfService/User/BasicUserData.tsv?Type=Transaction&id=<% $UserObj->id %>" class="button"><% $UserTxnButton %></a>
 </div>
 </&>
 
diff --git a/share/html/SelfService/User/RelatedData.tsv b/share/html/SelfService/User/RelatedData.tsv
index e0222e11c..bb61d6ff5 100644
--- a/share/html/SelfService/User/RelatedData.tsv
+++ b/share/html/SelfService/User/RelatedData.tsv
@@ -46,5 +46,5 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 <%INIT>
-$m->comp('/User/RelatedData.tsv', %ARGS);
+$m->comp('/User/BasicUserData.tsv', %ARGS);
 </%INIT>
diff --git a/share/html/User/RelatedData.tsv b/share/html/User/BasicUserData.tsv
similarity index 100%
rename from share/html/User/RelatedData.tsv
rename to share/html/User/BasicUserData.tsv
diff --git a/share/html/User/Elements/RelatedData b/share/html/User/Elements/BasicUserData
similarity index 88%
rename from share/html/User/Elements/RelatedData
rename to share/html/User/Elements/BasicUserData
index 051112d96..bc824f530 100644
--- a/share/html/User/Elements/RelatedData
+++ b/share/html/User/Elements/BasicUserData
@@ -50,11 +50,17 @@
     title => loc("User related info"),
 &>
 
-<div>
-    <a href="/User/RelatedData.tsv?Type=User&id=<% $UserObj->id %>" class="button"><% $UserDataButton %></a>
+<table>
+    <tr><td>
+        <a href="/User/BasicUserData.tsv?Type=User&id=<% $UserObj->id %>" class="button"><% $UserDataButton %></a>
+    </td></tr>
+    <tr><td>
     <a href="/Search/Results.tsv?Query=Requestor.id=<% $UserObj->id %>&Format=<% $Format | un %>" class="button"><% $UserTicketsButton %></a>
-    <a href="/User/RelatedData.tsv?Type=Transaction&id=<% $UserObj->id %>" class="button"><% $UserTxnButton %></a>
-</div>
+    </td></tr>
+    <tr><td>
+    <a href="/User/BasicUserData.tsv?Type=Transaction&id=<% $UserObj->id %>" class="button"><% $UserTxnButton %></a>
+    </td></tr>
+</table>
 </&>
 
 <%INIT>

commit 2fbff4077b551ae43ac3243b1ba528d62f2c7426
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Thu Dec 13 09:47:30 2018 -0500

    Create method AnonymizeUser in User.pm
    
    Create method 'AnonymizeUser' that will remove the personal
    identifying information from a user record, but keep the record alive.

diff --git a/lib/RT/User.pm b/lib/RT/User.pm
index daae994e7..92830fc3c 100644
--- a/lib/RT/User.pm
+++ b/lib/RT/User.pm
@@ -281,6 +281,93 @@ sub ValidateName {
     }
 }
 
+=head2 GenerateAnonymousName INT
+
+Generate a random username proceeded by 'anon_' and then a
+random string, Returns the AnonymousName string. The length of the
+random string can be set by providing an integer for character length.
+
+=cut
+
+sub GenerateAnonymousName {
+    my $self = shift;
+    my $length = shift;
+
+    my $invalid = 1;
+    my $name = '';
+
+    while ( $invalid ) {
+        my @Chars = ('a'..'z', 'A'..'Z', '0'..'9');
+        for (1..$length || 9) {
+            $name .= $Chars[int rand @Chars];
+        }
+        $invalid = !$self->ValidateName('anon_' . $name);
+    }
+    return 'anon_' . $name;
+}
+
+=head2 AnonymizeUser { clear_customfields }
+
+Remove all personal identifying information on the user record, but keep
+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.
+
+=cut
+
+sub AnonymizeUser {
+    my $self = shift;
+    my %args = (
+        ClearCustomFields  => undef,
+        @_,
+    );
+
+    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
+    );
+
+    $RT::Handle->BeginTransaction();
+    # Remove identifying user information from record
+    foreach my $attr (@user_idenifying_info) {
+        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->_Set(Field => 'Password', Value => '*NO-PASSWORD*' );
+        RT::Logger->error($msg) unless $ret;
+    }
+
+    # Generate the random anon username
+    my ($ret, $msg) = $self->SetName($self->GenerateAnonymousName);
+    RT::Logger->error($msg) unless $ret;
+
+    # Remove user customfield values
+    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) {
+            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');
+}
+
 =head2 ValidatePassword STRING
 
 Returns either (0, "failure reason") or 1 depending on whether the given

commit b5bd61f46378b96b25616bf31dde2cd2f78bbcfe
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Thu Dec 13 09:49:00 2018 -0500

    Create modal mason component

diff --git a/share/html/Elements/Modal b/share/html/Elements/Modal
new file mode 100644
index 000000000..ed81cb7ef
--- /dev/null
+++ b/share/html/Elements/Modal
@@ -0,0 +1,71 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2018 Best Practical Solutions, LLC
+%#                                          <sales at bestpractical.com>
+%#
+%# (Except where explicitly superseded by other copyright notices)
+%#
+%#
+%# LICENSE:
+%#
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%#
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+%# General Public License for more details.
+%#
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+%#
+%#
+%# CONTRIBUTION SUBMISSION POLICY:
+%#
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%#
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%#
+%# END BPS TAGGED BLOCK }}}
+<div id="<% $ModalId %>" class="<% $Class %>" align="center">
+    <form action="<% $Action %>" method="<% $Method %>" id="<% $ModalId %>" name="<% $Name %>" >
+% foreach my $field (@{$Fields}) {
+        <p><% $field->{'Label'} %>
+%   if ( $field->{'Input'} ) {
+        <input type="<% $field->{'Input'} %>" class="<% $field->{'Class'} %>" name="<% $field->{'Name'} %>" value="<% $field->{'Value'} %>">
+%   }
+        </p>
+% }
+        <a href="#" rel="modal:close" class="button"><&|/l, $Cancel &>[_1]</&></a>
+        <button type="Submit" class="button"><&|/l, $Accept &>[_1]</&></button>
+    </form>
+</div>
+
+<%ARGS>
+$Fields   => undef
+$Name     => undef
+$ModalId  => undef
+$Class    => 'modal'
+$Action   => undef
+$Method   => 'GET'
+$Accept   => 'Ok'
+$Cancel   => 'Cancel'
+</%ARGS>

commit d179f129231ba0248080f154d99335ee8921797c
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Thu Dec 13 11:33:06 2018 -0500

    Allow TSVExport filename to be set through Filename arg

diff --git a/share/html/Elements/TSVExport b/share/html/Elements/TSVExport
index df7105f79..3f6d5d813 100644
--- a/share/html/Elements/TSVExport
+++ b/share/html/Elements/TSVExport
@@ -50,6 +50,7 @@ $Class => undef
 $Collection
 $Format
 $PreserveNewLines => 0
+$Filename  => undef
 </%ARGS>
 <%ONCE>
 my $no_html = HTML::Scrubber->new( deny => '*' );
@@ -59,6 +60,7 @@ require HTML::Entities;
 $Class ||= $Collection->ColumnMapClassName;
 
 $r->content_type('application/vnd.ms-excel');
+$r->header_out( 'Content-disposition' => "attachment; filename=$Filename" ) if $Filename;
 
 my $DisplayFormat = $m->comp('/Elements/ScrubHTML', Content => $Format);
 

commit 6b4706d73a7c111791ed8524d4f266c1cb5daef8
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Thu Dec 13 09:50:15 2018 -0500

    Create portlet for removing user information
    
    Mason template that has three buttons for removing user information. The
    buttons are 'Anonymize user', 'Replace User' and 'Remove User'.
    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/User/BasicUserData.tsv b/share/html/User/BasicUserData.tsv
index 25804686d..016912a5e 100644
--- a/share/html/User/BasicUserData.tsv
+++ b/share/html/User/BasicUserData.tsv
@@ -50,6 +50,7 @@ $PreserveNewLines => 0
 $Type             => 'User'
 $Format           => undef
 $id
+$Filename         => undef
 </%ARGS>
 
 <%INIT>
@@ -81,5 +82,7 @@ if ( $Type eq 'User' ) {
     $Collection->Limit( FIELD => 'Type',       VALUE => 'Comment' );
 }
 
-$m->comp( "/Elements/TSVExport", Collection => $Collection, Format => $Format, PreserveNewLines => $PreserveNewLines );
+$m->comp( "/Elements/TSVExport", Collection => $Collection, Format => $Format,
+    PreserveNewLines => $PreserveNewLines, Filename => $Filename,
+);
 </%INIT>
diff --git a/share/html/User/Elements/BasicUserData b/share/html/User/Elements/BasicUserData
index bc824f530..c49fb1817 100644
--- a/share/html/User/Elements/BasicUserData
+++ b/share/html/User/Elements/BasicUserData
@@ -47,20 +47,28 @@
 %# END BPS TAGGED BLOCK }}}
 <&|/Widgets/TitleBox,
     class => 'user-related-info',
-    title => loc("User related info"),
+    title => loc("Manage User Data"),
 &>
 
-<table>
-    <tr><td>
-        <a href="/User/BasicUserData.tsv?Type=User&id=<% $UserObj->id %>" class="button"><% $UserDataButton %></a>
-    </td></tr>
-    <tr><td>
-    <a href="/Search/Results.tsv?Query=Requestor.id=<% $UserObj->id %>&Format=<% $Format | un %>" class="button"><% $UserTicketsButton %></a>
-    </td></tr>
-    <tr><td>
-    <a href="/User/BasicUserData.tsv?Type=Transaction&id=<% $UserObj->id %>" class="button"><% $UserTxnButton %></a>
-    </td></tr>
-</table>
+<div>
+    <h4>Download User Information:</h4>
+    <div class="inline-row">
+        <div><a class="button" href="/User/BasicUserData.tsv?Type=User&id=<% $UserObj->id %>&Filename='UserData.tsv'"><% $UserDataButton %></a></div>
+        <div><a class="button" href="/Search/Results.tsv?Query=Requestor.id=<% $UserObj->id %>&Format=<% $Format | un %>&Filename='UserTicketData.tsv'"><% $UserTicketsButton %></a></div>
+        <div><a class="button" href="/User/BasicUserData.tsv?Type=Transaction&id=<% $UserObj->id %>&Filename='UserTransactionData.tsv'"><% $UserTxnButton %></a></div>
+    </div>
+    <h4>Remove User Information:</h4>
+    <div class="inline-row">
+        <div><a class="button" href="#user-info-modal" rel="modal:open" name="anonymize_user"><&|/l&>Anonymize User</&></a></div>
+        <div><a class="button" 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"><&|/l&>Replace User</&></a></div>
+        <div><a class="button" href="<%RT->Config->Get('WebPath')%>/Admin/Tools/Shredder/index.html?Plugin=Users&Users%3Astatus=enabled&Users%3Aname=<% $UserObj->Name %>&Search=Search&remove_user" name="remove-user"><&|/l&>Remove User</&></a></div>
+    </div>
+    <div class="inline-row">
+        <div><i class="label"><&|/l&><b>Anonymize User</b>: Remove user information with anonymous username</&></i></div>
+        <div><i class="label"><&|/l&><b>Replace User</b>: Replace user links in the database with "Nobody" user</&></i></div>
+        <div><i class="label"><&|/l&><b>Remove User</b>: Remove all references to user and links to user</&></i></div>
+    </div>
+</div>
 </&>
 
 <%INIT>
@@ -69,7 +77,7 @@ my $Format = RT->Config->Get('UserTicketDataResultFormat') || RT->Config->Get('D
 
 <%ARGS>
 $UserObj
-$UserDataButton    => loc( 'Download User Data' )
-$UserTicketsButton => loc( 'Download User Tickets' )
-$UserTxnButton     => loc( 'Download User Transaction Data' )
+$UserDataButton    => loc( 'User Data' )
+$UserTicketsButton => loc( 'User Tickets' )
+$UserTxnButton     => loc( 'User Transactions' )
 </%ARGS>
diff --git a/share/static/css/base/misc.css b/share/static/css/base/misc.css
index 25ec20c69..3833eab61 100644
--- a/share/static/css/base/misc.css
+++ b/share/static/css/base/misc.css
@@ -127,3 +127,23 @@ td.current-recipients {
     vertical-align: top;
     padding-left: 50px;
 }
+
+.inline-row {
+    display: inline-flex;
+    width: 80%;
+}
+
+div.inline-row div {
+    width: 100%;
+    display: inline-flex;
+}
+
+div.inline-row a {
+    text-align: center;
+    width: 100%;
+}
+
+div.inline-row i {
+    text-align: left;
+    width: 100%;
+}
diff --git a/share/static/css/base/test.css b/share/static/css/base/test.css
new file mode 100644
index 000000000..8b1378917
--- /dev/null
+++ b/share/static/css/base/test.css
@@ -0,0 +1 @@
+

commit 3566d5a053989093f12dc450d7269039af486707
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Thu Dec 13 09:51:34 2018 -0500

    Add remove user info portlet to user modify page

diff --git a/share/html/Admin/Users/Modify.html b/share/html/Admin/Users/Modify.html
index 9281661d4..88c87dc96 100644
--- a/share/html/Admin/Users/Modify.html
+++ b/share/html/Admin/Users/Modify.html
@@ -237,6 +237,21 @@
 % }
 </form>
 
+% if ( $UserObj->Id ) {
+    <& /Elements/Modal, ModalId => "user-info-modal", Method => 'POST', Action => RT->Config->Get('WebPath') . '/Admin/Users/Modify.html', Fields => [
+    { Label   => "Are you sure you want to anonymize user: ". $UserObj->Name . "?" },
+    { Input => 'Hidden', Value => $UserObj->Id, Name => 'id' },
+    { Input => 'Hidden', Value => 1, Name => 'Anonymize' },
+    {
+        Label    => "Check to clear user customfields:",
+        Input    => 'checkbox',
+        Class    => 'checkbox',
+        Name     => 'clear_customfields',
+        Value    => 'On',
+    },
+]
+&>
+% }
 <%INIT>
 
 my $UserObj = RT::User->new($session{'CurrentUser'});
@@ -300,6 +315,11 @@ if ($Create) {
     }
 }
 
+if ( $ARGS{'Anonymize'} and $UserObj->Id ) {
+    my ($ret, $msg) = $UserObj->AnonymizeUser(ClearCustomFields => $ARGS{'clear_customfields'});
+    push @results, $msg;
+}
+
 if ( $UserObj->Id ) {
     # Deal with Password field
     my ($status, $msg) = $UserObj->SafeSetPassword(

commit d6cf3a6db74949bb1ccca6a4053dae97dd59b103
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Thu Dec 13 09:52:42 2018 -0500

    Create test for remove user information

diff --git a/t/web/remove_user_info.t b/t/web/remove_user_info.t
new file mode 100644
index 000000000..cfb95a3a1
--- /dev/null
+++ b/t/web/remove_user_info.t
@@ -0,0 +1,156 @@
+use strict;
+use warnings;
+
+use RT::Test tests => undef;
+
+RT::Config->Set( 'ShredderStoragePath', RT::Test->temp_directory . '' );
+
+my ( $baseurl, $agent ) = RT::Test->started_ok;
+
+diag("Test server running at $baseurl");
+my $url = $agent->rt_base_url;
+
+# Login
+$agent->login( 'root' => 'password' );
+
+# Anonymize User
+{
+    my $user = RT::Test->load_or_create_user( Name => 'Test User' );
+    ok $user && $user->id;
+
+    my $user_id = $user->id;
+
+    $agent->get_ok( $url . "Admin/Users/Modify.html?id=" . $user_id );
+    $agent->follow_link_ok( { text => 'Anonymize User' } );
+
+    $agent->submit_form_ok( { form_id => 'user-info-modal', },
+        "Anonymize user" );
+
+    $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 ) = $user->Load($user_id);
+    ok $ret;
+
+    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) {
+        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
+    my $customfield = RT::CustomField->new( RT->SystemUser );
+    ( $ret, $msg ) = $customfield->Create(
+        Name       => 'TestCustomfield',
+        LookupType => 'RT::User',
+        Type       => 'FreeformSingle',
+    );
+    ok $ret, $msg;
+
+    ( $ret, $msg ) = $customfield->AddToObject($user);
+    ok( $ret, "Added CF to user object - " . $msg );
+
+    ( $ret, $msg ) = $user->AddCustomFieldValue(
+        Field => 'TestCustomfield',
+        Value => 'Testing'
+    );
+    ok $ret, $msg;
+
+    is $user->FirstCustomFieldValue('TestCustomfield'), 'Testing',
+        'Customfield exists and has value for user.';
+
+    $agent->get_ok( $url . "Admin/Users/Modify.html?id=" . $user->id );
+    $agent->follow_link_ok( { text => 'Anonymize User' } );
+
+    $agent->submit_form_ok(
+        {   form_id => 'user-info-modal',
+            fields  => { clear_customfields => 'On' },
+        },
+        "Anonymize user and customfields"
+    );
+
+    is $user->FirstCustomFieldValue('TestCustomfield'), undef,
+        'Customfield value cleared';
+}
+
+# Test replace user
+{
+    my $user = RT::Test->load_or_create_user(
+        Name       => 'user',
+        Password   => 'password',
+        Privileged => 1
+    );
+    ok $user && $user->id;
+
+    ok( RT::Test->set_rights(
+            { Principal => $user, Right => [qw(SuperUser)] },
+        ),
+        'set rights'
+      );
+
+    ok $agent->logout;
+    ok $agent->login( 'root' => 'password' );
+
+    $agent->get_ok( $url . "Admin/Users/Modify.html?id=" . $user->id );
+    $agent->follow_link_ok( { text => 'Replace User' } );
+
+    $agent->submit_form_ok(
+        {   form_id => 'shredder-search-form',
+            fields  => { WipeoutObject => 'RT::User-' . $user->Name, },
+            button  => 'Wipeout'
+        },
+        "Replace user"
+    );
+
+    my ($ret, $msg) = $user->Load($user->Id);
+
+    is $ret, 0,
+        'User successfully deleted with replace';
+}
+
+# Test Remove user
+{
+    my $user = RT::Test->load_or_create_user(
+        Name       => 'user',
+        Password   => 'password',
+        Privileged => 1
+    );
+    ok $user && $user->id;
+
+    ok( RT::Test->set_rights(
+            { Principal => $user, Right => [qw(SuperUser)] },
+        ),
+        'set rights'
+      );
+
+    $agent->logout;
+    $agent->login( 'root' => 'password' );
+
+    $agent->get_ok( $url . "Admin/Users/Modify.html?id=" . $user->id );
+    $agent->follow_link_ok( { text => 'Remove User' } );
+
+    $agent->submit_form_ok(
+        {   form_id => 'shredder-search-form',
+            fields  => { WipeoutObject => 'RT::User-' . $user->Name, },
+            button  => 'Wipeout'
+        },
+        "Remove user"
+    );
+
+    my ($ret, $msg) = $user->Load($user->Id);
+
+    is $ret, 0,
+        'User successfully deleted with remove';
+}
+
+done_testing();

-----------------------------------------------------------------------


More information about the rt-commit mailing list