[solved] Variable in admin that reveals user group?

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
Cerulean
Forum Members
Forum Members
Posts: 172
Joined: Mon Nov 01, 2010 8:56 am
Location: New Zealand

[solved] Variable in admin that reveals user group?

Post 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.
Last edited by Cerulean on Thu Oct 02, 2014 1:35 am, edited 1 time in total.
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Location: Maidenhead, UK
Contact:

Re: Variable in admin that reveals user group?

Post 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}
Cerulean
Forum Members
Forum Members
Posts: 172
Joined: Mon Nov 01, 2010 8:56 am
Location: New Zealand

Re: Variable in admin that reveals user group?

Post 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.
User avatar
paulbaker
Dev Team Member
Dev Team Member
Posts: 1465
Joined: Sat Apr 18, 2009 10:09 pm
Location: Maidenhead, UK
Contact:

Re: Variable in admin that reveals user group?

Post by paulbaker »

Ah, sorry I misunderstood. I don't know how to show back end group.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1922
Joined: Mon Jan 29, 2007 4:47 pm

Re: Variable in admin that reveals user group?

Post 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.
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
Cerulean
Forum Members
Forum Members
Posts: 172
Joined: Mon Nov 01, 2010 8:56 am
Location: New Zealand

Re: Variable in admin that reveals user group?

Post 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.)
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Variable in admin that reveals user group?

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Cerulean
Forum Members
Forum Members
Posts: 172
Joined: Mon Nov 01, 2010 8:56 am
Location: New Zealand

Re: Variable in admin that reveals user group?

Post 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.
Post Reply

Return to “CMSMS Core”