Skip to content

Commit 2a5bf1f

Browse files
committed
Merge remote-tracking branch 'origin/MC-17149' into 2.3-develop-pr78
2 parents 6d81c4a + d22b6b8 commit 2a5bf1f

File tree

564 files changed

+11211
-2808
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

564 files changed

+11211
-2808
lines changed

CHANGELOG.md

Lines changed: 412 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\AdminAnalytics\Controller\Adminhtml\Config;
9+
10+
use Magento\Backend\App\Action;
11+
use Magento\Framework\App\Action\HttpPostActionInterface;
12+
use Magento\Framework\Controller\ResultFactory;
13+
use Magento\AdminAnalytics\Model\ResourceModel\Viewer\Logger as NotificationLogger;
14+
use Magento\Framework\App\ProductMetadataInterface;
15+
use Magento\Framework\Controller\ResultInterface;
16+
use Magento\Config\Model\Config\Factory;
17+
18+
/**
19+
* Controller to record Admin analytics usage log
20+
*/
21+
class DisableAdminUsage extends Action implements HttpPostActionInterface
22+
{
23+
/**
24+
* @var Factory
25+
*/
26+
private $configFactory;
27+
28+
/**
29+
* @var ProductMetadataInterface
30+
*/
31+
private $productMetadata;
32+
33+
/**
34+
* @var NotificationLogger
35+
*/
36+
private $notificationLogger;
37+
38+
/**
39+
* DisableAdminUsage constructor.
40+
*
41+
* @param Action\Context $context
42+
* @param ProductMetadataInterface $productMetadata
43+
* @param NotificationLogger $notificationLogger
44+
* @param Factory $configFactory
45+
*/
46+
public function __construct(
47+
Action\Context $context,
48+
ProductMetadataInterface $productMetadata,
49+
NotificationLogger $notificationLogger,
50+
Factory $configFactory
51+
) {
52+
parent::__construct($context);
53+
$this->configFactory = $configFactory;
54+
$this->productMetadata = $productMetadata;
55+
$this->notificationLogger = $notificationLogger;
56+
}
57+
58+
/**
59+
* Change the value of config/admin/usage/enabled
60+
*/
61+
private function disableAdminUsage()
62+
{
63+
$configModel = $this->configFactory->create();
64+
$configModel->setDataByPath('admin/usage/enabled', 0);
65+
$configModel->save();
66+
}
67+
68+
/**
69+
* Log information about the last admin usage selection
70+
*
71+
* @return ResultInterface
72+
*/
73+
private function markUserNotified(): ResultInterface
74+
{
75+
$responseContent = [
76+
'success' => $this->notificationLogger->log(
77+
$this->productMetadata->getVersion()
78+
),
79+
'error_message' => ''
80+
];
81+
82+
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
83+
return $resultJson->setData($responseContent);
84+
}
85+
86+
/**
87+
* Log information about the last shown advertisement
88+
*
89+
* @return ResultInterface
90+
*/
91+
public function execute()
92+
{
93+
$this->disableAdminUsage();
94+
$this->markUserNotified();
95+
}
96+
97+
/**
98+
* @inheritDoc
99+
*/
100+
protected function _isAllowed()
101+
{
102+
return $this->_authorization->isAllowed(static::ADMIN_RESOURCE);
103+
}
104+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\AdminAnalytics\Controller\Adminhtml\Config;
9+
10+
use Magento\Backend\App\Action;
11+
use Magento\Framework\App\Action\HttpPostActionInterface;
12+
use Magento\Framework\Controller\ResultFactory;
13+
use Magento\AdminAnalytics\Model\ResourceModel\Viewer\Logger as NotificationLogger;
14+
use Magento\Framework\App\ProductMetadataInterface;
15+
use Magento\Framework\Controller\ResultInterface;
16+
use Magento\Config\Model\Config\Factory;
17+
18+
/**
19+
* Controller to record that the current admin user has responded to Admin Analytics notice
20+
*/
21+
class EnableAdminUsage extends Action implements HttpPostActionInterface
22+
{
23+
/**
24+
* @var Factory
25+
*/
26+
private $configFactory;
27+
28+
/**
29+
* @var ProductMetadataInterface
30+
*/
31+
private $productMetadata;
32+
33+
/**
34+
* @var NotificationLogger
35+
*/
36+
private $notificationLogger;
37+
38+
/**
39+
* @param Action\Context $context
40+
* @param ProductMetadataInterface $productMetadata
41+
* @param NotificationLogger $notificationLogger
42+
* @param Factory $configFactory
43+
*/
44+
public function __construct(
45+
Action\Context $context,
46+
ProductMetadataInterface $productMetadata,
47+
NotificationLogger $notificationLogger,
48+
Factory $configFactory
49+
) {
50+
parent::__construct($context);
51+
$this->configFactory = $configFactory;
52+
$this->productMetadata = $productMetadata;
53+
$this->notificationLogger = $notificationLogger;
54+
}
55+
56+
/**
57+
* Change the value of config/admin/usage/enabled
58+
*/
59+
private function enableAdminUsage()
60+
{
61+
$configModel = $this->configFactory->create();
62+
$configModel->setDataByPath('admin/usage/enabled', 1);
63+
$configModel->save();
64+
}
65+
66+
/**
67+
* Log information about the last user response
68+
*
69+
* @return ResultInterface
70+
*/
71+
private function markUserNotified(): ResultInterface
72+
{
73+
$responseContent = [
74+
'success' => $this->notificationLogger->log(
75+
$this->productMetadata->getVersion()
76+
),
77+
'error_message' => ''
78+
];
79+
80+
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
81+
return $resultJson->setData($responseContent);
82+
}
83+
84+
/**
85+
* Log information about the last shown advertisement
86+
*
87+
* @return \Magento\Framework\Controller\ResultInterface
88+
*/
89+
public function execute()
90+
{
91+
$this->enableAdminUsage();
92+
$this->markUserNotified();
93+
}
94+
95+
/**
96+
* @inheritDoc
97+
*/
98+
protected function _isAllowed()
99+
{
100+
return $this->_authorization->isAllowed(static::ADMIN_RESOURCE);
101+
}
102+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\AdminAnalytics\Model\Condition;
9+
10+
use Magento\AdminAnalytics\Model\ResourceModel\Viewer\Logger;
11+
use Magento\Framework\View\Layout\Condition\VisibilityConditionInterface;
12+
use Magento\Framework\App\CacheInterface;
13+
14+
/**
15+
* Dynamic validator for UI admin analytics notification, control UI component visibility.
16+
*/
17+
class CanViewNotification implements VisibilityConditionInterface
18+
{
19+
/**
20+
* Unique condition name.
21+
*
22+
* @var string
23+
*/
24+
private static $conditionName = 'can_view_admin_usage_notification';
25+
26+
/**
27+
* Prefix for cache
28+
*
29+
* @var string
30+
*/
31+
private static $cachePrefix = 'admin-usage-notification-popup';
32+
33+
/**
34+
* @var Logger
35+
*/
36+
private $viewerLogger;
37+
38+
/**
39+
* @var CacheInterface
40+
*/
41+
private $cacheStorage;
42+
43+
/**
44+
* @param Logger $viewerLogger
45+
* @param CacheInterface $cacheStorage
46+
*/
47+
public function __construct(
48+
Logger $viewerLogger,
49+
CacheInterface $cacheStorage
50+
) {
51+
$this->viewerLogger = $viewerLogger;
52+
$this->cacheStorage = $cacheStorage;
53+
}
54+
55+
/**
56+
* Validate if notification popup can be shown and set the notification flag
57+
*
58+
* @param array $arguments Attributes from element node.
59+
* @inheritdoc
60+
*/
61+
public function isVisible(array $arguments): bool
62+
{
63+
$cacheKey = self::$cachePrefix;
64+
$value = $this->cacheStorage->load($cacheKey);
65+
if ($value !== 'log-exists') {
66+
$logExists = $this->viewerLogger->checkLogExists();
67+
if ($logExists) {
68+
$this->cacheStorage->save('log-exists', $cacheKey);
69+
}
70+
return !$logExists;
71+
}
72+
return false;
73+
}
74+
75+
/**
76+
* Get condition name
77+
*
78+
* @return string
79+
*/
80+
public function getName(): string
81+
{
82+
return self::$conditionName;
83+
}
84+
}

0 commit comments

Comments
 (0)