[Rt-commit] rt branch, 3.9-trunk, updated. rt-3.8.8-131-g192bfd1

Shawn Moore sartak at bestpractical.com
Thu Jul 8 22:32:59 EDT 2010


The branch, 3.9-trunk has been updated
       via  192bfd1eb90e68eaaf897c83236c48d4f7341507 (commit)
      from  fca2797a2b6ab91e28f877730452039f248d2b88 (commit)

Summary of changes:
 lib/RT/Dashboard.pm                                |   32 +++--------------
 lib/RT/SavedSearch.pm                              |    4 ++-
 lib/RT/SharedSetting.pm                            |   36 ++++++++++++++++++++
 .../html/Dashboards/Elements/DashboardsForObjects  |    4 +--
 share/html/Dashboards/Elements/ListOfDashboards    |    2 +-
 share/html/Dashboards/Elements/Tabs                |    2 +-
 share/html/Dashboards/Modify.html                  |    3 +-
 share/html/Tools/Elements/Tabs                     |    6 ++--
 share/html/Tools/index.html                        |    6 ++--
 9 files changed, 56 insertions(+), 39 deletions(-)

- Log -----------------------------------------------------------------
commit 192bfd1eb90e68eaaf897c83236c48d4f7341507
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Thu Jul 8 22:34:16 2010 -0400

    Refactor Dashboard->_PrivacyObjects into more useful methods

diff --git a/lib/RT/Dashboard.pm b/lib/RT/Dashboard.pm
index c0531c4..d33d69c 100644
--- a/lib/RT/Dashboard.pm
+++ b/lib/RT/Dashboard.pm
@@ -230,44 +230,24 @@ sub PossibleHiddenSearches {
 }
 
 # _PrivacyObjects: returns a list of objects that can be used to load
-# dashboards from. If the Modify parameter is true, then check modify rights.
-# If the Create parameter is true, then check create rights. Otherwise, check
-# read rights.
+# dashboards from. You probably want to use the wrapper methods like
+# ObjectsForLoading, ObjectsForCreating, etc.
 
 sub _PrivacyObjects {
     my $self = shift;
-    my %args = @_;
 
-    my $CurrentUser = $self->CurrentUser;
     my @objects;
 
-    my $prefix = $args{Modify} ? "Modify"
-               : $args{Create} ? "Create"
-                               : "See";
-
-    push @objects, $CurrentUser->UserObj
-        if $self->CurrentUser->HasRight(
-            Right  => "${prefix}OwnDashboard",
-            Object => $RT::System,
-        );
+    my $CurrentUser = $self->CurrentUser;
+    push @objects, $CurrentUser->UserObj;
 
     my $groups = RT::Groups->new($CurrentUser);
     $groups->LimitToUserDefinedGroups;
     $groups->WithMember( PrincipalId => $CurrentUser->Id,
                          Recursively => 1 );
+    push @objects, @{ $groups->ItemsArrayRef };
 
-    push @objects, grep {
-        $self->CurrentUser->HasRight(
-            Right  => "${prefix}GroupDashboard",
-            Object => $_,
-        )
-    } @{ $groups->ItemsArrayRef };
-
-    push @objects, RT::System->new($CurrentUser)
-        if $CurrentUser->HasRight(
-            Right  => "${prefix}Dashboard",
-            Object => $RT::System,
-        );
+    push @objects, RT::System->new($CurrentUser);
 
     return @objects;
 }
diff --git a/lib/RT/SavedSearch.pm b/lib/RT/SavedSearch.pm
index afcc4a6..746e4c2 100644
--- a/lib/RT/SavedSearch.pm
+++ b/lib/RT/SavedSearch.pm
@@ -128,7 +128,9 @@ sub Type {
 
 ### Internal methods
 
-# _PrivacyObjects: returns a list of objects that can be used to load saved searches from.
+# _PrivacyObjects: returns a list of objects that can be used to load, create,
+# etc. saved searches from. You probably want to use the wrapper methods like
+# ObjectsForLoading, ObjectsForCreating, etc.
 
 sub _PrivacyObjects {
     my $self        = shift;
diff --git a/lib/RT/SharedSetting.pm b/lib/RT/SharedSetting.pm
index e92f9cd..d905b0b 100644
--- a/lib/RT/SharedSetting.pm
+++ b/lib/RT/SharedSetting.pm
@@ -456,6 +456,42 @@ sub _build_privacy {
          : undef;
 }
 
+=head2 ObjectsForLoading
+
+Returns a list of objects that can be used to load this shared setting. It
+is ACL checked.
+
+=cut
+
+sub ObjectsForLoading {
+    my $self = shift;
+    return grep { $self->CurrentUserCanSee($_) } $self->_PrivacyObjects;
+}
+
+=head2 ObjectsForCreating
+
+Returns a list of objects that can be used to create this shared setting. It
+is ACL checked.
+
+=cut
+
+sub ObjectsForCreating {
+    my $self = shift;
+    return grep { $self->CurrentUserCanCreate($_) } $self->_PrivacyObjects;
+}
+
+=head2 ObjectsForModifying
+
+Returns a list of objects that can be used to modify this shared setting. It
+is ACL checked.
+
+=cut
+
+sub ObjectsForModifying {
+    my $self = shift;
+    return grep { $self->CurrentUserCanModify($_) } $self->_PrivacyObjects;
+}
+
 eval "require RT::SharedSetting_Vendor";
 die $@ if ($@ && $@ !~ qr{^Can't locate RT/SharedSetting_Vendor.pm});
 eval "require RT::SharedSetting_Local";
diff --git a/share/html/Dashboards/Elements/DashboardsForObjects b/share/html/Dashboards/Elements/DashboardsForObjects
index b4fdcf7..f3dd3c0 100644
--- a/share/html/Dashboards/Elements/DashboardsForObjects
+++ b/share/html/Dashboards/Elements/DashboardsForObjects
@@ -53,7 +53,7 @@ $flatten => 0
 <%init>
 # Returns a hash of dashboards associated with @Objects
 if (!defined($Objects)) {
-    @$Objects = RT::Dashboard->new($session{CurrentUser})->_PrivacyObjects;
+    @$Objects = RT::Dashboard->new($session{CurrentUser})->ObjectsForLoading;
 }
 
 for my $object (@$Objects) {
@@ -77,5 +77,3 @@ if ($flatten) {
 
 return $dashboards;
 </%init>
-
-
diff --git a/share/html/Dashboards/Elements/ListOfDashboards b/share/html/Dashboards/Elements/ListOfDashboards
index b2cbd3e..9b2043d 100644
--- a/share/html/Dashboards/Elements/ListOfDashboards
+++ b/share/html/Dashboards/Elements/ListOfDashboards
@@ -2,7 +2,7 @@
 # put the list of dashboards into the navigation
 use RT::Dashboard;
 
-my @objs = RT::Dashboard->new($session{CurrentUser})->_PrivacyObjects(ShowSystem => 1);
+my @objs = RT::Dashboard->new($session{CurrentUser})->ObjectsForLoading;
 my $dashboard_map = $m->comp("/Dashboards/Elements/DashboardsForObjects", Objects => \@objs);
 
 my @dashboards = (
diff --git a/share/html/Dashboards/Elements/Tabs b/share/html/Dashboards/Elements/Tabs
index d82b9d0..3c3d88d 100755
--- a/share/html/Dashboards/Elements/Tabs
+++ b/share/html/Dashboards/Elements/Tabs
@@ -95,7 +95,7 @@ else {
     };
 
     my $dashboard = RT::Dashboard->new($session{'CurrentUser'});
-    my @objects = $dashboard->_PrivacyObjects(Create => 1);
+    my @objects = $dashboard->ObjectsForCreating;
 
     if (@objects) {
         $subtabs->{"b_Create"} = {
diff --git a/share/html/Dashboards/Modify.html b/share/html/Dashboards/Modify.html
index 35a8046..724d705 100755
--- a/share/html/Dashboards/Modify.html
+++ b/share/html/Dashboards/Modify.html
@@ -93,7 +93,8 @@ $Create = 1 if !$id;
 use RT::Dashboard;
 
 my $Dashboard = RT::Dashboard->new($session{'CurrentUser'});
-my @privacies = $Dashboard->_PrivacyObjects(($Create ? 'Create' : 'Modify') => 1);
+my $method = $Create ? 'ObjectsForCreating' : 'ObjectsForModifying';
+my @privacies = $Dashboard->$method;
 
 Abort(loc("Permission denied")) if @privacies == 0;
 
diff --git a/share/html/Tools/Elements/Tabs b/share/html/Tools/Elements/Tabs
index d06d0af..b266f4c 100644
--- a/share/html/Tools/Elements/Tabs
+++ b/share/html/Tools/Elements/Tabs
@@ -69,9 +69,9 @@ my $tabs = {
 };
 
 my $can_see_dashboards = $session{CurrentUser}->HasRight(Right => 'SubscribeDashboard', Object => $RT::System)
-                       || RT::Dashboard->new($session{CurrentUser})->_PrivacyObjects
-                       || RT::Dashboard->new($session{CurrentUser})->_PrivacyObjects( Create => 1 )
-                       || RT::Dashboard->new($session{CurrentUser})->_PrivacyObjects( Modify => 1 );
+                       || RT::Dashboard->new($session{CurrentUser})->ObjectsForLoading
+                       || RT::Dashboard->new($session{CurrentUser})->ObjectsForCreating
+                       || RT::Dashboard->new($session{CurrentUser})->ObjectsForModifying;
 
 if ($can_see_dashboards) {
     $tabs->{a} = {
diff --git a/share/html/Tools/index.html b/share/html/Tools/index.html
index 0faaf38..5ebc06a 100644
--- a/share/html/Tools/index.html
+++ b/share/html/Tools/index.html
@@ -72,9 +72,9 @@ my $tabs = {
 };
 
 my $can_see_dashboards = $session{CurrentUser}->HasRight(Right => 'SubscribeDashboard', Object => $RT::System)
-                       || RT::Dashboard->new($session{CurrentUser})->_PrivacyObjects
-                       || RT::Dashboard->new($session{CurrentUser})->_PrivacyObjects( Create => 1 )
-                       || RT::Dashboard->new($session{CurrentUser})->_PrivacyObjects( Modify => 1 );
+                       || RT::Dashboard->new($session{CurrentUser})->ObjectsForLoading
+                       || RT::Dashboard->new($session{CurrentUser})->ObjectsForCreating
+                       || RT::Dashboard->new($session{CurrentUser})->ObjectsForModifying;
 
 if ($can_see_dashboards) {
     $tabs->{A} = {

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


More information about the Rt-commit mailing list