diff options
author | Maxence Lange <maxence@nextcloud.com> | 2017-08-13 13:25:29 +0300 |
---|---|---|
committer | Maxence Lange <maxence@nextcloud.com> | 2017-08-13 13:25:29 +0300 |
commit | 7119702596814eba098fb1d3902e4debda9883ff (patch) | |
tree | e90c23ea1242799109d2cb2eeb310dd36fd1c510 /lib | |
parent | 9fa777a786745fba87bcb06ddb62d05f03695f61 (diff) |
multiple type members
Signed-off-by: Maxence Lange <maxence@nextcloud.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Api/v1/Circles.php | 19 | ||||
-rw-r--r-- | lib/Controller/MembersController.php | 10 | ||||
-rw-r--r-- | lib/Exceptions/MemberTypeCantEditLevelException.php | 32 | ||||
-rw-r--r-- | lib/Model/BaseCircle.php | 1 | ||||
-rw-r--r-- | lib/Model/Member.php | 13 | ||||
-rw-r--r-- | lib/Service/MembersService.php | 8 |
6 files changed, 67 insertions, 16 deletions
diff --git a/lib/Api/v1/Circles.php b/lib/Api/v1/Circles.php index 14267505..ff51c575 100644 --- a/lib/Api/v1/Circles.php +++ b/lib/Api/v1/Circles.php @@ -231,7 +231,7 @@ class Circles { /** - * Circles::addMember(); + * Circles::addLocalMember(); * * This function will add a user as member of the circle. Current user need at least to be * Moderator. @@ -241,7 +241,7 @@ class Circles { * * @return Member[] */ - public static function addMember($circleUniqueId, $userId) { + public static function addLocalMember($circleUniqueId, $userId) { $c = self::getContainer(); return $c->query('MembersService') @@ -257,14 +257,15 @@ class Circles { * * @param string $circleUniqueId * @param string $userId + * @param int $userType * * @return Member */ - public static function getLocalMember($circleUniqueId, $userId) { + public static function getMember($circleUniqueId, $userId, $userType) { $c = self::getContainer(); return $c->query('MembersService') - ->getMember($circleUniqueId, $userId, Member::TYPE_USER); + ->getMember($circleUniqueId, $userId, $userType); } @@ -276,14 +277,15 @@ class Circles { * * @param string $circleUniqueId * @param string $userId + * @param int $userType * * @return Member[] */ - public static function removeMember($circleUniqueId, $userId) { + public static function removeMember($circleUniqueId, $userId, $userType) { $c = self::getContainer(); return $c->query('MembersService') - ->removeMember($circleUniqueId, $userId); + ->removeMember($circleUniqueId, $userId, $userType); } @@ -297,15 +299,16 @@ class Circles { * * @param string $circleUniqueId * @param string $userId + * @param int $userType * @param int $level * * @return Member[] */ - public static function levelMember($circleUniqueId, $userId, $level) { + public static function levelMember($circleUniqueId, $userId, $userType, $level) { $c = self::getContainer(); return $c->query('MembersService') - ->levelMember($circleUniqueId, $userId, $level); + ->levelMember($circleUniqueId, $userId, $userType, $level); } diff --git a/lib/Controller/MembersController.php b/lib/Controller/MembersController.php index 0002fb9f..656d87df 100644 --- a/lib/Controller/MembersController.php +++ b/lib/Controller/MembersController.php @@ -143,14 +143,15 @@ class MembersController extends BaseController { * * @param string $uniqueId * @param string $member + * @param int $type * @param int $level * * @return DataResponse */ - public function level($uniqueId, $member, $level) { + public function levelMember($uniqueId, $member, $type, $level) { try { - $data = $this->membersService->levelLocalMember($uniqueId, $member, $level); + $data = $this->membersService->levelMember($uniqueId, $member, $type, $level); } catch (\Exception $e) { return $this->fail( @@ -182,13 +183,14 @@ class MembersController extends BaseController { * * @param string $uniqueId * @param string $member + * @param int $type * * @return DataResponse */ - public function removeLocalMember($uniqueId, $member) { + public function removeMember($uniqueId, $member, $type) { try { - $data = $this->membersService->removeMember($uniqueId, $member, Member::TYPE_USER); + $data = $this->membersService->removeMember($uniqueId, $member, $type); } catch (\Exception $e) { return $this->fail( diff --git a/lib/Exceptions/MemberTypeCantEditLevelException.php b/lib/Exceptions/MemberTypeCantEditLevelException.php new file mode 100644 index 00000000..6ba4664f --- /dev/null +++ b/lib/Exceptions/MemberTypeCantEditLevelException.php @@ -0,0 +1,32 @@ +<?php +/** + * Circles - Bring cloud-users closer together. + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Maxence Lange <maxence@pontapreta.net> + * @copyright 2017 + * @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 OCA\Circles\Exceptions; + +class MemberTypeCantEditLevelException extends \Exception { + +} + diff --git a/lib/Model/BaseCircle.php b/lib/Model/BaseCircle.php index dac700f3..ecad20e1 100644 --- a/lib/Model/BaseCircle.php +++ b/lib/Model/BaseCircle.php @@ -138,6 +138,7 @@ class BaseCircle { public function generateUniqueId() { $uniqueId = bin2hex(openssl_random_pseudo_bytes(24)); $this->setUniqueId($uniqueId); + $this->setId($this->getUniqueId()); } public function setName($name) { diff --git a/lib/Model/Member.php b/lib/Model/Member.php index 36b62ba8..e15eb1cb 100644 --- a/lib/Model/Member.php +++ b/lib/Model/Member.php @@ -35,6 +35,7 @@ use OCA\Circles\Exceptions\MemberIsNotAdminException; use OCA\Circles\Exceptions\MemberIsNotModeratorException; use OCA\Circles\Exceptions\MemberIsNotOwnerException; use OCA\Circles\Exceptions\MemberIsOwnerException; +use OCA\Circles\Exceptions\MemberTypeCantEditLevelException; use OCA\Circles\Exceptions\ModeratorIsNotHighEnoughException; class Member extends BaseMember { @@ -220,6 +221,18 @@ class Member extends BaseMember { /** + * @throws MemberTypeCantEditLevelException + */ + public function levelHasToBeEditable() { + if ($this->getType() !== self::TYPE_USER) { + throw new MemberTypeCantEditLevelException( + $this->l10n->t('Level cannot be changed for that type of member') + ); + } + } + + + /** * @throws MemberAlreadyExistsException * @throws MemberIsBlockedException */ diff --git a/lib/Service/MembersService.php b/lib/Service/MembersService.php index 70d63f83..4c07c67e 100644 --- a/lib/Service/MembersService.php +++ b/lib/Service/MembersService.php @@ -264,12 +264,13 @@ class MembersService { /** * @param string $circleUniqueId * @param string $name + * @param int $type * @param int $level * * @return array * @throws \Exception */ - public function levelLocalMember($circleUniqueId, $name, $level) { + public function levelMember($circleUniqueId, $name, $type, $level) { $level = (int)$level; try { @@ -280,9 +281,8 @@ class MembersService { ); } - $member = $this->membersRequest->forceGetMember( - $circle->getUniqueId(), $name, Member::TYPE_USER - ); + $member = $this->membersRequest->forceGetMember($circle->getUniqueId(), $name, $type); + $member->levelHasToBeEditable(); if ($member->getLevel() !== $level) { if ($level === Member::LEVEL_OWNER) { $this->switchOwner($circle, $member); |