[Rt-commit] r12037 - in rt/branches/3.8-TESTING: .
sartak at bestpractical.com
sartak at bestpractical.com
Fri May 2 20:46:33 EDT 2008
Author: sartak
Date: Fri May 2 20:46:14 2008
New Revision: 12037
Modified:
rt/branches/3.8-TESTING/ (props changed)
rt/branches/3.8-TESTING/lib/RT/Dashboard.pm
rt/branches/3.8-TESTING/lib/RT/SavedSearch.pm
rt/branches/3.8-TESTING/lib/RT/SharedSetting.pm
Log:
r54849 at Macintosh: sartak | 2008-05-02 20:45:44 -0400
Refactor more methods into RT::SharedSetting
Modified: rt/branches/3.8-TESTING/lib/RT/Dashboard.pm
==============================================================================
--- rt/branches/3.8-TESTING/lib/RT/Dashboard.pm (original)
+++ rt/branches/3.8-TESTING/lib/RT/Dashboard.pm Fri May 2 20:46:14 2008
@@ -177,64 +177,6 @@
return SavedSearch => join('-', $type, 'SavedSearch', $id);
}
-### Internal methods
-
-sub _load_privacy_object {
- my ($self, $obj_type, $obj_id) = @_;
- if ( $obj_type eq 'RT::User' && $obj_id == $self->CurrentUser->Id) {
- return $self->CurrentUser->UserObj;
- }
- elsif ($obj_type eq 'RT::Group') {
- my $group = RT::Group->new($self->CurrentUser);
- $group->Load($obj_id);
- return $group;
- }
- elsif ($obj_type eq 'RT::System') {
- return RT::System->new($self->CurrentUser);
- }
-
- $RT::Logger->error("Tried to load a dashboard belonging to an $obj_type, which is neither a user nor a group");
- return undef;
-}
-
-# _GetObject: helper routine to load the correct object whose parameters
-# have been passed.
-
-sub _GetObject {
- my $self = shift;
- my $privacy = shift;
-
- my ($obj_type, $obj_id) = split(/\-/, ($privacy || ''));
- if (!defined $obj_id) {
- $RT::Logger->warning("Invalid privacy string \"$privacy\" passed to _GetObject");
- return undef;
- }
-
- my $object = $self->_load_privacy_object($obj_type, $obj_id);
-
- unless (ref($object) eq $obj_type) {
- $RT::Logger->error("Could not load object of type $obj_type with ID $obj_id, got object of type " . (ref($object) || 'undef'));
- return undef;
- }
-
- # Do not allow the loading of a user object other than the current
- # user, or of a group object of which the current user is not a member.
-
- if ($obj_type eq 'RT::User'
- && $object->Id != $self->CurrentUser->UserObj->Id()) {
- $RT::Logger->debug("Permission denied for user other than self");
- return undef;
- }
- if ($obj_type eq 'RT::Group' &&
- !$object->HasMemberRecursively($self->CurrentUser->PrincipalObj)) {
- $RT::Logger->debug("Permission denied, ".$self->CurrentUser->Name.
- " is not a member of group");
- return undef;
- }
-
- return $object;
-}
-
# _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/branches/3.8-TESTING/lib/RT/SavedSearch.pm
==============================================================================
--- rt/branches/3.8-TESTING/lib/RT/SavedSearch.pm (original)
+++ rt/branches/3.8-TESTING/lib/RT/SavedSearch.pm Fri May 2 20:46:14 2008
@@ -111,31 +111,6 @@
return ($status, $msg);
}
-=head2 GetParameter
-
-Returns the given named parameter of the search, e.g. 'Query', 'Format'.
-
-=cut
-
-sub GetParameter {
- my $self = shift;
- my $param = shift;
- return unless ref($self->{'Attribute'}) eq 'RT::Attribute';
- return $self->{'Attribute'}->SubValue($param);
-}
-
-=head2 Privacy
-
-Returns the principal object to whom this search belongs, in a string
-"<class>-<id>", e.g. "RT::Group-16".
-
-=cut
-
-sub Privacy {
- my $self = shift;
- return $self->{'Privacy'};
-}
-
=head2 Type
Returns the type of this search, e.g. 'Ticket'. Useful for denoting the
@@ -148,60 +123,6 @@
return $self->{'Type'};
}
-### Internal methods
-
-sub _load_privacy_object {
- my ($self, $obj_type, $obj_id) = @_;
- if ( $obj_type eq 'RT::User' && $obj_id == $self->CurrentUser->Id) {
- return $self->CurrentUser->UserObj;
- }
- elsif ($obj_type eq 'RT::Group') {
- my $group = RT::Group->new($self->CurrentUser);
- $group->Load($obj_id);
- return $group;
- }
- elsif ($obj_type eq 'RT::System') {
- return RT::System->new($self->CurrentUser);
- }
-
- $RT::Logger->error("Tried to load a search belonging to an $obj_type, which is neither a user nor a group");
- return undef;
-}
-
-# _GetObject: helper routine to load the correct object whose parameters
-# have been passed.
-
-sub _GetObject {
- my $self = shift;
- my $privacy = shift;
-
- my ($obj_type, $obj_id) = split(/\-/, $privacy);
-
- my $object = $self->_load_privacy_object($obj_type, $obj_id);
-
- unless (ref($object) eq $obj_type) {
- $RT::Logger->error("Could not load object of type $obj_type with ID $obj_id");
- return undef;
- }
-
- # Do not allow the loading of a user object other than the current
- # user, or of a group object of which the current user is not a member.
-
- if ($obj_type eq 'RT::User'
- && $object->Id != $self->CurrentUser->UserObj->Id()) {
- $RT::Logger->debug("Permission denied for user other than self");
- return undef;
- }
- if ($obj_type eq 'RT::Group' &&
- !$object->HasMemberRecursively($self->CurrentUser->PrincipalObj)) {
- $RT::Logger->debug("Permission denied, ".$self->CurrentUser->Name.
- " is not a member of group");
- return undef;
- }
-
- return $object;
-}
-
eval "require RT::SavedSearch_Vendor";
die $@ if ($@ && $@ !~ qr{^Can't locate RT/SavedSearch_Vendor.pm});
eval "require RT::SavedSearch_Local";
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 Fri May 2 20:46:14 2008
@@ -244,6 +244,76 @@
return $self->{'Privacy'};
}
+=head2 GetParameter
+
+Returns the given named parameter of the setting.
+
+=cut
+
+sub GetParameter {
+ my $self = shift;
+ my $param = shift;
+ return unless ref($self->{'Attribute'}) eq 'RT::Attribute';
+ return $self->{'Attribute'}->SubValue($param);
+}
+
+### Internal methods
+
+# _GetObject: helper routine to load the correct object whose parameters
+# have been passed.
+
+sub _GetObject {
+ my $self = shift;
+ my $privacy = shift;
+
+ my ($obj_type, $obj_id) = split(/\-/, ($privacy || ''));
+ if (!defined $obj_id) {
+ $RT::Logger->warning("Invalid privacy string \"$privacy\" passed to _GetObject");
+ return undef;
+ }
+
+ my $object = $self->_load_privacy_object($obj_type, $obj_id);
+
+ unless (ref($object) eq $obj_type) {
+ $RT::Logger->error("Could not load object of type $obj_type with ID $obj_id, got object of type " . (ref($object) || 'undef'));
+ return undef;
+ }
+
+ # Do not allow the loading of a user object other than the current
+ # user, or of a group object of which the current user is not a member.
+
+ if ($obj_type eq 'RT::User' && $object->Id != $self->CurrentUser->UserObj->Id) {
+ $RT::Logger->debug("Permission denied for user other than self");
+ return undef;
+ }
+
+ if ($obj_type eq 'RT::Group' && !$object->HasMemberRecursively($self->CurrentUser->PrincipalObj)) {
+ $RT::Logger->debug("Permission denied, ".$self->CurrentUser->Name.
+ " is not a member of group");
+ return undef;
+ }
+
+ return $object;
+}
+
+sub _load_privacy_object {
+ my ($self, $obj_type, $obj_id) = @_;
+ if ( $obj_type eq 'RT::User' && $obj_id == $self->CurrentUser->Id) {
+ return $self->CurrentUser->UserObj;
+ }
+ elsif ($obj_type eq 'RT::Group') {
+ my $group = RT::Group->new($self->CurrentUser);
+ $group->Load($obj_id);
+ return $group;
+ }
+ elsif ($obj_type eq 'RT::System') {
+ return RT::System->new($self->CurrentUser);
+ }
+
+ $RT::Logger->error("Tried to load a " . $self->ObjectName . " belonging to an $obj_type, which is neither a user nor a group");
+ return 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