[Rt-commit] rt branch, 3.9-trunk, updated. rt-3.9.4-505-gf3d065e

Shawn Moore sartak at bestpractical.com
Wed Nov 17 17:43:17 EST 2010


The branch, 3.9-trunk has been updated
       via  f3d065e41fac655e9f0ad948aace04fdd1406665 (commit)
       via  64f5f03a51a326ebf337917e4595abe521cb3561 (commit)
       via  ac5e49237dcd3303a5f062e60742019b59b37a0e (commit)
       via  fff54d9814df655d2be41fd07f698d3037d8fcab (commit)
       via  a89d1bda2b6c7f3f07ecb6e945deb2324822da74 (commit)
       via  1ece9c5bcc0f94d188c13b0e8d7a6e3b02f57f95 (commit)
       via  a6c39c17dfea928476fde317cea467eb7b7fd0d2 (commit)
      from  334d4a2c4dcc5f02784b009a7cfef9753aa9209a (commit)

Summary of changes:
 lib/RT/Dashboard.pm                                |   21 +++++
 lib/RT/{ACL.pm => Dashboards.pm}                   |   61 ++++++++-------
 lib/RT/SavedSearches.pm                            |   81 +------------------
 lib/RT/{SavedSearches.pm => SharedSettings.pm}     |   52 ++-----------
 share/html/Dashboards/Subscription.html            |   27 ++-----
 share/html/Elements/Dashboards                     |   37 ++++++---
 .../{RT__Template => RT__Dashboard}/ColumnMap      |   31 +++-----
 7 files changed, 113 insertions(+), 197 deletions(-)
 copy lib/RT/{ACL.pm => Dashboards.pm} (65%)
 mode change 100755 => 100644
 copy lib/RT/{SavedSearches.pm => SharedSettings.pm} (67%)
 copy share/html/Elements/{RT__Template => RT__Dashboard}/ColumnMap (81%)

- Log -----------------------------------------------------------------
commit a6c39c17dfea928476fde317cea467eb7b7fd0d2
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Wed Nov 17 16:14:53 2010 -0500

    Fix our SavedSearches synopsis..

diff --git a/lib/RT/SavedSearches.pm b/lib/RT/SavedSearches.pm
index d73ac72..11a48ae 100644
--- a/lib/RT/SavedSearches.pm
+++ b/lib/RT/SavedSearches.pm
@@ -52,7 +52,7 @@
 
 =head1 SYNOPSIS
 
-  use RT::SavedSearch
+  use RT::SavedSearches
 
 =head1 DESCRIPTION
 

commit 1ece9c5bcc0f94d188c13b0e8d7a6e3b02f57f95
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Wed Nov 17 16:28:05 2010 -0500

    Refactor most of RT::SavedSearches into a new RT::SharedSettings

diff --git a/lib/RT/SavedSearches.pm b/lib/RT/SavedSearches.pm
index 11a48ae..9c34403 100644
--- a/lib/RT/SavedSearches.pm
+++ b/lib/RT/SavedSearches.pm
@@ -70,17 +70,10 @@ package RT::SavedSearches;
 use RT::SavedSearch;
 
 use strict;
-use base 'RT::Base';
-
-sub new  {
-    my $proto = shift;
-    my $class = ref($proto) || $proto;
-    my $self  = {};
-    bless ($self, $class);
-    $self->CurrentUser(@_);
-    $self->{'idx'} = 0;
-    $self->{'objects'} = [];
-    return $self;
+use base 'RT::SharedSettings';
+
+sub RecordClass {
+    return 'RT::SavedSearch';
 }
 
 =head2 LimitToPrivacy
@@ -115,72 +108,8 @@ sub LimitToPrivacy {
     }
 }
 
-### Accessor methods
-
-=head2 Next
-
-Returns the next object in the collection.
-
-=cut
-
-sub Next {
-    my $self = shift;
-    my $search = $self->{'objects'}->[$self->{'idx'}];
-    if ($search) {
-        $self->{'idx'}++;
-    } else {
-        # We have run out of objects; reset the counter.
-        $self->{'idx'} = 0;
-    }
-    return $search;
-}
-
-=head2 Count
-
-Returns the number of search objects found.
-
-=cut
-
-sub Count {
-    my $self = shift;
-    return scalar @{$self->{'objects'}};
-}
-
-=head2 CountAll
-
-Returns the number of search objects found
-
-=cut
-
-sub CountAll {
-    my $self = shift;
-    return $self->Count;
-}
-
-=head2 GotoPage
-
-Act more like a normal L<DBIx::SearchBuilder> collection.
-Moves the internal index around
-
-=cut
-
-sub GotoPage {
-    my $self = shift;
-    $self->{idx} = shift;
-}
-
 ### Internal methods
 
-# _GetObject: helper routine to load the correct object whose parameters
-#  have been passed.
-
-sub _GetObject {
-    my $self = shift;
-    my $privacy = shift;
-
-    return RT::SavedSearch->new($self->CurrentUser)->_GetObject($privacy);
-}
-
 sub _PrivacyObjects {
     my $self = shift;
     Carp::carp("RT::SavedSearches->_PrivacyObjects is deprecated. Please use RT::SavedSearch->_PrivacyObjects");
diff --git a/lib/RT/SavedSearches.pm b/lib/RT/SharedSettings.pm
similarity index 67%
copy from lib/RT/SavedSearches.pm
copy to lib/RT/SharedSettings.pm
index 11a48ae..ec68d02 100644
--- a/lib/RT/SavedSearches.pm
+++ b/lib/RT/SharedSettings.pm
@@ -48,15 +48,15 @@
 
 =head1 NAME
 
-  RT::SavedSearches - a pseudo-collection for SavedSearch objects.
+  RT::SharedSettings - a pseudo-collection for SharedSetting objects.
 
 =head1 SYNOPSIS
 
-  use RT::SavedSearches
+  use RT::SharedSettings
 
 =head1 DESCRIPTION
 
-  SavedSearches is an object consisting of a number of SavedSearch objects.
+  SharedSettings is an object consisting of a number of SharedSetting objects.
   It works more or less like a DBIx::SearchBuilder collection, although it
   is not.
 
@@ -65,9 +65,9 @@
 
 =cut
 
-package RT::SavedSearches;
+package RT::SharedSettings;
 
-use RT::SavedSearch;
+use RT::SharedSetting;
 
 use strict;
 use base 'RT::Base';
@@ -83,38 +83,6 @@ sub new  {
     return $self;
 }
 
-=head2 LimitToPrivacy
-
-Takes two argumets: a privacy string, of the format "<class>-<id>", as
-produced by RT::SavedSearch::Privacy(); and a type string, as produced
-by RT::SavedSearch::Type().  The SavedSearches object will load the
-searches belonging to that user or group that are of the type
-specified.  If no type is specified, all the searches belonging to the
-user/group will be loaded.  Repeated calls to the same object should DTRT.
-
-=cut
-
-sub LimitToPrivacy {
-    my $self = shift;
-    my $privacy = shift;
-    my $type = shift;
-
-    my $object = $self->_GetObject($privacy);
-
-    if ($object) {
-        $self->{'objects'} = [];
-        my @search_atts = $object->Attributes->Named('SavedSearch');
-        foreach my $att (@search_atts) {
-            my $search = RT::SavedSearch->new($self->CurrentUser);
-            $search->Load($privacy, $att->Id);
-            next if $type && $search->Type && $search->Type ne $type;
-            push(@{$self->{'objects'}}, $search);
-        }
-    } else {
-        $RT::Logger->error("Could not load object $privacy");
-    }
-}
-
 ### Accessor methods
 
 =head2 Next
@@ -178,16 +146,10 @@ sub _GetObject {
     my $self = shift;
     my $privacy = shift;
 
-    return RT::SavedSearch->new($self->CurrentUser)->_GetObject($privacy);
-}
-
-sub _PrivacyObjects {
-    my $self = shift;
-    Carp::carp("RT::SavedSearches->_PrivacyObjects is deprecated. Please use RT::SavedSearch->_PrivacyObjects");
-    my $search = RT::SavedSearch->new($self->CurrentUser);
-    return $search->_PrivacyObjects(@_);
+    return $self->RecordClass->new($self->CurrentUser)->_GetObject($privacy);
 }
 
 RT::Base->_ImportOverlays();
 
 1;
+

commit a89d1bda2b6c7f3f07ecb6e945deb2324822da74
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Wed Nov 17 16:28:20 2010 -0500

    Create an RT::Dashboards pseudo-collection using RT::SharedSettings

diff --git a/lib/RT/Dashboards.pm b/lib/RT/Dashboards.pm
new file mode 100644
index 0000000..0360467
--- /dev/null
+++ b/lib/RT/Dashboards.pm
@@ -0,0 +1,109 @@
+# BEGIN BPS TAGGED BLOCK {{{
+#
+# COPYRIGHT:
+#
+# This software is Copyright (c) 1996-2010 Best Practical Solutions, LLC
+#                                          <jesse 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 }}}
+
+=head1 NAME
+
+  RT::Dashboards - a pseudo-collection for Dashboard objects.
+
+=head1 SYNOPSIS
+
+  use RT::Dashboards
+
+=head1 DESCRIPTION
+
+  Dashboards is an object consisting of a number of Dashboard objects.
+  It works more or less like a DBIx::SearchBuilder collection, although it
+  is not.
+
+=head1 METHODS
+
+
+=cut
+
+package RT::Dashboards;
+
+use RT::Dashboard;
+
+use strict;
+use base 'RT::SharedSettings';
+
+sub RecordClass {
+    return 'RT::Dashboard';
+}
+
+=head2 LimitToPrivacy
+
+Takes one argument: a privacy string, of the format "<class>-<id>", as produced
+by RT::Dashboard::Privacy(). The Dashboards object will load the dashboards
+belonging to that user or group. Repeated calls to the same object should DTRT.
+
+=cut
+
+sub LimitToPrivacy {
+    my $self = shift;
+    my $privacy = shift;
+
+    my $object = $self->_GetObject($privacy);
+
+    if ($object) {
+        $self->{'objects'} = [];
+        my @dashboard_atts = $object->Attributes->Named('Dashboard');
+        foreach my $att (@dashboard_atts) {
+            my $dashboard = RT::Dashboard->new($self->CurrentUser);
+            $dashboard->Load($privacy, $att->Id);
+            push(@{$self->{'objects'}}, $dashboard);
+        }
+    } else {
+        $RT::Logger->error("Could not load object $privacy");
+    }
+}
+
+
+RT::Base->_ImportOverlays();
+
+1;

commit fff54d9814df655d2be41fd07f698d3037d8fcab
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Wed Nov 17 16:36:22 2010 -0500

    Factor out loading a Dashboard's subscription into a method

diff --git a/lib/RT/Dashboard.pm b/lib/RT/Dashboard.pm
index 622e137..6c5a7c6 100644
--- a/lib/RT/Dashboard.pm
+++ b/lib/RT/Dashboard.pm
@@ -343,6 +343,27 @@ sub CurrentUserCanSubscribe {
     $self->_CurrentUserCan($privacy, FullRight => 'SubscribeDashboard');
 }
 
+=head2 Subscription
+
+Returns the L<RT::Attribute> representing the current user's subscription
+to this dashboard if there is one; otherwise, returns C<undef>.
+
+=cut
+
+sub Subscription {
+    my $self = shift;
+
+    # no subscription to unloaded dashboards
+    return unless $self->id;
+
+    for my $sub ($self->CurrentUser->UserObj->Attributes->Named('Subscription')) {
+        return $sub if $sub->SubValue('DashboardId') == $self->id;
+    }
+
+    return;
+}
+
+
 RT::Base->_ImportOverlays();
 
 1;
diff --git a/share/html/Dashboards/Subscription.html b/share/html/Dashboards/Subscription.html
index cc90ac7..c835ab8 100644
--- a/share/html/Dashboards/Subscription.html
+++ b/share/html/Dashboards/Subscription.html
@@ -171,7 +171,7 @@
 </tr>
 </table>
 
-% if ($SubscriptionObj->Id) {
+% if ($SubscriptionObj) {
     <& /Elements/Submit, Name => "Save", Label => loc('Save Changes') &>
 % } else {
     <& /Elements/Submit, Name => "Save", Label => loc('Subscribe') &>
@@ -187,23 +187,13 @@ my $timezone = $session{'CurrentUser'}->UserObj->Timezone || RT->Config->Get('Ti
 
 use RT::Dashboard;
 my $DashboardObj = RT::Dashboard->new($session{'CurrentUser'});
-
-my $SubscriptionObj = RT::Attribute->new($session{'CurrentUser'});
-
-# first let's see if we already have a subscription to this DashboardId
-for my $sub ($session{'CurrentUser'}->UserObj->Attributes->Named('Subscription')) {
-    next unless $sub->SubValue('DashboardId') == $id;
-    $SubscriptionObj = $sub;
-    last;
-}
-
-$id = $SubscriptionObj->Id
-             ? $SubscriptionObj->SubValue('DashboardId')
-             : $ARGS{'id'};
-
 ($val, $msg) = $DashboardObj->LoadById($id);
 $val || Abort(loc("Couldn't load dashboard [_1]: [_2].", $id, $msg));
 
+my $SubscriptionObj = $DashboardObj->Subscription;
+
+$id = $SubscriptionObj ? $SubscriptionObj->SubValue('DashboardId') : $ARGS{'id'};
+
 my %fields = (
     DashboardId => $id,
     Frequency   => 'daily',
@@ -217,7 +207,7 @@ my %fields = (
 );
 
 # update any fields with the values from the subscription object
-if ($SubscriptionObj->Id) {
+if ($SubscriptionObj) {
     for my $field (keys %fields) {
         $fields{$field} = $SubscriptionObj->SubValue($field);
     }
@@ -232,7 +222,7 @@ for my $field (keys %fields) {
 # this'll be defined on submit
 if (defined $ARGS{Save}) {
     # update
-    if ($SubscriptionObj->Id) {
+    if ($SubscriptionObj) {
         $id = delete $fields{'DashboardId'}; # immutable
         ($val, $msg) = $SubscriptionObj->SetSubValues(%fields);
         $fields{'DashboardId'} = $id;
@@ -249,6 +239,7 @@ if (defined $ARGS{Save}) {
         Abort(loc("Unable to subscribe to dashboard [_1]: Permission denied", $id))
             unless $DashboardObj->CurrentUserCanSubscribe;
 
+        $SubscriptionObj = RT::Attribute->new($session{CurrentUser});
         my ($val, $msg) = $SubscriptionObj->Create(
             Name        => 'Subscription',
             Description => 'Subscription to dashboard ' . $id,
@@ -267,7 +258,7 @@ if (defined $ARGS{Save}) {
     }
 }
 
-if ($SubscriptionObj->Id) {
+if ($SubscriptionObj) {
     $title = loc("Modify the subscription to dashboard [_1]", $DashboardObj->Name);
 }
 else {

commit ac5e49237dcd3303a5f062e60742019b59b37a0e
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Wed Nov 17 16:40:29 2010 -0500

    Convert Elements/Dashboards to using CollectionList

diff --git a/share/html/Elements/Dashboards b/share/html/Elements/Dashboards
index de653da..a23134a 100644
--- a/share/html/Elements/Dashboards
+++ b/share/html/Elements/Dashboards
@@ -45,18 +45,26 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<div class="dashboards">
-<& /Dashboards/Elements/ShowDashboards,
-    Dashboards => \@dashboards,
-    Verbose => 0,
-    Title => loc("Dashboards"),
-    title_href => RT->Config->Get('WebPath').'/Dashboards/index.html',
-    bodyclass => "",
-    titleright => loc("Edit"),
-    titleright_href => RT->Config->Get('WebPath').'/Dashboards/',
+<&|/Widgets/TitleBox, title => loc('Dashboards') &>
+% foreach my $Object (@Objects) {
+%   my $Dashboards = RT::Dashboards->new($session{CurrentUser});
+%   $Dashboards->LimitToPrivacy(join('-',ref($Object),$Object->Id));
+%   my $title;
+%   if (ref $Object eq 'RT::User' && $Object->Id == $session{CurrentUser}->Id) {
+%       $title = loc("My dashboards");
+%   } else {
+%       $title = loc("[_1]'s dashboards",$Object->Name);
+%   }
+%   $title = $m->interp->apply_escapes($title, 'h');
+<& /Elements/CollectionList,
+    %ARGS,
+    Format => qq{'<a href="__WebPath__/Dashboards/__id__/__Name__">__Name__</a>/TITLE:$title'},
+    Collection => $Dashboards,
 &>
-</div>
-<%INIT>
-my @dashboards = $m->comp("/Dashboards/Elements/ListOfDashboards");
-</%INIT>
+% }
+</&>
+<%init>
+use RT::Dashboards;
 
+my @Objects = RT::Dashboard->new($session{CurrentUser})->ObjectsForLoading;
+</%init>

commit 64f5f03a51a326ebf337917e4595abe521cb3561
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Wed Nov 17 16:41:56 2010 -0500

    Add the Edit link for dashboards back in

diff --git a/share/html/Elements/Dashboards b/share/html/Elements/Dashboards
index a23134a..d96805e 100644
--- a/share/html/Elements/Dashboards
+++ b/share/html/Elements/Dashboards
@@ -45,7 +45,12 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<&|/Widgets/TitleBox, title => loc('Dashboards') &>
+<&|/Widgets/TitleBox,
+    title => loc('Dashboards'),
+    titleright => loc("Edit"),
+    titleright_href => RT->Config->Get('WebPath').'/Dashboards/index.html',
+&>
+
 % foreach my $Object (@Objects) {
 %   my $Dashboards = RT::Dashboards->new($session{CurrentUser});
 %   $Dashboards->LimitToPrivacy(join('-',ref($Object),$Object->Id));

commit f3d065e41fac655e9f0ad948aace04fdd1406665
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Wed Nov 17 17:42:04 2010 -0500

    Add a ColumnMap for Dashboards and use its ShowURL

diff --git a/share/html/Elements/Dashboards b/share/html/Elements/Dashboards
index d96805e..f5b435f 100644
--- a/share/html/Elements/Dashboards
+++ b/share/html/Elements/Dashboards
@@ -63,7 +63,7 @@
 %   $title = $m->interp->apply_escapes($title, 'h');
 <& /Elements/CollectionList,
     %ARGS,
-    Format => qq{'<a href="__WebPath__/Dashboards/__id__/__Name__">__Name__</a>/TITLE:$title'},
+    Format => qq{'<a href="__WebPath__/__ShowURL__">__Name__</a>/TITLE:$title'},
     Collection => $Dashboards,
 &>
 % }
diff --git a/share/html/Elements/Dashboards b/share/html/Elements/RT__Dashboard/ColumnMap
similarity index 69%
copy from share/html/Elements/Dashboards
copy to share/html/Elements/RT__Dashboard/ColumnMap
index d96805e..15a9461 100644
--- a/share/html/Elements/Dashboards
+++ b/share/html/Elements/RT__Dashboard/ColumnMap
@@ -45,31 +45,38 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<&|/Widgets/TitleBox,
-    title => loc('Dashboards'),
-    titleright => loc("Edit"),
-    titleright_href => RT->Config->Get('WebPath').'/Dashboards/index.html',
-&>
+<%ARGS>
+$Name
+$Attr => undef
+</%ARGS>
+<%ONCE>
+my $COLUMN_MAP = {
+    id => {
+        title     => '#', # loc
+        attribute => 'id',
+        align     => 'right',
+        value     => sub { return $_[0]->Id },
+    },
+    Name => {
+        title     => sub { return "foo" }, #'Name', # loc
+        attribute => 'Name',
+        value     => sub { return $_[0]->Name()||loc("Unnamed dashboard") },
+    },
+    ShowURL => {
+        title     => '',
+        attribute => 'ShowURL',
+        value     => sub {
+            my $dashboard = shift;
+            my $id = $dashboard->Id;
+            my $name = $dashboard->Name;
 
-% foreach my $Object (@Objects) {
-%   my $Dashboards = RT::Dashboards->new($session{CurrentUser});
-%   $Dashboards->LimitToPrivacy(join('-',ref($Object),$Object->Id));
-%   my $title;
-%   if (ref $Object eq 'RT::User' && $Object->Id == $session{CurrentUser}->Id) {
-%       $title = loc("My dashboards");
-%   } else {
-%       $title = loc("[_1]'s dashboards",$Object->Name);
-%   }
-%   $title = $m->interp->apply_escapes($title, 'h');
-<& /Elements/CollectionList,
-    %ARGS,
-    Format => qq{'<a href="__WebPath__/Dashboards/__id__/__Name__">__Name__</a>/TITLE:$title'},
-    Collection => $Dashboards,
-&>
-% }
-</&>
-<%init>
-use RT::Dashboards;
+            return "Dashboards/$id/$name";
+        },
+    }
+};
 
-my @Objects = RT::Dashboard->new($session{CurrentUser})->ObjectsForLoading;
-</%init>
+</%ONCE>
+<%INIT>
+$m->callback( COLUMN_MAP => $COLUMN_MAP, CallbackName => 'ColumnMap', CallbackOnce => 1 );
+return GetColumnMapEntry( Map => $COLUMN_MAP, Name => $Name, Attribute => $Attr );
+</%INIT>

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


More information about the Rt-commit mailing list