[Rt-devel] scrip check group membership of Requestor not CurrentUser

Dale L Bewley dlbewley at ucdavis.edu
Sun Feb 26 13:38:44 EST 2006


After much poking and prodding, I have a working scrip now. I would 
appreciate if anyone pointed out blatant inefficiencies in how I'm doing 
this. Any other comments are also welcome.

I'll contribute this to the Wiki once it shakes out a bit.

BTW, I found that my custom condition code is ignored, so I have to 
replicate it in the action portion. Any idea why?

I'm on rt-3.4.5.


Problem:
--------
Department heads want to see and comment on all tickets 
emminating from their staff.

Solution:
---------
All tickets have a Department custom field mapping the ticket to a dept.
I globally grant the Cc role ShowTicket and ReplyToTicket permission and 
then add the department head as Cc on their staff's tickets. This way they can 
add comments and be aware of issues in their department. I do not yet wish 
to give them powers such as ModifyTicket, so they can't monkey with 
priorities etc.  Therefore, I felt Cc more appropriate than AdminCc even 
after granting extra rights to Cc.

Scrip follows:
--------------
* Description: ''OnCreateSetDeptHeadCc''
* Condition: ''On Create''
* Action: ''User Defined''
* Template: ''Global template: Blank''
* Stage: ''TransactionCreate''

* Custom Condition:

Actually, I have discovered that this is not working. So, you should
instead put this in the preparation code portion. (without the return 1;
of course)

  # make sure we are called from a on create condition and
  # make sure department is filled out
  return undef unless (
         ($self->TransactionObj->Type eq "Create") &&
         ($self->TicketObj->FirstCustomFieldValue('Department')) &&
         ($self->TicketObj->FirstCustomFieldValue('Department') ne 'None')
         );

  return 1;

* Custom action preparation code:

  # example: for 'Systems' the group is 'Head Systems'
  my $derivedGroupName = 'Head ' .
      $self->TicketObj->FirstCustomFieldValue('Department');

  # instantiated a group object
  my $groupObj = RT::Group->new($RT::SystemUser);
  $groupObj->LoadUserDefinedGroup($derivedGroupName);
  return undef unless $groupObj;

  # one doesn't want to be a requestor and a Cc on the same ticket.
  # don't add group as CC if requestor is in that group.
  # this could certainly be a problem if there are multiple members
  my $requestorsGroupObj = $self->TicketObj->Requestors;
  # UMO grabs group members in subgroups too. it is recursive
  my $requestorsMembersObj = $requestorsGroupObj->UserMembersObj;

  my $userObj;
  while ($userObj = $requestorsMembersObj->Next) {
      if ($groupObj->HasMember($userObj->PrincipalObj)) {
          $RT::Logger->info("Requestor '" . $userObj->Name .
              "' is in group '$derivedGroupName' not adding Cc on ticket #" .
              $self->TicketObj->id );

          return undef;
      }
  }

  # add group as Cc on ticket. see Ticket_Overlay.pm
  $RT::Logger->info("Add group '$derivedGroupName' as Cc on ticket #" .
      $self->TicketObj->id );
  my ($success, $msg)= $self->TicketObj->AddWatcher(
                               Type => "Cc",
                               PrincipalId => $groupObj->PrincipalId);

  if (! $success) {
   $RT::Logger->info($msg);
   return undef;
  } else {
   return 1;
  }

* Custom action cleanup code:

  # blank



-- 
Dale Bewley - dlbewley a/t lib.ucdavis.edu
Unix Administrator - Shields Library UC Davis


More information about the Rt-devel mailing list