From 8be4c90104d5025a27b66440f9718799ca05240c Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Tue, 28 Apr 2020 19:31:19 +0300 Subject: [PATCH 1/4] LAC-27: Log admin actions with Login as Customer. --- .../Api/Data/LogInterface.php | 208 +++++++++++++++++ .../Api/Data/LogSearchResultsInterface.php | 28 +++ .../Api/GetLogsListInterface.php | 23 ++ .../Block/Adminhtml/Login.php | 27 --- .../Controller/Adminhtml/Log/Index.php | 34 +++ .../Controller/Adminhtml/Login/Grid.php | 36 --- .../Controller/Adminhtml/Login/Index.php | 51 ----- .../LoginAsCustomerLog/Model/GetLogList.php | 80 +++++++ .../Magento/LoginAsCustomerLog/Model/Log.php | 215 ++++++++++++++++++ .../Model/LogSearchResults.php | 18 ++ .../LoginAsCustomerLog/Model/Login.php | 22 -- .../Model/ResourceModel/Log.php | 27 +++ .../Model/ResourceModel/Log/Collection.php | 26 +++ .../Model/ResourceModel/Login.php | 22 -- .../Model/ResourceModel/Login/Collection.php | 26 --- .../ResourceModel/Login/Grid/Collection.php | 44 ---- .../Ui/DataProvider/LogDataProvider.php | 90 ++++++++ .../LoginAsCustomerLog/etc/adminhtml/menu.xml | 2 +- .../etc/adminhtml/routes.xml | 2 +- .../LoginAsCustomerLog/etc/db_schema.xml | 28 +++ .../etc/db_schema_whitelist.json | 23 ++ .../Magento/LoginAsCustomerLog/etc/di.xml | 12 + ....xml => loginascustomer_log_log_index.xml} | 4 +- .../layout/loginascustomer_login_grid.xml | 14 -- .../loginascustomer_login_grid_block.xml | 66 ------ .../login_as_customer_log_listing.xml | 69 ++++++ 26 files changed, 884 insertions(+), 313 deletions(-) create mode 100644 app/code/Magento/LoginAsCustomerLog/Api/Data/LogInterface.php create mode 100644 app/code/Magento/LoginAsCustomerLog/Api/Data/LogSearchResultsInterface.php create mode 100644 app/code/Magento/LoginAsCustomerLog/Api/GetLogsListInterface.php delete mode 100644 app/code/Magento/LoginAsCustomerLog/Block/Adminhtml/Login.php create mode 100644 app/code/Magento/LoginAsCustomerLog/Controller/Adminhtml/Log/Index.php delete mode 100644 app/code/Magento/LoginAsCustomerLog/Controller/Adminhtml/Login/Grid.php delete mode 100644 app/code/Magento/LoginAsCustomerLog/Controller/Adminhtml/Login/Index.php create mode 100644 app/code/Magento/LoginAsCustomerLog/Model/GetLogList.php create mode 100644 app/code/Magento/LoginAsCustomerLog/Model/Log.php create mode 100644 app/code/Magento/LoginAsCustomerLog/Model/LogSearchResults.php delete mode 100644 app/code/Magento/LoginAsCustomerLog/Model/Login.php create mode 100644 app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Log.php create mode 100644 app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Log/Collection.php delete mode 100644 app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Login.php delete mode 100644 app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Login/Collection.php delete mode 100644 app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Login/Grid/Collection.php create mode 100644 app/code/Magento/LoginAsCustomerLog/Ui/DataProvider/LogDataProvider.php create mode 100644 app/code/Magento/LoginAsCustomerLog/etc/db_schema.xml create mode 100644 app/code/Magento/LoginAsCustomerLog/etc/db_schema_whitelist.json create mode 100755 app/code/Magento/LoginAsCustomerLog/etc/di.xml rename app/code/Magento/LoginAsCustomerLog/view/adminhtml/layout/{loginascustomer_login_index.xml => loginascustomer_log_log_index.xml} (66%) delete mode 100644 app/code/Magento/LoginAsCustomerLog/view/adminhtml/layout/loginascustomer_login_grid.xml delete mode 100644 app/code/Magento/LoginAsCustomerLog/view/adminhtml/layout/loginascustomer_login_grid_block.xml create mode 100644 app/code/Magento/LoginAsCustomerLog/view/adminhtml/ui_component/login_as_customer_log_listing.xml diff --git a/app/code/Magento/LoginAsCustomerLog/Api/Data/LogInterface.php b/app/code/Magento/LoginAsCustomerLog/Api/Data/LogInterface.php new file mode 100644 index 0000000000000..d77e83bd1c8c0 --- /dev/null +++ b/app/code/Magento/LoginAsCustomerLog/Api/Data/LogInterface.php @@ -0,0 +1,208 @@ +removeButton('add'); - } -} diff --git a/app/code/Magento/LoginAsCustomerLog/Controller/Adminhtml/Log/Index.php b/app/code/Magento/LoginAsCustomerLog/Controller/Adminhtml/Log/Index.php new file mode 100644 index 0000000000000..4911a06b5eff6 --- /dev/null +++ b/app/code/Magento/LoginAsCustomerLog/Controller/Adminhtml/Log/Index.php @@ -0,0 +1,34 @@ +resultFactory->create(ResultFactory::TYPE_PAGE); + $resultPage->setActiveMenu('Magento_LoginAsCustomerLog::login_log') + ->addBreadcrumb(__('Login as Customer Log'), __('List')); + $resultPage->getConfig()->getTitle()->prepend(__('Login as Customer Log')); + + return $resultPage; + } +} diff --git a/app/code/Magento/LoginAsCustomerLog/Controller/Adminhtml/Login/Grid.php b/app/code/Magento/LoginAsCustomerLog/Controller/Adminhtml/Login/Grid.php deleted file mode 100644 index ca47050199598..0000000000000 --- a/app/code/Magento/LoginAsCustomerLog/Controller/Adminhtml/Login/Grid.php +++ /dev/null @@ -1,36 +0,0 @@ -resultFactory->create(ResultFactory::TYPE_PAGE); - } -} diff --git a/app/code/Magento/LoginAsCustomerLog/Controller/Adminhtml/Login/Index.php b/app/code/Magento/LoginAsCustomerLog/Controller/Adminhtml/Login/Index.php deleted file mode 100644 index b1a65efc217e1..0000000000000 --- a/app/code/Magento/LoginAsCustomerLog/Controller/Adminhtml/Login/Index.php +++ /dev/null @@ -1,51 +0,0 @@ -getRequest()->isXmlHttpRequest()) { - $resultForward = $this->resultFactory->create(ResultFactory::TYPE_FORWARD); - $resultForward->forward('grid'); - return $resultForward; - } - - /** @var Page $resultPage */ - $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); - $resultPage->setActiveMenu('Magento_LoginAsCustomerLog::login_log') - ->addBreadcrumb(__('Customer'), __('Login As Customer Log')); - $resultPage->getConfig()->getTitle()->prepend(__('Login As Customer Log')); - - return $resultPage; - } -} diff --git a/app/code/Magento/LoginAsCustomerLog/Model/GetLogList.php b/app/code/Magento/LoginAsCustomerLog/Model/GetLogList.php new file mode 100644 index 0000000000000..e5c7f9a1b9aec --- /dev/null +++ b/app/code/Magento/LoginAsCustomerLog/Model/GetLogList.php @@ -0,0 +1,80 @@ +logCollectionFactory = $logCollectionFactory; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + $this->collectionProcessor = $collectionProcessor; + $this->logSearchResultsFactory = $logSearchResultsFactory; + } + + /** + * @inheritDoc + */ + public function execute(SearchCriteriaInterface $searchCriteria = null): LogSearchResultsInterface + { + $collection = $this->logCollectionFactory->create(); + if (null === $searchCriteria) { + $searchCriteria = $this->searchCriteriaBuilder->create(); + } else { + $this->collectionProcessor->process($searchCriteria, $collection); + } + + $searchResult = $this->logSearchResultsFactory->create(); + $searchResult->setItems($collection->getItems()); + $searchResult->setTotalCount($collection->getSize()); + $searchResult->setSearchCriteria($searchCriteria); + + return $searchResult; + } +} diff --git a/app/code/Magento/LoginAsCustomerLog/Model/Log.php b/app/code/Magento/LoginAsCustomerLog/Model/Log.php new file mode 100644 index 0000000000000..1ce2f4edceb3f --- /dev/null +++ b/app/code/Magento/LoginAsCustomerLog/Model/Log.php @@ -0,0 +1,215 @@ +setData(LogInterface::LOG_ID); + } + + /** + * @inheritDoc + */ + public function getLogId(): ?int + { + return $this->getData(LogInterface::LOG_ID) ? (int)$this->getData(LogInterface::LOG_ID) : null; + } + + /** + * @inheritDoc + */ + public function setTime(string $name): void + { + $this->setData(LogInterface::TIME); + } + + /** + * @inheritDoc + */ + public function getTime(): ?string + { + return $this->getData(LogInterface::TIME); + } + + /** + * @inheritDoc + */ + public function setActionGroup(string $actionGroup): void + { + $this->setData(LogInterface::ACTION_GROUP); + } + + /** + * @inheritDoc + */ + public function getActionGroup(): ?string + { + return $this->getData(LogInterface::ACTION_GROUP); + } + + /** + * @inheritDoc + */ + public function setAction(string $action): void + { + $this->setData(LogInterface::ACTION); + } + + /** + * @inheritDoc + */ + public function getAction(): ?string + { + return $this->getData(LogInterface::ACTION); + } + + /** + * @inheritDoc + */ + public function setFullActionName(string $fullActionName): void + { + $this->setData(LogInterface::FULL_ACTION_NAME); + } + + /** + * @inheritDoc + */ + public function getFullActionName(): ?string + { + return $this->getData(LogInterface::FULL_ACTION_NAME); + } + + /** + * @inheritDoc + */ + public function setResult(int $result): void + { + $this->setData(LogInterface::RESULT); + } + + /** + * @inheritDoc + */ + public function getResult(): ?int + { + return $this->getData(LogInterface::RESULT); + } + + /** + * @inheritDoc + */ + public function setDetails(string $details): void + { + $this->setData(LogInterface::DETAILS); + } + + /** + * @inheritDoc + */ + public function getDetails(): ?string + { + return $this->getData(LogInterface::DETAILS); + } + + /** + * @inheritDoc + */ + public function setError(string $error): void + { + $this->setData(LogInterface::ERROR); + } + + /** + * @inheritDoc + */ + public function getError(): ?string + { + return $this->getData(LogInterface::ERROR); + } + + /** + * @inheritDoc + */ + public function setIpAddress(int $ipAddress): void + { + $this->setData(LogInterface::IP_ADDRESS); + } + + /** + * @inheritDoc + */ + public function getIpAddress(): ?int + { + return $this->getData(LogInterface::IP_ADDRESS) + ? (int)$this->getData(LogInterface::IP_ADDRESS) + : null; + } + + /** + * @inheritDoc + */ + public function setUsername(string $username): void + { + $this->setData(LogInterface::USERNAME); + } + + /** + * @inheritDoc + */ + public function getUsername(): ?string + { + return $this->getData(LogInterface::USERNAME); + } + + /** + * @inheritDoc + */ + public function setCustomerId(int $customerId): void + { + $this->setData(LogInterface::CUSTOMER_ID); + } + + /** + * @inheritDoc + */ + public function getCustomerId(): ?int + { + return $this->getData(LogInterface::CUSTOMER_ID) ? + (int)$this->getData(LogInterface::CUSTOMER_ID) + : null; + } + + /** + * @inheritdoc + */ + public function setExtensionAttributes(LogExtensionInterface $extensionAttributes): void + { + $this->_setExtensionAttributes($extensionAttributes); + } + + /** + * @inheritDoc + */ + public function getExtensionAttributes(): LogExtensionInterface + { + return $this->_getExtensionAttributes(); + } +} diff --git a/app/code/Magento/LoginAsCustomerLog/Model/LogSearchResults.php b/app/code/Magento/LoginAsCustomerLog/Model/LogSearchResults.php new file mode 100644 index 0000000000000..da85cc06c0865 --- /dev/null +++ b/app/code/Magento/LoginAsCustomerLog/Model/LogSearchResults.php @@ -0,0 +1,18 @@ +_init(\Magento\LoginAsCustomerLog\Model\ResourceModel\Login::class); - } -} diff --git a/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Log.php b/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Log.php new file mode 100644 index 0000000000000..45b6bde6abab5 --- /dev/null +++ b/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Log.php @@ -0,0 +1,27 @@ +_init(self::TABLE_NAME_LOG, LogInterface::LOG_ID); + } +} diff --git a/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Log/Collection.php b/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Log/Collection.php new file mode 100644 index 0000000000000..a700b96cfaff0 --- /dev/null +++ b/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Log/Collection.php @@ -0,0 +1,26 @@ +_init(Log::class, LogResource::class); + } +} diff --git a/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Login.php b/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Login.php deleted file mode 100644 index 91c360e3717c0..0000000000000 --- a/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Login.php +++ /dev/null @@ -1,22 +0,0 @@ -_init('login_as_customer', 'secret'); - } -} diff --git a/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Login/Collection.php b/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Login/Collection.php deleted file mode 100644 index 8b2f270499987..0000000000000 --- a/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Login/Collection.php +++ /dev/null @@ -1,26 +0,0 @@ -_init( - \Magento\LoginAsCustomerLog\Model\Login::class, - \Magento\LoginAsCustomerLog\Model\ResourceModel\Login::class - ); - } -} diff --git a/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Login/Grid/Collection.php b/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Login/Grid/Collection.php deleted file mode 100644 index 1b91d2afc11b2..0000000000000 --- a/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Login/Grid/Collection.php +++ /dev/null @@ -1,44 +0,0 @@ -_map['fields']['email'] = 'c.email'; - } - - /** - * Init collection select - * - * @return $this - */ - protected function _initSelect(): self - { - parent::_initSelect(); - $this->getSelect() - ->joinLeft( - ['c' => $this->getTable('customer_entity')], - 'c.entity_id = main_table.customer_id', - ['email'] - )->joinLeft( - ['a' => $this->getTable('admin_user')], - 'a.user_id = main_table.admin_id', - ['username'] - ); - return $this; - } -} diff --git a/app/code/Magento/LoginAsCustomerLog/Ui/DataProvider/LogDataProvider.php b/app/code/Magento/LoginAsCustomerLog/Ui/DataProvider/LogDataProvider.php new file mode 100644 index 0000000000000..41a052f283fbd --- /dev/null +++ b/app/code/Magento/LoginAsCustomerLog/Ui/DataProvider/LogDataProvider.php @@ -0,0 +1,90 @@ +logRepository = $logRepository; + $this->searchResultFactory = $searchResultFactory; + } + + /** + * @inheritdoc + */ + public function getSearchResult() + { + $searchCriteria = $this->getSearchCriteria(); + $result = $this->logRepository->execute($searchCriteria); + + return $this->searchResultFactory->create( + $result->getItems(), + $result->getTotalCount(), + $searchCriteria, + LogInterface::LOG_ID + ); + } +} diff --git a/app/code/Magento/LoginAsCustomerLog/etc/adminhtml/menu.xml b/app/code/Magento/LoginAsCustomerLog/etc/adminhtml/menu.xml index f3fd02874e04e..e44b41b9b8a6a 100644 --- a/app/code/Magento/LoginAsCustomerLog/etc/adminhtml/menu.xml +++ b/app/code/Magento/LoginAsCustomerLog/etc/adminhtml/menu.xml @@ -14,6 +14,6 @@ parent="Magento_Customer::customer" sortOrder="40" resource="Magento_LoginAsCustomer::login_log" - action="loginascustomer"/> + action="loginascustomer_log/log/index"/> diff --git a/app/code/Magento/LoginAsCustomerLog/etc/adminhtml/routes.xml b/app/code/Magento/LoginAsCustomerLog/etc/adminhtml/routes.xml index 3c3df84a63424..9201e5e7ac91f 100644 --- a/app/code/Magento/LoginAsCustomerLog/etc/adminhtml/routes.xml +++ b/app/code/Magento/LoginAsCustomerLog/etc/adminhtml/routes.xml @@ -8,7 +8,7 @@ - + diff --git a/app/code/Magento/LoginAsCustomerLog/etc/db_schema.xml b/app/code/Magento/LoginAsCustomerLog/etc/db_schema.xml new file mode 100644 index 0000000000000..9d72b3fa26128 --- /dev/null +++ b/app/code/Magento/LoginAsCustomerLog/etc/db_schema.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + +
+
diff --git a/app/code/Magento/LoginAsCustomerLog/etc/db_schema_whitelist.json b/app/code/Magento/LoginAsCustomerLog/etc/db_schema_whitelist.json new file mode 100644 index 0000000000000..ca53da9475b2c --- /dev/null +++ b/app/code/Magento/LoginAsCustomerLog/etc/db_schema_whitelist.json @@ -0,0 +1,23 @@ +{ + "magento_login_as_customer_log": { + "column": { + "log_id": true, + "ip": true, + "x_forwarded_ip": true, + "event_code": true, + "time": true, + "action": true, + "info": true, + "status": true, + "user": true, + "user_id": true, + "customer_id": true, + "fullaction": true, + "error_message": true + }, + "constraint": { + "PRIMARY": true, + "MAGENTO_LOGIN_AS_CUSTOMER_LOG_USER_ID_ADMIN_USER_USER_ID": true + } + } +} diff --git a/app/code/Magento/LoginAsCustomerLog/etc/di.xml b/app/code/Magento/LoginAsCustomerLog/etc/di.xml new file mode 100755 index 0000000000000..4c90d5c417ebb --- /dev/null +++ b/app/code/Magento/LoginAsCustomerLog/etc/di.xml @@ -0,0 +1,12 @@ + + + + + + + diff --git a/app/code/Magento/LoginAsCustomerLog/view/adminhtml/layout/loginascustomer_login_index.xml b/app/code/Magento/LoginAsCustomerLog/view/adminhtml/layout/loginascustomer_log_log_index.xml similarity index 66% rename from app/code/Magento/LoginAsCustomerLog/view/adminhtml/layout/loginascustomer_login_index.xml rename to app/code/Magento/LoginAsCustomerLog/view/adminhtml/layout/loginascustomer_log_log_index.xml index 50d0a83210176..4ec4853877419 100644 --- a/app/code/Magento/LoginAsCustomerLog/view/adminhtml/layout/loginascustomer_login_index.xml +++ b/app/code/Magento/LoginAsCustomerLog/view/adminhtml/layout/loginascustomer_log_log_index.xml @@ -6,11 +6,9 @@ */ --> - - - + diff --git a/app/code/Magento/LoginAsCustomerLog/view/adminhtml/layout/loginascustomer_login_grid.xml b/app/code/Magento/LoginAsCustomerLog/view/adminhtml/layout/loginascustomer_login_grid.xml deleted file mode 100644 index e298729b5422b..0000000000000 --- a/app/code/Magento/LoginAsCustomerLog/view/adminhtml/layout/loginascustomer_login_grid.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - diff --git a/app/code/Magento/LoginAsCustomerLog/view/adminhtml/layout/loginascustomer_login_grid_block.xml b/app/code/Magento/LoginAsCustomerLog/view/adminhtml/layout/loginascustomer_login_grid_block.xml deleted file mode 100644 index 68f0d857be082..0000000000000 --- a/app/code/Magento/LoginAsCustomerLog/view/adminhtml/layout/loginascustomer_login_grid_block.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - subscriberGrid - Magento\LoginAsCustomerLog\Model\ResourceModel\Login\Grid\Collection - created_at - desc - 1 - - - - - - Customer ID - customer_id - col-title - col-title - - - - - Customer Email - email - col-title - col-title - - - - - Admin ID - admin_id - col-title - col-title - - - - - Admin Name - username - col-title - col-title - - - - - Logged In - created_at - datetime - col-first-name - col-first-name - - - - - - - diff --git a/app/code/Magento/LoginAsCustomerLog/view/adminhtml/ui_component/login_as_customer_log_listing.xml b/app/code/Magento/LoginAsCustomerLog/view/adminhtml/ui_component/login_as_customer_log_listing.xml new file mode 100644 index 0000000000000..21762e11081b4 --- /dev/null +++ b/app/code/Magento/LoginAsCustomerLog/view/adminhtml/ui_component/login_as_customer_log_listing.xml @@ -0,0 +1,69 @@ + + ++ + + login_as_customer_log_listing.login_as_customer_log_listing_data_source + + + + login_as_customer_log_listing_columns + + login_as_customer_log_listing.login_as_customer_log_listing_data_source + + + + + + log_id + + + + Magento_LoginAsCustomer::login_log + + + log_id + log_id + + + + + + true + + + + + + + + + + + + + + + + + + + text + + + + true + + + + + + From 5b402d5167a3b29ad5d79adbb15b8cd502b67586 Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Wed, 29 Apr 2020 11:24:57 +0300 Subject: [PATCH 2/4] LAC-27: Log admin actions with Login as Customer. --- .../Api/Data/LogInterface.php | 130 ++++-------------- .../Api/Data/LogSearchResultsInterface.php | 7 +- .../Api/GetLogsListInterface.php | 4 +- .../Api/SaveLogsInterface.php | 22 +++ .../Magento/LoginAsCustomerLog/Model/Log.php | 122 +++------------- .../Model/LogSearchResults.php | 2 +- .../Model/ResourceModel/Log.php | 2 +- .../Model/ResourceModel/Log/Collection.php | 2 +- .../Model/ResourceModel/SaveLogs.php | 55 ++++++++ .../LogAuthenticationPlugin.php | 85 ++++++++++++ .../LoginAsCustomerLog/etc/db_schema.xml | 14 +- .../etc/db_schema_whitelist.json | 15 +- .../Magento/LoginAsCustomerLog/etc/di.xml | 1 + .../LoginAsCustomerLog/etc/frontend/di.xml | 12 ++ .../login_as_customer_log_listing.xml | 41 ++++-- 15 files changed, 270 insertions(+), 244 deletions(-) create mode 100644 app/code/Magento/LoginAsCustomerLog/Api/SaveLogsInterface.php create mode 100644 app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/SaveLogs.php create mode 100644 app/code/Magento/LoginAsCustomerLog/Plugin/LoginAsCustomerApi/Api/AuthenticateCustomerInterface/LogAuthenticationPlugin.php create mode 100755 app/code/Magento/LoginAsCustomerLog/etc/frontend/di.xml diff --git a/app/code/Magento/LoginAsCustomerLog/Api/Data/LogInterface.php b/app/code/Magento/LoginAsCustomerLog/Api/Data/LogInterface.php index d77e83bd1c8c0..587745b6e7ecc 100644 --- a/app/code/Magento/LoginAsCustomerLog/Api/Data/LogInterface.php +++ b/app/code/Magento/LoginAsCustomerLog/Api/Data/LogInterface.php @@ -16,15 +16,10 @@ interface LogInterface extends ExtensibleDataInterface { const LOG_ID = 'log_id'; const TIME = 'time'; - const ACTION_GROUP = 'action_group'; - const ACTION = 'action'; - const FULL_ACTION_NAME = 'full_action_name'; - const RESULT = 'result'; - const DETAILS = 'details'; - const ERROR = 'error'; - const IP_ADDRESS = 'ip_address'; - const USERNAME = 'username'; const CUSTOMER_ID = 'customer_id'; + const CUSTOMER_EMAIL = 'customer_email'; + const USER_ID = 'user_id'; + const USERNAME = 'user_name'; /** * Set login as customer log id. @@ -44,10 +39,10 @@ public function getLogId(): ?int; /** * Set login as customer log time. * - * @param string $name + * @param string $time * @return void */ - public function setTime(string $name): void; + public function setTime(string $time): void; /** * Retrieve login as customer log time. @@ -57,139 +52,64 @@ public function setTime(string $name): void; public function getTime(): ?string; /** - * Set login as customer log action group. + * Set login as customer log user id. * - * @param string $actionGroup + * @param int $userId * @return void */ - public function setActionGroup(string $actionGroup): void; + public function setUserId(int $userId): void; /** - * Retrieve login as customer log action group. - * - * @return null|string - */ - public function getActionGroup(): ?string; - - /** - * Set login as customer log action. - * - * @param string $action - * @return void - */ - public function setAction(string $action): void; - - /** - * Retrieve login as customer log action. - * - * @return null|string - */ - public function getAction(): ?string; - - /** - * Set login as customer log full action name. - * - * @param string $fullActionName - * @return void - */ - public function setFullActionName(string $fullActionName): void; - - /** - * Retrieve login as customer log full action name. - * - * @return null|string - */ - public function getFullActionName(): ?string; - - /** - * Set login as customer log result. - * - * @param int $result - * @return void - */ - public function setResult(int $result): void; - - /** - * Retrieve login as customer log result. + * Retrieve login as customer log user id. * * @return null|int */ - public function getResult(): ?int; + public function getUserId(): ?int; /** - * Set login as customer log details. + * Set login as customer log user name. * - * @param string $details + * @param string $userName * @return void */ - public function setDetails(string $details): void; + public function setUserName(string $userName): void; /** - * Retrieve login as customer log details. + * Retrieve login as customer log user name. * * @return null|string */ - public function getDetails(): ?string; + public function getUserName(): ?string; /** - * Set login as customer log error. - * - * @param string $error - * @return void - */ - public function setError(string $error): void; - - /** - * Retrieve login as customer log error. - * - * @return string|null - */ - public function getError(): ?string; - - /** - * Set login as customer log ip address. + * Set login as customer log customer id. * - * @param int $ipAddress + * @param int $customerId * @return void */ - public function setIpAddress(int $ipAddress): void; + public function setCustomerId(int $customerId): void; /** - * Retrieve login as customer log ip address. + * Retrieve login as customer log customer id. * * @return null|int */ - public function getIpAddress(): ?int; + public function getCustomerId(): ?int; /** - * Set login as customer log user name. + * Set login as customer log customer email. * - * @param string $username + * @param string $customerEmail * @return void */ - public function setUsername(string $username): void; + public function setCustomerEmail(string $customerEmail): void; /** - * Retrieve login as customer log user name. + * Retrieve login as customer log customer email. * * @return null|string */ - public function getUsername(): ?string; - - /** - * Set login as customer log customer id. - * - * @param int $customerId - * @return void - */ - public function setCustomerId(int $customerId): void; - - /** - * Retrieve login as customer log customer id. - * - * @return null|int - */ - public function getCustomerId(): ?int; + public function getCustomerEmail(): ?string; /** * Set log extension attributes. diff --git a/app/code/Magento/LoginAsCustomerLog/Api/Data/LogSearchResultsInterface.php b/app/code/Magento/LoginAsCustomerLog/Api/Data/LogSearchResultsInterface.php index 817e580d919df..58c28f55a4b1b 100644 --- a/app/code/Magento/LoginAsCustomerLog/Api/Data/LogSearchResultsInterface.php +++ b/app/code/Magento/LoginAsCustomerLog/Api/Data/LogSearchResultsInterface.php @@ -9,17 +9,20 @@ use \Magento\Framework\Api\SearchResultsInterface; +/** + * Login as customer log entity search results interface. + */ interface LogSearchResultsInterface extends SearchResultsInterface { /** - * Get sources list + * Get log list. * * @return \Magento\LoginAsCustomerLog\Api\Data\LogInterface[] */ public function getItems(); /** - * Set sources list + * Set log list. * * @param \Magento\LoginAsCustomerLog\Api\Data\LogInterface[] $items * @return void diff --git a/app/code/Magento/LoginAsCustomerLog/Api/GetLogsListInterface.php b/app/code/Magento/LoginAsCustomerLog/Api/GetLogsListInterface.php index 759fb6326ed33..9face90f18fc9 100644 --- a/app/code/Magento/LoginAsCustomerLog/Api/GetLogsListInterface.php +++ b/app/code/Magento/LoginAsCustomerLog/Api/GetLogsListInterface.php @@ -11,11 +11,13 @@ use Magento\LoginAsCustomerLog\Api\Data\LogSearchResultsInterface; /** - * @todo: add description. + * Get login as customer log list considering search criteria. */ interface GetLogsListInterface { /** + * Retrieve list of log entities. + * * @param SearchCriteriaInterface $searchCriteria * @return LogSearchResultsInterface */ diff --git a/app/code/Magento/LoginAsCustomerLog/Api/SaveLogsInterface.php b/app/code/Magento/LoginAsCustomerLog/Api/SaveLogsInterface.php new file mode 100644 index 0000000000000..7ca95263aedfb --- /dev/null +++ b/app/code/Magento/LoginAsCustomerLog/Api/SaveLogsInterface.php @@ -0,0 +1,22 @@ +setData(LogInterface::LOG_ID); + $this->setData(LogInterface::LOG_ID, $logId); } /** @@ -36,9 +36,9 @@ public function getLogId(): ?int /** * @inheritDoc */ - public function setTime(string $name): void + public function setTime(string $time): void { - $this->setData(LogInterface::TIME); + $this->setData(LogInterface::TIME, $time); } /** @@ -52,149 +52,67 @@ public function getTime(): ?string /** * @inheritDoc */ - public function setActionGroup(string $actionGroup): void + public function setUserId(int $userId): void { - $this->setData(LogInterface::ACTION_GROUP); + $this->setData(LogInterface::USER_ID, $userId); } /** * @inheritDoc */ - public function getActionGroup(): ?string + public function getUserId(): ?int { - return $this->getData(LogInterface::ACTION_GROUP); + return $this->getData(LogInterface::USER_ID) ? (int)$this->getData(LogInterface::USER_ID) : null; } /** * @inheritDoc */ - public function setAction(string $action): void + public function setUserName(string $userName): void { - $this->setData(LogInterface::ACTION); + $this->setData(LogInterface::USERNAME, $userName); } /** * @inheritDoc */ - public function getAction(): ?string + public function getUserName(): ?string { - return $this->getData(LogInterface::ACTION); - } - - /** - * @inheritDoc - */ - public function setFullActionName(string $fullActionName): void - { - $this->setData(LogInterface::FULL_ACTION_NAME); - } - - /** - * @inheritDoc - */ - public function getFullActionName(): ?string - { - return $this->getData(LogInterface::FULL_ACTION_NAME); - } - - /** - * @inheritDoc - */ - public function setResult(int $result): void - { - $this->setData(LogInterface::RESULT); - } - - /** - * @inheritDoc - */ - public function getResult(): ?int - { - return $this->getData(LogInterface::RESULT); - } - - /** - * @inheritDoc - */ - public function setDetails(string $details): void - { - $this->setData(LogInterface::DETAILS); - } - - /** - * @inheritDoc - */ - public function getDetails(): ?string - { - return $this->getData(LogInterface::DETAILS); - } - - /** - * @inheritDoc - */ - public function setError(string $error): void - { - $this->setData(LogInterface::ERROR); - } - - /** - * @inheritDoc - */ - public function getError(): ?string - { - return $this->getData(LogInterface::ERROR); + return $this->getData(LogInterface::USERNAME); } /** * @inheritDoc */ - public function setIpAddress(int $ipAddress): void + public function setCustomerId(int $customerId): void { - $this->setData(LogInterface::IP_ADDRESS); + $this->setData(LogInterface::CUSTOMER_ID, $customerId); } /** * @inheritDoc */ - public function getIpAddress(): ?int + public function getCustomerId(): ?int { - return $this->getData(LogInterface::IP_ADDRESS) - ? (int)$this->getData(LogInterface::IP_ADDRESS) + return $this->getData(LogInterface::CUSTOMER_ID) ? + (int)$this->getData(LogInterface::CUSTOMER_ID) : null; } /** * @inheritDoc */ - public function setUsername(string $username): void + public function setCustomerEmail(string $customerEmail): void { - $this->setData(LogInterface::USERNAME); + $this->setData(LogInterface::CUSTOMER_EMAIL, $customerEmail); } /** * @inheritDoc */ - public function getUsername(): ?string + public function getCustomerEmail(): ?string { - return $this->getData(LogInterface::USERNAME); - } - - /** - * @inheritDoc - */ - public function setCustomerId(int $customerId): void - { - $this->setData(LogInterface::CUSTOMER_ID); - } - - /** - * @inheritDoc - */ - public function getCustomerId(): ?int - { - return $this->getData(LogInterface::CUSTOMER_ID) ? - (int)$this->getData(LogInterface::CUSTOMER_ID) - : null; + return $this->getData(LogInterface::CUSTOMER_EMAIL); } /** diff --git a/app/code/Magento/LoginAsCustomerLog/Model/LogSearchResults.php b/app/code/Magento/LoginAsCustomerLog/Model/LogSearchResults.php index da85cc06c0865..2def7b0e09c6c 100644 --- a/app/code/Magento/LoginAsCustomerLog/Model/LogSearchResults.php +++ b/app/code/Magento/LoginAsCustomerLog/Model/LogSearchResults.php @@ -11,7 +11,7 @@ use Magento\LoginAsCustomerLog\Api\Data\LogSearchResultsInterface; /** - * todo: add description. + * @inheritDoc */ class LogSearchResults extends SearchResults implements LogSearchResultsInterface { diff --git a/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Log.php b/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Log.php index 45b6bde6abab5..11c142c078322 100644 --- a/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Log.php +++ b/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Log.php @@ -11,7 +11,7 @@ use Magento\LoginAsCustomerLog\Api\Data\LogInterface; /** - * Todo: add description. + * Login as customer log resource model. */ class Log extends AbstractDb { diff --git a/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Log/Collection.php b/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Log/Collection.php index a700b96cfaff0..a5df9a0067ad1 100644 --- a/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Log/Collection.php +++ b/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/Log/Collection.php @@ -12,7 +12,7 @@ use Magento\LoginAsCustomerLog\Model\ResourceModel\Log as LogResource; /** - * Todo: add description. + * Login as customer log entities collection. */ class Collection extends AbstractCollection { diff --git a/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/SaveLogs.php b/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/SaveLogs.php new file mode 100644 index 0000000000000..42fb45ad738c8 --- /dev/null +++ b/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/SaveLogs.php @@ -0,0 +1,55 @@ +resourceConnection = $resourceConnection; + $this->dateTime = $dateTime; + } + + /** + * @inheritDoc + */ + public function execute(array $logs): void + { + $logsData = []; + foreach ($logs as $log) { + if (!$log->getTime()) { + $log->setTime($this->dateTime->gmtDate()); + } + $logsData[] = $log->getData(); + } + $logTable = $this->resourceConnection->getTableName(Log::TABLE_NAME_LOG); + $connection = $this->resourceConnection->getConnection(); + $connection->insertOnDuplicate($logTable, $logsData); + } +} diff --git a/app/code/Magento/LoginAsCustomerLog/Plugin/LoginAsCustomerApi/Api/AuthenticateCustomerInterface/LogAuthenticationPlugin.php b/app/code/Magento/LoginAsCustomerLog/Plugin/LoginAsCustomerApi/Api/AuthenticateCustomerInterface/LogAuthenticationPlugin.php new file mode 100644 index 0000000000000..f72e46bd53a6d --- /dev/null +++ b/app/code/Magento/LoginAsCustomerLog/Plugin/LoginAsCustomerApi/Api/AuthenticateCustomerInterface/LogAuthenticationPlugin.php @@ -0,0 +1,85 @@ +logFactory = $logFactory; + $this->saveLogs = $saveLogs; + $this->customerRepository = $customerRepository; + $this->userFactory = $userFactory; + } + + /** + * Log user authentication as customer. + * + * @param AuthenticateCustomerInterface $subject + * @param void $result + * @param AuthenticationDataInterface $data + * @return void + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterExecute( + AuthenticateCustomerInterface $subject, + $result, + AuthenticationDataInterface $data + ): void { + $customerId = $data->getCustomerId(); + $customerEmail = $this->customerRepository->getById($customerId)->getEmail(); + $userId = $data->getAdminId(); + $userName = $this->userFactory->create()->load($userId)->getUserName(); + $log = $this->logFactory->create(); + $log->setCustomerId($customerId); + $log->setUserId($userId); + $log->setCustomerEmail($customerEmail); + $log->setUserName($userName); + $this->saveLogs->execute([$log]); + } +} diff --git a/app/code/Magento/LoginAsCustomerLog/etc/db_schema.xml b/app/code/Magento/LoginAsCustomerLog/etc/db_schema.xml index 9d72b3fa26128..056b5f705d0cf 100644 --- a/app/code/Magento/LoginAsCustomerLog/etc/db_schema.xml +++ b/app/code/Magento/LoginAsCustomerLog/etc/db_schema.xml @@ -8,21 +8,13 @@ - - - - - - - - + + - - + -
diff --git a/app/code/Magento/LoginAsCustomerLog/etc/db_schema_whitelist.json b/app/code/Magento/LoginAsCustomerLog/etc/db_schema_whitelist.json index ca53da9475b2c..472f2114169f4 100644 --- a/app/code/Magento/LoginAsCustomerLog/etc/db_schema_whitelist.json +++ b/app/code/Magento/LoginAsCustomerLog/etc/db_schema_whitelist.json @@ -2,22 +2,13 @@ "magento_login_as_customer_log": { "column": { "log_id": true, - "ip": true, - "x_forwarded_ip": true, - "event_code": true, - "time": true, - "action": true, - "info": true, - "status": true, - "user": true, + "user_name": true, "user_id": true, "customer_id": true, - "fullaction": true, - "error_message": true + "customer_email": true }, "constraint": { - "PRIMARY": true, - "MAGENTO_LOGIN_AS_CUSTOMER_LOG_USER_ID_ADMIN_USER_USER_ID": true + "PRIMARY": true } } } diff --git a/app/code/Magento/LoginAsCustomerLog/etc/di.xml b/app/code/Magento/LoginAsCustomerLog/etc/di.xml index 4c90d5c417ebb..49d19d85f0d65 100755 --- a/app/code/Magento/LoginAsCustomerLog/etc/di.xml +++ b/app/code/Magento/LoginAsCustomerLog/etc/di.xml @@ -9,4 +9,5 @@ +
diff --git a/app/code/Magento/LoginAsCustomerLog/etc/frontend/di.xml b/app/code/Magento/LoginAsCustomerLog/etc/frontend/di.xml new file mode 100755 index 0000000000000..e370839eef4b6 --- /dev/null +++ b/app/code/Magento/LoginAsCustomerLog/etc/frontend/di.xml @@ -0,0 +1,12 @@ + + + + + + + diff --git a/app/code/Magento/LoginAsCustomerLog/view/adminhtml/ui_component/login_as_customer_log_listing.xml b/app/code/Magento/LoginAsCustomerLog/view/adminhtml/ui_component/login_as_customer_log_listing.xml index 21762e11081b4..1a53b235c9dc6 100644 --- a/app/code/Magento/LoginAsCustomerLog/view/adminhtml/ui_component/login_as_customer_log_listing.xml +++ b/app/code/Magento/LoginAsCustomerLog/view/adminhtml/ui_component/login_as_customer_log_listing.xml @@ -28,7 +28,7 @@ log_id - log_id + Id @@ -54,15 +54,40 @@ - + text - - - - true - - + + + + + + text + + + + + + text + + + + + + text + + + + + + text + + + + + + text + From 6d7e97db01993dd9c1c77f550254d32f0009efc0 Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Wed, 29 Apr 2020 14:39:15 +0300 Subject: [PATCH 3/4] LAC-27: Log admin actions with Login as Customer. --- .../Controller/Adminhtml/Log/Index.php | 2 +- .../LoginAsCustomerLog/Model/GetLogList.php | 7 ++-- .../Model/ResourceModel/SaveLogs.php | 2 +- .../LogAuthenticationPlugin.php | 29 +++++++++++++---- .../Ui/DataProvider/LogDataProvider.php | 32 ++++++++++++++----- .../Magento/LoginAsCustomerLog/composer.json | 6 +++- .../Magento/LoginAsCustomerLog/etc/acl.xml | 2 +- .../LoginAsCustomerLog/etc/adminhtml/menu.xml | 2 +- .../LoginAsCustomerLog/etc/db_schema.xml | 3 ++ .../etc/db_schema_whitelist.json | 3 ++ .../login_as_customer_log_listing.xml | 2 +- 11 files changed, 64 insertions(+), 26 deletions(-) diff --git a/app/code/Magento/LoginAsCustomerLog/Controller/Adminhtml/Log/Index.php b/app/code/Magento/LoginAsCustomerLog/Controller/Adminhtml/Log/Index.php index 4911a06b5eff6..ce0c50bf347fc 100644 --- a/app/code/Magento/LoginAsCustomerLog/Controller/Adminhtml/Log/Index.php +++ b/app/code/Magento/LoginAsCustomerLog/Controller/Adminhtml/Log/Index.php @@ -17,7 +17,7 @@ */ class Index extends Action implements HttpGetActionInterface { - const ADMIN_RESOURCE = 'Magento_LoginAsCustomer::login_log'; + const ADMIN_RESOURCE = 'Magento_LoginAsCustomerLog::login_log'; /** * @inheritdoc diff --git a/app/code/Magento/LoginAsCustomerLog/Model/GetLogList.php b/app/code/Magento/LoginAsCustomerLog/Model/GetLogList.php index e5c7f9a1b9aec..de46b75dab3b9 100644 --- a/app/code/Magento/LoginAsCustomerLog/Model/GetLogList.php +++ b/app/code/Magento/LoginAsCustomerLog/Model/GetLogList.php @@ -64,11 +64,8 @@ public function __construct( public function execute(SearchCriteriaInterface $searchCriteria = null): LogSearchResultsInterface { $collection = $this->logCollectionFactory->create(); - if (null === $searchCriteria) { - $searchCriteria = $this->searchCriteriaBuilder->create(); - } else { - $this->collectionProcessor->process($searchCriteria, $collection); - } + $searchCriteria = $searchCriteria ?: $this->searchCriteriaBuilder->create(); + $this->collectionProcessor->process($searchCriteria, $collection); $searchResult = $this->logSearchResultsFactory->create(); $searchResult->setItems($collection->getItems()); diff --git a/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/SaveLogs.php b/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/SaveLogs.php index 42fb45ad738c8..f793f75e678cc 100644 --- a/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/SaveLogs.php +++ b/app/code/Magento/LoginAsCustomerLog/Model/ResourceModel/SaveLogs.php @@ -50,6 +50,6 @@ public function execute(array $logs): void } $logTable = $this->resourceConnection->getTableName(Log::TABLE_NAME_LOG); $connection = $this->resourceConnection->getConnection(); - $connection->insertOnDuplicate($logTable, $logsData); + $connection->insertMultiple($logTable, $logsData); } } diff --git a/app/code/Magento/LoginAsCustomerLog/Plugin/LoginAsCustomerApi/Api/AuthenticateCustomerInterface/LogAuthenticationPlugin.php b/app/code/Magento/LoginAsCustomerLog/Plugin/LoginAsCustomerApi/Api/AuthenticateCustomerInterface/LogAuthenticationPlugin.php index f72e46bd53a6d..c1d999b552821 100644 --- a/app/code/Magento/LoginAsCustomerLog/Plugin/LoginAsCustomerApi/Api/AuthenticateCustomerInterface/LogAuthenticationPlugin.php +++ b/app/code/Magento/LoginAsCustomerLog/Plugin/LoginAsCustomerApi/Api/AuthenticateCustomerInterface/LogAuthenticationPlugin.php @@ -13,6 +13,7 @@ use Magento\LoginAsCustomerLog\Api\Data\LogInterfaceFactory; use Magento\LoginAsCustomerLog\Api\SaveLogsInterface; use Magento\User\Api\Data\UserInterfaceFactory; +use Magento\User\Model\ResourceModel\User; /** * Log user logged in as customer plugin. @@ -39,22 +40,30 @@ class LogAuthenticationPlugin */ private $userFactory; + /** + * @var User + */ + private $userResource; + /** * @param LogInterfaceFactory $logFactory * @param SaveLogsInterface $saveLogs * @param CustomerRepositoryInterface $customerRepository * @param UserInterfaceFactory $userFactory + * @param User $userResource */ public function __construct( LogInterfaceFactory $logFactory, SaveLogsInterface $saveLogs, CustomerRepositoryInterface $customerRepository, - UserInterfaceFactory $userFactory + UserInterfaceFactory $userFactory, + User $userResource ) { $this->logFactory = $logFactory; $this->saveLogs = $saveLogs; $this->customerRepository = $customerRepository; $this->userFactory = $userFactory; + $this->userResource = $userResource; } /** @@ -74,12 +83,18 @@ public function afterExecute( $customerId = $data->getCustomerId(); $customerEmail = $this->customerRepository->getById($customerId)->getEmail(); $userId = $data->getAdminId(); - $userName = $this->userFactory->create()->load($userId)->getUserName(); - $log = $this->logFactory->create(); - $log->setCustomerId($customerId); - $log->setUserId($userId); - $log->setCustomerEmail($customerEmail); - $log->setUserName($userName); + $user = $this->userFactory->create(); + $this->userResource->load($user, $userId); + $log = $this->logFactory->create( + [ + 'data' => [ + 'customer_id' => $customerId, + 'user_id' => $userId, + 'customer_email' => $customerEmail, + 'user_name' => $user->getUserName(), + ], + ] + ); $this->saveLogs->execute([$log]); } } diff --git a/app/code/Magento/LoginAsCustomerLog/Ui/DataProvider/LogDataProvider.php b/app/code/Magento/LoginAsCustomerLog/Ui/DataProvider/LogDataProvider.php index 41a052f283fbd..53a76b08432d9 100644 --- a/app/code/Magento/LoginAsCustomerLog/Ui/DataProvider/LogDataProvider.php +++ b/app/code/Magento/LoginAsCustomerLog/Ui/DataProvider/LogDataProvider.php @@ -10,6 +10,7 @@ use Magento\Framework\Api\FilterBuilder; use Magento\Framework\Api\Search\ReportingInterface; use Magento\Framework\Api\Search\SearchCriteriaBuilder; +use Magento\Framework\Api\SortOrderBuilder; use Magento\Framework\App\RequestInterface; use Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider; use Magento\LoginAsCustomerLog\Api\Data\LogInterface; @@ -24,7 +25,7 @@ class LogDataProvider extends DataProvider /** * @var GetLogsListInterface */ - private $logRepository; + private $getLogsList; /** * @var SearchResultFactory @@ -32,17 +33,24 @@ class LogDataProvider extends DataProvider private $searchResultFactory; /** - * @param $name - * @param $primaryFieldName - * @param $requestFieldName + * @var SortOrderBuilder + */ + private $sortOrderBuilder; + + /** + * @param string $name + * @param string $primaryFieldName + * @param string $requestFieldName * @param ReportingInterface $reporting * @param SearchCriteriaBuilder $searchCriteriaBuilder * @param RequestInterface $request * @param FilterBuilder $filterBuilder - * @param GetLogsListInterface $logRepository + * @param GetLogsListInterface $getLogsList * @param SearchResultFactory $searchResultFactory + * @param SortOrderBuilder $sortOrderBuilder * @param array $meta * @param array $data + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( $name, @@ -52,8 +60,9 @@ public function __construct( SearchCriteriaBuilder $searchCriteriaBuilder, RequestInterface $request, FilterBuilder $filterBuilder, - GetLogsListInterface $logRepository, + GetLogsListInterface $getLogsList, SearchResultFactory $searchResultFactory, + SortOrderBuilder $sortOrderBuilder, array $meta = [], array $data = [] ) { @@ -68,8 +77,9 @@ public function __construct( $meta, $data ); - $this->logRepository = $logRepository; + $this->getLogsList = $getLogsList; $this->searchResultFactory = $searchResultFactory; + $this->sortOrderBuilder = $sortOrderBuilder; } /** @@ -78,7 +88,13 @@ public function __construct( public function getSearchResult() { $searchCriteria = $this->getSearchCriteria(); - $result = $this->logRepository->execute($searchCriteria); + $sortOrders = $searchCriteria->getSortOrders(); + $sortOrder = current($sortOrders); + if (!$sortOrder->getField()) { + $sortOrder = $this->sortOrderBuilder->setDescendingDirection()->setField(LogInterface::TIME)->create(); + $searchCriteria->setSortOrders([$sortOrder]); + } + $result = $this->getLogsList->execute($searchCriteria); return $this->searchResultFactory->create( $result->getItems(), diff --git a/app/code/Magento/LoginAsCustomerLog/composer.json b/app/code/Magento/LoginAsCustomerLog/composer.json index 7ad41ee1aecee..3ee07ca7565a0 100644 --- a/app/code/Magento/LoginAsCustomerLog/composer.json +++ b/app/code/Magento/LoginAsCustomerLog/composer.json @@ -4,7 +4,11 @@ "require": { "php": "~7.1.3||~7.2.0||~7.3.0", "magento/framework": "*", - "magento/module-backend": "*" + "magento/module-backend": "*", + "magento/module-customer": "*", + "magento/module-login-as-customer-api": "*", + "magento/module-ui": "*", + "magento/module-user": "*" }, "suggest": { "magento/module-login-as-customer": "*" diff --git a/app/code/Magento/LoginAsCustomerLog/etc/acl.xml b/app/code/Magento/LoginAsCustomerLog/etc/acl.xml index aaf4eb009368e..0a46616b4ad7b 100644 --- a/app/code/Magento/LoginAsCustomerLog/etc/acl.xml +++ b/app/code/Magento/LoginAsCustomerLog/etc/acl.xml @@ -11,7 +11,7 @@ - + diff --git a/app/code/Magento/LoginAsCustomerLog/etc/adminhtml/menu.xml b/app/code/Magento/LoginAsCustomerLog/etc/adminhtml/menu.xml index e44b41b9b8a6a..143e0ad4b5a6c 100644 --- a/app/code/Magento/LoginAsCustomerLog/etc/adminhtml/menu.xml +++ b/app/code/Magento/LoginAsCustomerLog/etc/adminhtml/menu.xml @@ -13,7 +13,7 @@ module="Magento_LoginAsCustomerLog" parent="Magento_Customer::customer" sortOrder="40" - resource="Magento_LoginAsCustomer::login_log" + resource="Magento_LoginAsCustomerLog::login_log" action="loginascustomer_log/log/index"/> diff --git a/app/code/Magento/LoginAsCustomerLog/etc/db_schema.xml b/app/code/Magento/LoginAsCustomerLog/etc/db_schema.xml index 056b5f705d0cf..a1f40b4e5bbf5 100644 --- a/app/code/Magento/LoginAsCustomerLog/etc/db_schema.xml +++ b/app/code/Magento/LoginAsCustomerLog/etc/db_schema.xml @@ -16,5 +16,8 @@ + + + diff --git a/app/code/Magento/LoginAsCustomerLog/etc/db_schema_whitelist.json b/app/code/Magento/LoginAsCustomerLog/etc/db_schema_whitelist.json index 472f2114169f4..6523a283edd0f 100644 --- a/app/code/Magento/LoginAsCustomerLog/etc/db_schema_whitelist.json +++ b/app/code/Magento/LoginAsCustomerLog/etc/db_schema_whitelist.json @@ -9,6 +9,9 @@ }, "constraint": { "PRIMARY": true + }, + "index": { + "MAGENTO_LOGIN_AS_CUSTOMER_LOG_USER_ID": true } } } diff --git a/app/code/Magento/LoginAsCustomerLog/view/adminhtml/ui_component/login_as_customer_log_listing.xml b/app/code/Magento/LoginAsCustomerLog/view/adminhtml/ui_component/login_as_customer_log_listing.xml index 1a53b235c9dc6..077fd6e18db7c 100644 --- a/app/code/Magento/LoginAsCustomerLog/view/adminhtml/ui_component/login_as_customer_log_listing.xml +++ b/app/code/Magento/LoginAsCustomerLog/view/adminhtml/ui_component/login_as_customer_log_listing.xml @@ -24,7 +24,7 @@ - Magento_LoginAsCustomer::login_log + Magento_LoginAsCustomerLog::login_log log_id From 72c0773437a69c901082301d290a57ad85d643af Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Thu, 30 Apr 2020 16:17:15 +0300 Subject: [PATCH 4/4] LAC-27: Log admin actions with Login as Customer. --- app/code/Magento/LoginAsCustomerLog/Api/Data/LogInterface.php | 2 ++ .../LoginAsCustomerLog/Api/Data/LogSearchResultsInterface.php | 2 ++ .../Magento/LoginAsCustomerLog/Api/GetLogsListInterface.php | 2 ++ app/code/Magento/LoginAsCustomerLog/Api/SaveLogsInterface.php | 2 ++ 4 files changed, 8 insertions(+) diff --git a/app/code/Magento/LoginAsCustomerLog/Api/Data/LogInterface.php b/app/code/Magento/LoginAsCustomerLog/Api/Data/LogInterface.php index 587745b6e7ecc..10d793d6c4c0b 100644 --- a/app/code/Magento/LoginAsCustomerLog/Api/Data/LogInterface.php +++ b/app/code/Magento/LoginAsCustomerLog/Api/Data/LogInterface.php @@ -11,6 +11,8 @@ /** * Data interface for login as customer log. + * + * @api */ interface LogInterface extends ExtensibleDataInterface { diff --git a/app/code/Magento/LoginAsCustomerLog/Api/Data/LogSearchResultsInterface.php b/app/code/Magento/LoginAsCustomerLog/Api/Data/LogSearchResultsInterface.php index 58c28f55a4b1b..5b08d28af6335 100644 --- a/app/code/Magento/LoginAsCustomerLog/Api/Data/LogSearchResultsInterface.php +++ b/app/code/Magento/LoginAsCustomerLog/Api/Data/LogSearchResultsInterface.php @@ -11,6 +11,8 @@ /** * Login as customer log entity search results interface. + * + * @api */ interface LogSearchResultsInterface extends SearchResultsInterface { diff --git a/app/code/Magento/LoginAsCustomerLog/Api/GetLogsListInterface.php b/app/code/Magento/LoginAsCustomerLog/Api/GetLogsListInterface.php index 9face90f18fc9..4b5ee382c908a 100644 --- a/app/code/Magento/LoginAsCustomerLog/Api/GetLogsListInterface.php +++ b/app/code/Magento/LoginAsCustomerLog/Api/GetLogsListInterface.php @@ -12,6 +12,8 @@ /** * Get login as customer log list considering search criteria. + * + * @api */ interface GetLogsListInterface { diff --git a/app/code/Magento/LoginAsCustomerLog/Api/SaveLogsInterface.php b/app/code/Magento/LoginAsCustomerLog/Api/SaveLogsInterface.php index 7ca95263aedfb..67e1ece477727 100644 --- a/app/code/Magento/LoginAsCustomerLog/Api/SaveLogsInterface.php +++ b/app/code/Magento/LoginAsCustomerLog/Api/SaveLogsInterface.php @@ -9,6 +9,8 @@ /** * Save login as custom logs entities. + * + * @api */ interface SaveLogsInterface {