From cf0501d632ade26aae8600e53a26455822bd7eec Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Sun, 25 Mar 2018 21:04:03 +0200 Subject: [PATCH] Make the group backends also possible using interfaces Just like for the user backends the group backends should also be properly done using interfaces. This adds the interfaces and abstract class to get started Signed-off-by: Roeland Jago Douma --- lib/public/Group/Backend/ABackend.php | 67 +++++++++++++++++++ .../Group/Backend/IAddToGroupBackend.php | 36 ++++++++++ .../Group/Backend/ICountUsersBackend.php | 36 ++++++++++ .../Group/Backend/ICreateGroupBackend.php | 36 ++++++++++ .../Group/Backend/IDeleteGroupBackend.php | 36 ++++++++++ .../Group/Backend/IGroupDetailsBackend.php | 36 ++++++++++ lib/public/Group/Backend/IIsAdminBackend.php | 36 ++++++++++ .../Group/Backend/IRemoveFromGroupBackend.php | 36 ++++++++++ 8 files changed, 319 insertions(+) create mode 100644 lib/public/Group/Backend/ABackend.php create mode 100644 lib/public/Group/Backend/IAddToGroupBackend.php create mode 100644 lib/public/Group/Backend/ICountUsersBackend.php create mode 100644 lib/public/Group/Backend/ICreateGroupBackend.php create mode 100644 lib/public/Group/Backend/IDeleteGroupBackend.php create mode 100644 lib/public/Group/Backend/IGroupDetailsBackend.php create mode 100644 lib/public/Group/Backend/IIsAdminBackend.php create mode 100644 lib/public/Group/Backend/IRemoveFromGroupBackend.php 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); +}