Page 1 of 1

Cheking if a user is in a specific group

PostPosted: Fri Apr 28, 2006 6:59 am
by amason
Hi,

Couldn't find this mentioned anywhere in the forum... probably too easy ;)

I want to make a method that checks if the current user is in a specific group.

for example:

function checkGroup(GroupName){
if current user is in GroupName, return true;
}

how would I do that?

THanks,

Andrew

PostPosted: Fri Apr 28, 2006 10:33 am
by automazione
While the Servoy dev-team 8) does not add a new function... this one may work for you:

Code: Select all
var group_id   = security.getGroupId(arguments[0]) ; // the id of the group name passed as parameter
var user_groups = security.getUserGroups(); // all the groups associated to the current user
for ( var i = 1 ; i <= user_groups.getMaxRowIndex() ; i++ )
{
   if (group_id  == user_groups.getValue(i,1)) return true;
}
return false;


just call it passing a text var containing the group name to check