Skip to content
Snippets Groups Projects

Resolve #2994481 "Nullable service"

Merged Steven Ayers requested to merge issue/ldap-2994481:2994481-nullable-service into 8.x-4.x
4 files
+ 24
104
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -4,13 +4,14 @@ declare(strict_types = 1);
namespace Drupal\ldap_user\Processor;
use Drupal\authorization\AuthorizationServiceInterface;
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;
@@ -97,6 +98,13 @@ class GroupUserUpdateProcessor {
*/
protected $authorizationManager;
/**
* Whether to use LDAP authorization.
*
* @var bool
*/
protected $ldapAuthorizationExists = FALSE;
/**
* Constructor for update process.
*
@@ -108,6 +116,8 @@ class GroupUserUpdateProcessor {
* Config factory.
* @param \Drupal\Core\State\StateInterface $state
* State.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* Module handler service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* Entity type manager.
* @param \Drupal\externalauth\Authmap $external_auth
@@ -116,7 +126,7 @@ class GroupUserUpdateProcessor {
* Query controller.
* @param \Drupal\ldap_user\Processor\DrupalUserProcessor $drupal_user_processor
* Drupal user processor.
* @param \Drupal\ldap_user\LdapUserAuthorizationInterface $authorization_manager
* @param \Drupal\authorization\AuthorizationServiceInterface|null $authorization_manager
* Authorization service.
*/
public function __construct(
@@ -124,11 +134,12 @@ class GroupUserUpdateProcessor {
LdapDetailLog $detail_log,
ConfigFactory $config,
StateInterface $state,
ModuleHandlerInterface $module_handler,
EntityTypeManagerInterface $entity_type_manager,
Authmap $external_auth,
QueryController $query_controller,
DrupalUserProcessor $drupal_user_processor,
LdapUserAuthorizationInterface $authorization_manager) {
?AuthorizationServiceInterface $authorization_manager) {
$this->logger = $logger;
$this->detailLog = $detail_log;
$this->config = $config->get('ldap_user.settings');
@@ -144,6 +155,8 @@ class GroupUserUpdateProcessor {
->load($this->config->get('drupalAcctProvisionServer'));
$this->userStorage = $this->entityTypeManager
->getStorage('user');
$this->ldapAuthorizationExists = $module_handler->moduleExists('ldap_authorization');
}
/**
@@ -198,7 +211,12 @@ class GroupUserUpdateProcessor {
* @throws \Drupal\Core\Entity\EntityStorageException
*/
private function updateAuthorizations(UserInterface $user): void {
$this->authorizationManager->user($user);
if (!$this->ldapAuthorizationExists) {
$user->save();
return;
}
$this->authorizationManager->setUser($user);
$this->authorizationManager->setAllProfiles();
}
/**
Loading