[Rt-commit] rt branch, 4.2/bookmarks-in-lib, updated. rt-4.0.0rc6-165-g3cd39ce
Shawn Moore
sartak at bestpractical.com
Tue Mar 8 15:28:39 EST 2011
The branch, 4.2/bookmarks-in-lib has been updated
via 3cd39ce62de0460a8153aaff6fec1d9bb362d0ec (commit)
from f2aa0a1d86839d72d74ac0d2ca7de07f52a65ea5 (commit)
Summary of changes:
lib/RT/Ticket.pm | 54 ---------------------------------
lib/RT/User.pm | 56 +++++++++++++++++++++++++++++++++++
share/html/Ticket/Elements/Bookmark | 4 +-
t/web/mobile.t | 2 +-
4 files changed, 59 insertions(+), 57 deletions(-)
- Log -----------------------------------------------------------------
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