[Rt-commit] rt branch, 4.4/download-user-info, created. rt-4.4.2-246-gf64314d26

Craig Kaiser craig at bestpractical.com
Tue Jun 5 09:21:40 EDT 2018


The branch, 4.4/download-user-info has been created
        at  f64314d2642f12aab6fa920e1a7c39df1bc87941 (commit)

- Log -----------------------------------------------------------------
commit 725dd1cde1646eb33656127662154472e093c1ff
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Mon May 21 13:32:56 2018 -0400

    Create helper for exporting TSV data

diff --git a/share/html/Helpers/Results.tsv b/share/html/Helpers/Results.tsv
new file mode 100644
index 000000000..6b488b478
--- /dev/null
+++ b/share/html/Helpers/Results.tsv
@@ -0,0 +1,107 @@
+%# 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 }}}
+<%ARGS>
+$Format           => undef
+$Query            => ''
+$OrderBy          => 'id'
+$Order            => 'ASC'
+$PreserveNewLines => 0
+$Type             => undef
+$UserId           => undef
+</%ARGS>
+
+<%INIT>
+my $Collection;
+
+if ( !$Type ) {
+    $Collection = RT::Tickets->new( $session{'CurrentUser'} );
+    $Format = RT->Config->Get('UserDataSearchResultFormat') || RT->Config->Get('DefaultSearchResultFormat');
+    $Collection->FromSQL( $Query );
+    if ( $OrderBy =~ /\|/ ) {
+        # Multiple Sorts
+        my @OrderBy = split /\|/, $OrderBy;
+        my @Order   = split /\|/, $Order;
+        $Collection->OrderByCols(
+            map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } }
+            ( 0 .. $#OrderBy )
+        );
+    }
+    else {
+        $Collection->OrderBy( FIELD => $OrderBy, ORDER => $Order );
+    }
+} elsif ( $Type eq 'User' ) {
+    $Format = RT->Config->Get('UserDataSearchResultFormat') || "'__id__', '__Name__', '__EmailAddress__', '__RealName__', '__NickName__', '__Organization__', '__HomePhone__', '__WorkPhone__','__MobilePhone__', '__PagerPhone__', '__Address1__', '__Address2__', '__City__', '__State__','__Zip__', '__Country__', '__Gecos__', '__Lang__', '__FreeFormContactInfo__'";
+
+    my $user = RT::User->new($session{'CurrentUser'});
+    if ( $UserId ) {
+        $user->Load( $UserId );
+    } else {
+        $user->Load($session{'CurrentUser'});
+    }
+
+    $Collection = RT::Users->new($session{'CurrentUser'});
+    $Collection->Limit( FIELD => 'id', VALUE => $user->Id );
+
+} elsif ( $Type eq 'Transaction' ) {
+    $Format = RT->Config->Get('UserDataSearchResultFormat') || "'__ObjectId__', '__id__', '__Created__', '__Description__', '__OldValue__', '__NewValue__', '__Content__'";
+
+    my $user = RT::User->new($session{'CurrentUser'});
+    if ( $UserId ) {
+        $user->Load( $UserId );
+    } else {
+        $user->Load($session{'CurrentUser'});
+    }
+
+    $Collection = RT::Transactions->new($session{'CurrentUser'});
+    $Collection->Limit( FIELD => 'Creator', VALUE => $user->Id );
+    $Collection->Limit( FIELD => 'Type', VALUE => 'Correspondence' );
+    $Collection->Limit( FIELD => 'Type', VALUE => 'Comment' );
+}
+
+$m->comp( "/Elements/TSVExport", Collection => $Collection, Format => $Format, PreserveNewLines => $PreserveNewLines );
+</%INIT>
diff --git a/share/html/Search/Results.tsv b/share/html/Search/Results.tsv
deleted file mode 100644
index 1bbdded74..000000000
--- a/share/html/Search/Results.tsv
+++ /dev/null
@@ -1,72 +0,0 @@
-%# 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 }}}
-<%ARGS>
-$Format => undef
-$Query => ''
-$OrderBy => 'id'
-$Order => 'ASC'
-$PreserveNewLines => 0
-</%ARGS>
-<%INIT>
-my $Tickets = RT::Tickets->new( $session{'CurrentUser'} );
-$Tickets->FromSQL( $Query );
-if ( $OrderBy =~ /\|/ ) {
-    # Multiple Sorts
-    my @OrderBy = split /\|/, $OrderBy;
-    my @Order   = split /\|/, $Order;
-    $Tickets->OrderByCols(
-        map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } }
-        ( 0 .. $#OrderBy )
-    );
-}
-else {
-    $Tickets->OrderBy( FIELD => $OrderBy, ORDER => $Order );
-}
-
-$m->comp( "/Elements/TSVExport", Collection => $Tickets, Format => $Format, PreserveNewLines => $PreserveNewLines );
-</%INIT>

commit 196535932ab76e9f409906bc92debf982f4bf3bd
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Mon May 21 13:35:01 2018 -0400

    Update ticket search to use tsv helper

diff --git a/share/html/Elements/Tabs b/share/html/Elements/Tabs
index 40cb43e7c..b2f3b2cf9 100644
--- a/share/html/Elements/Tabs
+++ b/share/html/Elements/Tabs
@@ -982,7 +982,7 @@ my $build_main_nav = sub {
 
             my $more = $current_search_menu->child( more => title => loc('Feeds') );
 
-            $more->child( spreadsheet => title => loc('Spreadsheet'), path => "/Search/Results.tsv$args" );
+            $more->child( spreadsheet => title => loc('Spreadsheet'), path => "/Helpers/Results.tsv$args" );
 
             my %rss_data = map {
                 $_ => $QueryArgs->{$_} || $fallback_query_args{$_} || '' }

commit a1c91325c467eaa69f5465dbdcfb857f4a47c53f
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Mon May 21 13:38:15 2018 -0400

    Add column to transaction column map for content

diff --git a/share/html/Elements/RT__Transaction/ColumnMap b/share/html/Elements/RT__Transaction/ColumnMap
index 28a82f1e0..d709a5440 100644
--- a/share/html/Elements/RT__Transaction/ColumnMap
+++ b/share/html/Elements/RT__Transaction/ColumnMap
@@ -105,6 +105,11 @@ my $COLUMN_MAP = {
             }
         },
     },
+    Content => {
+        title       => 'Content', # loc
+        Attribute   => 'Content', # loc
+        value       => sub { return $_[0]->Content },
+    },
 };
 
 

commit 8e171c740bbc7e0bb9e1a6bf0cbefca59c3382b4
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Mon May 21 13:42:54 2018 -0400

    Add portlet for downloading user information

diff --git a/share/html/Elements/UserRelatedInfo b/share/html/Elements/UserRelatedInfo
new file mode 100644
index 000000000..7b4b9e80a
--- /dev/null
+++ b/share/html/Elements/UserRelatedInfo
@@ -0,0 +1,71 @@
+%# 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 }}}
+<&|/Widgets/TitleBox,
+    class => 'user-related-info',
+    title => loc("User related info"),
+&>
+
+<div class="row">
+    <div class="col-md-12">
+        <a href="/Helpers/Results.tsv?Type=User&UserId=<% $id %>"><button>Download My User Info</button></a>
+        <a href="/Helpers/Results.tsv?<% $query_tickets %>"><button>Download My Tickets</button></a>
+        <a href="/Helpers/Results.tsv?Type=Transaction&UserId=<% $id %>"><button>Download My Transaction Info</button></a>
+    </div>
+</div>
+</&>
+<%init>
+my $user = RT::User->new($session{'CurrentUser'});
+$user->Load( $id );
+
+# Build Ticket Query
+my $query_tickets = "Query=Requestor.id = " . $id ? $id : '';
+</%init>
+
+<%ARGS>
+$id        => undef
+</%ARGS>

commit 03da87ec0540004f3236048016934bf1bc35d3fd
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Mon May 21 13:43:18 2018 -0400

    Add user download portlet to Admin modify page

diff --git a/share/html/Admin/Users/Modify.html b/share/html/Admin/Users/Modify.html
index 3b8bc42fc..d657df51e 100644
--- a/share/html/Admin/Users/Modify.html
+++ b/share/html/Admin/Users/Modify.html
@@ -232,6 +232,8 @@
 % }
 </form>
 
+<& /Elements/UserRelatedInfo, id => $id &>
+
 <%INIT>
 
 my $UserObj = RT::User->new($session{'CurrentUser'});
@@ -308,6 +310,27 @@ 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_email = 1;
+    my $number = '';
+    while ( $valid_email ) {
+        my @Chars = ('1'..'9');
+        for (1..9) {
+            $number .= $Chars[int rand @Chars];
+        }
+        $valid_email = !$UserObj->ValidateEmail('anon_' . $number . '@example.com');
+    }
+    $UserObj->SetName('anon_' . $number);
+    $UserObj->SetEmailAddress('anon_' . $number . '@example.com');
+}
+
 # This code does automatic redirection if any updates happen.
 MaybeRedirectForResults(
     Actions   => \@results,

commit 12a55916f3cfcedd2004fceb8d091230116a74db
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Mon May 21 15:10:53 2018 -0400

    Add test for user tsv info download

diff --git a/t/download_user_info.t b/t/download_user_info.t
new file mode 100644
index 000000000..fcbe81883
--- /dev/null
+++ b/t/download_user_info.t
@@ -0,0 +1,39 @@
+
+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;
+
+    $agent->get( $url . "/Helpers/Results.tsv?Type=User&id=" . $root->id );
+    ok $agent;
+
+    my @info = split '	', $agent->res->{_content};;
+    is($info[19], 'root');
+    is($info[20], 'root at localhost');
+    is($info[21], 'Enoch Root');
+}
+
+done_testing();
\ No newline at end of file

commit 443a3d521c3498a716956cb3ea0f9201af9b76df
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Mon May 21 15:27:52 2018 -0400

    Add test for user tickets download

diff --git a/t/download_user_info.t b/t/download_user_info.t
index fcbe81883..e4dc83898 100644
--- a/t/download_user_info.t
+++ b/t/download_user_info.t
@@ -31,9 +31,22 @@ my $url = $agent->rt_base_url;
     ok $agent;
 
     my @info = split '	', $agent->res->{_content};;
-    is($info[19], 'root');
-    is($info[20], 'root at localhost');
-    is($info[21], 'Enoch Root');
+    is($info[19], 'root', 'Name exported correctly');
+    is($info[20], 'root at localhost', 'EmailAddress exported correctly');
+    is($info[21], 'Enoch Root', 'RealName exported correctly');
+
+    my $ticket = RT::Ticket->new( $root );
+    my ($id) = $ticket->Create( Subject => 'test', Requestor => 'root', Queue => $queue );
+    ok $id;
+
+    $agent->get( $url . "/Helpers/Results.tsv?Query=Requestor.id=" . $root->id );
+    ok $agent;
+
+    my @data = split '	', $agent->res->{_content};
+    is($data[11], 'test', 'Subject exported correcty');
+    is($data[12], 'new', 'Status exported correctly');
+    is($data[13], 'General', 'Queue exported correctly');
+    is($data[16], 'root (Enoch Root)', 'Requestors exported correctly');
 }
 
 done_testing();
\ No newline at end of file

commit f64314d2642f12aab6fa920e1a7c39df1bc87941
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Mon May 21 15:43:05 2018 -0400

    Add test for user transaction download

diff --git a/t/download_user_info.t b/t/download_user_info.t
index e4dc83898..e775d905b 100644
--- a/t/download_user_info.t
+++ b/t/download_user_info.t
@@ -47,6 +47,16 @@ my $url = $agent->rt_base_url;
     is($data[12], 'new', 'Status exported correctly');
     is($data[13], 'General', 'Queue exported correctly');
     is($data[16], 'root (Enoch Root)', 'Requestors exported correctly');
+
+    $ticket->LoadById( $id );
+    $ticket->Comment(Content => 'Test');
+
+    $agent->get( $url . "/Helpers/Results.tsv?Type=Transaction&UserId=" . $root->id );
+    ok $agent;
+
+    @data = split '	', $agent->res->{_content};
+    is($data[12], "Test\n", 'Transaction content correct');
+    is($data[9], 'Comments added', 'Transaction description correct');
 }
 
 done_testing();
\ No newline at end of file

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


More information about the rt-commit mailing list