0

I have a problem on my Magento webiste and I can't figure why is this happened.

I have 2 admin roles: administrator and shopmanager. Administrator role has all the permissions and shopmanager has custom permissions. There are two users registered, one is administrator_user and the other is shopmanager_user.

When I edit the shopmanager role (give more permissions or delete some permissions) the role of the shopmanager_user is automatically unchecked, and there is no role checked for this user, therefore shopmanager_user can't login until the administrator will check the user role again.

Did anyone has this problem because I don't know where to look? Can you help me with this please?

1 Answer 1

0

So after searching and searching on Google and debugging my code, I found where is the problem but I don't know exactly why is the problem. When permission role is edited in RoleController in saveRoleAction() method all the users all deleted from the role and then are again added, the code is:

foreach($oldRoleUsers as $oUid) {
    $this->_deleteUserFromRole($oUid, $role->getId());
}

foreach ($roleUsers as $nRuid) {
    $this->_addUserToRole($nRuid, $role->getId());
}

So the user is deleted but in the _addUserToRole() method

protected function _addUserToRole(){
    $user = Mage::getModel('admin/user')->load($userId);
    $user->setRoleId($roleId)->setUserId($userId);

    if( $user->roleUserExists() === true ) {
        return false;
    } else {
        $user->add();
        return true;
    }
}

the roleUserExists() returns true, so the user isn't added again. I couldn't find why this method returns true, because the role is deleted from admin_role table, so I changed _addUserToRole() method code like this:

protected function _addUserToRole(){
    $user = Mage::getModel('admin/user')->load($userId);
    $user->setRoleId($roleId)->setUserId($userId);

    $user->add();
    return true;
}

and now everything work fine and user role doesn't uncheck anymore. I know this is not the best way to do it but it works fine for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.