[Rt-commit] r13590 - in rt/3.8/trunk: . t/web

sartak at bestpractical.com sartak at bestpractical.com
Wed Jun 25 15:00:26 EDT 2008


Author: sartak
Date: Wed Jun 25 15:00:24 2008
New Revision: 13590

Modified:
   rt/3.8/trunk/   (props changed)
   rt/3.8/trunk/lib/RT/Dashboard.pm
   rt/3.8/trunk/lib/RT/SharedSetting.pm
   rt/3.8/trunk/t/web/dashboards.t

Log:
 r63236 at onn:  sartak | 2008-06-25 15:00:04 -0400
 Add some methods to SharedSetting and Dashboards to detect when a search would be hidden form another user. Needs more tests.


Modified: rt/3.8/trunk/lib/RT/Dashboard.pm
==============================================================================
--- rt/3.8/trunk/lib/RT/Dashboard.pm	(original)
+++ rt/3.8/trunk/lib/RT/Dashboard.pm	Wed Jun 25 15:00:24 2008
@@ -202,6 +202,21 @@
     return SavedSearch => join('-', $type, 'SavedSearch', $id);
 }
 
+=head2 PossibleHiddenSearches
+
+This will return a list of saved searches that are potentially not visible by
+all users for whom the dashboard is visible. You may pass in a privacy to
+use instead of the dashboard's privacy.
+
+=cut
+
+sub PossibleHiddenSearches {
+    my $self = shift;
+    my $privacy = shift || $self->Privacy;
+
+    return grep { !$_->IsVisibleTo($privacy) } $self->Searches;
+}
+
 # _PrivacyObjects: returns a list of objects that can be used to load
 # dashboards from. Unlike SavedSearch, this will return the System object if
 # applicable. You may pass in a paramhash of ShowSystem to force

Modified: rt/3.8/trunk/lib/RT/SharedSetting.pm
==============================================================================
--- rt/3.8/trunk/lib/RT/SharedSetting.pm	(original)
+++ rt/3.8/trunk/lib/RT/SharedSetting.pm	Wed Jun 25 15:00:24 2008
@@ -324,6 +324,44 @@
     return $self->{'Attribute'}->SubValue($param);
 }
 
+=head2 IsVisibleTo Privacy
+
+Returns true if the setting is visible to all principals of the given privacy.
+
+=cut
+
+sub IsVisibleTo {
+    my $self    = shift;
+    my $to      = shift;
+    my $privacy = $self->Privacy;
+
+    # if the privacies are the same, then they can be seen. this handles
+    # a personal setting being visible to that user.
+    return 1 if $privacy eq $to;
+
+    # If the setting is systemwide, then any user can see it.
+    return 1 if $privacy =~ /^RT::System/;
+
+    # Only privacies that are RT::System can be seen by everyone.
+    return 0 if $to eq /^RT::System/;
+
+    # If the setting is group-wide...
+    if ($privacy =~ /^RT::Group-(\d+)$/) {
+        my $setting_group = RT::Group->new($self->CurrentUser);
+        $setting_group->Load($1);
+
+        if ($to =~ /-(\d+)$/) {
+            my $to_id = $1;
+
+            # then any principal that is a member of the setting's group can see
+            # the setting
+            return $setting_group->HasMemberRecursively($to_id);
+        }
+    }
+
+    return 0;
+}
+
 ### Internal methods
 
 # _GetObject: helper routine to load the correct object whose parameters

Modified: rt/3.8/trunk/t/web/dashboards.t
==============================================================================
--- rt/3.8/trunk/t/web/dashboards.t	(original)
+++ rt/3.8/trunk/t/web/dashboards.t	Wed Jun 25 15:00:24 2008
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 use strict;
 
-use Test::More tests => 66;
+use Test::More tests => 68;
 use RT::Test;
 my ($baseurl, $m) = RT::Test->started_ok;
 
@@ -71,6 +71,9 @@
 $dashboard->LoadById($id);
 is($dashboard->Name, "different dashboard");
 
+is($dashboard->Privacy, 'RT::User-' . $user_obj->Id, "correct privacy");
+is($dashboard->PossibleHiddenSearches, 0, "all searches are visible");
+
 my @searches = $dashboard->Searches;
 is(@searches, 1, "one saved search in the dashboard");
 like($searches[0]->Name, qr/newest unowned tickets/, "correct search name");


More information about the Rt-commit mailing list