Magento - How to query admin's role name?


Question

I am trying to get the name of the role of the currently logged in admin. I can get the admin user, but I can't figure out how to query their role name. The Magento docs are weak =/

$usr = Mage::getSingleton('admin/session')->getUser();

Ideas anyone?

1
6
1/7/2010 11:48:47 PM

Accepted Answer

Spoke too soon... I got the role name as follows:

$roleId = implode('', Mage::getSingleton('admin/session')->getUser()->getRoles());
$roleName = Mage::getModel('admin/roles')->load($roleId)->getRoleName();
7
1/7/2010 11:56:22 PM

Here's another one that may be a little friendlier:

$acl = Mage::getResourceModel('admin/acl')->loadAcl();
$acl->isAllowed($user->getAclRole(), 'admin/foo/bar'));

That will return a boolean. $user is an admin/user object.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon