Skip to content

Commit

Permalink
Merge pull request #40839 from nextcloud/fix/noid/ldap-group-config-di
Browse files Browse the repository at this point in the history
Pass IConfig by constructor to Group_LDAP
  • Loading branch information
blizzz authored Oct 11, 2023
2 parents 9e2d9d5 + c1480aa commit b848841
Show file tree
Hide file tree
Showing 4 changed files with 275 additions and 443 deletions.
12 changes: 5 additions & 7 deletions apps/user_ldap/lib/Group_LDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ class Group_LDAP extends ABackend implements GroupInterface, IGroupLDAP, IGetDis
* @var string $ldapGroupMemberAssocAttr contains the LDAP setting (in lower case) with the same name
*/
protected string $ldapGroupMemberAssocAttr;
private IConfig $config;

public function __construct(Access $access, GroupPluginManager $groupPluginManager) {
public function __construct(Access $access, GroupPluginManager $groupPluginManager, IConfig $config) {
$this->access = $access;
$filter = $this->access->connection->ldapGroupFilter;
$gAssoc = $this->access->connection->ldapGroupMemberAssocAttr;
Expand All @@ -89,6 +90,7 @@ public function __construct(Access $access, GroupPluginManager $groupPluginManag
$this->groupPluginManager = $groupPluginManager;
$this->logger = Server::get(LoggerInterface::class);
$this->ldapGroupMemberAssocAttr = strtolower((string)$gAssoc);
$this->config = $config;
}

/**
Expand Down Expand Up @@ -684,9 +686,7 @@ public function getUserGroups($uid): array {
if ($user instanceof OfflineUser) {
// We load known group memberships from configuration for remnants,
// because LDAP server does not contain them anymore
/** @var IConfig $config */
$config = Server::get(IConfig::class);
$groupStr = $config->getUserValue($uid, 'user_ldap', 'cached-group-memberships-' . $this->access->connection->getConfigPrefix(), '[]');
$groupStr = $this->config->getUserValue($uid, 'user_ldap', 'cached-group-memberships-' . $this->access->connection->getConfigPrefix(), '[]');
return json_decode($groupStr) ?? [];
}

Expand Down Expand Up @@ -803,10 +803,8 @@ public function getUserGroups($uid): array {

$groups = array_unique($groups, SORT_LOCALE_STRING);
$this->access->connection->writeToCache($cacheKey, $groups);
/** @var IConfig $config */
$config = Server::get(IConfig::class);
$groupStr = \json_encode($groups);
$config->setUserValue($ncUid, 'user_ldap', 'cached-group-memberships-' . $this->access->connection->getConfigPrefix(), $groupStr);
$this->config->setUserValue($ncUid, 'user_ldap', 'cached-group-memberships-' . $this->access->connection->getConfigPrefix(), $groupStr);

return $groups;
}
Expand Down
8 changes: 6 additions & 2 deletions apps/user_ldap/lib/Group_Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,27 @@
use OCP\Group\Backend\IGroupDetailsBackend;
use OCP\Group\Backend\INamedBackend;
use OCP\GroupInterface;
use OCP\IConfig;

class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGetDisplayNameBackend, INamedBackend, IDeleteGroupBackend, IBatchMethodsBackend {
private $backends = [];
private ?Group_LDAP $refBackend = null;
private Helper $helper;
private GroupPluginManager $groupPluginManager;
private bool $isSetUp = false;
private IConfig $config;

public function __construct(
Helper $helper,
ILDAPWrapper $ldap,
AccessFactory $accessFactory,
GroupPluginManager $groupPluginManager
GroupPluginManager $groupPluginManager,
IConfig $config,
) {
parent::__construct($ldap, $accessFactory);
$this->helper = $helper;
$this->groupPluginManager = $groupPluginManager;
$this->config = $config;
}

protected function setup(): void {
Expand All @@ -62,7 +66,7 @@ protected function setup(): void {
$serverConfigPrefixes = $this->helper->getServerConfigurationPrefixes(true);
foreach ($serverConfigPrefixes as $configPrefix) {
$this->backends[$configPrefix] =
new Group_LDAP($this->getAccess($configPrefix), $this->groupPluginManager);
new Group_LDAP($this->getAccess($configPrefix), $this->groupPluginManager, $this->config);
if (is_null($this->refBackend)) {
$this->refBackend = &$this->backends[$configPrefix];
}
Expand Down
Loading

0 comments on commit b848841

Please sign in to comment.