-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Admin user auth controller refactor #16560
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
Admin user auth controller refactor #16560
Conversation
Hi @AnshuMishra17. Thank you for your contribution
For more details, please, review the Magento Contributor Assistant documentation |
/** | ||
* @var \Magento\Backend\Helper\Data | ||
*/ | ||
protected $_backendHelper; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is actually a backendDataHelper
. The Backend\Helper
namespace has more Helper
classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
*/ | ||
public function __construct( | ||
\Magento\Backend\App\Action\Context $context, | ||
\Magento\User\Model\UserFactory $userFactory | ||
\Magento\User\Model\UserFactory $userFactory, | ||
\Magento\Backend\Helper\Data $backendHelper = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you could do the PR on 2.3-develop
instead for the refactoring. Than you can remove the = null
part and you don't need the if statement on line 42 and 43.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do a forwardport for 2.3-develop.
@@ -6,6 +6,7 @@ | |||
namespace Magento\User\Controller\Adminhtml; | |||
|
|||
use Magento\Framework\Encryption\Helper\Security; | |||
use Magento\Framework\App\ObjectManager; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you are refactoring, please add import statement for all used classes in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Please also do the ones on line 24 and 29.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -7,26 +7,38 @@ | |||
namespace Magento\User\Controller\Adminhtml\Auth; | |||
|
|||
use Magento\Security\Model\SecurityManager; | |||
use Magento\Framework\App\ObjectManager; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please import all used classes in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
*/ | ||
public function __construct( | ||
\Magento\Backend\App\Action\Context $context, | ||
\Magento\User\Model\UserFactory $userFactory, | ||
\Magento\Security\Model\SecurityManager $securityManager | ||
\Magento\Security\Model\SecurityManager $securityManager, | ||
\Magento\User\Model\ResourceModel\User\CollectionFactory $userCollectionFactory = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you could do the PR on 2.3-develop instead for the refactoring. Than you can remove the = null part and you don't need the if statement on line 40 and 41.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do a forwardport for 2.3-develop.
@@ -54,7 +66,7 @@ public function execute() | |||
$this->messageManager->addErrorMessage($exception->getMessage()); | |||
return $resultRedirect->setPath('admin'); | |||
} | |||
$collection = $this->_objectManager->get(\Magento\User\Model\ResourceModel\User\Collection::class); | |||
$collection = $this->userCollectionFactory->create(); | |||
/** @var $collection \Magento\User\Model\ResourceModel\User\Collection */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch line 69 and 70
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
use Magento\Framework\App\ObjectManager; | ||
use Magento\Backend\App\Action\Context; | ||
use Magento\User\Model\UserFactory; | ||
use Magento\Security\Model\SecurityManager; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This specific one is now imported twice. Please fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@AnshuMishra17 could you make the PR to 2.3-develop, than you could make it backwards-incompatible and remove the ObjectManager |
\Magento\User\Model\UserFactory $userFactory | ||
Context $context, | ||
UserFactory $userFactory, | ||
Data $backendDataHelper = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do PR on 2.3-develop and remove the =null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part was done correctly, no need to introduce backward incompatible changes if possible
) { | ||
parent::__construct($context); | ||
$this->_userFactory = $userFactory; | ||
$this->_backendDataHelper = $backendDataHelper ?: ObjectManager::getInstance()->get(Data::class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do PR on 2.3-develop and remove the ?: ObjectManager::getInstance()->get(Data::class);
part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part was done correctly, no need to introduce backward incompatible changes if possible
Context $context, | ||
UserFactory $userFactory, | ||
SecurityManager $securityManager, | ||
CollectionFactory $userCollectionFactory = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do PR on 2.3-develop and remove the =null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part was done correctly, no need to introduce backward incompatible changes if possible
) { | ||
parent::__construct($context, $userFactory); | ||
$this->securityManager = $securityManager; | ||
$this->userCollectionFactory = $userCollectionFactory ?: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do PR on 2.3-develop and remove the ?: ObjectManager::getInstance()->get(Data::class);
part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part was done correctly, no need to introduce backward incompatible changes if possible
How can I make backward incompatible? |
@arnoudhgz Second option seems to be better. But I am not aware of how to fetch/pull 2.3-develop. I would be nice and helpful if you can share correct steps. |
@AnshuMishra17 You created a local branch from 2.2-develop, right?
|
\Magento\User\Model\UserFactory $userFactory | ||
Context $context, | ||
UserFactory $userFactory, | ||
Data $backendDataHelper = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part was done correctly, no need to introduce backward incompatible changes if possible
) { | ||
parent::__construct($context); | ||
$this->_userFactory = $userFactory; | ||
$this->_backendDataHelper = $backendDataHelper ?: ObjectManager::getInstance()->get(Data::class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part was done correctly, no need to introduce backward incompatible changes if possible
Context $context, | ||
UserFactory $userFactory, | ||
SecurityManager $securityManager, | ||
CollectionFactory $userCollectionFactory = null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part was done correctly, no need to introduce backward incompatible changes if possible
) { | ||
parent::__construct($context, $userFactory); | ||
$this->securityManager = $securityManager; | ||
$this->userCollectionFactory = $userCollectionFactory ?: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part was done correctly, no need to introduce backward incompatible changes if possible
/** | ||
* @var Data | ||
*/ | ||
protected $_backendDataHelper; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please make this variable private and remove underscore
@AnshuMishra17 my apologies, I thought you shouldn't use the ObjectManager anymore like this. Please let @ihor-sviziev help you out with this PR. Thanks @ihor-sviziev I learned something today too. |
Hi @ihor-sviziev, thank you for the review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
Intregration tests failed and DI compile also failed. Please try to fix them
Hi @ihor-sviziev, thank you for the review. |
Hi @AnshuMishra17. Thank you for your contribution. Please, consider to port this solution to 2.3 release line. |
Description
Refactor the code by removing the direct use of ObjectManager and includes the dependencies using Constructor Dependency Injection
Manual testing scenarios