-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