summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2019-01-29 22:13:41 +0100
committerGitHub <noreply@github.com>2019-01-29 22:13:41 +0100
commit139055c1ddec25465dd7644de9866cd6a1048da2 (patch)
treeb02635beb3033e482fbb2a0867c497b30c57f117 /lib
parent6b653635a771a0707bae3b6afb89f760faaab8b6 (diff)
parent15abcff2a199f9d80baabbc39778765a2458acd2 (diff)
downloadnextcloud-server-139055c1ddec25465dd7644de9866cd6a1048da2.tar.gz
nextcloud-server-139055c1ddec25465dd7644de9866cd6a1048da2.zip
Merge pull request #13880 from nextcloud/enh/expose_subadmin_to_ocp
Expose subadmin to OCP
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php1
-rw-r--r--lib/composer/composer/autoload_static.php1
-rw-r--r--lib/private/Server.php3
-rw-r--r--lib/private/SubAdmin.php35
-rw-r--r--lib/public/Group/ISubAdmin.php99
5 files changed, 117 insertions, 22 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 37d36e4fc1a..28f0cb0ea0c 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -263,6 +263,7 @@ return array(
'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\\Group\\ISubAdmin' => $baseDir . '/lib/public/Group/ISubAdmin.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 09e24155a46..840fd3acc34 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -293,6 +293,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'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\\Group\\ISubAdmin' => __DIR__ . '/../../..' . '/lib/public/Group/ISubAdmin.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/Server.php b/lib/private/Server.php
index 5a8aad4107c..a20676e5271 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -141,6 +141,7 @@ use OCP\Files\NotFoundException;
use OCP\Files\Storage\IStorageFactory;
use OCP\FullTextSearch\IFullTextSearchManager;
use OCP\GlobalScale\IConfig;
+use OCP\Group\ISubAdmin;
use OCP\ICacheFactory;
use OCP\IDBConnection;
use OCP\IL10N;
@@ -1201,6 +1202,8 @@ class Server extends ServerContainer implements IServerContainer {
);
});
+ $this->registerAlias(ISubAdmin::class, SubAdmin::class);
+
$this->connectDispatcher();
}
diff --git a/lib/private/SubAdmin.php b/lib/private/SubAdmin.php
index 44d79d8994e..f79a0b1ae5a 100644
--- a/lib/private/SubAdmin.php
+++ b/lib/private/SubAdmin.php
@@ -29,13 +29,14 @@
namespace OC;
use OC\Hooks\PublicEmitter;
+use OCP\Group\ISubAdmin;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IDBConnection;
-class SubAdmin extends PublicEmitter {
+class SubAdmin extends PublicEmitter implements ISubAdmin {
/** @var IUserManager */
private $userManager;
@@ -70,9 +71,8 @@ class SubAdmin extends PublicEmitter {
* add a SubAdmin
* @param IUser $user user to be SubAdmin
* @param IGroup $group group $user becomes subadmin of
- * @return bool
*/
- public function createSubAdmin(IUser $user, IGroup $group) {
+ public function createSubAdmin(IUser $user, IGroup $group): void {
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('group_admin')
@@ -84,16 +84,14 @@ class SubAdmin extends PublicEmitter {
$this->emit('\OC\SubAdmin', 'postCreateSubAdmin', [$user, $group]);
\OC_Hook::emit("OC_SubAdmin", "post_createSubAdmin", ["gid" => $group->getGID()]);
- return true;
}
/**
* delete a SubAdmin
* @param IUser $user the user that is the SubAdmin
* @param IGroup $group the group
- * @return bool
*/
- public function deleteSubAdmin(IUser $user, IGroup $group) {
+ public function deleteSubAdmin(IUser $user, IGroup $group): void {
$qb = $this->dbConn->getQueryBuilder();
$qb->delete('group_admin')
@@ -103,7 +101,6 @@ class SubAdmin extends PublicEmitter {
$this->emit('\OC\SubAdmin', 'postDeleteSubAdmin', [$user, $group]);
\OC_Hook::emit("OC_SubAdmin", "post_deleteSubAdmin", ["gid" => $group->getGID()]);
- return true;
}
/**
@@ -111,7 +108,7 @@ class SubAdmin extends PublicEmitter {
* @param IUser $user the SubAdmin
* @return IGroup[]
*/
- public function getSubAdminsGroups(IUser $user) {
+ public function getSubAdminsGroups(IUser $user): array {
$qb = $this->dbConn->getQueryBuilder();
$result = $qb->select('gid')
@@ -136,7 +133,7 @@ class SubAdmin extends PublicEmitter {
* @param IUser $user
* @return array ['displayName' => displayname]
*/
- public function getSubAdminsGroupsName(IUser $user) {
+ public function getSubAdminsGroupsName(IUser $user): array {
return array_map(function($group) {
return array('displayName' => $group->getDisplayName());
}, $this->getSubAdminsGroups($user));
@@ -147,7 +144,7 @@ class SubAdmin extends PublicEmitter {
* @param IGroup $group the group
* @return IUser[]
*/
- public function getGroupsSubAdmins(IGroup $group) {
+ public function getGroupsSubAdmins(IGroup $group): array {
$qb = $this->dbConn->getQueryBuilder();
$result = $qb->select('uid')
@@ -171,7 +168,7 @@ class SubAdmin extends PublicEmitter {
* get all SubAdmins
* @return array
*/
- public function getAllSubAdmins() {
+ public function getAllSubAdmins(): array {
$qb = $this->dbConn->getQueryBuilder();
$result = $qb->select('*')
@@ -200,7 +197,7 @@ class SubAdmin extends PublicEmitter {
* @param IGroup $group
* @return bool
*/
- public function isSubAdminOfGroup(IUser $user, IGroup $group) {
+ public function isSubAdminOfGroup(IUser $user, IGroup $group): bool {
$qb = $this->dbConn->getQueryBuilder();
/*
@@ -224,7 +221,7 @@ class SubAdmin extends PublicEmitter {
* @param IUser $user
* @return bool
*/
- public function isSubAdmin(IUser $user) {
+ public function isSubAdmin(IUser $user): bool {
// Check if the user is already an admin
if ($this->groupManager->isAdmin($user->getUID())) {
return true;
@@ -250,7 +247,7 @@ class SubAdmin extends PublicEmitter {
* @param IUser $user
* @return bool
*/
- public function isUserAccessible($subadmin, $user) {
+ public function isUserAccessible(IUser $subadmin, IUser $user): bool {
if(!$this->isSubAdmin($subadmin)) {
return false;
}
@@ -269,30 +266,24 @@ class SubAdmin extends PublicEmitter {
/**
* delete all SubAdmins by $user
* @param IUser $user
- * @return boolean
*/
- private function post_deleteUser($user) {
+ private function post_deleteUser(IUser $user) {
$qb = $this->dbConn->getQueryBuilder();
$qb->delete('group_admin')
->where($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
->execute();
-
- return true;
}
/**
* delete all SubAdmins by $group
* @param IGroup $group
- * @return boolean
*/
- private function post_deleteGroup($group) {
+ private function post_deleteGroup(IGroup $group) {
$qb = $this->dbConn->getQueryBuilder();
$qb->delete('group_admin')
->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID())))
->execute();
-
- return true;
}
}
diff --git a/lib/public/Group/ISubAdmin.php b/lib/public/Group/ISubAdmin.php
new file mode 100644
index 00000000000..571b9e3db63
--- /dev/null
+++ b/lib/public/Group/ISubAdmin.php
@@ -0,0 +1,99 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019, 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;
+
+use OCP\IGroup;
+use OCP\IUser;
+
+/**
+ * @since 16.0.0
+ */
+interface ISubAdmin {
+
+ /**
+ * add a SubAdmin
+ * @param IUser $user user to be SubAdmin
+ * @param IGroup $group group $user becomes subadmin of
+ *
+ * @since 16.0.0
+ */
+ public function createSubAdmin(IUser $user, IGroup $group): void;
+
+ /**
+ * delete a SubAdmin
+ * @param IUser $user the user that is the SubAdmin
+ * @param IGroup $group the group
+ *
+ * @since 16.0.0
+ */
+ public function deleteSubAdmin(IUser $user, IGroup $group): void;
+
+ /**
+ * get groups of a SubAdmin
+ * @param IUser $user the SubAdmin
+ * @return IGroup[]
+ *
+ * @since 16.0.0
+ */
+ public function getSubAdminsGroups(IUser $user): array;
+
+ /**
+ * get SubAdmins of a group
+ * @param IGroup $group the group
+ * @return IUser[]
+ *
+ * @since 16.0.0
+ */
+ public function getGroupsSubAdmins(IGroup $group): array;
+
+ /**
+ * checks if a user is a SubAdmin of a group
+ * @param IUser $user
+ * @param IGroup $group
+ * @return bool
+ *
+ * @since 16.0.0
+ */
+ public function isSubAdminOfGroup(IUser $user, IGroup $group): bool;
+
+ /**
+ * checks if a user is a SubAdmin
+ * @param IUser $user
+ * @return bool
+ *
+ * @since 16.0.0
+ */
+ public function isSubAdmin(IUser $user): bool;
+
+ /**
+ * checks if a user is a accessible by a subadmin
+ * @param IUser $subadmin
+ * @param IUser $user
+ * @return bool
+ *
+ * @since 16.0.0
+ */
+ public function isUserAccessible(IUser $subadmin, IUser $user): bool;
+}