-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '2.3-develop' of github.com:magento/graphql-ce into issu…
…e-416
- Loading branch information
Showing
1,651 changed files
with
50,536 additions
and
8,877 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
104 changes: 104 additions & 0 deletions
104
app/code/Magento/AdminAnalytics/Controller/Adminhtml/Config/DisableAdminUsage.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\AdminAnalytics\Controller\Adminhtml\Config; | ||
|
||
use Magento\Backend\App\Action; | ||
use Magento\Framework\App\Action\HttpPostActionInterface; | ||
use Magento\Framework\Controller\ResultFactory; | ||
use Magento\AdminAnalytics\Model\ResourceModel\Viewer\Logger as NotificationLogger; | ||
use Magento\Framework\App\ProductMetadataInterface; | ||
use Magento\Framework\Controller\ResultInterface; | ||
use Magento\Config\Model\Config\Factory; | ||
|
||
/** | ||
* Controller to record Admin analytics usage log | ||
*/ | ||
class DisableAdminUsage extends Action implements HttpPostActionInterface | ||
{ | ||
/** | ||
* @var Factory | ||
*/ | ||
private $configFactory; | ||
|
||
/** | ||
* @var ProductMetadataInterface | ||
*/ | ||
private $productMetadata; | ||
|
||
/** | ||
* @var NotificationLogger | ||
*/ | ||
private $notificationLogger; | ||
|
||
/** | ||
* DisableAdminUsage constructor. | ||
* | ||
* @param Action\Context $context | ||
* @param ProductMetadataInterface $productMetadata | ||
* @param NotificationLogger $notificationLogger | ||
* @param Factory $configFactory | ||
*/ | ||
public function __construct( | ||
Action\Context $context, | ||
ProductMetadataInterface $productMetadata, | ||
NotificationLogger $notificationLogger, | ||
Factory $configFactory | ||
) { | ||
parent::__construct($context); | ||
$this->configFactory = $configFactory; | ||
$this->productMetadata = $productMetadata; | ||
$this->notificationLogger = $notificationLogger; | ||
} | ||
|
||
/** | ||
* Change the value of config/admin/usage/enabled | ||
*/ | ||
private function disableAdminUsage() | ||
{ | ||
$configModel = $this->configFactory->create(); | ||
$configModel->setDataByPath('admin/usage/enabled', 0); | ||
$configModel->save(); | ||
} | ||
|
||
/** | ||
* Log information about the last admin usage selection | ||
* | ||
* @return ResultInterface | ||
*/ | ||
private function markUserNotified(): ResultInterface | ||
{ | ||
$responseContent = [ | ||
'success' => $this->notificationLogger->log( | ||
$this->productMetadata->getVersion() | ||
), | ||
'error_message' => '' | ||
]; | ||
|
||
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON); | ||
return $resultJson->setData($responseContent); | ||
} | ||
|
||
/** | ||
* Log information about the last shown advertisement | ||
* | ||
* @return ResultInterface | ||
*/ | ||
public function execute() | ||
{ | ||
$this->disableAdminUsage(); | ||
$this->markUserNotified(); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function _isAllowed() | ||
{ | ||
return $this->_authorization->isAllowed(static::ADMIN_RESOURCE); | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
app/code/Magento/AdminAnalytics/Controller/Adminhtml/Config/EnableAdminUsage.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\AdminAnalytics\Controller\Adminhtml\Config; | ||
|
||
use Magento\Backend\App\Action; | ||
use Magento\Framework\App\Action\HttpPostActionInterface; | ||
use Magento\Framework\Controller\ResultFactory; | ||
use Magento\AdminAnalytics\Model\ResourceModel\Viewer\Logger as NotificationLogger; | ||
use Magento\Framework\App\ProductMetadataInterface; | ||
use Magento\Framework\Controller\ResultInterface; | ||
use Magento\Config\Model\Config\Factory; | ||
|
||
/** | ||
* Controller to record that the current admin user has responded to Admin Analytics notice | ||
*/ | ||
class EnableAdminUsage extends Action implements HttpPostActionInterface | ||
{ | ||
/** | ||
* @var Factory | ||
*/ | ||
private $configFactory; | ||
|
||
/** | ||
* @var ProductMetadataInterface | ||
*/ | ||
private $productMetadata; | ||
|
||
/** | ||
* @var NotificationLogger | ||
*/ | ||
private $notificationLogger; | ||
|
||
/** | ||
* @param Action\Context $context | ||
* @param ProductMetadataInterface $productMetadata | ||
* @param NotificationLogger $notificationLogger | ||
* @param Factory $configFactory | ||
*/ | ||
public function __construct( | ||
Action\Context $context, | ||
ProductMetadataInterface $productMetadata, | ||
NotificationLogger $notificationLogger, | ||
Factory $configFactory | ||
) { | ||
parent::__construct($context); | ||
$this->configFactory = $configFactory; | ||
$this->productMetadata = $productMetadata; | ||
$this->notificationLogger = $notificationLogger; | ||
} | ||
|
||
/** | ||
* Change the value of config/admin/usage/enabled | ||
*/ | ||
private function enableAdminUsage() | ||
{ | ||
$configModel = $this->configFactory->create(); | ||
$configModel->setDataByPath('admin/usage/enabled', 1); | ||
$configModel->save(); | ||
} | ||
|
||
/** | ||
* Log information about the last user response | ||
* | ||
* @return ResultInterface | ||
*/ | ||
private function markUserNotified(): ResultInterface | ||
{ | ||
$responseContent = [ | ||
'success' => $this->notificationLogger->log( | ||
$this->productMetadata->getVersion() | ||
), | ||
'error_message' => '' | ||
]; | ||
|
||
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON); | ||
return $resultJson->setData($responseContent); | ||
} | ||
|
||
/** | ||
* Log information about the last shown advertisement | ||
* | ||
* @return \Magento\Framework\Controller\ResultInterface | ||
*/ | ||
public function execute() | ||
{ | ||
$this->enableAdminUsage(); | ||
$this->markUserNotified(); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function _isAllowed() | ||
{ | ||
return $this->_authorization->isAllowed(static::ADMIN_RESOURCE); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
app/code/Magento/AdminAnalytics/Model/Condition/CanViewNotification.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\AdminAnalytics\Model\Condition; | ||
|
||
use Magento\AdminAnalytics\Model\ResourceModel\Viewer\Logger; | ||
use Magento\Framework\View\Layout\Condition\VisibilityConditionInterface; | ||
use Magento\Framework\App\CacheInterface; | ||
|
||
/** | ||
* Dynamic validator for UI admin analytics notification, control UI component visibility. | ||
*/ | ||
class CanViewNotification implements VisibilityConditionInterface | ||
{ | ||
/** | ||
* Unique condition name. | ||
* | ||
* @var string | ||
*/ | ||
private static $conditionName = 'can_view_admin_usage_notification'; | ||
|
||
/** | ||
* Prefix for cache | ||
* | ||
* @var string | ||
*/ | ||
private static $cachePrefix = 'admin-usage-notification-popup'; | ||
|
||
/** | ||
* @var Logger | ||
*/ | ||
private $viewerLogger; | ||
|
||
/** | ||
* @var CacheInterface | ||
*/ | ||
private $cacheStorage; | ||
|
||
/** | ||
* @param Logger $viewerLogger | ||
* @param CacheInterface $cacheStorage | ||
*/ | ||
public function __construct( | ||
Logger $viewerLogger, | ||
CacheInterface $cacheStorage | ||
) { | ||
$this->viewerLogger = $viewerLogger; | ||
$this->cacheStorage = $cacheStorage; | ||
} | ||
|
||
/** | ||
* Validate if notification popup can be shown and set the notification flag | ||
* | ||
* @param array $arguments Attributes from element node. | ||
* @inheritdoc | ||
*/ | ||
public function isVisible(array $arguments): bool | ||
{ | ||
$cacheKey = self::$cachePrefix; | ||
$value = $this->cacheStorage->load($cacheKey); | ||
if ($value !== 'log-exists') { | ||
$logExists = $this->viewerLogger->checkLogExists(); | ||
if ($logExists) { | ||
$this->cacheStorage->save('log-exists', $cacheKey); | ||
} | ||
return !$logExists; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Get condition name | ||
* | ||
* @return string | ||
*/ | ||
public function getName(): string | ||
{ | ||
return self::$conditionName; | ||
} | ||
} |
Oops, something went wrong.