diff options
Diffstat (limited to 'rt/lib/RT/Queue.pm')
-rwxr-xr-x | rt/lib/RT/Queue.pm | 961 |
1 files changed, 767 insertions, 194 deletions
diff --git a/rt/lib/RT/Queue.pm b/rt/lib/RT/Queue.pm index b362c9f0d..1656903b3 100755 --- a/rt/lib/RT/Queue.pm +++ b/rt/lib/RT/Queue.pm @@ -1,371 +1,944 @@ -# BEGIN LICENSE BLOCK -# -# Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com> -# -# (Except where explictly superceded by other copyright notices) -# -# This work is made available to you under the terms of Version 2 of -# the GNU General Public License. A copy of that license should have -# been provided with this software, but in any event can be snarfed -# from www.gnu.org. -# -# This work is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# Unless otherwise specified, all modifications, corrections or -# extensions to this work which alter its source code become the -# property of Best Practical Solutions, LLC when submitted for -# inclusion in the work. -# -# -# END LICENSE BLOCK -# Autogenerated by DBIx::SearchBuilder factory (by <jesse@bestpractical.com>) -# WARNING: THIS FILE IS AUTOGENERATED. ALL CHANGES TO THIS FILE WILL BE LOST. -# -# !! DO NOT EDIT THIS FILE !! -# - -use strict; - +# $Header: /home/cvs/cvsroot/freeside/rt/lib/RT/Queue.pm,v 1.1 2002-08-12 06:17:07 ivan Exp $ =head1 NAME -RT::Queue - + RT::Queue - an RT Queue object =head1 SYNOPSIS + use RT::Queue; + =head1 DESCRIPTION + =head1 METHODS +=begin testing +use RT::TestHarness; + +use RT::Queue; + +=end testing + =cut + + package RT::Queue; -use RT::Record; +use RT::Record; + +@ISA= qw(RT::Record); + +use vars (@STATUS); + +@STATUS = qw(new open stalled resolved dead); + +=head2 StatusArray + +Returns an array of all statuses for this queue + +=cut + +sub StatusArray { + my $self = shift; + return (@STATUS); +} + + +=head2 IsValidStatus VALUE + +Returns true if VALUE is a valid status. Otherwise, returns 0 + +=for testing +my $q = new RT::Queue($RT::SystemUser); +ok($q->IsValidStatus('new')== 1, 'New is a valid status'); +ok($q->IsValidStatus('f00')== 0, 'f00 is not a valid status'); + +=cut + +sub IsValidStatus { + my $self = shift; + my $value = shift; + + my $retval = grep (/^$value$/, $self->StatusArray); + return ($retval); + +} + + + + +# {{{ sub _Init +sub _Init { + my $self = shift; + $self->{'table'} = "Queues"; + return ($self->SUPER::_Init(@_)); +} +# }}} + +# {{{ sub _Accessible + +sub _Accessible { + my $self = shift; + my %Cols = ( Name => 'read/write', + CorrespondAddress => 'read/write', + Description => 'read/write', + CommentAddress => 'read/write', + InitialPriority => 'read/write', + FinalPriority => 'read/write', + DefaultDueIn => 'read/write', + Creator => 'read/auto', + Created => 'read/auto', + LastUpdatedBy => 'read/auto', + LastUpdated => 'read/auto', + Disabled => 'read/write', + + ); + return($self->SUPER::_Accessible(@_, %Cols)); +} + +# }}} +# {{{ sub Create -use vars qw( @ISA ); -@ISA= qw( RT::Record ); +=head2 Create -sub _Init { - my $self = shift; +Create takes the name of the new queue +If you pass the ACL check, it creates the queue and returns its queue id. - $self->Table('Queues'); - $self->SUPER::_Init(@_); +=cut + +sub Create { + my $self = shift; + my %args = ( Name => undef, + CorrespondAddress => '', + Description => '', + CommentAddress => '', + InitialPriority => "0", + FinalPriority => "0", + DefaultDueIn => "0", + @_); + + unless ($self->CurrentUser->HasSystemRight('AdminQueue')) { #Check them ACLs + return (0, "No permission to create queues") + } + + unless ($self->ValidateName($args{'Name'})) { + return(0, 'Queue already exists'); + } + #TODO better input validation + + my $id = $self->SUPER::Create(%args); + unless ($id) { + return (0, 'Queue could not be created'); + } + + return ($id, "Queue $id created"); } +# }}} +# {{{ sub Delete +sub Delete { + my $self = shift; + return (0, 'Deleting this object would break referential integrity'); +} +# }}} -=item Create PARAMHASH +# {{{ sub SetDisabled -Create takes a hash of values and creates a row in the database: +=head2 SetDisabled - varchar(200) 'Name'. - varchar(255) 'Description'. - varchar(120) 'CorrespondAddress'. - varchar(120) 'CommentAddress'. - int(11) 'InitialPriority'. - int(11) 'FinalPriority'. - int(11) 'DefaultDueIn'. - smallint(6) 'Disabled'. +Takes a boolean. +1 will cause this queue to no longer be avaialble for tickets. +0 will re-enable this queue =cut +# }}} +# {{{ sub Load +=head2 Load -sub Create { +Takes either a numerical id or a textual Name and loads the specified queue. + +=cut + +sub Load { my $self = shift; - my %args = ( - Name => '', - Description => '', - CorrespondAddress => '', - CommentAddress => '', - InitialPriority => '0', - FinalPriority => '0', - DefaultDueIn => '0', - Disabled => '0', + + my $identifier = shift; + if (!$identifier) { + return (undef); + } + + if ($identifier !~ /\D/) { + $self->SUPER::LoadById($identifier); + } + else { + $self->LoadByCol("Name", $identifier); + } + + return ($self->Id); - @_); - $self->SUPER::Create( - Name => $args{'Name'}, - Description => $args{'Description'}, - CorrespondAddress => $args{'CorrespondAddress'}, - CommentAddress => $args{'CommentAddress'}, - InitialPriority => $args{'InitialPriority'}, - FinalPriority => $args{'FinalPriority'}, - DefaultDueIn => $args{'DefaultDueIn'}, - Disabled => $args{'Disabled'}, -); } +# }}} +# {{{ sub ValidateName +=head2 ValidateName NAME -=item id +Takes a queue name. Returns true if it's an ok name for +a new queue. Returns undef if there's already a queue by that name. -Returns the current value of id. -(In the database, id is stored as int(11).) +=cut +sub ValidateName { + my $self = shift; + my $name = shift; + + my $tempqueue = new RT::Queue($RT::SystemUser); + $tempqueue->Load($name); + + #If we couldn't load it :) + unless ($tempqueue->id()) { + return(1); + } + + #If this queue exists, return undef + #Avoid the ACL check. + if ($tempqueue->Name()){ + return(undef); + } + + #If the queue doesn't exist, return 1 + else { + return(1); + } + +} + + +# }}} + +# {{{ sub Templates + +=head2 Templates + +Returns an RT::Templates object of all of this queue's templates. =cut +sub Templates { + my $self = shift; + -=item Name + my $templates = RT::Templates->new($self->CurrentUser); -Returns the current value of Name. -(In the database, Name is stored as varchar(200).) + if ($self->CurrentUserHasRight('ShowTemplate')) { + $templates->LimitToQueue($self->id); + } + + return ($templates); +} + +# }}} +# {{{ Dealing with watchers +# {{{ sub Watchers -=item SetName VALUE +=head2 Watchers +Watchers returns a Watchers object preloaded with this queue\'s watchers. -Set Name to VALUE. -Returns (1, 'Status message') on success and (0, 'Error Message') on failure. -(In the database, Name will be stored as a varchar(200).) +=cut +sub Watchers { + my $self = shift; + + require RT::Watchers; + my $watchers =RT::Watchers->new($self->CurrentUser); + + if ($self->CurrentUserHasRight('SeeQueue')) { + $watchers->LimitToQueue($self->id); + } + + return($watchers); +} + +# }}} + +# {{{ sub WatchersAsString +=head2 WatchersAsString + +Returns a string of all queue watchers email addresses concatenated with ','s. =cut +sub WatchersAsString { + my $self=shift; + return($self->Watchers->EmailsAsString()); +} + +# }}} + +# {{{ sub AdminCcAsString -=item Description +=head2 AdminCcAsString -Returns the current value of Description. -(In the database, Description is stored as varchar(255).) +Takes nothing. returns a string: All Ticket/Queue AdminCcs. +=cut -=item SetDescription VALUE +sub AdminCcAsString { + my $self=shift; + + return($self->AdminCc->EmailsAsString()); + } +# }}} -Set Description to VALUE. -Returns (1, 'Status message') on success and (0, 'Error Message') on failure. -(In the database, Description will be stored as a varchar(255).) +# {{{ sub CcAsString +=head2 CcAsString + +B<Returns> String: All Queue Ccs as a comma delimited set of email addresses. =cut +sub CcAsString { + my $self=shift; + + return ($self->Cc->EmailsAsString()); +} + +# }}} + +# {{{ sub Cc + +=head2 Cc + +Takes nothing. +Returns a watchers object which contains this queue\'s Cc watchers -=item CorrespondAddress +=cut -Returns the current value of CorrespondAddress. -(In the database, CorrespondAddress is stored as varchar(120).) +sub Cc { + my $self = shift; + my $cc = $self->Watchers(); + if ($self->CurrentUserHasRight('SeeQueue')) { + $cc->LimitToCc(); + } + return ($cc); +} +# A helper function for Cc, so that we can call it from the ACL checks +# without going through acl checks. +sub _Cc { + my $self = shift; + my $cc = $self->Watchers(); + $cc->LimitToCc(); + return($cc); + +} -=item SetCorrespondAddress VALUE +# }}} +# {{{ sub AdminCc -Set CorrespondAddress to VALUE. -Returns (1, 'Status message') on success and (0, 'Error Message') on failure. -(In the database, CorrespondAddress will be stored as a varchar(120).) +=head2 AdminCc +Takes nothing. +Returns this queue's administrative Ccs as an RT::Watchers object =cut +sub AdminCc { + my $self = shift; + my $admin_cc = $self->Watchers(); + if ($self->CurrentUserHasRight('SeeQueue')) { + $admin_cc->LimitToAdminCc(); + } + return($admin_cc); +} + +#helper function for AdminCc so we can call it without ACLs +sub _AdminCc { + my $self = shift; + my $admin_cc = $self->Watchers(); + $admin_cc->LimitToAdminCc(); + return($admin_cc); +} -=item CommentAddress +# }}} -Returns the current value of CommentAddress. -(In the database, CommentAddress is stored as varchar(120).) +# {{{ IsWatcher, IsCc, IsAdminCc + +# {{{ sub IsWatcher + +# a generic routine to be called by IsRequestor, IsCc and IsAdminCc + +=head2 IsWatcher + +Takes a param hash with the attributes Type and User. User is either a user object or string containing an email address. Returns true if that user or string +is a queue watcher. Returns undef otherwise + +=cut + +sub IsWatcher { + my $self = shift; + + my %args = ( Type => 'Requestor', + Id => undef, + Email => undef, + @_ + ); + #ACL check - can't do it. we need this method for ACL checks + # unless ($self->CurrentUserHasRight('SeeQueue')) { + # return(undef); + # } + + + my %cols = ('Type' => $args{'Type'}, + 'Scope' => 'Queue', + 'Value' => $self->Id + ); + if (defined ($args{'Id'})) { + if (ref($args{'Id'})){ #If it's a ref, assume it's an RT::User object; + #Dangerous but ok for now + $cols{'Owner'} = $args{'Id'}->Id; + } + elsif ($args{'Id'} =~ /^\d+$/) { # if it's an integer, it's an RT::User obj + $cols{'Owner'} = $args{'Id'}; + } + else { + $cols{'Email'} = $args{'Id'}; + } + } + + if (defined $args{'Email'}) { + $cols{'Email'} = $args{'Email'}; + } + + my ($description); + $description = join(":",%cols); + + #If we've cached a positive match... + if (defined $self->{'watchers_cache'}->{"$description"}) { + if ($self->{'watchers_cache'}->{"$description"} == 1) { + return(1); + } + #If we've cached a negative match... + else { + return(undef); + } + } + + require RT::Watcher; + my $watcher = new RT::Watcher($self->CurrentUser); + $watcher->LoadByCols(%cols); + + + if ($watcher->id) { + $self->{'watchers_cache'}->{"$description"} = 1; + return(1); + } + else { + $self->{'watchers_cache'}->{"$description"} = 0; + return(undef); + } + +} +# }}} +# {{{ sub IsCc -=item SetCommentAddress VALUE +=head2 IsCc +Takes a string. Returns true if the string is a Cc watcher of the current queue -Set CommentAddress to VALUE. -Returns (1, 'Status message') on success and (0, 'Error Message') on failure. -(In the database, CommentAddress will be stored as a varchar(120).) +=item Bugs +Should also be able to handle an RT::User object =cut -=item InitialPriority +sub IsCc { + my $self = shift; + my $cc = shift; + + return ($self->IsWatcher( Type => 'Cc', Id => $cc )); + +} + +# }}} + +# {{{ sub IsAdminCc + +=head2 IsAdminCc + +Takes a string. Returns true if the string is an AdminCc watcher of the current queue -Returns the current value of InitialPriority. -(In the database, InitialPriority is stored as int(11).) +=item Bugs +Should also be able to handle an RT::User object + +=cut + +sub IsAdminCc { + my $self = shift; + my $admincc = shift; + + return ($self->IsWatcher( Type => 'AdminCc', Id => $admincc )); + +} +# }}} -=item SetInitialPriority VALUE +# }}} +# {{{ sub AddWatcher -Set InitialPriority to VALUE. -Returns (1, 'Status message') on success and (0, 'Error Message') on failure. -(In the database, InitialPriority will be stored as a int(11).) +=head2 AddWatcher +Takes a paramhash of Email, Owner and Type. Type is one of 'Cc' or 'AdminCc', +We need either an Email Address in Email or a userid in Owner =cut +sub AddWatcher { + my $self = shift; + my %args = ( Email => undef, + Type => undef, + Owner => 0, + @_ + ); + + # {{{ Check ACLS + #If the watcher we're trying to add is for the current user + if ( ( ( defined $args{'Email'}) && + ( $args{'Email'} eq $self->CurrentUser->EmailAddress) ) or + ($args{'Owner'} eq $self->CurrentUser->Id)) { + + # If it's an AdminCc and they don't have + # 'WatchAsAdminCc' or 'ModifyQueueWatchers', bail + if ($args{'Type'} eq 'AdminCc') { + unless ($self->CurrentUserHasRight('ModifyQueueWatchers') or + $self->CurrentUserHasRight('WatchAsAdminCc')) { + return(0, 'Permission Denied'); + } + } + + # If it's a Requestor or Cc and they don't have + # 'Watch' or 'ModifyQueueWatchers', bail + elsif ($args{'Type'} eq 'Cc') { + unless ($self->CurrentUserHasRight('ModifyQueueWatchers') or + $self->CurrentUserHasRight('Watch')) { + return(0, 'Permission Denied'); + } + } + else { + $RT::Logger->warn("$self -> AddWatcher hit code". + " it never should. We got passed ". + " a type of ". $args{'Type'}); + return (0,'Error in parameters to $self AddWatcher'); + } + } + # If the watcher isn't the current user + # and the current user doesn't have 'ModifyQueueWatchers' + # bail + else { + unless ($self->CurrentUserHasRight('ModifyQueueWatchers')) { + return (0, "Permission Denied"); + } + } + # }}} + + require RT::Watcher; + my $Watcher = new RT::Watcher ($self->CurrentUser); + return ($Watcher->Create(Scope => 'Queue', + Value => $self->Id, + Email => $args{'Email'}, + Type => $args{'Type'}, + Owner => $args{'Owner'} + )); +} -=item FinalPriority +# }}} -Returns the current value of FinalPriority. -(In the database, FinalPriority is stored as int(11).) +# {{{ sub AddCc +=head2 AddCc +Add a Cc to this queue. +Takes a paramhash of Email and Owner. +We need either an Email Address in Email or a userid in Owner -=item SetFinalPriority VALUE +=cut -Set FinalPriority to VALUE. -Returns (1, 'Status message') on success and (0, 'Error Message') on failure. -(In the database, FinalPriority will be stored as a int(11).) +sub AddCc { + my $self = shift; + return ($self->AddWatcher( Type => 'Cc', @_)); +} +# }}} +# {{{ sub AddAdminCc + +=head2 AddAdminCc + +Add an Administrative Cc to this queue. +Takes a paramhash of Email and Owner. +We need either an Email Address in Email or a userid in Owner =cut +sub AddAdminCc { + my $self = shift; + return ($self->AddWatcher( Type => 'AdminCc', @_)); +} +# }}} + +# {{{ sub DeleteWatcher + +=head2 DeleteWatcher id [type] -=item DefaultDueIn +DeleteWatcher takes a single argument which is either an email address +or a watcher id. +If the first argument is an email address, you need to specify the watcher type you're talking +about as the second argument. Valid values are 'Cc' or 'AdminCc'. +It removes that watcher from this Queue\'s list of watchers. -Returns the current value of DefaultDueIn. -(In the database, DefaultDueIn is stored as int(11).) +=cut -=item SetDefaultDueIn VALUE +sub DeleteWatcher { + my $self = shift; + my $id = shift; + + my $type; + + $type = shift if (@_); + + + require RT::Watcher; + my $Watcher = new RT::Watcher($self->CurrentUser); + + #If it\'s a numeric watcherid + if ($id =~ /^(\d*)$/) { + $Watcher->Load($id); + } + + #Otherwise, we'll assume it's an email address + elsif ($type) { + my ($result, $msg) = + $Watcher->LoadByValue( Email => $id, + Scope => 'Queue', + Value => $self->id, + Type => $type); + return (0,$msg) unless ($result); + } + + else { + return(0,"Can\'t delete a watcher by email address without specifying a type"); + } + + # {{{ Check ACLS + + #If the watcher we're trying to delete is for the current user + if ($Watcher->Email eq $self->CurrentUser->EmailAddress) { + + # If it's an AdminCc and they don't have + # 'WatchAsAdminCc' or 'ModifyQueueWatchers', bail + if ($Watcher->Type eq 'AdminCc') { + unless ($self->CurrentUserHasRight('ModifyQueueWatchers') or + $self->CurrentUserHasRight('WatchAsAdminCc')) { + return(0, 'Permission Denied'); + } + } + + # If it's a Cc and they don't have + # 'Watch' or 'ModifyQueueWatchers', bail + elsif ($Watcher->Type eq 'Cc') { + unless ($self->CurrentUserHasRight('ModifyQueueWatchers') or + $self->CurrentUserHasRight('Watch')) { + return(0, 'Permission Denied'); + } + } + else { + $RT::Logger->warn("$self -> DeleteWatcher hit code". + " it never should. We got passed ". + " a type of ". $args{'Type'}); + return (0,'Error in parameters to $self DeleteWatcher'); + } + } + # If the watcher isn't the current user + # and the current user doesn't have 'ModifyQueueWatchers' + # bail + else { + unless ($self->CurrentUserHasRight('ModifyQueueWatchers')) { + return (0, "Permission Denied"); + } + } + + # }}} + + unless (($Watcher->Scope eq 'Queue') and + ($Watcher->Value == $self->id) ) { + return (0, "Not a watcher for this queue"); + } + + + #Clear out the watchers hash. + $self->{'watchers'} = undef; + + my $retval = $Watcher->Delete(); + + unless ($retval) { + return(0,"Watcher could not be deleted."); + } + + return(1, "Watcher deleted"); +} + +# {{{ sub DeleteCc +=head2 DeleteCc EMAIL -Set DefaultDueIn to VALUE. -Returns (1, 'Status message') on success and (0, 'Error Message') on failure. -(In the database, DefaultDueIn will be stored as a int(11).) +Takes an email address. It calls DeleteWatcher with a preset +type of 'Cc' =cut +sub DeleteCc { + my $self = shift; + my $id = shift; + return ($self->DeleteWatcher ($id, 'Cc')) +} + +# }}} -=item Creator +# {{{ sub DeleteAdminCc -Returns the current value of Creator. -(In the database, Creator is stored as int(11).) +=head2 DeleteAdminCc EMAIL + +Takes an email address. It calls DeleteWatcher with a preset +type of 'AdminCc' =cut +sub DeleteAdminCc { + my $self = shift; + my $id = shift; + return ($self->DeleteWatcher ($id, 'AdminCc')) +} -=item Created +# }}} -Returns the current value of Created. -(In the database, Created is stored as datetime.) +# }}} + +# }}} + +# {{{ Dealing with keyword selects + +# {{{ sub AddKeywordSelect + +=head2 AddKeywordSelect + +Takes a paramhash of Name, Keyword, Depth and Single. Adds a new KeywordSelect for +this queue with those attributes. =cut -=item LastUpdatedBy +sub AddKeywordSelect { + my $self = shift; + my %args = ( Keyword => undef, + Depth => undef, + Single => undef, + Name => undef, + @_); + + #ACLS get handled in KeywordSelect + my $NewKeywordSelect = new RT::KeywordSelect($self->CurrentUser); + + return ($NewKeywordSelect->Create (Keyword => $args{'Keyword'}, + Depth => $args{'Depth'}, + Name => $args{'Name'}, + Single => $args{'Single'}, + ObjectType => 'Ticket', + ObjectField => 'Queue', + ObjectValue => $self->Id() + ) ); +} + +# }}} + +# {{{ sub KeywordSelect -Returns the current value of LastUpdatedBy. -(In the database, LastUpdatedBy is stored as int(11).) +=head2 KeywordSelect([NAME]) +Takes the name of a keyword select for this queue or that's global. +Returns the relevant KeywordSelect object. Prefers a keywordselect that's +specific to this queue over a global one. If it can't find the proper +Keword select or the user doesn't have permission, returns an empty +KeywordSelect object =cut +sub KeywordSelect { + my $self = shift; + my $name = shift; + + require RT::KeywordSelect; + + my $select = RT::KeywordSelect->new($self->CurrentUser); + if ($self->CurrentUserHasRight('SeeQueue')) { + $select->LoadByName( Name => $name, Queue => $self->Id); + } + return ($select); +} + -=item LastUpdated +# }}} -Returns the current value of LastUpdated. -(In the database, LastUpdated is stored as datetime.) +# {{{ sub KeywordSelects +=head2 KeywordSelects + +Returns an B<RT::KeywordSelects> object containing the collection of +B<RT::KeywordSelect> objects which apply to this queue. (Both queue specific keyword selects +and global keyword selects. =cut +sub KeywordSelects { + my $self = shift; -=item Disabled -Returns the current value of Disabled. -(In the database, Disabled is stored as smallint(6).) + use RT::KeywordSelects; + my $KeywordSelects = new RT::KeywordSelects($self->CurrentUser); + if ($self->CurrentUserHasRight('SeeQueue')) { + $KeywordSelects->LimitToQueue($self->id); + $KeywordSelects->IncludeGlobals(); + } + return ($KeywordSelects); +} +# }}} +# }}} -=item SetDisabled VALUE +# {{{ ACCESS CONTROL +# {{{ sub ACL -Set Disabled to VALUE. -Returns (1, 'Status message') on success and (0, 'Error Message') on failure. -(In the database, Disabled will be stored as a smallint(6).) +=head2 ACL +#Returns an RT::ACL object of ACEs everyone who has anything to do with this queue. =cut +sub ACL { + my $self = shift; + + use RT::ACL; + my $acl = new RT::ACL($self->CurrentUser); + + if ($self->CurrentUserHasRight('ShowACL')) { + $acl->LimitToQueue($self->Id); + } + + return ($acl); +} + +# }}} + +# {{{ sub _Set +sub _Set { + my $self = shift; + unless ($self->CurrentUserHasRight('AdminQueue')) { + return(0, 'Permission Denied'); + } + return ($self->SUPER::_Set(@_)); +} +# }}} -sub _ClassAccessible { - { - - id => - {read => 1, type => 'int(11)', default => ''}, - Name => - {read => 1, write => 1, type => 'varchar(200)', default => ''}, - Description => - {read => 1, write => 1, type => 'varchar(255)', default => ''}, - CorrespondAddress => - {read => 1, write => 1, type => 'varchar(120)', default => ''}, - CommentAddress => - {read => 1, write => 1, type => 'varchar(120)', default => ''}, - InitialPriority => - {read => 1, write => 1, type => 'int(11)', default => '0'}, - FinalPriority => - {read => 1, write => 1, type => 'int(11)', default => '0'}, - DefaultDueIn => - {read => 1, write => 1, type => 'int(11)', default => '0'}, - Creator => - {read => 1, auto => 1, type => 'int(11)', default => '0'}, - Created => - {read => 1, auto => 1, type => 'datetime', default => ''}, - LastUpdatedBy => - {read => 1, auto => 1, type => 'int(11)', default => '0'}, - LastUpdated => - {read => 1, auto => 1, type => 'datetime', default => ''}, - Disabled => - {read => 1, write => 1, type => 'smallint(6)', default => '0'}, +# {{{ sub _Value - } -}; +sub _Value { + my $self = shift; + unless ($self->CurrentUserHasRight('SeeQueue')) { + return (undef); + } - eval "require RT::Queue_Overlay"; - if ($@ && $@ !~ qr{^Can't locate RT/Queue_Overlay.pm}) { - die $@; - }; + return ($self->__Value(@_)); +} - eval "require RT::Queue_Vendor"; - if ($@ && $@ !~ qr{^Can't locate RT/Queue_Vendor.pm}) { - die $@; - }; +# }}} - eval "require RT::Queue_Local"; - if ($@ && $@ !~ qr{^Can't locate RT/Queue_Local.pm}) { - die $@; - }; +# {{{ sub CurrentUserHasRight +=head2 CurrentUserHasRight +Takes one argument. A textual string with the name of the right we want to check. +Returns true if the current user has that right for this queue. +Returns undef otherwise. +=cut -=head1 SEE ALSO +sub CurrentUserHasRight { + my $self = shift; + my $right = shift; -This class allows "overlay" methods to be placed -into the following files _Overlay is for a System overlay by the original author, -_Vendor is for 3rd-party vendor add-ons, while _Local is for site-local customizations. + return ($self->HasRight( Principal=> $self->CurrentUser, + Right => "$right")); -These overlay files can contain new subs or subs to replace existing subs in this module. +} -If you'll be working with perl 5.6.0 or greater, each of these files should begin with the line +# }}} - no warnings qw(redefine); +# {{{ sub HasRight -so that perl does not kick and scream when you redefine a subroutine or variable in your overlay. +=head2 HasRight -RT::Queue_Overlay, RT::Queue_Vendor, RT::Queue_Local +Takes a param hash with the fields 'Right' and 'Principal'. +Principal defaults to the current user. +Returns true if the principal has that right for this queue. +Returns undef otherwise. =cut +# TAKES: Right and optional "Principal" which defaults to the current user +sub HasRight { + my $self = shift; + my %args = ( Right => undef, + Principal => $self->CurrentUser, + @_); + unless(defined $args{'Principal'}) { + $RT::Logger->debug("Principal undefined in Queue::HasRight"); + + } + return($args{'Principal'}->HasQueueRight(QueueObj => $self, + Right => $args{'Right'})); +} +# }}} + +# }}} 1; |