mirror of
https://github.com/netzbegruenung/circles.git
synced 2024-05-07 14:13:39 +02:00
statuscode
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
This commit is contained in:
parent
71877c14e2
commit
71d0aaf87f
|
@ -80,7 +80,7 @@ class LocalController extends OcsController {
|
|||
|
||||
|
||||
/**
|
||||
* BaseController constructor.
|
||||
* LocalController constructor.
|
||||
*
|
||||
* @param string $appName
|
||||
* @param IRequest $request
|
||||
|
@ -118,7 +118,7 @@ class LocalController extends OcsController {
|
|||
public function create(string $name, bool $personal = false): DataResponse {
|
||||
try {
|
||||
$this->setCurrentFederatedUser();
|
||||
$circle = $this->circleService->create($name);
|
||||
$circle = $this->circleService->create($name, null, $personal);
|
||||
|
||||
return new DataResponse($circle->jsonSerialize());
|
||||
} catch (Exception $e) {
|
||||
|
|
|
@ -28,12 +28,16 @@ declare(strict_types=1);
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
namespace OCA\Circles\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
|
||||
class SingleCircleNotFoundException extends Exception {
|
||||
/**
|
||||
* Class SingleCircleNotFoundException
|
||||
*
|
||||
* @package OCA\Circles\Exceptions
|
||||
*/
|
||||
class SingleCircleNotFoundException extends FederatedItemServerException {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -108,13 +108,13 @@ class CircleCreate implements
|
|||
|
||||
try {
|
||||
$this->circleRequest->getCircle($circle->getId());
|
||||
throw new FederatedEventDSyncException('circle already exist');
|
||||
throw new FederatedEventDSyncException('Circle already exist');
|
||||
} catch (CircleNotFoundException $e) {
|
||||
}
|
||||
|
||||
try {
|
||||
$this->memberRequest->getMember($owner->getId());
|
||||
throw new FederatedEventDSyncException('owner already exist');
|
||||
throw new FederatedEventDSyncException('Owner already exist');
|
||||
} catch (MemberNotFoundException $e) {
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,6 @@ use OCA\Circles\Exceptions\FederatedItemServerException;
|
|||
use OCA\Circles\Exceptions\FederatedUserException;
|
||||
use OCA\Circles\Exceptions\FederatedUserNotFoundException;
|
||||
use OCA\Circles\Exceptions\InvalidIdException;
|
||||
use OCA\Circles\Exceptions\MemberAlreadyExistsException;
|
||||
use OCA\Circles\Exceptions\MemberNotFoundException;
|
||||
use OCA\Circles\Exceptions\OwnerNotFoundException;
|
||||
use OCA\Circles\Exceptions\RemoteInstanceException;
|
||||
|
@ -75,6 +74,7 @@ use OCA\Circles\Service\CircleEventService;
|
|||
use OCA\Circles\Service\CircleService;
|
||||
use OCA\Circles\Service\ConfigService;
|
||||
use OCA\Circles\Service\FederatedUserService;
|
||||
use OCA\Circles\StatusCode;
|
||||
use OCP\IL10N;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
|
@ -171,10 +171,7 @@ class MemberAdd implements
|
|||
$federatedUser =
|
||||
$this->federatedUserService->getFederatedUser($federatedId, $member->getUserType());
|
||||
} catch (MemberNotFoundException $e) {
|
||||
throw new MemberNotFoundException(
|
||||
ucfirst(Member::$DEF_TYPE[$member->getUserType()]) . ' \'%s\' not found',
|
||||
['member' => $member->getUserId() . '@' . $member->getInstance()]
|
||||
);
|
||||
throw new FederatedItemBadRequestException(StatusCode::$MEMBER_ADD[120], 120);
|
||||
}
|
||||
|
||||
$member->importFromIFederatedUser($federatedUser);
|
||||
|
@ -182,10 +179,7 @@ class MemberAdd implements
|
|||
try {
|
||||
$knownMember = $this->memberRequest->searchMember($member);
|
||||
// TODO: maybe member is requesting access
|
||||
throw new MemberAlreadyExistsException(
|
||||
ucfirst(Member::$DEF_TYPE[$member->getUserType()]) . ' %s is already a member',
|
||||
['member' => $member->getUserId() . '@' . $member->getInstance()]
|
||||
);
|
||||
throw new FederatedItemBadRequestException(StatusCode::$MEMBER_ADD[121], 121);
|
||||
} catch (MemberNotFoundException $e) {
|
||||
}
|
||||
|
||||
|
|
|
@ -122,6 +122,7 @@ class CircleService {
|
|||
/**
|
||||
* @param string $name
|
||||
* @param FederatedUser|null $owner
|
||||
* @param bool $personal
|
||||
*
|
||||
* @return SimpleDataStore
|
||||
* @throws FederatedEventException
|
||||
|
@ -135,7 +136,12 @@ class CircleService {
|
|||
* @throws SignatoryException
|
||||
* @throws UnknownRemoteException
|
||||
*/
|
||||
public function create(string $name, ?FederatedUser $owner = null): SimpleDataStore {
|
||||
public function create(
|
||||
string $name,
|
||||
?FederatedUser $owner = null,
|
||||
bool $personal = false
|
||||
): SimpleDataStore {
|
||||
|
||||
$this->federatedUserService->mustHaveCurrentUser();
|
||||
if (is_null($owner)) {
|
||||
$owner = $this->federatedUserService->getCurrentUser();
|
||||
|
@ -144,6 +150,9 @@ class CircleService {
|
|||
$circle = new Circle();
|
||||
$circle->setName($name);
|
||||
$circle->setId($this->token(ManagedModel::ID_LENGTH));
|
||||
if ($personal) {
|
||||
$circle->setConfig(Circle::CFG_SINGLE);
|
||||
}
|
||||
|
||||
$member = new Member();
|
||||
$member->importFromIFederatedUser($owner);
|
||||
|
|
74
lib/StatusCode.php
Normal file
74
lib/StatusCode.php
Normal file
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
/**
|
||||
* 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@artificial-owl.com>
|
||||
* @copyright 2021
|
||||
* @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;
|
||||
|
||||
|
||||
/**
|
||||
* Class StatusCode
|
||||
*
|
||||
* @package OCA\Circles
|
||||
*/
|
||||
class StatusCode {
|
||||
|
||||
|
||||
static $CIRCLE_CREATE = [
|
||||
120 => 'Duplicate name'
|
||||
];
|
||||
|
||||
static $CIRCLE_CONFIG = [
|
||||
120 => 'Invalid configuration'
|
||||
];
|
||||
|
||||
static $CIRCLE_JOIN = [
|
||||
120 => 'You are already a member',
|
||||
121 => 'Circle is full',
|
||||
];
|
||||
|
||||
static $CIRCLE_LEAVE = [
|
||||
];
|
||||
|
||||
static $MEMBER_ADD = [
|
||||
120 => 'Unknown entity',
|
||||
121 => 'Already member of the circle',
|
||||
122 => 'Circle is full',
|
||||
123 => 'The designed circle cannot be added'
|
||||
];
|
||||
|
||||
static $MEMBER_LEVEL = [
|
||||
120 => 'The designed member\'s level is too high'
|
||||
];
|
||||
|
||||
static $MEMBER_REMOVE = [
|
||||
120 => 'The designed member\'s level is too high',
|
||||
];
|
||||
|
||||
}
|
Loading…
Reference in a new issue