Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento: How to get user role from user id

Tags:

magento

I am building a custom admin extension, I need to find a user's role having it's ID, any way to do this, I've been trying to find where does magento store the info on what users are what role with no luck so far. Any help would be very appreciated.

like image 513
changeling Avatar asked Mar 20 '12 22:03

changeling


2 Answers

Assuming you're talking about the users who log into the admin console, this should get you what you want.

//By ID
$id = 2;
$role_data = Mage::getModel('admin/user')->load($id)->getRole()->getData();
var_dump($role_data);

//By Username
$username = 'admin';
$role_data = Mage::getModel('admin/user')->getCollection()->addFieldToFilter('username',$username)->getFirstItem()->getRole()->getData();
var_dump($role_data);
like image 131
Alan Storm Avatar answered Nov 23 '22 17:11

Alan Storm


Using this code you will get the role of current user

$admin_user_session = Mage::getSingleton('admin/session');
$adminuserId = $admin_user_session->getUser()->getUserId();
$role_data = Mage::getModel('admin/user')->load($adminuserId)->getRole()->getData();
$role_name = $role_data['role_name'];
like image 41
user2753425 Avatar answered Nov 23 '22 19:11

user2753425