diff --git a/src/FederationLib/Enums/Standard/Methods.php b/src/FederationLib/Enums/Standard/Methods.php index c5ddc28..2adc0f6 100644 --- a/src/FederationLib/Enums/Standard/Methods.php +++ b/src/FederationLib/Enums/Standard/Methods.php @@ -11,6 +11,8 @@ public const GET_CLIENT = 'get_client'; public const UPDATE_CLIENT_NAME = 'update_client_name'; public const UPDATE_CLIENT_DESCRIPTION = 'update_client_description'; + public const UPDATE_CLIENT_PERMISSION_ROLE = 'update_client_permission_role'; + public const ALL = [ self::PING, @@ -19,6 +21,7 @@ self::CREATE_CLIENT, self::GET_CLIENT, self::UPDATE_CLIENT_NAME, - self::UPDATE_CLIENT_DESCRIPTION + self::UPDATE_CLIENT_DESCRIPTION, + self::UPDATE_CLIENT_PERMISSION_ROLE, ]; } \ No newline at end of file diff --git a/src/FederationLib/FederationLib.php b/src/FederationLib/FederationLib.php index 03efa8d..68853d0 100755 --- a/src/FederationLib/FederationLib.php +++ b/src/FederationLib/FederationLib.php @@ -263,4 +263,78 @@ return true; } + + /** + * Updates the client's description, return True if successful + * + * @param ClientIdentity|null $identity + * @param string $client_uuid + * @param string|null $new_description + * @return bool + * @throws AccessDeniedException + * @throws ClientNotFoundException + * @throws DatabaseException // TODO: DatabaseException should not be returning from FederationLib, it's not standard + * @throws InternalServerException + * @throws InvalidClientDescriptionException + */ + public function updateClientDescription(?ClientIdentity $identity, string $client_uuid, ?string $new_description): bool + { + if(!$this->checkPermission(Methods::UPDATE_CLIENT_DESCRIPTION, $this->resolveIdentity($identity))) + { + throw new Exceptions\Standard\AccessDeniedException('You do not have sufficient permission to update the description of a client'); + } + + try + { + $this->client_manager->updateClientDescription($client_uuid, $new_description); + } + catch(Exception $e) + { + if(in_array($e->getCode(), ErrorCodes::ALL, true)) + { + throw $e; + } + + throw new Exceptions\Standard\InternalServerException('There was an error while updating the client description', $e); + } + + return true; + } + + /** + * Updates the client's permission role, return True if successful + * + * @param ClientIdentity|null $identity + * @param string $client_uuid + * @param int $new_permission_role + * @return bool + * @throws AccessDeniedException + * @throws ClientNotFoundException + * @throws DatabaseException + * @throws Exceptions\Standard\InvalidPermissionRoleException + * @throws InternalServerException + */ + public function updateClientPermissionRole(?ClientIdentity $identity, string $client_uuid, int $new_permission_role): bool + { + if(!$this->checkPermission(Methods::UPDATE_CLIENT_PERMISSION_ROLE, $this->resolveIdentity($identity))) + { + throw new Exceptions\Standard\AccessDeniedException('You do not have sufficient permission to update the permission role of a client'); + } + + try + { + $this->client_manager->updateClientPermissionRole($client_uuid, $new_permission_role); + } + catch(Exception $e) + { + if(in_array($e->getCode(), ErrorCodes::ALL, true)) + { + throw $e; + } + + throw new Exceptions\Standard\InternalServerException('There was an error while updating the client permission role', $e); + } + + return true; + } } \ No newline at end of file