- Posts: 31
- Thank you received: 5
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
How can I access user roles from my plugin?
- mhladun
- Topic Author
- Offline
- Junior Member
There doesn't appear to be a getUserRole method here , so I decided to use getUserGroups instead, but that doesn't give me a list of users in a user group - user group objects only have the group's ugid, name, description, and owner id.
Please Log in to join the conversation.
- mhladun
- Topic Author
- Offline
- Junior Member
- Posts: 31
- Thank you received: 5
It would be nice to achieve this with an API call likeprivate function getUserGroupAttributeByUserGroupName($user_group_name, $attribute)
{
foreach ($this->api->getUserGroups() as $i => $group){
if($group === $user_group_name){
return $group[$attribute];
}
}
return NULL;
}
// survey level settings for plugin
public function beforeSurveySettings()
{
$current_user_uid = $this->api->getCurrentUser();
$admin_ugid = $this->getUserGroupAttributeByUserGroupName('Admin', 'ugid');
$user_is_admin = $this->api->getUserInGroup($admin_ugid, $current_user_uid);
$admin_group_owner_id = $this->getUserGroupAttributeByUserGroupName('Admin', 'owner_id');
if(!is_null($user_is_admin) || $current_user_uid == $admin_group_owner_id){
// Only these users can access this block:
// - users in Admin user group
// - Admin user group owner
}
}
if( in_array('Admin', $this->api->getUserRoles($current_user_id)) ) { // code here }
Please Log in to join the conversation.
- DenisChenu
- Offline
- LimeSurvey Community Team
- Posts: 13642
- Thank you received: 2491
Sincerely,It would be nice to achieve this with an API call like
Code:if( in_array('Admin', $this->api->getUserRoles($current_user_id)) ) { // code here }
If i have to create API function for all usage i have : i didn't have a lot of plugin.
Else : feature + pull request are welcome.
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Please Log in to join the conversation.