Skip to content

Commit 0a2fb74

Browse files
committed
Merge remote-tracking branch 'magento/2.4-develop' into no-author/url-user-variable-weee
2 parents 8ba1b79 + f37b43c commit 0a2fb74

File tree

38 files changed

+1094
-461
lines changed

38 files changed

+1094
-461
lines changed

app/code/Magento/AsynchronousOperations/Model/AccessValidator.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
namespace Magento\AsynchronousOperations\Model;
88

9-
/**
10-
* Class AccessValidator
11-
*/
9+
use Magento\AsynchronousOperations\Api\Data\BulkSummaryInterface;
10+
use Magento\Authorization\Model\UserContextInterface;
11+
1212
class AccessValidator
1313
{
1414
/**
15-
* @var \Magento\Authorization\Model\UserContextInterface
15+
* @var UserContextInterface
1616
*/
1717
private $userContext;
1818

@@ -27,13 +27,12 @@ class AccessValidator
2727
private $bulkSummaryFactory;
2828

2929
/**
30-
* AccessValidator constructor.
31-
* @param \Magento\Authorization\Model\UserContextInterface $userContext
30+
* @param UserContextInterface $userContext
3231
* @param \Magento\Framework\EntityManager\EntityManager $entityManager
3332
* @param \Magento\AsynchronousOperations\Api\Data\BulkSummaryInterfaceFactory $bulkSummaryFactory
3433
*/
3534
public function __construct(
36-
\Magento\Authorization\Model\UserContextInterface $userContext,
35+
UserContextInterface $userContext,
3736
\Magento\Framework\EntityManager\EntityManager $entityManager,
3837
\Magento\AsynchronousOperations\Api\Data\BulkSummaryInterfaceFactory $bulkSummaryFactory
3938
) {
@@ -50,11 +49,15 @@ public function __construct(
5049
*/
5150
public function isAllowed($bulkUuid)
5251
{
53-
/** @var \Magento\AsynchronousOperations\Api\Data\BulkSummaryInterface $bulkSummary */
52+
/** @var BulkSummaryInterface $bulkSummary */
5453
$bulkSummary = $this->entityManager->load(
5554
$this->bulkSummaryFactory->create(),
5655
$bulkUuid
5756
);
57+
if ((int) $bulkSummary->getUserType() === UserContextInterface::USER_TYPE_INTEGRATION) {
58+
return true;
59+
}
60+
5861
return ((int) $bulkSummary->getUserId()) === ((int) $this->userContext->getUserId());
5962
}
6063
}

app/code/Magento/AsynchronousOperations/Model/BulkStatus/Options.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,29 @@
77

88
use Magento\AsynchronousOperations\Api\Data\BulkSummaryInterface;
99

10-
/**
11-
* Class Options
12-
*/
1310
class Options implements \Magento\Framework\Data\OptionSourceInterface
1411
{
1512
/**
16-
* @return array
13+
* @inheritDoc
1714
*/
1815
public function toOptionArray()
1916
{
2017
return [
2118
[
2219
'value' => BulkSummaryInterface::NOT_STARTED,
23-
'label' => 'Not Started'
20+
'label' => __('Not Started')
2421
],
2522
[
2623
'value' => BulkSummaryInterface::IN_PROGRESS,
27-
'label' => 'In Progress'
24+
'label' => __('In Progress')
2825
],
2926
[
3027
'value' => BulkSummaryInterface::FINISHED_SUCCESSFULLY,
31-
'label' => 'Finished Successfully'
28+
'label' => __('Finished Successfully')
3229
],
3330
[
3431
'value' => BulkSummaryInterface::FINISHED_WITH_FAILURE,
35-
'label' => 'Finished with Failure'
32+
'label' => __('Finished with Failure')
3633
]
3734
];
3835
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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\AsynchronousOperations\Model\BulkUserType;
9+
10+
use Magento\Authorization\Model\UserContextInterface;
11+
use Magento\Framework\Data\OptionSourceInterface;
12+
13+
class Options implements OptionSourceInterface
14+
{
15+
/**
16+
* @inheritDoc
17+
*/
18+
public function toOptionArray(): array
19+
{
20+
return [
21+
[
22+
'value' => UserContextInterface::USER_TYPE_ADMIN,
23+
'label' => __('Admin user')
24+
],
25+
[
26+
'value' => UserContextInterface::USER_TYPE_INTEGRATION,
27+
'label' => __('Integration')
28+
]
29+
];
30+
}
31+
}

app/code/Magento/AsynchronousOperations/Ui/Component/DataProvider/SearchResult.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface as FetchStrategy;
99
use Magento\Framework\Data\Collection\EntityFactoryInterface as EntityFactory;
1010
use Magento\Framework\Event\ManagerInterface as EventManager;
11+
use Magento\Framework\Model\ResourceModel\AbstractResource;
1112
use Psr\Log\LoggerInterface as Logger;
1213
use Magento\Authorization\Model\UserContextInterface;
1314
use Magento\Framework\Bulk\BulkSummaryInterface;
1415
use Magento\AsynchronousOperations\Model\StatusMapper;
1516
use Magento\AsynchronousOperations\Model\BulkStatus\CalculatedStatusSql;
1617

17-
/**
18-
* Class SearchResult
19-
*/
2018
class SearchResult extends \Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult
2119
{
2220
/**
@@ -40,7 +38,6 @@ class SearchResult extends \Magento\Framework\View\Element\UiComponent\DataProvi
4038
private $calculatedStatusSql;
4139

4240
/**
43-
* SearchResult constructor.
4441
* @param EntityFactory $entityFactory
4542
* @param Logger $logger
4643
* @param FetchStrategy $fetchStrategy
@@ -49,7 +46,7 @@ class SearchResult extends \Magento\Framework\View\Element\UiComponent\DataProvi
4946
* @param StatusMapper $statusMapper
5047
* @param CalculatedStatusSql $calculatedStatusSql
5148
* @param string $mainTable
52-
* @param null $resourceModel
49+
* @param AbstractResource $resourceModel
5350
* @param string $identifierName
5451
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
5552
*/
@@ -80,7 +77,7 @@ public function __construct(
8077
}
8178

8279
/**
83-
* {@inheritdoc}
80+
* @inheritdoc
8481
*/
8582
protected function _initSelect()
8683
{
@@ -93,12 +90,18 @@ protected function _initSelect()
9390
)->where(
9491
'user_id=?',
9592
$this->userContext->getUserId()
93+
)->where(
94+
'user_type=?',
95+
UserContextInterface::USER_TYPE_ADMIN
96+
)->orWhere(
97+
'user_type=?',
98+
UserContextInterface::USER_TYPE_INTEGRATION
9699
);
97100
return $this;
98101
}
99102

100103
/**
101-
* {@inheritdoc}
104+
* @inheritdoc
102105
*/
103106
protected function _afterLoad()
104107
{
@@ -110,7 +113,7 @@ protected function _afterLoad()
110113
}
111114

112115
/**
113-
* {@inheritdoc}
116+
* @inheritdoc
114117
*/
115118
public function addFieldToFilter($field, $condition = null)
116119
{
@@ -133,7 +136,7 @@ public function addFieldToFilter($field, $condition = null)
133136
}
134137

135138
/**
136-
* {@inheritdoc}
139+
* @inheritdoc
137140
*/
138141
public function getSelectCountSql()
139142
{

app/code/Magento/AsynchronousOperations/i18n/en_US.csv

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,10 @@ Error,Error
3333
"Dismiss All Completed Tasks","Dismiss All Completed Tasks"
3434
"Action Details - #","Action Details - #"
3535
"Number of Records Affected","Number of Records Affected"
36+
"User Type","User Type"
37+
"Admin user","Admin user"
38+
"Integration","Integration"
39+
"Not Started","Not Started"
40+
"In Progress","In Progress"
41+
"Finished Successfully","Finished Successfully"
42+
"Finished with Failure","Finished with Failure"

app/code/Magento/AsynchronousOperations/view/adminhtml/ui_component/bulk_listing.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@
8181
<label translate="true">Description of Operation</label>
8282
</settings>
8383
</column>
84+
<column name="user_type" component="Magento_Ui/js/grid/columns/select" sortOrder="55">
85+
<settings>
86+
<filter>select</filter>
87+
<options class="\Magento\AsynchronousOperations\Model\BulkUserType\Options"/>
88+
<dataType>select</dataType>
89+
<label translate="true">User Type</label>
90+
</settings>
91+
</column>
8492
<column name="status" component="Magento_Ui/js/grid/columns/select" sortOrder="60">
8593
<settings>
8694
<filter>select</filter>

app/code/Magento/AwsS3/Driver/AwsS3Factory.php

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,37 @@ class AwsS3Factory implements DriverFactoryInterface
5454
*/
5555
private $cachePrefix;
5656

57+
/**
58+
* @var CachedCredentialsProvider
59+
*/
60+
private $cachedCredentialsProvider;
61+
5762
/**
5863
* @param ObjectManagerInterface $objectManager
5964
* @param Config $config
6065
* @param MetadataProviderInterfaceFactory $metadataProviderFactory
6166
* @param CacheInterfaceFactory $cacheInterfaceFactory
6267
* @param CachedAdapterInterfaceFactory $cachedAdapterInterfaceFactory
6368
* @param string|null $cachePrefix
69+
* @param CachedCredentialsProvider|null $cachedCredentialsProvider
6470
*/
6571
public function __construct(
6672
ObjectManagerInterface $objectManager,
6773
Config $config,
6874
MetadataProviderInterfaceFactory $metadataProviderFactory,
6975
CacheInterfaceFactory $cacheInterfaceFactory,
7076
CachedAdapterInterfaceFactory $cachedAdapterInterfaceFactory,
71-
string $cachePrefix = null
77+
string $cachePrefix = null,
78+
?CachedCredentialsProvider $cachedCredentialsProvider = null,
7279
) {
7380
$this->objectManager = $objectManager;
7481
$this->config = $config;
7582
$this->metadataProviderFactory = $metadataProviderFactory;
7683
$this->cacheInterfaceFactory = $cacheInterfaceFactory;
7784
$this->cachedAdapterInterfaceFactory = $cachedAdapterInterfaceFactory;
7885
$this->cachePrefix = $cachePrefix;
86+
$this->cachedCredentialsProvider = $cachedCredentialsProvider ??
87+
$this->objectManager->get(CachedCredentialsProvider::class);
7988
}
8089

8190
/**
@@ -94,18 +103,19 @@ public function create(): RemoteDriverInterface
94103
}
95104

96105
/**
97-
* @inheritDoc
106+
* Prepare config for S3Client
107+
*
108+
* @param array $config
109+
* @return array
110+
* @throws DriverException
98111
*/
99-
public function createConfigured(
100-
array $config,
101-
string $prefix,
102-
string $cacheAdapter = '',
103-
array $cacheConfig = []
104-
): RemoteDriverInterface {
112+
private function prepareConfig(array $config)
113+
{
105114
$config['version'] = 'latest';
106115

107116
if (empty($config['credentials']['key']) || empty($config['credentials']['secret'])) {
108-
unset($config['credentials']);
117+
//Access keys were not provided; request token from AWS config (local or EC2) and cache result
118+
$config['credentials'] = $this->cachedCredentialsProvider->get();
109119
}
110120

111121
if (empty($config['bucket']) || empty($config['region'])) {
@@ -120,6 +130,19 @@ public function createConfigured(
120130
$config['use_path_style_endpoint'] = boolval($config['path_style']);
121131
}
122132

133+
return $config;
134+
}
135+
136+
/**
137+
* @inheritDoc
138+
*/
139+
public function createConfigured(
140+
array $config,
141+
string $prefix,
142+
string $cacheAdapter = '',
143+
array $cacheConfig = []
144+
): RemoteDriverInterface {
145+
$config = $this->prepareConfig($config);
123146
$client = new S3Client($config);
124147
$adapter = new AwsS3V3Adapter($client, $config['bucket'], $prefix);
125148
$cache = $this->cacheInterfaceFactory->create(
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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\AwsS3\Driver;
9+
10+
use Aws\Credentials\CredentialProvider;
11+
12+
class CachedCredentialsProvider
13+
{
14+
/**
15+
* @var CredentialsCache
16+
*/
17+
private $magentoCacheAdapter;
18+
19+
/**
20+
* @param CredentialsCache $magentoCacheAdapter
21+
*/
22+
public function __construct(CredentialsCache $magentoCacheAdapter)
23+
{
24+
$this->magentoCacheAdapter = $magentoCacheAdapter;
25+
}
26+
27+
/**
28+
* Provides cache mechanism to retrieve and store AWS credentials
29+
*
30+
* @return callable
31+
*/
32+
public function get()
33+
{
34+
//phpcs:ignore Magento2.Functions.DiscouragedFunction
35+
return call_user_func(
36+
[CredentialProvider::class, 'cache'],
37+
//phpcs:ignore Magento2.Functions.DiscouragedFunction
38+
call_user_func([CredentialProvider::class, 'defaultProvider']),
39+
$this->magentoCacheAdapter
40+
);
41+
}
42+
}

0 commit comments

Comments
 (0)