[Rt-commit] rt branch, 4.4/remove-user-info, created. rt-4.4.2-241-g432578d90
Craig Kaiser
craig at bestpractical.com
Wed May 23 09:14:22 EDT 2018
The branch, 4.4/remove-user-info has been created
at 432578d90c0d5003b4a93603f0fbc86db4bfe372 (commit)
- Log -----------------------------------------------------------------
commit 64af40e8e3b19fe594093101c7946b925c7fbae1
Author: Craig Kaiser <craig at bestpractical.com>
Date: Mon May 21 13:49:33 2018 -0400
Create portlet for removing user information
diff --git a/share/html/Elements/UserRelatedInfo b/share/html/Elements/UserRelatedInfo
new file mode 100644
index 000000000..9c48d9efc
--- /dev/null
+++ b/share/html/Elements/UserRelatedInfo
@@ -0,0 +1,92 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2017 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 class="modal" id="user-info-modal">
+% if ( $count > 500 ) {
+ <p>
+ You will need to update <% $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>
+ <a href="?id=<% $id %>&Anonymize=1"><button>Ok</button></a>
+ <a href="#" rel="modal:close"><button>Cancel</button></a>
+% }
+</div>
+<&|/Widgets/TitleBox,
+ class => 'user-related-info',
+ title => loc("User related info"),
+&>
+
+<div class="row">
+ <div class="col-md-12">
+ <a href="#user-info-modal" rel="modal:open"><button>Anonymize User</button></a>
+ <a href="/Admin/Tools/Shredder/index.html?Plugin=Users&Users%3Astatus=enabled&Users%3Aname=<% $user->Name %>&Users%3Areplace_relations=root&Search=Search"><button>Replace User Information</button></a>
+ <a href="/Admin/Tools/Shredder/index.html?Plugin=Users&Users%3Astatus=enabled&Users%3Aname=<% $user->Name %>&Search=Search"><button>Remove User Information</button></a>
+ </div>
+</div>
+</&>
+<%init>
+my $user = RT::User->new($session{'CurrentUser'});
+$user->Load($session{'CurrentUser'});
+
+# 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;
+ }
+}
+</%init>
+
+<%ARGS>
+$Anonymize => undef
+$id => undef
+</%ARGS>
commit b6f1f2e205b205a4de796e21569f57bfe8d2dded
Author: Craig Kaiser <craig at bestpractical.com>
Date: Mon May 21 13:49:54 2018 -0400
Add portlet for removing user info to modify page
diff --git a/share/html/Admin/Users/Modify.html b/share/html/Admin/Users/Modify.html
index 3b8bc42fc..3bcc94576 100644
--- a/share/html/Admin/Users/Modify.html
+++ b/share/html/Admin/Users/Modify.html
@@ -232,6 +232,8 @@
% }
</form>
+<& /Elements/UserRelatedInfo, id => $id, Anonymize => $ARGS{Anonymize} &>
+
<%INIT>
my $UserObj = RT::User->new($session{'CurrentUser'});
@@ -308,6 +310,38 @@ if ( $UserObj->Id ) {
}
}
+if ( $ARGS{Anonymize} ) {
+ my @attrs = keys %{ $UserObj->_CoreAccessible };
+
+ # 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 );
+ }
+}
+
# This code does automatic redirection if any updates happen.
MaybeRedirectForResults(
Actions => \@results,
commit 432578d90c0d5003b4a93603f0fbc86db4bfe372
Author: Craig Kaiser <craig at bestpractical.com>
Date: Mon May 21 16:49:28 2018 -0400
Check that user information is anonymized
diff --git a/t/remove_user_info.t b/t/remove_user_info.t
new file mode 100644
index 000000000..88fa0f527
--- /dev/null
+++ b/t/remove_user_info.t
@@ -0,0 +1,59 @@
+
+use strict;
+use warnings;
+use RT;
+use RT::Test tests => undef;
+
+{
+ok(require RT::User);
+}
+
+my ($baseurl, $agent) = RT::Test->started_ok;
+my $url = $agent->rt_base_url;
+
+# test a login
+{
+ $agent->login('root' => 'password');
+ # the field isn't named, so we have to click link 0
+ is( $agent->status, 200, "Fetched the page ok");
+ $agent->content_contains("Logout", "Found a logout link");
+}
+
+# Testing GDPR features
+{
+ 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
+ my $ticket = RT::Ticket->new( $root );
+ my ($id) = $ticket->Create( Subject => 'test', Requestor => 'root', Queue => $queue );
+ ok $id;
+
+ $agent->get($url . "Admin/Users/Modify.html?&Anonymize=1&id=" . $root->id);
+ ok $agent;
+
+ my $user = RT::User->new(RT->SystemUser);
+ ok !$user->Load('root'), 'Username removed';
+
+ # UserId is still the same, but all other records should be anonimyzed for root
+ $user->Load( $root->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 };
+ foreach my $attr (@attrs) {
+ if ( $attr eq 'Password' || $attr eq 'Name' || $attr eq 'id'
+ || $attr eq 'LastUpdatedBy' || $attr eq 'AuthToken' || $attr eq 'Created' || $attr eq 'Creator' || $attr eq 'LastUpdated') {
+ # Do nothing
+ } else {
+ ok $user->$attr eq '', 'Attribute ' . $attr . ' is blank';
+ }
+ }
+}
+
+done_testing();
-----------------------------------------------------------------------
More information about the rt-commit
mailing list