Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento: get roles and users

How can I get collection of all roles (System->Permission->Roles) and users which has this role?

Thanks.

like image 873
Alex Avatar asked Mar 04 '13 11:03

Alex


People also ask

What are default rest roles that can be used in Magento?

REST Roles grid is shown with two user types by default: Customer Guest Let's say, for example, that we are going to use the Magento REST service for updating Products and Customers, and we need Admin permissions for that. We don't want to enable neither Guest or Customer user to be able to do that.


1 Answers

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;
like image 139
Haijerome Avatar answered Sep 28 '22 17:09

Haijerome