[Rt-commit] r6490 - in rt/branches/3.6-EXPERIMENTAL-LONDRES: html/Prefs html/Search/Elements lib/RT

clkao at bestpractical.com clkao at bestpractical.com
Wed Nov 22 03:57:47 EST 2006


Author: clkao
Date: Wed Nov 22 03:57:46 2006
New Revision: 6490

Modified:
   rt/branches/3.6-EXPERIMENTAL-LONDRES/html/Prefs/MyRT.html
   rt/branches/3.6-EXPERIMENTAL-LONDRES/html/Search/Chart.html
   rt/branches/3.6-EXPERIMENTAL-LONDRES/html/Search/Elements/EditSearches
   rt/branches/3.6-EXPERIMENTAL-LONDRES/lib/RT/SavedSearches.pm

Log:
refactor the code for loading saved search privacies to RT::SavedSearches.

Modified: rt/branches/3.6-EXPERIMENTAL-LONDRES/html/Prefs/MyRT.html
==============================================================================
--- rt/branches/3.6-EXPERIMENTAL-LONDRES/html/Prefs/MyRT.html	(original)
+++ rt/branches/3.6-EXPERIMENTAL-LONDRES/html/Prefs/MyRT.html	Wed Nov 22 03:57:46 2006
@@ -65,6 +65,7 @@
 </form>
 </&>
 <%INIT>
+use RT::SavedSearches;
 my @actions;
 
 my $title = loc("Customize").' '.loc("RT at a glance");
@@ -96,14 +97,9 @@
 my $sys = RT::System->new($session{'CurrentUser'});
 my @objs = ($sys);
 
-if ($session{'CurrentUser'}->HasRight( Right => 'LoadSavedSearch',
-				       Object=> $RT::System )) {
-    my $groups = RT::Groups->new($session{'CurrentUser'});
-    $groups->LimitToUserDefinedGroups;
-    $groups->WithMember(PrincipalId => $session{'CurrentUser'}->Id,
-			Recursively => 1);
-    push @objs, ($user, @{$groups->ItemsArrayRef()});
-}
+push @objs, RT::SavedSearches->new( $session{CurrentUser} )->_PrivacyObjects
+    if $session{'CurrentUser'}->HasRight( Right  => 'LoadSavedSearch',
+                                          Object => $RT::System );
 
 my @sys_searches;
 for my $object (@objs) {

Modified: rt/branches/3.6-EXPERIMENTAL-LONDRES/html/Search/Chart.html
==============================================================================
--- rt/branches/3.6-EXPERIMENTAL-LONDRES/html/Search/Chart.html	(original)
+++ rt/branches/3.6-EXPERIMENTAL-LONDRES/html/Search/Chart.html	Wed Nov 22 03:57:46 2006
@@ -52,23 +52,12 @@
 
 </%args>
 <%init>
+my $title = loc( "Search results grouped by [_1]", $PrimaryGroupBy );
 
-my      $title = loc("Search results grouped by [_1]", $PrimaryGroupBy);
-
-my @Objects;
-
-push @Objects,  $session{CurrentUser}->UserObj;
-
-my $groups = RT::Groups->new($session{'CurrentUser'});
-
-$groups->LimitToUserDefinedGroups;
-$groups->WithMember(PrincipalId => $session{'CurrentUser'}->Id,
-                    Recursively => 1);
-
-push (@Objects, @{$groups->ItemsArrayRef()});
+my @Objects = RT::SavedSearches->new( $session{CurrentUser} )->_PrivacyObjects;
 push @Objects, RT::System->new($session{'CurrentUser'})
     if $session{'CurrentUser'}->HasRight( Object=> $RT::System,
-					  Right => 'SuperUser');
+                                          Right => 'SuperUser');
 
 if ( $ARGS{Save} ) {
     if ( $ARGS{'Owner'} =~ /^(.*?)-(\d+)$/ ) {

Modified: rt/branches/3.6-EXPERIMENTAL-LONDRES/html/Search/Elements/EditSearches
==============================================================================
--- rt/branches/3.6-EXPERIMENTAL-LONDRES/html/Search/Elements/EditSearches	(original)
+++ rt/branches/3.6-EXPERIMENTAL-LONDRES/html/Search/Elements/EditSearches	Wed Nov 22 03:57:46 2006
@@ -74,25 +74,17 @@
 </&>
 
 <%init>
-
+use RT::SavedSearches;
 unless ($session{'CurrentUser'}->HasRight( Right => 'LoadSavedSearch',
-                                          Object=> $RT::System )) {
+                                           Object=> $RT::System )) {
     return;
 }
-my @Objects;
-
-push @Objects,  $session{CurrentUser}->UserObj;
-
-my $groups = RT::Groups->new($session{'CurrentUser'});
 
-$groups->LimitToUserDefinedGroups;
-$groups->WithMember(PrincipalId => $session{'CurrentUser'}->Id,
-                    Recursively => 1);
-
-push (@Objects, @{$groups->ItemsArrayRef()});
+my @Objects = RT::SavedSearches->new($session{CurrentUser})->_PrivacyObjects;
 push @Objects, RT::System->new($session{'CurrentUser'})
     if $session{'CurrentUser'}->HasRight( Object=> $RT::System,
-					  Right => 'SuperUser');
+                                          Right => 'SuperUser');
+
 </%INIT>
 
 <%ARGS>

Modified: rt/branches/3.6-EXPERIMENTAL-LONDRES/lib/RT/SavedSearches.pm
==============================================================================
--- rt/branches/3.6-EXPERIMENTAL-LONDRES/lib/RT/SavedSearches.pm	(original)
+++ rt/branches/3.6-EXPERIMENTAL-LONDRES/lib/RT/SavedSearches.pm	Wed Nov 22 03:57:46 2006
@@ -197,6 +197,22 @@
     return $object;
 }
 
+### Internal methods
+
+# _PrivacyObjects: returns a list of objects that can be used to load saved searches from.
+
+sub _PrivacyObjects {
+    my $self        = shift;
+    my $CurrentUser = $self->CurrentUser;
+
+    my $groups = RT::Groups->new($CurrentUser);
+    $groups->LimitToUserDefinedGroups;
+    $groups->WithMember( PrincipalId => $CurrentUser->Id,
+                         Recursively => 1 );
+
+    return ( $CurrentUser->UserObj, @{ $groups->ItemsArrayRef() } );
+}
+
 eval "require RT::SavedSearches_Vendor";
 die $@ if ($@ && $@ !~ qr{^Can't locate RT/SavedSearches_Vendor.pm});
 eval "require RT::SavedSearches_Local";


More information about the Rt-commit mailing list