[Rt-commit] rt branch, 4.4/recently-viewed-bogus-tickets, repushed
Michel Rodriguez
michel at bestpractical.com
Wed Feb 26 06:26:20 EST 2020
The branch 4.4/recently-viewed-bogus-tickets was deleted and repushed:
was b0a6ca663319b47cd7368022d462f6478651bfb3
now 967526f8403a22d5331d1f5589c7615d761fff06
1: 8f74b4877 ! 1: 6c69944e2 Fix RecentlyViewedTickets to deal with shredded/merged tickets.
@@ -1,17 +1,19 @@
Author: michel <michel at bestpractical.com>
- fixes RecentlyViewedTickets to deal with shredded/merged tickets
+ Fix RecentlyViewedTickets to deal with shredded/merged tickets.
- if a ticket that was recently visited is:
+ If a ticket that was recently visited is:
shredded : it is now removed from the list
merged : the list is deduplicated if the parent was already included
- the cached RecentlyViewedTickets attribute is then updated
+ The cached RecentlyViewedTickets attribute is then updated
RecentlyViewedTickets now returns a list of hashes { id => , subject => }
so that the code in the template doesn't have to deal with this
Fixes: I#213199
+
+ cosm
diff --git a/lib/RT/User.pm b/lib/RT/User.pm
--- a/lib/RT/User.pm
@@ -34,38 +36,37 @@
my $self = shift;
- my $content = $self->FirstAttribute('RecentlyViewedTickets');
- return $content ? @{$content->Content} : ();
-+ my $recentlyViewedTickets = $self->FirstAttribute('RecentlyViewedTickets');
-+ my $content= $recentlyViewedTickets ? $recentlyViewedTickets->Content : undef;
-+ my @storedList= $content ? @$content : (); # [ [ <id>, <timestamp>], ...]
-+ my @toDisplay=(); # [ { id => <id>, title => <title> }, ... ]
-+ if( @storedList) {
++ my $recentlyViewedTickets = $self->FirstAttribute( 'RecentlyViewedTickets' );
++ my $content = $recentlyViewedTickets ? $recentlyViewedTickets->Content : undef;
++ my @storedList = $content ? @$content : (); # [ [ <id>, <timestamp>], ...]
++ my @toDisplay = (); # [ { id => <id>, title => <title> }, ... ]
++ if ( @storedList ) {
+ my @currentList; # same as @storedList, without deleted tickets
+ my $updateStoredList; # set to 1 if a ticket does not load
+ my %seen; # used to check that we don't have duplicates (in case of merges)
+
-+ foreach my $ticketRef ( @storedList) {
++ foreach my $ticketRef ( @storedList ) {
+ my ($ticketId, $timestamp) = @$ticketRef;
-+ my $ticket = RT::Ticket->new($self);
-+ $ticket->Load($ticketId);
++ my $ticket = RT::Ticket->new( $self );
++ $ticket->Load( $ticketId );
+ my $realId= $ticket->Id; # can be undef or changed in case of merge
-+ if( $ticket->Id && ! $seen{$realId}) {
++ if ( $ticket->Id && ! $seen{$realId} ) {
+ push @toDisplay, { id => $ticket->Id, subject => $ticket->Subject };
+ push @currentList, [ $ticketId, $timestamp ];
+ $seen{$realId}++;
+ } else {
+ # non existent ticket, do not add to @currentList, list needs to be updated
-+ $updateStoredList = 1;
++ $updateStoredList = 1;
+ }
+ }
+
-+ if( $updateStoredList) {
++ if ( $updateStoredList ) {
+ $self->SetAttribute(
+ Name => 'RecentlyViewedTickets',
+ Content => \@currentList,
+ );
-+ }
-+ }
-+
++ }
++ }
+ return @toDisplay;
}
@@ -94,9 +95,9 @@
- }
- $title = "#$ticketId: " . $title;
- $recents->child( "$ticketId" => title => $title, path => "/Ticket/Display.html?id=" . $ticket->Id );
-+ for my $ticket ($session{CurrentUser}->RecentlyViewedTickets) {
-+ my $title = $ticket->{subject} || loc("(No subject)");
-+ if (length $title > 50) {
++ for my $ticket ( $session{CurrentUser}->RecentlyViewedTickets ) {
++ my $title = $ticket->{subject} || loc( "(No subject)" );
++ if ( length $title > 50 ) {
+ $title = substr($title, 0, 47);
+ $title =~ s/\s+$//;
+ $title .= "...";
@@ -107,78 +108,3 @@
$search->child( articles => title => loc('Articles'), path => "/Articles/Article/Search.html" )
-diff --git a/t/ticket/recently_visited.t b/t/ticket/recently_visited.t
-new file mode 100644
---- /dev/null
-+++ b/t/ticket/recently_visited.t
-@@
-+use strict;
-+use warnings;
-+
-+# test the RecentlyViewedTickets method
-+
-+use Test::Deep;
-+use RT::Test::Shredder tests => 8;
-+my $test = "RT::Test::Shredder";
-+
-+$test->create_savepoint('clean');
-+
-+use RT::Ticket;
-+
-+{ my @tickets=(undef); # the empty element is there so that $ticket[$i]->Id is $i
-+ # (arrays start at 0, ids at 1);
-+
-+
-+ my $user = RT->SystemUser;
-+ is( $user->_visited_nb, 0, 'init: empty RecentlyViewedTickets');
-+
-+ foreach my $ticket_nb (1..20) {
-+ my $ticket = RT::Ticket->new( $user );
-+ my ($id) = $ticket->Create( Subject => "test #$ticket_nb", Queue => 1 );
-+ push @tickets, $ticket;
-+ $ticket->ApplyTransactionBatch;
-+ }
-+
-+ is( $user->_visited_nb, 0, 'tickets created: empty RecentlyViewedTickets');
-+
-+ foreach my $viewed ( 1, 2, 3, 4, 5, 2, 16, 17, 3) {
-+ $user->AddRecentlyViewedTicket( $tickets[$viewed]);
-+ }
-+
-+ is( $user->_visited, '3,17,16,2,5,4,1', 'visited tickets after inital visits');
-+
-+ my $shredder = $test->shredder_new();
-+
-+ $shredder->PutObjects( Objects => $tickets[13] );
-+ $shredder->WipeoutAll;
-+ is( $user->_visited, '3,17,16,2,5,4,1', 'visited tickets after shredding an unvisited ticket');
-+
-+ $shredder->PutObjects( Objects => $tickets[16]);
-+ $shredder->PutObjects( Objects => $tickets[4] );
-+ $shredder->WipeoutAll;
-+ is( $user->_visited, '3,17,2,5,1', 'visited tickets after shredding 2 visited tickets');
-+
-+ $tickets[2]->MergeInto( 10);
-+ is( $user->_visited, '3,17,10,5,1', 'visited tickets after merging into a ticket that was NOT on the list');
-+
-+ $tickets[5]->MergeInto( 10);
-+ is( $user->_visited, '3,17,10,1', 'visited tickets after merging into a ticket that was on the list');
-+
-+ foreach my $viewed ( 12, 14, 18, 10, 3, 8, 11, 3, 17, 3, 11, 9) {
-+ $user->AddRecentlyViewedTicket( $tickets[$viewed]);
-+ }
-+ is( $user->_visited, '9,11,3,17,8,10,18,14,12,1', 'visited more than 10 tickets');
-+}
-+
-+package RT::User;
-+
-+sub _visited_nb
-+ { return scalar shift->RecentlyViewedTickets; }
-+
-+sub _visited
-+ { return join ',', map { $_->{id} } shift->RecentlyViewedTickets; }
-+
-+
-+
-+
-
2: f06ee2882 < -: ------- Fixes RecentlyViewedTickets to deal with shredded/merged tickets
3: b0a6ca663 ! 2: 967526f84 Tests for recently-viewed-bogus-tickets.
@@ -1,6 +1,6 @@
Author: michel <michel at bestpractical.com>
- Added test to the fix
+ Tests for recently-viewed-bogus-tickets.
diff --git a/t/api/user_recently_visited.t b/t/api/user_recently_visited.t
new file mode 100644
More information about the rt-commit
mailing list