Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No throw when Mage_Admin_Model_User::delete fails #950

Closed
midlan opened this issue May 5, 2020 · 6 comments · Fixed by #1257
Closed

No throw when Mage_Admin_Model_User::delete fails #950

midlan opened this issue May 5, 2020 · 6 comments · Fixed by #1257
Labels
backwards compatibility Might affect backwards compatibility for some users bug confirmed

Comments

@midlan
Copy link
Contributor

midlan commented May 5, 2020

https://github.com/OpenMage/magento-lts/blob/1.9.4.x/app/code/core/Mage/Admin/Model/Resource/User.php#L219

inside this catch is not thrown any error, so user is not deleted and you get green message:

The user has been deleted.

But the user still remains in database and also can login. It return false but the return value is ignored in controller: \Mage_Adminhtml_Permissions_UserController::deleteAction

It is bug or it is there for some purpose?

@Sekiphp
Copy link
Contributor

Sekiphp commented May 5, 2020

@midlan In my opinion this is bug, because is ignored returned value from delete method on admin/user model.

I suggest that there should be (at least):

Use return value of model here https://github.com/OpenMage/magento-lts/blob/1.9.4.x/app/code/core/Mage/Adminhtml/controllers/Permissions/UserController.php#L187

            try {
                $model = Mage::getModel('admin/user');
                $model->setId($id);
                if ($model->delete()) {
                      Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The user has been deleted.'));
                }
                else {
                      Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Deleting of user was terminated!'));
                }
                $this->_redirect('*/*/');
                return;
            }
            catch (Exception $e) {
                Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
                $this->_redirect('*/*/edit', array('user_id' => $this->getRequest()->getParam('user_id')));
                return;
            }

Log exception which is lost here https://github.com/OpenMage/magento-lts/blob/1.9.4.x/app/code/core/Mage/Admin/Model/Resource/User.php#L209:

        try {
            $conditions = array(
                'user_id = ?' => $uid
            );

            $adapter->delete($this->getMainTable(), $conditions);
            $adapter->delete($this->getTable('admin/role'), $conditions);
            $adapter->commit();
        } catch (Mage_Core_Exception $e) {
            $adapter->rollBack();
            throw $e;
        } catch (Exception $e) {
            Mage::logException($e);
            $adapter->rollBack();
            return false;
        }

@colinmollenhour
Copy link
Member

I think instead of returning false on that second to last line of User.php the exception should simply be rethrown (throw $e;). This is the common pattern throughout Magento. The error message "Deleting of user was terminated!" doesn't help the user at all or even make sense so should just be removed and the return value not checked at all.

@midlan
Copy link
Contributor Author

midlan commented May 6, 2020

@colinmollenhour
I agree. But what about backcompatibility? Someone may rely on the return value and only catching exceptions of type Mage_Core_Exception .

@colinmollenhour
Copy link
Member

It should be noted then as a BC change. We are still working out exactly how to deal with BC changes, though...

@colinmollenhour colinmollenhour added backwards compatibility Might affect backwards compatibility for some users bug labels May 7, 2020
@addison74 addison74 added bug confirmed and removed bug backwards compatibility Might affect backwards compatibility for some users labels Jun 1, 2022
@elidrissidev elidrissidev added the backwards compatibility Might affect backwards compatibility for some users label Oct 11, 2022
@elidrissidev
Copy link
Member

Closing as fixed.

@addison74
Copy link
Contributor

Today, for the first time, the number of reported issues is equal to the number of open PRs. 135 :))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backwards compatibility Might affect backwards compatibility for some users bug confirmed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants