[Rt-commit] rt branch, master, updated. rt-4.0.0rc6-165-g3cd39ce

Thomas Sibley trs at bestpractical.com
Wed Mar 9 16:55:03 EST 2011


The branch, master has been updated
       via  3cd39ce62de0460a8153aaff6fec1d9bb362d0ec (commit)
       via  f2aa0a1d86839d72d74ac0d2ca7de07f52a65ea5 (commit)
       via  f5db1916c99d145fd70a16dc0d3f849a0d3972a2 (commit)
       via  d4e458bfd7ca89496b34eabe73543e7a36217678 (commit)
       via  2205ca5ae8213b30b1ff422f264f6b741f89eb45 (commit)
       via  b5f0c48a321bfb48d50f1768bf1494638f15f088 (commit)
       via  bb4923b4321666a6cc396db103f11a767143cce7 (commit)
       via  45136c18819e95d8793c720bb887fa869527559c (commit)
       via  93ff22864bca07ad2aae6ccc87faf60c38d8b5a3 (commit)
       via  c1d9ee3afbaed6d17820868a02e5e9863420bfd3 (commit)
      from  934d79e8d7690e93ad317ed06141085b852bca07 (commit)

Summary of changes:
 lib/RT/Ticket.pm                    |    1 -
 lib/RT/Tickets.pm                   |    7 +---
 lib/RT/User.pm                      |   73 +++++++++++++++++++++++++++++++++++
 share/html/Elements/ShowSearch      |    6 +--
 share/html/Ticket/Elements/Bookmark |   36 ++++-------------
 share/html/m/tickets/search         |    6 +--
 t/web/mobile.t                      |    5 ++-
 7 files changed, 90 insertions(+), 44 deletions(-)

- Log -----------------------------------------------------------------
commit c1d9ee3afbaed6d17820868a02e5e9863420bfd3
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Tue Mar 8 12:24:48 2011 -0500

    Ticket->IsBookmarked

diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index dd21181..c4e5a13 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -3680,6 +3680,23 @@ sub ACLEquivalenceObjects {
 
 }
 
+=head2 IsBookmarked
+
+Checks whether the ticket is bookmarked by the CurrentUser.
+
+=cut
+
+sub IsBookmarked {
+    my $self = shift;
+
+    my $bookmarks = $self->CurrentUser->UserObj->FirstAttribute('Bookmarks');
+    return 0 if !$bookmarks;
+
+    $bookmarks = $bookmarks->Content;
+    return 0 if !$bookmarks;
+
+    return $bookmarks->{ $self->id } ? 1 : 0;
+}
 
 1;
 

commit 93ff22864bca07ad2aae6ccc87faf60c38d8b5a3
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Tue Mar 8 12:45:57 2011 -0500

    First pass at Ticket->ToggleBookmark

diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index c4e5a13..28a2611 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -3698,6 +3698,40 @@ sub IsBookmarked {
     return $bookmarks->{ $self->id } ? 1 : 0;
 }
 
+=head2 ToggleBookmark
+
+Toggles whether the ticket is bookmarked by the CurrentUser.
+
+=cut
+
+sub ToggleBookmark {
+    my $self = shift;
+    my $id   = $self->id;
+
+    my @ids = $id;
+
+    if ($self->id != $self->EffectiveId) {
+        push @ids, $ticket->Merged;
+    }
+
+    my $bookmarked;
+
+    if ( grep $bookmarks->{ $_ }, @ids ) {
+        delete $bookmarks->{ $_ } foreach @ids;
+        $bookmarked = 0;
+    } else {
+        $bookmarks->{ $id } = 1;
+        $bookmarked = 1;
+    }
+
+    $self->CurrentUser->UserObj->SetAttribute(
+        Name    => 'Bookmarks',
+        Content => $bookmarks,
+    );
+
+    return $bookmarked;
+}
+
 1;
 
 =head1 AUTHOR
diff --git a/share/html/Ticket/Elements/Bookmark b/share/html/Ticket/Elements/Bookmark
index 414d79b..665dbc5 100644
--- a/share/html/Ticket/Elements/Bookmark
+++ b/share/html/Ticket/Elements/Bookmark
@@ -46,35 +46,15 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 <%INIT>
-my $bookmarks = $session{'CurrentUser'}->UserObj->FirstAttribute('Bookmarks');
-$bookmarks = $bookmarks->Content if $bookmarks;
-$bookmarks ||= {};
+my $ticket = RT::Ticket->new( $session{'CurrentUser'} );
+$ticket->Load( $id );
 
-my $bookmarked = $bookmarks->{ $id }; # we still not sure if it's undef
-
-my @ids;
-if ( $Toggle || !$bookmarked ) {
-    my $ticket = RT::Ticket->new( $session{'CurrentUser'} );
-    $ticket->Load( $id );
-    return unless $id = $ticket->id;
-
-    @ids = ($id, $ticket->Merged);
+my $bookmarked;
+if ($Toggle) {
+    $bookmarked = $ticket->ToggleBookmark;
 }
-
-if ( $Toggle ) {
-    if ( grep $bookmarks->{ $_ }, @ids ) {
-        delete $bookmarks->{ $_ } foreach @ids;
-        $bookmarked = 0;
-    } else {
-        $bookmarks->{ $id } = 1;
-        $bookmarked = 1;
-    }
-    $session{'CurrentUser'}->UserObj->SetAttribute(
-        Name    => 'Bookmarks',
-        Content => $bookmarks,
-    );
-} elsif ( !$bookmarked ) {
-    $bookmarked = grep $bookmarks->{ $_ }, @ids;
+else {
+    $bookmarked = $ticket->IsBookmarked;
 }
 </%INIT>
 <%ARGS>

commit 45136c18819e95d8793c720bb887fa869527559c
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Tue Mar 8 12:50:21 2011 -0500

    Various tidyings

diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 28a2611..cc60390 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -3714,14 +3714,14 @@ sub ToggleBookmark {
         push @ids, $ticket->Merged;
     }
 
-    my $bookmarked;
+    my $is_bookmarked;
 
-    if ( grep $bookmarks->{ $_ }, @ids ) {
+    if ( grep { $bookmarks->{ $_ } } @ids ) {
         delete $bookmarks->{ $_ } foreach @ids;
-        $bookmarked = 0;
+        $is_bookmarked = 0;
     } else {
         $bookmarks->{ $id } = 1;
-        $bookmarked = 1;
+        $is_bookmarked = 1;
     }
 
     $self->CurrentUser->UserObj->SetAttribute(
@@ -3729,7 +3729,7 @@ sub ToggleBookmark {
         Content => $bookmarks,
     );
 
-    return $bookmarked;
+    return $is_bookmarked;
 }
 
 1;
diff --git a/share/html/Ticket/Elements/Bookmark b/share/html/Ticket/Elements/Bookmark
index 665dbc5..493f373 100644
--- a/share/html/Ticket/Elements/Bookmark
+++ b/share/html/Ticket/Elements/Bookmark
@@ -49,12 +49,12 @@
 my $ticket = RT::Ticket->new( $session{'CurrentUser'} );
 $ticket->Load( $id );
 
-my $bookmarked;
+my $is_bookmarked;
 if ($Toggle) {
-    $bookmarked = $ticket->ToggleBookmark;
+    $is_bookmarked = $ticket->ToggleBookmark;
 }
 else {
-    $bookmarked = $ticket->IsBookmarked;
+    $is_bookmarked = $ticket->IsBookmarked;
 }
 </%INIT>
 <%ARGS>
@@ -64,7 +64,7 @@ $Toggle => 0
 <span class="toggle-bookmark-<% $id %>">
 % my $url = RT->Config->Get('WebPath') ."/Helpers/Toggle/TicketBookmark?id=". $id;
 <a align="right" href="<% $url %>" onclick="jQuery('.toggle-bookmark-<% $id |n%>').load('<% $url |n %>'); return false;" >
-% if ( $bookmarked ) {
+% if ( $is_bookmarked ) {
 <img src="<% RT->Config->Get('WebPath') %>/NoAuth/images/star.gif" alt="<% loc('Remove Bookmark') %>" style="border-style: none" />
 % } else {
 <img src="<% RT->Config->Get('WebPath') %>/NoAuth/images/empty_star.gif" alt="<% loc('Add Bookmark') %>" style="border-style: none" />

commit bb4923b4321666a6cc396db103f11a767143cce7
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Tue Mar 8 12:57:05 2011 -0500

    Make IsBookmarked on a merged ticket work again

diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index cc60390..1b1ce5d 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -3688,14 +3688,18 @@ Checks whether the ticket is bookmarked by the CurrentUser.
 
 sub IsBookmarked {
     my $self = shift;
+    my $id = $self->id;
 
-    my $bookmarks = $self->CurrentUser->UserObj->FirstAttribute('Bookmarks');
-    return 0 if !$bookmarks;
+    my @ids = $id;
+    if ($id != $self->EffectiveId) {
+        push @ids, $self->Merged;
+    }
 
-    $bookmarks = $bookmarks->Content;
-    return 0 if !$bookmarks;
+    my $bookmarks = $self->CurrentUser->UserObj->FirstAttribute('Bookmarks');
+    $bookmarks = $bookmarks ? $bookmarks->Content : {};
 
-    return $bookmarks->{ $self->id } ? 1 : 0;
+    my @bookmarked = grep { $bookmarks->{ $_ } } @ids;
+    return @bookmarked ? 1 : 0;
 }
 
 =head2 ToggleBookmark

commit b5f0c48a321bfb48d50f1768bf1494638f15f088
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Tue Mar 8 12:57:19 2011 -0500

    Pull out $bookmarks, reuse $id

diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 1b1ce5d..715b1c8 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -3713,11 +3713,13 @@ sub ToggleBookmark {
     my $id   = $self->id;
 
     my @ids = $id;
-
-    if ($self->id != $self->EffectiveId) {
-        push @ids, $ticket->Merged;
+    if ($id != $self->EffectiveId) {
+        push @ids, $self->Merged;
     }
 
+    my $bookmarks = $self->CurrentUser->UserObj->FirstAttribute('Bookmarks');
+    $bookmarks = $bookmarks ? $bookmarks->Content : {};
+
     my $is_bookmarked;
 
     if ( grep { $bookmarks->{ $_ } } @ids ) {

commit 2205ca5ae8213b30b1ff422f264f6b741f89eb45
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Tue Mar 8 14:27:25 2011 -0500

    Just always push on the Merged list

diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 715b1c8..b1689ff 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -3690,10 +3690,8 @@ sub IsBookmarked {
     my $self = shift;
     my $id = $self->id;
 
-    my @ids = $id;
-    if ($id != $self->EffectiveId) {
-        push @ids, $self->Merged;
-    }
+    # maintain bookmarks across merges
+    my @ids = ($id, $self->Merged);
 
     my $bookmarks = $self->CurrentUser->UserObj->FirstAttribute('Bookmarks');
     $bookmarks = $bookmarks ? $bookmarks->Content : {};
@@ -3712,10 +3710,8 @@ sub ToggleBookmark {
     my $self = shift;
     my $id   = $self->id;
 
-    my @ids = $id;
-    if ($id != $self->EffectiveId) {
-        push @ids, $self->Merged;
-    }
+    # maintain bookmarks across merges
+    my @ids = ($id, $self->Merged);
 
     my $bookmarks = $self->CurrentUser->UserObj->FirstAttribute('Bookmarks');
     $bookmarks = $bookmarks ? $bookmarks->Content : {};

commit d4e458bfd7ca89496b34eabe73543e7a36217678
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Tue Mar 8 15:02:08 2011 -0500

    Don't frob Bookmarks config directly in a test

diff --git a/t/web/mobile.t b/t/web/mobile.t
index 7cf9aee..e00af5a 100644
--- a/t/web/mobile.t
+++ b/t/web/mobile.t
@@ -179,7 +179,10 @@ ok( $m->find_link( text_regex => qr/ticket2/ ), 'has ticket2 link' );
 $m->back;
 
 diag "test bookmarked tickets link";
-$root->SetAttribute( Name => 'Bookmarks', Content => { 11 => 1 } );
+my $ticket = RT::Ticket->new(RT::CurrentUser->new('root'));
+$ticket->Load(11);
+$ticket->ToggleBookmark;
+
 $m->follow_link_ok( { text => 'Bookmarked tickets' } );
 $m->content_contains( 'Found 1 ticket', 'found 1 ticket' );
 ok( $m->find_link( text_regex => qr/ticket1/ ), 'has ticket1 link' );

commit f5db1916c99d145fd70a16dc0d3f849a0d3972a2
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Tue Mar 8 15:10:08 2011 -0500

    Refactor ->Bookmarks into RT::User

diff --git a/lib/RT/Tickets.pm b/lib/RT/Tickets.pm
index 99b43a8..3b01bdd 100644
--- a/lib/RT/Tickets.pm
+++ b/lib/RT/Tickets.pm
@@ -296,12 +296,7 @@ sub _BookmarkLimit {
     die "Invalid operator $op for __Bookmarked__ search on $field"
         unless $op =~ /^(=|!=)$/;
 
-    my @bookmarks = do {
-        my $tmp = $sb->CurrentUser->UserObj->FirstAttribute('Bookmarks');
-        $tmp = $tmp->Content if $tmp;
-        $tmp ||= {};
-        grep $_, keys %$tmp;
-    };
+    my @bookmarks = $sb->CurrentUser->UserObj->Bookmarks;
 
     return $sb->_SQLLimit(
         FIELD    => $field,
diff --git a/lib/RT/User.pm b/lib/RT/User.pm
index 205a920..dcedada 100644
--- a/lib/RT/User.pm
+++ b/lib/RT/User.pm
@@ -1591,6 +1591,23 @@ sub BasicColumns {
     );
 }
 
+=head2 Bookmarks
+
+Returns an unordered list of IDs representing the user's bookmarked tickets.
+
+=cut
+
+sub Bookmarks {
+    my $self = shift;
+    my $bookmarks = $self->FirstAttribute('Bookmarks');
+    return if !$bookmarks;
+
+    $bookmarks = $bookmarks->Content;
+    return if !$bookmarks;
+
+    return keys %$bookmarks;
+}
+
 =head2 Create PARAMHASH
 
 Create takes a hash of values and creates a row in the database:

commit f2aa0a1d86839d72d74ac0d2ca7de07f52a65ea5
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Tue Mar 8 15:12:36 2011 -0500

    Use User->Bookmarks in ShowSearch and m/tickets/search

diff --git a/share/html/Elements/ShowSearch b/share/html/Elements/ShowSearch
index d019081..9d8dcf3 100644
--- a/share/html/Elements/ShowSearch
+++ b/share/html/Elements/ShowSearch
@@ -132,10 +132,8 @@ foreach ( $SearchArg, $ProcessedSearchArg ) {
         $_->{'Rows'} = 999;
 
         # DEPRECATED: will be here for a while up to 3.10/4.0
-        my $bookmarks = $session{'CurrentUser'}->UserObj->FirstAttribute('Bookmarks');
-        $bookmarks = $bookmarks->Content if $bookmarks;
-        $bookmarks ||= {};
-        my $query = join(" OR ", map " id = '$_' ", grep $bookmarks->{ $_ }, keys %$bookmarks ) || 'id=0';
+        my @bookmarks = $session{'CurrentUser'}->UserObj->Bookmarks;
+        my $query = join(" OR ", map " id = '$_' ", @bookmarks ) || 'id=0';
         $_->{'Query'} =~ s/__Bookmarks__/( $query )/g;
     }
 }
diff --git a/share/html/m/tickets/search b/share/html/m/tickets/search
index a82763a..d4d1876 100644
--- a/share/html/m/tickets/search
+++ b/share/html/m/tickets/search
@@ -91,10 +91,8 @@ my $search;
             $_->{'Rows'} = 999;
 
             # DEPRECATED: will be here for a while up to 3.10/4.0
-            my $bookmarks = $session{'CurrentUser'}->UserObj->FirstAttribute('Bookmarks');
-            $bookmarks = $bookmarks->Content if $bookmarks;
-            $bookmarks ||= {};
-            my $query = join( " OR ", map " id = '$_' ", grep $bookmarks->{$_}, keys %$bookmarks ) || 'id=0';
+            my @bookmarks = $session{'CurrentUser'}->UserObj->Bookmarks;
+            my $query = join(" OR ", map " id = '$_' ", @bookmarks ) || 'id=0';
             $_->{'Query'} =~ s/__Bookmarks__/( $query )/g;
         }
     }

commit 3cd39ce62de0460a8153aaff6fec1d9bb362d0ec
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Tue Mar 8 15:28:24 2011 -0500

    Move Ticket->IsBookmarked and ->ToggleBookmark to RT::User

diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index b1689ff..3e869c6 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -3680,60 +3680,6 @@ sub ACLEquivalenceObjects {
 
 }
 
-=head2 IsBookmarked
-
-Checks whether the ticket is bookmarked by the CurrentUser.
-
-=cut
-
-sub IsBookmarked {
-    my $self = shift;
-    my $id = $self->id;
-
-    # maintain bookmarks across merges
-    my @ids = ($id, $self->Merged);
-
-    my $bookmarks = $self->CurrentUser->UserObj->FirstAttribute('Bookmarks');
-    $bookmarks = $bookmarks ? $bookmarks->Content : {};
-
-    my @bookmarked = grep { $bookmarks->{ $_ } } @ids;
-    return @bookmarked ? 1 : 0;
-}
-
-=head2 ToggleBookmark
-
-Toggles whether the ticket is bookmarked by the CurrentUser.
-
-=cut
-
-sub ToggleBookmark {
-    my $self = shift;
-    my $id   = $self->id;
-
-    # maintain bookmarks across merges
-    my @ids = ($id, $self->Merged);
-
-    my $bookmarks = $self->CurrentUser->UserObj->FirstAttribute('Bookmarks');
-    $bookmarks = $bookmarks ? $bookmarks->Content : {};
-
-    my $is_bookmarked;
-
-    if ( grep { $bookmarks->{ $_ } } @ids ) {
-        delete $bookmarks->{ $_ } foreach @ids;
-        $is_bookmarked = 0;
-    } else {
-        $bookmarks->{ $id } = 1;
-        $is_bookmarked = 1;
-    }
-
-    $self->CurrentUser->UserObj->SetAttribute(
-        Name    => 'Bookmarks',
-        Content => $bookmarks,
-    );
-
-    return $is_bookmarked;
-}
-
 1;
 
 =head1 AUTHOR
diff --git a/lib/RT/User.pm b/lib/RT/User.pm
index dcedada..1570afd 100644
--- a/lib/RT/User.pm
+++ b/lib/RT/User.pm
@@ -1608,6 +1608,62 @@ sub Bookmarks {
     return keys %$bookmarks;
 }
 
+=head2 HasBookmark TICKET
+
+Returns whether the provided ticket is bookmarked by the user.
+
+=cut
+
+sub HasBookmark {
+    my $self   = shift;
+    my $ticket = shift;
+    my $id     = $ticket->id;
+
+    # maintain bookmarks across merges
+    my @ids = ($id, $ticket->Merged);
+
+    my $bookmarks = $self->FirstAttribute('Bookmarks');
+    $bookmarks = $bookmarks ? $bookmarks->Content : {};
+
+    my @bookmarked = grep { $bookmarks->{ $_ } } $self->Bookmarks;
+    return @bookmarked ? 1 : 0;
+}
+
+=head2 ToggleBookmark TICKET
+
+Toggles whether the provided ticket is bookmarked by the user.
+
+=cut
+
+sub ToggleBookmark {
+    my $self   = shift;
+    my $ticket = shift;
+    my $id     = $ticket->id;
+
+    # maintain bookmarks across merges
+    my @ids = ($id, $ticket->Merged);
+
+    my $bookmarks = $self->FirstAttribute('Bookmarks');
+    $bookmarks = $bookmarks ? $bookmarks->Content : {};
+
+    my $is_bookmarked;
+
+    if ( grep { $bookmarks->{ $_ } } @ids ) {
+        delete $bookmarks->{ $_ } foreach @ids;
+        $is_bookmarked = 0;
+    } else {
+        $bookmarks->{ $id } = 1;
+        $is_bookmarked = 1;
+    }
+
+    $self->SetAttribute(
+        Name    => 'Bookmarks',
+        Content => $bookmarks,
+    );
+
+    return $is_bookmarked;
+}
+
 =head2 Create PARAMHASH
 
 Create takes a hash of values and creates a row in the database:
diff --git a/share/html/Ticket/Elements/Bookmark b/share/html/Ticket/Elements/Bookmark
index 493f373..d2828c3 100644
--- a/share/html/Ticket/Elements/Bookmark
+++ b/share/html/Ticket/Elements/Bookmark
@@ -51,10 +51,10 @@ $ticket->Load( $id );
 
 my $is_bookmarked;
 if ($Toggle) {
-    $is_bookmarked = $ticket->ToggleBookmark;
+    $is_bookmarked = $session{'CurrentUser'}->UserObj->ToggleBookmark($ticket);
 }
 else {
-    $is_bookmarked = $ticket->IsBookmarked;
+    $is_bookmarked = $session{'CurrentUser'}->UserObj->HasBookmark($ticket);
 }
 </%INIT>
 <%ARGS>
diff --git a/t/web/mobile.t b/t/web/mobile.t
index e00af5a..637abd9 100644
--- a/t/web/mobile.t
+++ b/t/web/mobile.t
@@ -181,7 +181,7 @@ $m->back;
 diag "test bookmarked tickets link";
 my $ticket = RT::Ticket->new(RT::CurrentUser->new('root'));
 $ticket->Load(11);
-$ticket->ToggleBookmark;
+$root->ToggleBookmark($ticket);
 
 $m->follow_link_ok( { text => 'Bookmarked tickets' } );
 $m->content_contains( 'Found 1 ticket', 'found 1 ticket' );

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


More information about the Rt-commit mailing list