aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2025-01-30 11:49:58 +0100
committerCôme Chilliet <come.chilliet@nextcloud.com>2025-01-30 11:49:58 +0100
commite55806b54626b6e4b8f7ab2baf2a11eab45c2dce (patch)
treea7ce145d01a3d643525cf0b91b0f1a414819a7ab
parent2c773033bcf44268cad1e427fffdb9bbcc6a0327 (diff)
downloadnextcloud-server-e55806b54626b6e4b8f7ab2baf2a11eab45c2dce.tar.gz
nextcloud-server-e55806b54626b6e4b8f7ab2baf2a11eab45c2dce.zip
feat(user_ldap): upstream common code into Proxy class and add public getters for backends
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
-rw-r--r--apps/user_ldap/lib/Group_Proxy.php25
-rw-r--r--apps/user_ldap/lib/Proxy.php41
-rw-r--r--apps/user_ldap/lib/User_Proxy.php40
3 files changed, 59 insertions, 47 deletions
diff --git a/apps/user_ldap/lib/Group_Proxy.php b/apps/user_ldap/lib/Group_Proxy.php
index 8ed3a5dd87d..2c9c6acfdd3 100644
--- a/apps/user_ldap/lib/Group_Proxy.php
+++ b/apps/user_ldap/lib/Group_Proxy.php
@@ -18,11 +18,10 @@ use OCP\GroupInterface;
use OCP\IConfig;
use OCP\IUserManager;
+/**
+ * @template-extends Proxy<Group_LDAP>
+ */
class Group_Proxy extends Proxy implements GroupInterface, IGroupLDAP, IGetDisplayNameBackend, INamedBackend, IDeleteGroupBackend, IBatchMethodsBackend, IIsAdminBackend {
- private $backends = [];
- private ?Group_LDAP $refBackend = null;
- private bool $isSetUp = false;
-
public function __construct(
private Helper $helper,
ILDAPWrapper $ldap,
@@ -31,24 +30,12 @@ class Group_Proxy extends Proxy implements GroupInterface, IGroupLDAP, IGetDispl
private IConfig $config,
private IUserManager $ncUserManager,
) {
- parent::__construct($ldap, $accessFactory);
+ parent::__construct($helper, $ldap, $accessFactory);
}
- protected function setup(): void {
- if ($this->isSetUp) {
- return;
- }
-
- $serverConfigPrefixes = $this->helper->getServerConfigurationPrefixes(true);
- foreach ($serverConfigPrefixes as $configPrefix) {
- $this->backends[$configPrefix] =
- new Group_LDAP($this->getAccess($configPrefix), $this->groupPluginManager, $this->config, $this->ncUserManager);
- if (is_null($this->refBackend)) {
- $this->refBackend = $this->backends[$configPrefix];
- }
- }
- $this->isSetUp = true;
+ protected function newInstance(string $configPrefix): Group_LDAP {
+ return new Group_LDAP($this->getAccess($configPrefix), $this->groupPluginManager, $this->config, $this->ncUserManager);
}
/**
diff --git a/apps/user_ldap/lib/Proxy.php b/apps/user_ldap/lib/Proxy.php
index ab8b9f451f0..fe86519884d 100644
--- a/apps/user_ldap/lib/Proxy.php
+++ b/apps/user_ldap/lib/Proxy.php
@@ -12,13 +12,24 @@ use OCA\User_LDAP\Mapping\UserMapping;
use OCP\ICache;
use OCP\Server;
+/**
+ * @template T
+ */
abstract class Proxy {
/** @var array<string,Access> */
private static array $accesses = [];
private ?bool $isSingleBackend = null;
private ?ICache $cache = null;
+ /** @var T[] */
+ protected array $backends = [];
+ /** @var ?T */
+ protected $refBackend = null;
+
+ protected bool $isSetUp = false;
+
public function __construct(
+ private Helper $helper,
private ILDAPWrapper $ldap,
private AccessFactory $accessFactory,
) {
@@ -28,6 +39,36 @@ abstract class Proxy {
}
}
+ protected function setup(): void {
+ if ($this->isSetUp) {
+ return;
+ }
+
+ $serverConfigPrefixes = $this->helper->getServerConfigurationPrefixes(true);
+ foreach ($serverConfigPrefixes as $configPrefix) {
+ $this->backends[$configPrefix] = $this->newInstance($configPrefix);
+
+ if (is_null($this->refBackend)) {
+ $this->refBackend = $this->backends[$configPrefix];
+ }
+ }
+
+ $this->isSetUp = true;
+ }
+
+ /**
+ * @return T
+ */
+ abstract protected function newInstance(string $configPrefix): object;
+
+ /**
+ * @return T
+ */
+ public function getBackend(string $configPrefix): object {
+ $this->setup();
+ return $this->backends[$configPrefix];
+ }
+
private function addAccess(string $configPrefix): void {
$userMap = Server::get(UserMapping::class);
$groupMap = Server::get(GroupMapping::class);
diff --git a/apps/user_ldap/lib/User_Proxy.php b/apps/user_ldap/lib/User_Proxy.php
index 5079830b83c..2739cdeba67 100644
--- a/apps/user_ldap/lib/User_Proxy.php
+++ b/apps/user_ldap/lib/User_Proxy.php
@@ -18,13 +18,10 @@ use OCP\User\Backend\IProvideEnabledStateBackend;
use OCP\UserInterface;
use Psr\Log\LoggerInterface;
+/**
+ * @template-extends Proxy<User_LDAP>
+ */
class User_Proxy extends Proxy implements IUserBackend, UserInterface, IUserLDAP, ILimitAwareCountUsersBackend, ICountMappedUsersBackend, IProvideEnabledStateBackend {
- /** @var User_LDAP[] */
- private array $backends = [];
- private ?User_LDAP $refBackend = null;
-
- private bool $isSetUp = false;
-
public function __construct(
private Helper $helper,
ILDAPWrapper $ldap,
@@ -34,30 +31,17 @@ class User_Proxy extends Proxy implements IUserBackend, UserInterface, IUserLDAP
private LoggerInterface $logger,
private DeletedUsersIndex $deletedUsersIndex,
) {
- parent::__construct($ldap, $accessFactory);
+ parent::__construct($helper, $ldap, $accessFactory);
}
- protected function setup(): void {
- if ($this->isSetUp) {
- return;
- }
-
- $serverConfigPrefixes = $this->helper->getServerConfigurationPrefixes(true);
- foreach ($serverConfigPrefixes as $configPrefix) {
- $this->backends[$configPrefix] = new User_LDAP(
- $this->getAccess($configPrefix),
- $this->notificationManager,
- $this->userPluginManager,
- $this->logger,
- $this->deletedUsersIndex,
- );
-
- if (is_null($this->refBackend)) {
- $this->refBackend = $this->backends[$configPrefix];
- }
- }
-
- $this->isSetUp = true;
+ protected function newInstance(string $configPrefix): User_LDAP {
+ return new User_LDAP(
+ $this->getAccess($configPrefix),
+ $this->notificationManager,
+ $this->userPluginManager,
+ $this->logger,
+ $this->deletedUsersIndex,
+ );
}
/**
s="o">= null; } }, showFileList: function ($el) { if (!this.recentFileList) { this.recentFileList = this._createRecentFileList($el); } return this.recentFileList; }, hideFileList: function () { if (this.recentFileList) { this.recentFileList.$fileList.empty(); } }, /** * Creates the recent file list. * * @param $el container for the file list * @return {OCA.Files.RecentFileList} file list */ _createRecentFileList: function ($el) { var fileActions = this._createFileActions(); // register recent list for sidebar section return new OCA.Files.RecentFileList( $el, { fileActions: fileActions, // The file list is created when a "show" event is handled, // so it should be marked as "shown" like it would have been // done if handling the event with the file list already // created. shown: true } ); }, _createFileActions: function () { // inherit file actions from the files app var fileActions = new OCA.Files.FileActions(); // note: not merging the legacy actions because legacy apps are not // compatible with the sharing overview and need to be adapted first fileActions.registerDefaultActions(); fileActions.merge(OCA.Files.fileActions); if (!this._globalActionsInitialized) { // in case actions are registered later this._onActionsUpdated = _.bind(this._onActionsUpdated, this); OCA.Files.fileActions.on('setDefault.plugin-recent', this._onActionsUpdated); OCA.Files.fileActions.on('registerAction.plugin-recent', this._onActionsUpdated); this._globalActionsInitialized = true; } // when the user clicks on a folder, redirect to the corresponding // folder in the files app instead of opening it directly fileActions.register('dir', 'Open', OC.PERMISSION_READ, '', function (filename, context) { OCA.Files.App.setActiveView('files', {silent: true}); var path = OC.joinPaths(context.$file.attr('data-path'), filename); OCA.Files.App.fileList.changeDirectory(path, true, true); }); fileActions.setDefault('dir', 'Open'); return fileActions; }, _onActionsUpdated: function (ev) { if (ev.action) { this.recentFileList.fileActions.registerAction(ev.action); } else if (ev.defaultAction) { this.recentFileList.fileActions.setDefault( ev.defaultAction.mime, ev.defaultAction.name ); } } }; })(OCA); OC.Plugins.register('OCA.Files.App', OCA.Files.RecentPlugin);