[Rt-commit] rt branch, 4.4/remove-user-info, repushed
Craig Kaiser
craig at bestpractical.com
Wed May 23 15:38:03 EDT 2018
The branch 4.4/remove-user-info was deleted and repushed:
was 432578d90c0d5003b4a93603f0fbc86db4bfe372
now 9478103196a4e240c8e4e6f6405e4c54e45693da
--: ------- > 1: 484bd6620 Add option to disable escaping HTML in articles
--: ------- > 2: dab73f8fa Updated Articles docs to include disabling escaped HTML
--: ------- > 3: 27238b8b2 Update article postfix loops from using $_ to a named variable
--: ------- > 4: 0b24dae38 Add keyboard shortcuts for reply and comment
--: ------- > 5: 843170cdb Allow rt-setup-fulltext-index to prompt for dba password
--: ------- > 6: d5902aaed Fix typo in POD
--: ------- > 7: 3c98ed63e Add AnonymizeEmail method for RT::Attachments
--: ------- > 8: a37f0a449 Add GenerateAnonymousName function for RT::User
1: 64af40e8e ! 9: 6ce4f84ad Create portlet for removing user information
@@ -1,6 +1,9 @@
Author: Craig Kaiser <craig at bestpractical.com>
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'.
diff --git a/share/html/Elements/UserRelatedInfo b/share/html/Elements/UserRelatedInfo
new file mode 100644
@@ -55,14 +58,14 @@
+%#
+%# END BPS TAGGED BLOCK }}}
+<div class="modal" id="user-info-modal">
-+% if ( $count > 500 ) {
++% if ( $attachments->Count > 500 ) {
+ <p>
-+ You will need to update <% $count %> attachment records to remove <% $user->EmailAddress ? $user->EmailAddress : $user->Name %>.
++ You will need to update <% $attachments->Count %> attachment records to remove <% $user->EmailAddress ? $user->EmailAddress : $user->Name %>.
+ please use the command line tool to avoid crashing the server.
+ </p>
+ <a href="#" rel="modal:close"><button>Ok</button></a>
+% } else {
-+ <p>Are you sure you want to update <% $count %> attachment records to remove <% $user->EmailAddress ? $user->EmailAddress : $user->Name %></p>
++ <p>Are you sure you want to update <% $attachments->Count %> attachment records to remove <% $user->EmailAddress ? $user->EmailAddress : $user->Name %></p>
+ <a href="?id=<% $id %>&Anonymize=1"><button>Ok</button></a>
+ <a href="#" rel="modal:close"><button>Cancel</button></a>
+% }
@@ -82,17 +85,14 @@
+</&>
+<%init>
+my $user = RT::User->new($session{'CurrentUser'});
-+$user->Load($session{'CurrentUser'});
++my ($ret, $msg) = $user->Load($session{'CurrentUser'});
++return ($ret, $msg) unless $ret;
+
+# Number of attachments that will be Anonymized
+my $attachments = RT::Attachments->new( $session{CurrentUser} );
-+$attachments->LimitNotEmpty();
-+my $count = 0;
-+while (my $attachment = $attachments->Next) {
-+ if ( $attachment->Content =~ /$user->EmailAddress/ ) {
-+ $count += 1;
-+ }
-+}
++$attachments->Limit(FIELD => 'Content', VALUE => $user->EmailAddress, OPERATOR => 'LIKE', CASESENSITIVE => 0, ENTRYAGGREGATOR => 'OR', SUBCLAUSE => 'email');
++$attachments->Limit(FIELD => 'Headers', VALUE => $user->EmailAddress, OPERATOR => 'LIKE', CASESENSITIVE => 0, ENTRYAGGREGATOR => 'OR', SUBCLAUSE => 'email');
++$attachments->Limit(FIELD => 'Subject', VALUE => $user->EmailAddress, OPERATOR => 'LIKE', CASESENSITIVE => 0, ENTRYAGGREGATOR => 'OR', SUBCLAUSE => 'email');
+</%init>
+
+<%ARGS>
2: b6f1f2e20 ! 10: 0bb300c35 Add portlet for removing user info to modify page
@@ -1,6 +1,10 @@
Author: Craig Kaiser <craig at bestpractical.com>
Add portlet for removing user info to modify page
+
+ Call the mason component for the options to remove user information.
+ Also handle if the Anonymize user option is selected in the INIT
+ section.
diff --git a/share/html/Admin/Users/Modify.html b/share/html/Admin/Users/Modify.html
--- a/share/html/Admin/Users/Modify.html
@@ -21,33 +25,19 @@
+if ( $ARGS{Anonymize} ) {
+ my @attrs = keys %{ $UserObj->_CoreAccessible };
+
++ my $attachments = RT::Attachments->new( $session{CurrentUser} );
++ my ($ret, $msg) = $attachments->AnonymizeEmail($UserObj->EmailAddress);
++ return ($ret, $msg) unless $ret;
++
+ # Remove identifying user information from record
+ foreach my $attr (@attrs) {
+ my $method = 'Set' . $attr;
+ $UserObj->$method('');
+ }
-+ my $valid_name = 1;
-+ my $number = '';
-+ while ( $valid_name ) {
-+ my @Chars = ('1'..'9');
-+ for (1..9) {
-+ $number .= $Chars[int rand @Chars];
-+ }
-+ $valid_name = !$UserObj->ValidateName('anon_' . $number);
-+ }
-+ $UserObj->SetName('anon_' . $number);
+
-+ my $attachments = RT::Attachments->new( $session{CurrentUser} );
-+ $attachments->LimitNotEmpty();
-+ while (my $attachment = $attachments->Next) {
-+ my $str = $attachment->Content;
-+ my $find = $UserObj->EmailAddress;
-+ my $replace = "anon\@example.com";
-+ $find = quotemeta $find;
-+
-+ $str =~ s/$find/$replace/gim;
-+ $attachment->_Set( Field => 'Content', Value => $str );
-+ }
++ my $anon_name = $UserObj->GenerateAnonymousName();
++ ($ret, $msg) = $UserObj->SetName($anon_name);
++ return ($ret, $msg) unless $ret;
+}
+
# This code does automatic redirection if any updates happen.
3: 432578d90 ! 11: 947810319 Check that user information is anonymized
@@ -28,30 +28,32 @@
+ $agent->content_contains("Logout", "Found a logout link");
+}
+
-+# Testing GDPR features
++# GDPR
+{
-+ my $root = RT::Test->load_or_create_user( Name => 'root' );
++ my $TestUser = RT::Test->load_or_create_user( Name => 'TestUser', EmailAddress => 'test at example.com' );
++ ok $TestUser && $TestUser->id;
++
++ my $root = RT::Test->load_or_create_user( Name => 'root');
+ ok $root && $root->id;
+
+ my $queue = RT::Test->load_or_create_queue( Name => 'General' );
+ ok $queue && $queue->id;
+
-+ # Create transaction on ticket by root user
++ # Create transaction on ticket by TestUser user
+ my $ticket = RT::Ticket->new( $root );
-+ my ($id) = $ticket->Create( Subject => 'test', Requestor => 'root', Queue => $queue );
++ my ($id) = $ticket->Create( Subject => 'test', Requestor => 'TestUser', Queue => $queue );
+ ok $id;
+
-+ $agent->get($url . "Admin/Users/Modify.html?&Anonymize=1&id=" . $root->id);
++ $agent->get($url . "Admin/Users/Modify.html?&Anonymize=1&id=" . $TestUser->id);
+ ok $agent;
+
+ my $user = RT::User->new(RT->SystemUser);
-+ ok !$user->Load('root'), 'Username removed';
++ ok !$user->Load('TestUser'), 'Username removed';
+
-+ # UserId is still the same, but all other records should be anonimyzed for root
-+ $user->Load( $root->id );
++ # UserId is still the same, but all other records should be anonimyzed for TestUser
++ $user->Load( $TestUser->id );
+
+ ok $user->Name =~ /anon_/, 'Username replaced with anon name';
-+ ok $user->EmailAddress =~ /anon_/, 'EmailAddress replaced with anon email';
+
+ # Ensure that all other user fields are blank
+ my @attrs = keys %{ $user->_CoreAccessible };
More information about the rt-commit
mailing list