aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2023-09-05 11:22:40 +0200
committerCôme Chilliet <come.chilliet@nextcloud.com>2023-09-05 16:56:48 +0200
commit2c8b415c55ead6a54989e74d9ff37e0418e6adb2 (patch)
treea6c898eeb3645d72f6506bc1b78d1d20c9f3554a
parenta5fa1e7715b31a804af56637a82e5717910c8e3f (diff)
downloadnextcloud-server-2c8b415c55ead6a54989e74d9ff37e0418e6adb2.tar.gz
nextcloud-server-2c8b415c55ead6a54989e74d9ff37e0418e6adb2.zip
Move new methods to a new interface in OCP
This avoids breaking compatibility for group backends not based on ABackend abstract class. Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
-rw-r--r--apps/user_ldap/lib/Group_Proxy.php3
-rw-r--r--lib/composer/composer/autoload_classmap.php1
-rw-r--r--lib/composer/composer/autoload_static.php1
-rw-r--r--lib/private/Group/Database.php2
-rw-r--r--lib/private/Group/Manager.php22
-rw-r--r--lib/public/Group/Backend/ABackend.php6
-rw-r--r--lib/public/Group/Backend/IBatchMethodsBackend.php61
-rw-r--r--lib/public/Group/Backend/IGroupDetailsBackend.php15
-rw-r--r--lib/public/GroupInterface.php13
9 files changed, 87 insertions, 37 deletions
diff --git a/apps/user_ldap/lib/Group_Proxy.php b/apps/user_ldap/lib/Group_Proxy.php
index 43997a09892..114902ff9ba 100644
--- a/apps/user_ldap/lib/Group_Proxy.php
+++ b/apps/user_ldap/lib/Group_Proxy.php
@@ -29,13 +29,14 @@
namespace OCA\User_LDAP;
use OC\ServerNotAvailableException;
+use OCP\Group\Backend\IBatchMethodsBackend;
use OCP\Group\Backend\IDeleteGroupBackend;
use OCP\Group\Backend\IGetDisplayNameBackend;
use OCP\Group\Backend\IGroupDetailsBackend;
use OCP\Group\Backend\INamedBackend;
use OCP\GroupInterface;
-class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGetDisplayNameBackend, INamedBackend, IDeleteGroupBackend {
+class Group_Proxy extends Proxy implements \OCP\GroupInterface, IGroupLDAP, IGetDisplayNameBackend, INamedBackend, IDeleteGroupBackend, IBatchMethodsBackend {
private $backends = [];
private ?Group_LDAP $refBackend = null;
private Helper $helper;
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 9bdd0bdc55f..8fc2438866f 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -421,6 +421,7 @@ return array(
'OCP\\GroupInterface' => $baseDir . '/lib/public/GroupInterface.php',
'OCP\\Group\\Backend\\ABackend' => $baseDir . '/lib/public/Group/Backend/ABackend.php',
'OCP\\Group\\Backend\\IAddToGroupBackend' => $baseDir . '/lib/public/Group/Backend/IAddToGroupBackend.php',
+ 'OCP\\Group\\Backend\\IBatchMethodsBackend' => $baseDir . '/lib/public/Group/Backend/IBatchMethodsBackend.php',
'OCP\\Group\\Backend\\ICountDisabledInGroup' => $baseDir . '/lib/public/Group/Backend/ICountDisabledInGroup.php',
'OCP\\Group\\Backend\\ICountUsersBackend' => $baseDir . '/lib/public/Group/Backend/ICountUsersBackend.php',
'OCP\\Group\\Backend\\ICreateGroupBackend' => $baseDir . '/lib/public/Group/Backend/ICreateGroupBackend.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index 2cdd9c8d3ca..fe306545fe3 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -454,6 +454,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\GroupInterface' => __DIR__ . '/../../..' . '/lib/public/GroupInterface.php',
'OCP\\Group\\Backend\\ABackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/ABackend.php',
'OCP\\Group\\Backend\\IAddToGroupBackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/IAddToGroupBackend.php',
+ 'OCP\\Group\\Backend\\IBatchMethodsBackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/IBatchMethodsBackend.php',
'OCP\\Group\\Backend\\ICountDisabledInGroup' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/ICountDisabledInGroup.php',
'OCP\\Group\\Backend\\ICountUsersBackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/ICountUsersBackend.php',
'OCP\\Group\\Backend\\ICreateGroupBackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/ICreateGroupBackend.php',
diff --git a/lib/private/Group/Database.php b/lib/private/Group/Database.php
index 0fcc151363b..4cfc3c1f45a 100644
--- a/lib/private/Group/Database.php
+++ b/lib/private/Group/Database.php
@@ -33,6 +33,7 @@ use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Group\Backend\ABackend;
use OCP\Group\Backend\IAddToGroupBackend;
+use OCP\Group\Backend\IBatchMethodsBackend;
use OCP\Group\Backend\ICountDisabledInGroup;
use OCP\Group\Backend\ICountUsersBackend;
use OCP\Group\Backend\ICreateGroupBackend;
@@ -61,6 +62,7 @@ class Database extends ABackend implements
IRemoveFromGroupBackend,
ISetDisplayNameBackend,
ISearchableGroupBackend,
+ IBatchMethodsBackend,
INamedBackend {
/** @var array<string, array{gid: string, displayname: string}> */
private $groupCache = [];
diff --git a/lib/private/Group/Manager.php b/lib/private/Group/Manager.php
index 924b9a3b6a6..47475121ea0 100644
--- a/lib/private/Group/Manager.php
+++ b/lib/private/Group/Manager.php
@@ -42,6 +42,7 @@ namespace OC\Group;
use OC\Hooks\PublicEmitter;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Group\Backend\IBatchMethodsBackend;
use OCP\Group\Backend\IGroupDetailsBackend;
use OCP\Group\Events\BeforeGroupCreatedEvent;
use OCP\Group\Events\GroupCreatedEvent;
@@ -212,7 +213,7 @@ class Manager extends PublicEmitter implements IGroupManager {
* @param array<string, string> $displayNames Array containing already know display name for a groupId
* @return array<string, IGroup>
*/
- protected function getGroupsObject(array $gids, array $displayNames = []): array {
+ protected function getGroupsObjects(array $gids, array $displayNames = []): array {
$backends = [];
$groups = [];
foreach ($gids as $gid) {
@@ -224,7 +225,14 @@ class Manager extends PublicEmitter implements IGroupManager {
foreach ($this->backends as $backend) {
if ($backend instanceof IGroupDetailsBackend || $backend->implementsActions(GroupInterface::GROUP_DETAILS)) {
/** @var IGroupDetailsBackend $backend */
- $groupDatas = $backend->getGroupsDetails($gids);
+ if ($backend instanceof IBatchMethodsBackend) {
+ $groupDatas = $backend->getGroupsDetails($gids);
+ } else {
+ $groupDatas = [];
+ foreach ($gids as $gid) {
+ $groupDatas[$gid] = $backend->getGroupDetails($gid);
+ }
+ }
foreach ($groupDatas as $gid => $groupData) {
if (!empty($groupData)) {
// take the display name from the last backend that has a non-null one
@@ -235,7 +243,11 @@ class Manager extends PublicEmitter implements IGroupManager {
}
}
} else {
- $existingGroups = $backend->groupsExists($gids);
+ if ($backend instanceof IBatchMethodsBackend) {
+ $existingGroups = $backend->groupsExists($gids);
+ } else {
+ $existingGroups = array_filter($gids, fn (string $gid): bool => $backend->groupExists($gid));
+ }
foreach ($existingGroups as $group) {
$backends[$group][] = $backend;
}
@@ -243,7 +255,7 @@ class Manager extends PublicEmitter implements IGroupManager {
}
foreach ($gids as $gid) {
if (count($backends[$gid]) === 0) {
- continue;
+ continue;
}
$this->cachedGroups[$gid] = new Group($gid, $backends[$gid], $this->dispatcher, $this->userManager, $this, $displayNames[$gid]);
$groups[$gid] = $this->cachedGroups[$gid];
@@ -295,7 +307,7 @@ class Manager extends PublicEmitter implements IGroupManager {
$groups = [];
foreach ($this->backends as $backend) {
$groupIds = $backend->getGroups($search, $limit ?? -1, $offset ?? 0);
- $newGroups = $this->getGroupsObject($groupIds);
+ $newGroups = $this->getGroupsObjects($groupIds);
foreach ($newGroups as $groupId => $group) {
$groups[$groupId] = $group;
}
diff --git a/lib/public/Group/Backend/ABackend.php b/lib/public/Group/Backend/ABackend.php
index 4ce4e430559..274b98655e4 100644
--- a/lib/public/Group/Backend/ABackend.php
+++ b/lib/public/Group/Backend/ABackend.php
@@ -31,7 +31,7 @@ use OCP\GroupInterface;
/**
* @since 14.0.0
*/
-abstract class ABackend implements GroupInterface {
+abstract class ABackend implements GroupInterface, IBatchMethodsBackend {
/**
* @deprecated 14.0.0
* @since 14.0.0
@@ -68,7 +68,7 @@ abstract class ABackend implements GroupInterface {
}
/**
- * @since 26.0.0
+ * @since 28.0.0
*/
public function groupsExists(array $gids): array {
return array_values(array_filter(
@@ -78,7 +78,7 @@ abstract class ABackend implements GroupInterface {
}
/**
- * @since 26.0.0
+ * @since 28.0.0
*/
public function getGroupsDetails(array $gids): array {
if (!($this instanceof IGroupDetailsBackend || $this->implementsActions(GroupInterface::GROUP_DETAILS))) {
diff --git a/lib/public/Group/Backend/IBatchMethodsBackend.php b/lib/public/Group/Backend/IBatchMethodsBackend.php
new file mode 100644
index 00000000000..109f398677f
--- /dev/null
+++ b/lib/public/Group/Backend/IBatchMethodsBackend.php
@@ -0,0 +1,61 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ * @author Carl Schwan <carl@carlschwan.eu>
+ * @author Côme Chilliet <come.chilliet@nextcloud.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace OCP\Group\Backend;
+
+/**
+ * @brief Optional interface for group backends
+ * @since 28.0.0
+ */
+interface IBatchMethodsBackend {
+ /**
+ * @brief Batch method to check if a list of groups exists
+ *
+ * The default implementation in ABackend will just call groupExists in
+ * a loop. But a GroupBackend implementation should provides a more optimized
+ * override this method to provide a more optimized way to execute this operation.
+ *
+ * @param list<string> $gids
+ * @return list<string> the list of group that exists
+ * @since 28.0.0
+ */
+ public function groupsExists(array $gids): array;
+
+ /**
+ * @brief Batch method to get the group details of a list of groups
+ *
+ * The default implementation in ABackend will just call getGroupDetail in
+ * a loop. But a GroupBackend implementation should provides a more optimized
+ * override this method to provide a more optimized way to execute this operation.
+ *
+ * @throw \RuntimeException if called on a backend that doesn't implements IGroupDetailsBackend
+ *
+ * @return array<string, array{displayName: string}>
+ * @since 28.0.0
+ */
+ public function getGroupsDetails(array $gids): array;
+}
diff --git a/lib/public/Group/Backend/IGroupDetailsBackend.php b/lib/public/Group/Backend/IGroupDetailsBackend.php
index a102c8c2eec..851c10388e0 100644
--- a/lib/public/Group/Backend/IGroupDetailsBackend.php
+++ b/lib/public/Group/Backend/IGroupDetailsBackend.php
@@ -41,19 +41,4 @@ interface IGroupDetailsBackend {
* @since 14.0.0
*/
public function getGroupDetails(string $gid): array;
-
-
- /**
- * @brief Batch method to get the group details of a list of groups
- *
- * The default implementation in ABackend will just call getGroupDetail in
- * a loop. But a GroupBackend implementation should provides a more optimized
- * override this method to provide a more optimized way to execute this operation.
- *
- * @throw \RuntimeException if called on a backend that doesn't implements IGroupDetailsBackend
- *
- * @return array<string, array{displayName: string}>
- * @since 26.0.0
- */
- public function getGroupsDetails(array $gids): array;
}
diff --git a/lib/public/GroupInterface.php b/lib/public/GroupInterface.php
index 50374e5a949..599a0eb2ff0 100644
--- a/lib/public/GroupInterface.php
+++ b/lib/public/GroupInterface.php
@@ -108,19 +108,6 @@ interface GroupInterface {
public function groupExists($gid);
/**
- * @brief Batch method to check if a list of groups exists
- *
- * The default implementation in ABackend will just call groupExists in
- * a loop. But a GroupBackend implementation should provides a more optimized
- * override this method to provide a more optimized way to execute this operation.
- *
- * @param list<string> $gids
- * @return list<string> the list of group that exists
- * @since 25.0.0
- */
- public function groupsExists(array $gids): array;
-
- /**
* @brief Get a list of user ids in a group matching the given search parameters.
*
* @param string $gid