Skip to content

Commit 44265c9

Browse files
AnujNehraAnujNehra
authored andcommitted
ACP2E-1776: Creating customer(-s) via Async REST API ignores group_id
1 parent efd50e6 commit 44265c9

File tree

3 files changed

+79
-5
lines changed

3 files changed

+79
-5
lines changed

app/code/Magento/Customer/Model/AccountManagement.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -877,11 +877,6 @@ public function getConfirmationStatus($customerId)
877877
*/
878878
public function createAccount(CustomerInterface $customer, $password = null, $redirectUrl = '')
879879
{
880-
$groupId = $customer->getGroupId();
881-
if (isset($groupId) && !$this->authorization->isAllowed(self::ADMIN_RESOURCE)) {
882-
$customer->setGroupId(null);
883-
}
884-
885880
if ($password !== null) {
886881
$this->checkPasswordStrength($password);
887882
$customerEmail = $customer->getEmail();
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\WebapiAsync\Plugin\AsynchronousOperations;
10+
11+
use Magento\Customer\Api\Data\CustomerInterface;
12+
use Magento\Framework\App\ObjectManager;
13+
use Magento\Framework\AuthorizationInterface;
14+
use Magento\Framework\Exception\AuthorizationException;
15+
use Magento\AsynchronousOperations\Model\MassSchedule as SubjectMassSchedule;
16+
17+
/**
18+
* Plugin to check anonymous request contains group id.
19+
*/
20+
class MassSchedule
21+
{
22+
/**
23+
* Authorization level of a basic admin session
24+
*
25+
* @see _isAllowed()
26+
*/
27+
public const ADMIN_RESOURCE = 'Magento_Customer::manage';
28+
29+
/**
30+
* @var AuthorizationInterface
31+
*/
32+
private $authorization;
33+
34+
/**
35+
*
36+
* @param AuthorizationInterface|null $authorization
37+
*/
38+
public function __construct(
39+
AuthorizationInterface $authorization = null
40+
) {
41+
$objectManager = ObjectManager::getInstance();
42+
$this->authorization = $authorization ?? $objectManager->get(AuthorizationInterface::class);
43+
}
44+
45+
/**
46+
* Validate groupId for anonymous request
47+
*
48+
* @param SubjectMassSchedule $subjectMassSchedule
49+
* @param string $topic
50+
* @param array $entitiesArray
51+
* @return void
52+
* @throws AuthorizationException
53+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
54+
*/
55+
public function beforePublishMass(
56+
SubjectMassSchedule $subjectMassSchedule,
57+
string $topic,
58+
array $entitiesArray
59+
): void {
60+
foreach ($entitiesArray as $entityParams) {
61+
foreach ($entityParams as $customer) {
62+
if ($customer instanceof CustomerInterface) {
63+
$groupId = $customer->getGroupId();
64+
if (isset($groupId) && !$this->authorization->isAllowed(self::ADMIN_RESOURCE)) {
65+
$params = ['resources' => self::ADMIN_RESOURCE];
66+
throw new AuthorizationException(
67+
__("The consumer isn't authorized to access %resources.", $params)
68+
);
69+
}
70+
}
71+
}
72+
}
73+
}
74+
}

app/code/Magento/WebapiAsync/etc/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,9 @@
7474
type="Magento\WebapiAsync\Plugin\AsynchronousOperations\MassConsumerEnvelopeCallback"
7575
/>
7676
</type>
77+
<type name="Magento\AsynchronousOperations\Model\MassSchedule">
78+
<plugin name="anonymousRequestForAsynchronousOperationsMassSchedule"
79+
type="Magento\WebapiAsync\Plugin\AsynchronousOperations\MassSchedule"
80+
/>
81+
</type>
7782
</config>

0 commit comments

Comments
 (0)