Merge pull request #9275 from nextcloud/group_backends
Make the group backends also possible using interfaces
This commit is contained in:
commit
000f41ba01
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* @since 14.0.0
|
||||
*/
|
||||
interface IAddToGroupBackend {
|
||||
|
||||
/**
|
||||
* @since 14.0.0
|
||||
*/
|
||||
public function addToGroup(string $uid, string $gid): bool;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* @since 14.0.0
|
||||
*/
|
||||
interface ICountUsersBackend {
|
||||
|
||||
/**
|
||||
* @since 14.0.0
|
||||
*/
|
||||
public function countUsersInGroup(string $gid, string $search = ''): int;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* @since 14.0.0
|
||||
*/
|
||||
interface ICreateGroupBackend {
|
||||
|
||||
/**
|
||||
* @since 14.0.0
|
||||
*/
|
||||
public function createGroup(string $gid): bool;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* @since 14.0.0
|
||||
*/
|
||||
interface IDeleteGroupBackend {
|
||||
|
||||
/**
|
||||
* @since 14.0.0
|
||||
*/
|
||||
public function deleteGroup(string $gid): bool;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* @since 14.0.0
|
||||
*/
|
||||
interface IGroupDetailsBackend {
|
||||
|
||||
/**
|
||||
* @since 14.0.0
|
||||
*/
|
||||
public function getGroupDetails(string $gid): array;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* @since 14.0.0
|
||||
*/
|
||||
interface IIsAdminBackend {
|
||||
|
||||
/**
|
||||
* @since 14.0.0
|
||||
*/
|
||||
public function isAdmin(string $uid): bool;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* @since 14.0.0
|
||||
*/
|
||||
interface IRemoveFromGroupBackend {
|
||||
|
||||
/**
|
||||
* @since 14.0.0
|
||||
*/
|
||||
public function removeFromGroup(string $uid, string $gid);
|
||||
}
|
Loading…
Reference in New Issue