TestGroupMembership: Difference between revisions

From Request Tracker Wiki
Jump to navigation Jump to search
m (2 revisions imported)
 
(No difference)

Latest revision as of 15:39, 6 April 2016

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
}