TestGroupMembership

From Request Tracker Wiki
Jump to navigation Jump to search

If you want to test for group membership, you can do it the following way:

my $GroupObj = RT::Group->new($user);
$GroupObj->LoadUserDefinedGroup( 'IT Staff' );
my $PrincipalObj = RT::Principal->new($user);
$PrincipalObj->Load($user->id);
my $prinid = $user->PrincipalId;
print $user->Name . "\n";                  #Note: These are debugs
print $GroupObj->Name . "\n";              #Remove them from production
print $PrincipalObj->PrincipalType . "\n"; #
if ($GroupObj->HasMemberRecursively($PrincipalObj)) {
  do_stuff(); #Fill in with work to do
}