|
55 | 55 | use Magento\Store\Model\ScopeInterface;
|
56 | 56 | use Magento\Store\Model\StoreManagerInterface;
|
57 | 57 | use Psr\Log\LoggerInterface as PsrLogger;
|
| 58 | +use Magento\Framework\AuthorizationInterface; |
58 | 59 |
|
59 | 60 | /**
|
60 | 61 | * Handle various customer account actions
|
@@ -205,6 +206,13 @@ class AccountManagement implements AccountManagementInterface
|
205 | 206 | */
|
206 | 207 | const MIN_PASSWORD_LENGTH = 6;
|
207 | 208 |
|
| 209 | + /** |
| 210 | + * Authorization level of a basic admin session |
| 211 | + * |
| 212 | + * @see _isAllowed() |
| 213 | + */ |
| 214 | + const ADMIN_RESOURCE = 'Magento_Customer::manage'; |
| 215 | + |
208 | 216 | /**
|
209 | 217 | * @var CustomerFactory
|
210 | 218 | */
|
@@ -375,6 +383,11 @@ class AccountManagement implements AccountManagementInterface
|
375 | 383 | */
|
376 | 384 | private $sessionCleaner;
|
377 | 385 |
|
| 386 | + /** |
| 387 | + * @var AuthorizationInterface |
| 388 | + */ |
| 389 | + protected $authorization; |
| 390 | + |
378 | 391 | /**
|
379 | 392 | * @param CustomerFactory $customerFactory
|
380 | 393 | * @param ManagerInterface $eventManager
|
@@ -410,6 +423,7 @@ class AccountManagement implements AccountManagementInterface
|
410 | 423 | * @param GetCustomerByToken|null $getByToken
|
411 | 424 | * @param AllowedCountries|null $allowedCountriesReader
|
412 | 425 | * @param SessionCleanerInterface|null $sessionCleaner
|
| 426 | + * @param AuthorizationInterface|null $authorization |
413 | 427 | * @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
414 | 428 | * @SuppressWarnings(PHPMD.ExcessiveParameterList)
|
415 | 429 | * @SuppressWarnings(PHPMD.NPathComplexity)
|
@@ -450,7 +464,8 @@ public function __construct(
|
450 | 464 | AddressRegistry $addressRegistry = null,
|
451 | 465 | GetCustomerByToken $getByToken = null,
|
452 | 466 | AllowedCountries $allowedCountriesReader = null,
|
453 |
| - SessionCleanerInterface $sessionCleaner = null |
| 467 | + SessionCleanerInterface $sessionCleaner = null, |
| 468 | + AuthorizationInterface $authorization = null |
454 | 469 | ) {
|
455 | 470 | $this->customerFactory = $customerFactory;
|
456 | 471 | $this->eventManager = $eventManager;
|
@@ -490,6 +505,7 @@ public function __construct(
|
490 | 505 | $this->allowedCountriesReader = $allowedCountriesReader
|
491 | 506 | ?: $objectManager->get(AllowedCountries::class);
|
492 | 507 | $this->sessionCleaner = $sessionCleaner ?? $objectManager->get(SessionCleanerInterface::class);
|
| 508 | + $this->authorization = $authorization ?? $objectManager->get(AuthorizationInterface::class); |
493 | 509 | }
|
494 | 510 |
|
495 | 511 | /**
|
@@ -833,6 +849,11 @@ public function getConfirmationStatus($customerId)
|
833 | 849 | */
|
834 | 850 | public function createAccount(CustomerInterface $customer, $password = null, $redirectUrl = '')
|
835 | 851 | {
|
| 852 | + $groupId = $customer->getGroupId(); |
| 853 | + if (isset($groupId) && !$this->authorization->isAllowed(self::ADMIN_RESOURCE)) { |
| 854 | + $customer->setGroupId(null); |
| 855 | + } |
| 856 | + |
836 | 857 | if ($password !== null) {
|
837 | 858 | $this->checkPasswordStrength($password);
|
838 | 859 | $customerEmail = $customer->getEmail();
|
|
0 commit comments