Added additional methods to FederationLib

This commit is contained in:
Netkas 2023-06-23 00:34:53 -04:00
parent 1be08be54d
commit 34e1f27878
No known key found for this signature in database
GPG key ID: 5DAF58535614062B
2 changed files with 78 additions and 1 deletions

View file

@ -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,
];
}

View file

@ -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;
}
}