Skip to content

Commit

Permalink
MC-40099: Changing groupId functionality on createAccount()
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Berube committed Jan 25, 2021
1 parent 970d67a commit ed95272
Show file tree
Hide file tree
Showing 2 changed files with 397 additions and 73 deletions.
22 changes: 21 additions & 1 deletion app/code/Magento/Customer/Model/AccountManagement.php
Expand Up @@ -55,6 +55,7 @@
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;
use Psr\Log\LoggerInterface as PsrLogger;
use Magento\Framework\AuthorizationInterface;

/**
* Handle various customer account actions
Expand Down Expand Up @@ -205,6 +206,13 @@ class AccountManagement implements AccountManagementInterface
*/
const MIN_PASSWORD_LENGTH = 6;

/**
* Authorization level of a basic admin session
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Magento_Customer::manage';

/**
* @var CustomerFactory
*/
Expand Down Expand Up @@ -375,6 +383,11 @@ class AccountManagement implements AccountManagementInterface
*/
private $sessionCleaner;

/**
* @var AuthorizationInterface
*/
protected $authorization;

/**
* @param CustomerFactory $customerFactory
* @param ManagerInterface $eventManager
Expand Down Expand Up @@ -410,6 +423,7 @@ class AccountManagement implements AccountManagementInterface
* @param GetCustomerByToken|null $getByToken
* @param AllowedCountries|null $allowedCountriesReader
* @param SessionCleanerInterface|null $sessionCleaner
* @param AuthorizationInterface|null $authorization
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
* @SuppressWarnings(PHPMD.NPathComplexity)
Expand Down Expand Up @@ -450,7 +464,8 @@ public function __construct(
AddressRegistry $addressRegistry = null,
GetCustomerByToken $getByToken = null,
AllowedCountries $allowedCountriesReader = null,
SessionCleanerInterface $sessionCleaner = null
SessionCleanerInterface $sessionCleaner = null,
AuthorizationInterface $authorization = null
) {
$this->customerFactory = $customerFactory;
$this->eventManager = $eventManager;
Expand Down Expand Up @@ -490,6 +505,7 @@ public function __construct(
$this->allowedCountriesReader = $allowedCountriesReader
?: $objectManager->get(AllowedCountries::class);
$this->sessionCleaner = $sessionCleaner ?? $objectManager->get(SessionCleanerInterface::class);
$this->authorization = $authorization ?? $objectManager->get(AuthorizationInterface::class);
}

/**
Expand Down Expand Up @@ -833,6 +849,10 @@ public function getConfirmationStatus($customerId)
*/
public function createAccount(CustomerInterface $customer, $password = null, $redirectUrl = '')
{
if ($customer->getGroupId() && !$this->authorization->isAllowed(self::ADMIN_RESOURCE)) {
$customer->setGroupId(null);
}

if ($password !== null) {
$this->checkPasswordStrength($password);
$customerEmail = $customer->getEmail();
Expand Down

0 comments on commit ed95272

Please sign in to comment.