diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index c24b1832ec..19cb583cc9 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -185,6 +185,14 @@ return array( 'OCP\\Files\\UnseekableException' => $baseDir . '/lib/public/Files/UnseekableException.php', 'OCP\\GlobalScale\\IConfig' => $baseDir . '/lib/public/GlobalScale/IConfig.php', '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\\ICountUsersBackend' => $baseDir . '/lib/public/Group/Backend/ICountUsersBackend.php', + 'OCP\\Group\\Backend\\ICreateGroupBackend' => $baseDir . '/lib/public/Group/Backend/ICreateGroupBackend.php', + 'OCP\\Group\\Backend\\IDeleteGroupBackend' => $baseDir . '/lib/public/Group/Backend/IDeleteGroupBackend.php', + 'OCP\\Group\\Backend\\IGroupDetailsBackend' => $baseDir . '/lib/public/Group/Backend/IGroupDetailsBackend.php', + 'OCP\\Group\\Backend\\IIsAdminBackend' => $baseDir . '/lib/public/Group/Backend/IIsAdminBackend.php', + 'OCP\\Group\\Backend\\IRemoveFromGroupBackend' => $baseDir . '/lib/public/Group/Backend/IRemoveFromGroupBackend.php', 'OCP\\Http\\Client\\IClient' => $baseDir . '/lib/public/Http/Client/IClient.php', 'OCP\\Http\\Client\\IClientService' => $baseDir . '/lib/public/Http/Client/IClientService.php', 'OCP\\Http\\Client\\IResponse' => $baseDir . '/lib/public/Http/Client/IResponse.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index b4af81e36c..a913b0498b 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -215,6 +215,14 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OCP\\Files\\UnseekableException' => __DIR__ . '/../../..' . '/lib/public/Files/UnseekableException.php', 'OCP\\GlobalScale\\IConfig' => __DIR__ . '/../../..' . '/lib/public/GlobalScale/IConfig.php', '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\\ICountUsersBackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/ICountUsersBackend.php', + 'OCP\\Group\\Backend\\ICreateGroupBackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/ICreateGroupBackend.php', + 'OCP\\Group\\Backend\\IDeleteGroupBackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/IDeleteGroupBackend.php', + 'OCP\\Group\\Backend\\IGroupDetailsBackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/IGroupDetailsBackend.php', + 'OCP\\Group\\Backend\\IIsAdminBackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/IIsAdminBackend.php', + 'OCP\\Group\\Backend\\IRemoveFromGroupBackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/IRemoveFromGroupBackend.php', 'OCP\\Http\\Client\\IClient' => __DIR__ . '/../../..' . '/lib/public/Http/Client/IClient.php', 'OCP\\Http\\Client\\IClientService' => __DIR__ . '/../../..' . '/lib/public/Http/Client/IClientService.php', 'OCP\\Http\\Client\\IResponse' => __DIR__ . '/../../..' . '/lib/public/Http/Client/IResponse.php', diff --git a/lib/private/Group/Database.php b/lib/private/Group/Database.php index abd7f6ee6e..639df3de0d 100644 --- a/lib/private/Group/Database.php +++ b/lib/private/Group/Database.php @@ -40,12 +40,23 @@ namespace OC\Group; +use OCP\Group\Backend\ABackend; +use OCP\Group\Backend\IAddToGroupBackend; +use OCP\Group\Backend\ICountUsersBackend; +use OCP\Group\Backend\ICreateGroupBackend; +use OCP\Group\Backend\IDeleteGroupBackend; +use OCP\Group\Backend\IRemoveFromGroupBackend; use OCP\IDBConnection; /** * Class for group management in a SQL Database (e.g. MySQL, SQLite) */ -class Database extends Backend { +class Database extends ABackend + implements IAddToGroupBackend, + ICountUsersBackend, + ICreateGroupBackend, + IDeleteGroupBackend, + IRemoveFromGroupBackend { /** @var string[] */ private $groupCache = []; @@ -79,7 +90,7 @@ class Database extends Backend { * Tries to create a new group. If the group name already exists, false will * be returned. */ - public function createGroup( $gid ) { + public function createGroup(string $gid): bool { $this->fixDI(); // Add group @@ -100,7 +111,7 @@ class Database extends Backend { * * Deletes a group and removes it from the group_user-table */ - public function deleteGroup( $gid ) { + public function deleteGroup(string $gid): bool { $this->fixDI(); // Delete the group @@ -160,7 +171,7 @@ class Database extends Backend { * * Adds a user to a group. */ - public function addToGroup( $uid, $gid ) { + public function addToGroup(string $uid, string $gid): bool { $this->fixDI(); // No duplicate entries! @@ -184,7 +195,7 @@ class Database extends Backend { * * removes the user from a group. */ - public function removeFromGroup( $uid, $gid ) { + public function removeFromGroup(string $uid, string $gid): bool { $this->fixDI(); $qb = $this->dbConn->getQueryBuilder(); @@ -333,9 +344,9 @@ class Database extends Backend { * get the number of all users matching the search string in a group * @param string $gid * @param string $search - * @return int|false + * @return int */ - public function countUsersInGroup($gid, $search = '') { + public function countUsersInGroup(string $gid, string $search = ''): int { $this->fixDI(); $query = $this->dbConn->getQueryBuilder(); @@ -355,7 +366,10 @@ class Database extends Backend { if ($count !== false) { $count = (int)$count; + } else { + $count = 0; } + return $count; } diff --git a/lib/public/Group/Backend/ABackend.php b/lib/public/Group/Backend/ABackend.php new file mode 100644 index 0000000000..507b922550 --- /dev/null +++ b/lib/public/Group/Backend/ABackend.php @@ -0,0 +1,67 @@ + + * + * @author Roeland Jago Douma + * + * @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 . + * + */ + +namespace OCP\Group\Backend; + +use OCP\GroupInterface; + +/** + * @since 14.0.0 + */ +abstract class ABackend implements GroupInterface { + + /** + * @deprecated 14.0.0 + * + * @param int $actions The action to check for + * @return bool + */ + public function implementsActions($actions): bool { + $implements = 0; + + if ($this instanceof IAddToGroupBackend) { + $implements |= GroupInterface::ADD_TO_GROUP; + } + if ($this instanceof ICountUsersBackend) { + $implements |= GroupInterface::COUNT_USERS; + } + if ($this instanceof ICreateGroupBackend) { + $implements |= GroupInterface::CREATE_GROUP; + } + if ($this instanceof IDeleteGroupBackend) { + $implements |= GroupInterface::DELETE_GROUP; + } + if ($this instanceof IGroupDetailsBackend) { + $implements |= GroupInterface::GROUP_DETAILS; + } + if ($this instanceof IIsAdminBackend) { + $implements |= GroupInterface::IS_ADMIN; + } + if ($this instanceof IRemoveFromGroupBackend) { + $implements |= GroupInterface::REMOVE_FROM_GOUP; + } + + return (bool)($actions & $implements); + } +} diff --git a/lib/public/Group/Backend/IAddToGroupBackend.php b/lib/public/Group/Backend/IAddToGroupBackend.php new file mode 100644 index 0000000000..aba0444e9b --- /dev/null +++ b/lib/public/Group/Backend/IAddToGroupBackend.php @@ -0,0 +1,36 @@ + + * + * @author Roeland Jago Douma + * + * @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 . + * + */ + +namespace OCP\Group\Backend; + +/** + * @since 14.0.0 + */ +interface IAddToGroupBackend { + + /** + * @since 14.0.0 + */ + public function addToGroup(string $uid, string $gid): bool; +} diff --git a/lib/public/Group/Backend/ICountUsersBackend.php b/lib/public/Group/Backend/ICountUsersBackend.php new file mode 100644 index 0000000000..1bdf54b4fd --- /dev/null +++ b/lib/public/Group/Backend/ICountUsersBackend.php @@ -0,0 +1,36 @@ + + * + * @author Roeland Jago Douma + * + * @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 . + * + */ + +namespace OCP\Group\Backend; + +/** + * @since 14.0.0 + */ +interface ICountUsersBackend { + + /** + * @since 14.0.0 + */ + public function countUsersInGroup(string $gid, string $search = ''): int; +} diff --git a/lib/public/Group/Backend/ICreateGroupBackend.php b/lib/public/Group/Backend/ICreateGroupBackend.php new file mode 100644 index 0000000000..1a49bc221c --- /dev/null +++ b/lib/public/Group/Backend/ICreateGroupBackend.php @@ -0,0 +1,36 @@ + + * + * @author Roeland Jago Douma + * + * @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 . + * + */ + +namespace OCP\Group\Backend; + +/** + * @since 14.0.0 + */ +interface ICreateGroupBackend { + + /** + * @since 14.0.0 + */ + public function createGroup(string $gid): bool; +} diff --git a/lib/public/Group/Backend/IDeleteGroupBackend.php b/lib/public/Group/Backend/IDeleteGroupBackend.php new file mode 100644 index 0000000000..09ca789d38 --- /dev/null +++ b/lib/public/Group/Backend/IDeleteGroupBackend.php @@ -0,0 +1,36 @@ + + * + * @author Roeland Jago Douma + * + * @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 . + * + */ + +namespace OCP\Group\Backend; + +/** + * @since 14.0.0 + */ +interface IDeleteGroupBackend { + + /** + * @since 14.0.0 + */ + public function deleteGroup(string $gid): bool; +} diff --git a/lib/public/Group/Backend/IGroupDetailsBackend.php b/lib/public/Group/Backend/IGroupDetailsBackend.php new file mode 100644 index 0000000000..fd43510c6b --- /dev/null +++ b/lib/public/Group/Backend/IGroupDetailsBackend.php @@ -0,0 +1,36 @@ + + * + * @author Roeland Jago Douma + * + * @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 . + * + */ + +namespace OCP\Group\Backend; + +/** + * @since 14.0.0 + */ +interface IGroupDetailsBackend { + + /** + * @since 14.0.0 + */ + public function getGroupDetails(string $gid): array; +} diff --git a/lib/public/Group/Backend/IIsAdminBackend.php b/lib/public/Group/Backend/IIsAdminBackend.php new file mode 100644 index 0000000000..e253a293dc --- /dev/null +++ b/lib/public/Group/Backend/IIsAdminBackend.php @@ -0,0 +1,36 @@ + + * + * @author Roeland Jago Douma + * + * @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 . + * + */ + +namespace OCP\Group\Backend; + +/** + * @since 14.0.0 + */ +interface IIsAdminBackend { + + /** + * @since 14.0.0 + */ + public function isAdmin(string $uid): bool; +} diff --git a/lib/public/Group/Backend/IRemoveFromGroupBackend.php b/lib/public/Group/Backend/IRemoveFromGroupBackend.php new file mode 100644 index 0000000000..885a5bbcdc --- /dev/null +++ b/lib/public/Group/Backend/IRemoveFromGroupBackend.php @@ -0,0 +1,36 @@ + + * + * @author Roeland Jago Douma + * + * @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 . + * + */ + +namespace OCP\Group\Backend; + +/** + * @since 14.0.0 + */ +interface IRemoveFromGroupBackend { + + /** + * @since 14.0.0 + */ + public function removeFromGroup(string $uid, string $gid); +}