TestGroupMembership

From Request Tracker Wiki
Revision as of 15:39, 6 April 2016 by Admin (talk | contribs) (2 revisions imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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
}