Admin Role – How to List All Admins of a Specific Role

adminrole

How can I retrieve the list of all admin that has the same role?

For example, I create a new role called "Seller" and assign some admin users to that role.

How to list all admin users with the role "Seller"?

Thank you very much

Best Answer

To get all the Roles

   $roles = Mage::getModel('admin/roles')->getCollection();
   foreach($roles as $role):
      echo '<br/>Role : '.$role->getId()." | ".$role->getRoleName();
   endforeach;

To get the Role users

  $roles_users = Mage::getResourceModel('admin/roles_user_collection');
  foreach($roles_users as $roleuser):
   $user = Mage::getModel('admin/user')->load($roleuser->getUserId());
   echo '<br/>User : '.$user->getUsername()." | ".$user->getFirstname();
  endforeach;

Or in your database you can check in the table admin_role which role you want to check, for example id=1 is my administrator and then with the query

select * from admin_role where parent_id='1' 

You get all users with the Administrator role. And I have customer service with id=2 so the query would be

select * from admin_role where parent_id='2'

Which gives me all users with the role customer service and so on...

Related Topic