Page 1 of 1

[solved] Variable in admin that reveals user group?

Posted: Wed Oct 01, 2014 12:28 am
by Cerulean
Is there a variable available in the CMSMS admin that reveals the Group that a logged in User belongs to? I've examined the $user object which contains several pieces of information about the logged in user, but not the group it seems.

In my custom admin theme I'd like to include a CSS file based on whether or not the user is in the "Editor" group, so I need to test for the user's group.

Re: Variable in admin that reveals user group?

Posted: Wed Oct 01, 2014 9:33 am
by paulbaker
memberof? I have this in the template of a working site:

Code: Select all

{if $ccuser->loggedin() AND !$ccuser->memberof('members') AND !$ccuser->memberof('members-hr') AND $position >= 2}

Re: Variable in admin that reveals user group?

Posted: Wed Oct 01, 2014 10:05 am
by Cerulean
Thanks, but your code is for frontend users and I'm talking about backend (admin) users.

I'm looking for a way to test what Group an admin User belongs to, as per the "Users & Groups" section of the CMSMS admin. The test will occur in the template for my custom admin theme.

Re: Variable in admin that reveals user group?

Posted: Wed Oct 01, 2014 10:13 am
by paulbaker
Ah, sorry I misunderstood. I don't know how to show back end group.

Re: Variable in admin that reveals user group?

Posted: Wed Oct 01, 2014 12:24 pm
by Jo Morg
Cerulean wrote:Is there a variable available in the CMSMS admin that reveals the Group that a logged in User belongs to?
Not that I know of, as admin templates check for specific permissions that should be common to all admin templates. That is a different mechanism than the one you are looking for. You will probably be able to compute the group the current logged in user belongs by using CMSMS API, eventually by using UserOperations.

Re: Variable in admin that reveals user group?

Posted: Thu Oct 02, 2014 12:24 am
by Cerulean
using @print_r on $theme reveals:

Code: Select all

[_perms:CmsAdminThemeBase:private] => Array
        (
            [htmlPerms] => 0
            [pagePerms] => 1
            [contentPerms] => 1
            [templatePerms] => 0
            [cssPerms] => 0
            [cssAssocPerms] => 0
            [layoutPerms] => 0
            [filePerms] => 1
            [userPerms] => 0
            [groupPerms] => 0
            [groupPermPerms] => 
            [groupMemberPerms] => 
            [usersGroupsPerms] => 0
            [sitePrefPerms] => 0
            [adminPerms] => 0
            [siteAdminPerms] => 0
            [codeBlockPerms] => 
            [modulePerms] => 
            [eventPerms] => 
            [taghelpPerms] => 
            [extensionsPerms] => 0
        )
Am I able to access any of these permissions settings in my admin template? (I could use one of the permission settings to derive the user's group by making sure the setting was unique to the group.)

Re: Variable in admin that reveals user group?

Posted: Thu Oct 02, 2014 1:04 am
by calguy1000
You are NOT able to access any of the private members of the theme object.
You CAN however use the CMSMS API functions to determine what groupS (multiple) the currently logged in user is a member of.

Take a look at the UserOperations class in the API docs.
Keep in mind that the 'Editor' group is merely a group created on install. That group can be deleted or renamed, and re-created

Therefore, in anything but a special purpose admin theme for a special site you really cannot rely on a group id or its name.

Therefore, doing special things for special groups (considering you cannot guarantee that there is an 'Editor' group, or that the group with editor privilege is group 2, and because any admin user can belong to one or more groups) is generally a bad idea.

Re: Variable in admin that reveals user group?

Posted: Thu Oct 02, 2014 1:30 am
by Cerulean
Thanks Calguy, I was just on the verge of figuring that out by myself... :)

I understand what you're saying about it not being a very robust solution because the group ID can change and multiple group assignments are possible, but on all my sites I am the only admin with permissions to create users or assign groups, and I always assign my users to the Editor group.

My solution:
In my custom admin theme PHP...

Code: Select all

$smarty->assign('is_editor', $userops->UserInGroup(get_userid(), 2)); // "2" is the default group id for the Editor group
...and in pagetemplate.tpl...

Code: Select all

{if !empty($is_editor)}
...stuff that is just for users in the Editor group...
{/if}
In my case, I am using jQuery to hide links to the (godawful) Image Manager from editors while still allowing them the Modify Files permission so they can create folders, etc, via TinyMCE.