Skip to content
Snippets Groups Projects

Issue #2994481 by szato, bluegeek9: Remove static calls to authorization.manager

Merged Steven Ayers requested to merge issue/ldap-2994481:2994481-remove-static-calls into 8.x-4.x
Files
4
@@ -6,11 +6,11 @@ namespace Drupal\ldap_user\Processor;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\State\StateInterface;
use Drupal\externalauth\Authmap;
use Drupal\ldap_query\Controller\QueryController;
use Drupal\ldap_servers\Logger\LdapDetailLog;
use Drupal\ldap_user\LdapUserAuthorizationInterface;
use Drupal\user\UserInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Ldap\Entry;
@@ -48,13 +48,6 @@ class GroupUserUpdateProcessor {
*/
protected $state;
/**
* Module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Entity Type Manager.
*
@@ -97,6 +90,13 @@ class GroupUserUpdateProcessor {
*/
protected $userStorage;
/**
* Authorization service.
*
* @var \Drupal\ldap_user\LdapUserAuthorizationInterface
*/
protected $authorizationManager;
/**
* Constructor for update process.
*
@@ -108,8 +108,6 @@ class GroupUserUpdateProcessor {
* Config factory.
* @param \Drupal\Core\State\StateInterface $state
* State.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* Module handler.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* Entity type manager.
* @param \Drupal\externalauth\Authmap $external_auth
@@ -118,26 +116,28 @@ class GroupUserUpdateProcessor {
* Query controller.
* @param \Drupal\ldap_user\Processor\DrupalUserProcessor $drupal_user_processor
* Drupal user processor.
* @param \Drupal\ldap_user\LdapUserAuthorizationInterface $authorization_manager
* Authorization service.
*/
public function __construct(
LoggerInterface $logger,
LdapDetailLog $detail_log,
ConfigFactory $config,
StateInterface $state,
ModuleHandlerInterface $module_handler,
EntityTypeManagerInterface $entity_type_manager,
Authmap $external_auth,
QueryController $query_controller,
DrupalUserProcessor $drupal_user_processor) {
DrupalUserProcessor $drupal_user_processor,
LdapUserAuthorizationInterface $authorization_manager) {
$this->logger = $logger;
$this->detailLog = $detail_log;
$this->config = $config->get('ldap_user.settings');
$this->drupalUserProcessor = $drupal_user_processor;
$this->state = $state;
$this->moduleHandler = $module_handler;
$this->entityTypeManager = $entity_type_manager;
$this->externalAuth = $external_auth;
$this->queryController = $query_controller;
$this->authorizationManager = $authorization_manager;
$this->ldapServer = $this->entityTypeManager
->getStorage('ldap_server')
@@ -198,21 +198,7 @@ class GroupUserUpdateProcessor {
* @throws \Drupal\Core\Entity\EntityStorageException
*/
private function updateAuthorizations(UserInterface $user): void {
if ($this->moduleHandler->moduleExists('ldap_authorization')) {
// We are not injecting this service properly to avoid forcing this
// dependency on authorization.
/** @var \Drupal\authorization\AuthorizationServiceInterface $authorization_manager */
// phpcs:ignore
$authorization_manager = \Drupal::service('authorization.manager');
$authorization_manager->setUser($user);
$authorization_manager->setAllProfiles();
}
else {
// We are saving here for sites without ldap_authorization since saving is
// embedded in setAllProfiles().
// @todo Provide method for decoupling saving users and use it instead.
$user->save();
}
$this->authorizationManager->user($user);
}
/**
Loading