[Rt-commit] r12081 - in rt/branches/3.8-TESTING: . html/Prefs/Dashboards html/Prefs/Dashboards/Elements

sartak at bestpractical.com sartak at bestpractical.com
Mon May 5 19:52:57 EDT 2008


Author: sartak
Date: Mon May  5 19:52:57 2008
New Revision: 12081

Modified:
   rt/branches/3.8-TESTING/   (props changed)
   rt/branches/3.8-TESTING/html/Prefs/Dashboards/Elements/DashboardsForObject
   rt/branches/3.8-TESTING/html/Prefs/Dashboards/Elements/ShowDashboards
   rt/branches/3.8-TESTING/html/Prefs/Dashboards/Elements/ShowSubscription
   rt/branches/3.8-TESTING/html/Prefs/Dashboards/Elements/Tabs
   rt/branches/3.8-TESTING/html/Prefs/Dashboards/Modify.html
   rt/branches/3.8-TESTING/html/Prefs/Dashboards/Queries.html
   rt/branches/3.8-TESTING/html/Prefs/Dashboards/Render.html
   rt/branches/3.8-TESTING/html/Prefs/Dashboards/Subscription.html
   rt/branches/3.8-TESTING/lib/RT/SharedSetting.pm

Log:
 r55063 at onn:  sartak | 2008-05-05 19:52:05 -0400
 RT::SharedSetting->LoadById so we don't require Privacy in any of the dashboard templates


Modified: rt/branches/3.8-TESTING/html/Prefs/Dashboards/Elements/DashboardsForObject
==============================================================================
--- rt/branches/3.8-TESTING/html/Prefs/Dashboards/Elements/DashboardsForObject	(original)
+++ rt/branches/3.8-TESTING/html/Prefs/Dashboards/Elements/DashboardsForObject	Mon May  5 19:52:57 2008
@@ -53,10 +53,7 @@
 
 use RT::Dashboard;
 my @dashboards;
-my $privacy = $Object->isa('RT::User')   ? 'RT::User-'  . $Object->Id
-            : $Object->isa('RT::Group')  ? 'RT::Group-' . $Object->Id
-            : $Object->isa('RT::System') ? 'RT::System'
-            : '';
+my $privacy = RT::Dashboard->_build_privacy($Object);
 
 while (my $attr = $Object->Attributes->Next) {
     if ($attr->Name =~ /^Dashboard\b/) {

Modified: rt/branches/3.8-TESTING/html/Prefs/Dashboards/Elements/ShowDashboards
==============================================================================
--- rt/branches/3.8-TESTING/html/Prefs/Dashboards/Elements/ShowDashboards	(original)
+++ rt/branches/3.8-TESTING/html/Prefs/Dashboards/Elements/ShowDashboards	Mon May  5 19:52:57 2008
@@ -59,10 +59,9 @@
 
 %   my $i = 0;
 %   for my $dashboard (sort {$b->Id <=> $a->Id} @$Dashboards) {
-%       my $url = sprintf '%s/Prefs/Dashboards/Modify.html?id=%d&Privacy=%s',
+%       my $url = sprintf '%s/Prefs/Dashboards/Modify.html?id=%d',
 %                 $RT::WebPath,
-%                 $dashboard->Id,
-%                 $dashboard->Privacy; 
+%                 $dashboard->Id;
 
         <tr class="collection-as-table <% ++$i % 2 ? 'oddline' : 'evenline' %>">
             <td class="collection-as-table">

Modified: rt/branches/3.8-TESTING/html/Prefs/Dashboards/Elements/ShowSubscription
==============================================================================
--- rt/branches/3.8-TESTING/html/Prefs/Dashboards/Elements/ShowSubscription	(original)
+++ rt/branches/3.8-TESTING/html/Prefs/Dashboards/Elements/ShowSubscription	Mon May  5 19:52:57 2008
@@ -51,10 +51,9 @@
 $Subscription => undef
 </%ARGS>
 <%INIT>
-my $url = sprintf '%s/Prefs/Dashboards/Subscription.html?DashboardId=%d&Privacy=%s',
+my $url = sprintf '%s/Prefs/Dashboards/Subscription.html?DashboardId=%d',
           $RT::WebPath,
-          $Dashboard->Id,
-          $Dashboard->Privacy;
+          $Dashboard->Id,;
 
 my $frequency = loc("None");
 

Modified: rt/branches/3.8-TESTING/html/Prefs/Dashboards/Elements/Tabs
==============================================================================
--- rt/branches/3.8-TESTING/html/Prefs/Dashboards/Elements/Tabs	(original)
+++ rt/branches/3.8-TESTING/html/Prefs/Dashboards/Elements/Tabs	Mon May  5 19:52:57 2008
@@ -55,9 +55,8 @@
 my $tabs;
 my $real_subtab = $current_subtab;
 if ( $DashboardObj and $DashboardObj->Id ) {
-    my $idpriv = sprintf 'id=%d&Privacy=%s',
-                 $DashboardObj->Id,
-                 $DashboardObj->Privacy;
+    my $idpriv = sprintf 'id=%d',
+                 $DashboardObj->Id;
     my $modify  = "Prefs/Dashboards/Modify.html?$idpriv";
     my $queries = "Prefs/Dashboards/Queries.html?$idpriv";
     my $render  = "Prefs/Dashboards/Render.html?$idpriv";
@@ -76,7 +75,7 @@
             },
 
             c_Subscription => { title => loc('Subscription'),
-                                path  => "Prefs/Dashboards/Subscription.html?DashboardId=" . $DashboardObj->Id . "&Privacy=" . $DashboardObj->Privacy
+                                path  => "Prefs/Dashboards/Subscription.html?DashboardId=" . $DashboardObj->Id
             },
 
 

Modified: rt/branches/3.8-TESTING/html/Prefs/Dashboards/Modify.html
==============================================================================
--- rt/branches/3.8-TESTING/html/Prefs/Dashboards/Modify.html	(original)
+++ rt/branches/3.8-TESTING/html/Prefs/Dashboards/Modify.html	Mon May  5 19:52:57 2008
@@ -114,15 +114,13 @@
         $id = $Dashboard->Id;
     }
     else {
-        $Dashboard->Load($ARGS{'Privacy'}, $id)
-            or Abort('Could not load dashboard');
+        my ($ok) = $Dashboard->LoadById($id);
+        $ok || Abort('Could not load dashboard');
     }
 
     if ($id) {
         $title = loc("Modify the dashboard [_1]", $Dashboard->Name);
-        $current_subtab = 'Prefs/Dashboards/Modify.html?id='
-                        . $id
-                        . '&Privacy=' . $Privacy;
+        $current_subtab = 'Prefs/Dashboards/Modify.html?id=' . $id;
     }	
     # If the create failed
     else {
@@ -155,7 +153,6 @@
 <%ARGS>
 $Create => undef
 $Name => undef
-$Privacy => undef
 $id => '' unless defined $id
 </%ARGS>
 

Modified: rt/branches/3.8-TESTING/html/Prefs/Dashboards/Queries.html
==============================================================================
--- rt/branches/3.8-TESTING/html/Prefs/Dashboards/Queries.html	(original)
+++ rt/branches/3.8-TESTING/html/Prefs/Dashboards/Queries.html	Mon May  5 19:52:57 2008
@@ -78,15 +78,13 @@
 
 <%INIT>
 
-my $current_subtab = 'Prefs/Dashboards/Queries.html?id='
-                   . $id
-                   . '&Privacy=' . $Privacy;
+my $current_subtab = 'Prefs/Dashboards/Queries.html?id=' . $id;
 my @results;
 
 use RT::Dashboard;
 my $Dashboard = new RT::Dashboard($session{'CurrentUser'});
-$Dashboard->Load($ARGS{'Privacy'}, $id)
-    or Abort("Couldn't load dashboard.");
+my ($ok) = $Dashboard->LoadById($id)
+$ok || Abort("Couldn't load dashboard.");
 my $title = loc("Modify the queries of dashboard [_1]", $Dashboard->Name);
 
 my %desc_of;
@@ -161,7 +159,7 @@
 
 </%INIT>
 <%ARGS>
-$Privacy => undef
+$Privacy
 $id => '' unless defined $id
 </%ARGS>
 

Modified: rt/branches/3.8-TESTING/html/Prefs/Dashboards/Render.html
==============================================================================
--- rt/branches/3.8-TESTING/html/Prefs/Dashboards/Render.html	(original)
+++ rt/branches/3.8-TESTING/html/Prefs/Dashboards/Render.html	Mon May  5 19:52:57 2008
@@ -67,14 +67,12 @@
 
 <%INIT>
 
-my $current_subtab = 'Prefs/Dashboards/Render.html?id='
-                   . $id
-                   . '&Privacy=' . $Privacy;
+my $current_subtab = 'Prefs/Dashboards/Render.html?id=' $id;
 
 use RT::Dashboard;
 my $DashboardObj = RT::Dashboard->new($session{'CurrentUser'});
-$DashboardObj->Load($Privacy, $id)
-    or Abort('Could not load dashboard');
+my ($ok) = $DashboardObj->LoadById($id);
+Abort('Could not load dashboard') if !$ok;
 
 my $SubscriptionObj = RT::Attribute->new($session{'CurrentUser'});
 my $Loaded = 0;
@@ -92,7 +90,6 @@
 
 </%INIT>
 <%ARGS>
-$id    => undef
-$Privacy     => undef
+$id => undef
 </%ARGS>
 

Modified: rt/branches/3.8-TESTING/html/Prefs/Dashboards/Subscription.html
==============================================================================
--- rt/branches/3.8-TESTING/html/Prefs/Dashboards/Subscription.html	(original)
+++ rt/branches/3.8-TESTING/html/Prefs/Dashboards/Subscription.html	Mon May  5 19:52:57 2008
@@ -162,9 +162,7 @@
 
 <%INIT>
 
-my $current_subtab = 'Prefs/Dashboards/Subscription.html?DashboardId='
-                   . $DashboardId
-                   . '&Privacy=' . $Privacy;
+my $current_subtab = 'Prefs/Dashboards/Subscription.html?DashboardId=' . $DashboardId;
 
 my ($title, @results);
 my ($val, $msg);
@@ -179,16 +177,12 @@
 # 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') == $DashboardId;
-    $Loaded = 1;
     $SubscriptionObj = $sub;
-    $DashboardObj->Load($SubscriptionObj->SubValue('Privacy'), 
-                     $SubscriptionObj->SubValue('DashboardId'));
-
+    ($Loaded) = $DashboardObj->LoadById($SubscriptionObj->SubValue('DashboardId'));
 }
 
 if (!$Loaded) {
-    my ($ok, $msg) = $DashboardObj->Load($ARGS{'Privacy'}, 
-                                      $ARGS{'DashboardId'});
+    my ($ok, $msg) = $DashboardObj->LoadById($ARGS{'DashboardId'});
     $ok || Abort("Couldn't subscribe to dashboard $DashboardId: $msg.");
 
     if ($session{'CurrentUser'}->HasRight(Right => 'SubscribeDashboard', Object => $RT::System)) {
@@ -251,13 +245,13 @@
 
 </%INIT>
 <%ARGS>
-$DashboardId    => undef
-$Privacy     => undef
+$DashboardId => undef
 $Frequency   => undef
 $Hour        => undef
 $Dow         => undef
 $Dom         => undef
 $Rows        => undef
 $Unsubscribe => undef
+$Privacy
 </%ARGS>
 

Modified: rt/branches/3.8-TESTING/lib/RT/SharedSetting.pm
==============================================================================
--- rt/branches/3.8-TESTING/lib/RT/SharedSetting.pm	(original)
+++ rt/branches/3.8-TESTING/lib/RT/SharedSetting.pm	Mon May  5 19:52:57 2008
@@ -81,10 +81,10 @@
 
 =head2 Load
 
-Takes a privacy specification, an object ID, and a shared-setting ID.  Loads the
-given object ID if it belongs to the stated user or group.  Calls the PostLoad
-method on success for any further initialization. Returns a tuple of status and
-message, where status is true on success.
+Takes a privacy specification and a shared-setting ID.  Loads the given object
+ID if it belongs to the stated user or group. Calls the PostLoad method on
+success for any further initialization. Returns a tuple of status and message,
+where status is true on success.
 
 =cut
 
@@ -113,6 +113,30 @@
 
 sub PostLoad { }
 
+=head2 LoadById
+
+First loads up the L<RT::Attribute> for this shared setting by ID, then calls
+L</Load> with the correct parameters. Returns a tuple of status and message,
+where status is true on success.
+
+=cut
+
+sub LoadById {
+    my $self = shift;
+    my $id   = shift;
+
+    my $attr = RT::Attribute->new($self->CurrentUser);
+    unless ($attr->LoadById($id)) {
+        return (0, $self->loc("Failed to load attribute [_1]", $id))
+    }
+
+    my $privacy = $self->_build_privacy($attr->ObjectType, $attr->ObjectId);
+    return (0, $self->loc("Bad privacy for attribute [_1], $id"))
+        if !$privacy;
+
+    return $self->Load($privacy, $id);
+}
+
 =head2 Save
 
 Takes a privacy, a name, and any other arguments. Saves the given parameters to
@@ -310,6 +334,24 @@
     return undef;
 }
 
+sub _build_privacy {
+    my ($self, $obj_type, $obj_id) = @_;
+
+    # allow passing in just an object to find its privacy string
+    if (ref($obj_type)) {
+        my $Object = $obj_type;
+        return $Object->isa('RT::User')   ? 'RT::User-'  . $Object->Id
+             : $Object->isa('RT::Group')  ? 'RT::Group-' . $Object->Id
+             : $Object->isa('RT::System') ? 'RT::System'
+             : undef;
+    }
+
+    return $obj_type eq 'RT::User'   ? "$obj_type-$obj_id"
+         : $obj_type eq 'RT::Group'  ? "$obj_type-$obj_id"
+         : $obj_type eq 'RT::System' ? $obj_type
+         : undef;
+}
+
 eval "require RT::SharedSetting_Vendor";
 die $@ if ($@ && $@ !~ qr{^Can't locate RT/SharedSetting_Vendor.pm});
 eval "require RT::SharedSetting_Local";


More information about the Rt-commit mailing list