Skip to content

Commit

Permalink
Update OCP
Browse files Browse the repository at this point in the history
  • Loading branch information
nextcloud-command committed Sep 12, 2023
1 parent 671134b commit 8999be9
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 3 deletions.
28 changes: 27 additions & 1 deletion OCP/Group/Backend/ABackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl>
*
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Carl Schwan <carl@carlschwan.eu>
*
* @license GNU AGPL version 3 or any later version
*
Expand All @@ -30,7 +31,7 @@
/**
* @since 14.0.0
*/
abstract class ABackend implements GroupInterface {
abstract class ABackend implements GroupInterface, IBatchMethodsBackend {
/**
* @deprecated 14.0.0
* @since 14.0.0
Expand Down Expand Up @@ -65,4 +66,29 @@ public function implementsActions($actions): bool {

return (bool)($actions & $implements);
}

/**
* @since 28.0.0
*/
public function groupsExists(array $gids): array {
return array_values(array_filter(
$gids,
fn (string $gid): bool => $this->groupExists($gid),
));
}

/**
* @since 28.0.0
*/
public function getGroupsDetails(array $gids): array {
if (!($this instanceof IGroupDetailsBackend || $this->implementsActions(GroupInterface::GROUP_DETAILS))) {
throw new \Exception("Should not have been called");
}
/** @var IGroupDetailsBackend $this */
$groupData = [];
foreach ($gids as $gid) {
$groupData[$gid] = $this->getGroupDetails($gid);
}
return $groupData;
}
}
61 changes: 61 additions & 0 deletions OCP/Group/Backend/IBatchMethodsBackend.php
Original file line number Diff line number Diff line change
@@ -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 getGroupDetails in
* a loop. But a GroupBackend implementation should 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;
}
8 changes: 8 additions & 0 deletions OCP/Group/Backend/IGroupDetailsBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl>
*
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Carl Schwan <carl@carlschwan.eu>
*
* @license GNU AGPL version 3 or any later version
*
Expand All @@ -26,10 +27,17 @@
namespace OCP\Group\Backend;

/**
* @brief Optional interface for group backends
* @since 14.0.0
*/
interface IGroupDetailsBackend {
/**
* @brief Get additional details for a group, for example the display name.
*
* The array returned can be empty when no additional information is available
* for the group.
*
* @return array{displayName?: string}
* @since 14.0.0
*/
public function getGroupDetails(string $gid): array;
Expand Down
6 changes: 4 additions & 2 deletions OCP/GroupInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public function inGroup($uid, $gid);
public function getUserGroups($uid);

/**
* get a list of all groups
* @brief Get a list of all groups
*
* @param string $search
* @param int $limit
* @param int $offset
Expand All @@ -98,7 +99,8 @@ public function getUserGroups($uid);
public function getGroups(string $search = '', int $limit = -1, int $offset = 0);

/**
* check if a group exists
* @brief Check if a group exists
*
* @param string $gid
* @return bool
* @since 4.5.0
Expand Down

0 comments on commit 8999be9

Please sign in to comment.