diff options
Diffstat (limited to 'apps/user_status/lib/Controller/UserStatusController.php')
-rw-r--r-- | apps/user_status/lib/Controller/UserStatusController.php | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/apps/user_status/lib/Controller/UserStatusController.php b/apps/user_status/lib/Controller/UserStatusController.php index 70bf619253b..9b3807ce86e 100644 --- a/apps/user_status/lib/Controller/UserStatusController.php +++ b/apps/user_status/lib/Controller/UserStatusController.php @@ -20,6 +20,7 @@ use OCA\UserStatus\Service\StatusService; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Http; use OCP\AppFramework\Http\Attribute\ApiRoute; +use OCP\AppFramework\Http\Attribute\NoAdminRequired; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSBadRequestException; use OCP\AppFramework\OCS\OCSNotFoundException; @@ -35,7 +36,7 @@ class UserStatusController extends OCSController { public function __construct( string $appName, IRequest $request, - private string $userId, + private ?string $userId, private LoggerInterface $logger, private StatusService $service, private CalendarStatusService $calendarStatusService, @@ -46,13 +47,12 @@ class UserStatusController extends OCSController { /** * Get the status of the current user * - * @NoAdminRequired - * * @return DataResponse<Http::STATUS_OK, UserStatusPrivate, array{}> * @throws OCSNotFoundException The user was not found * * 200: The status was found successfully */ + #[NoAdminRequired] #[ApiRoute(verb: 'GET', url: '/api/v1/user_status')] public function getStatus(): DataResponse { try { @@ -68,14 +68,13 @@ class UserStatusController extends OCSController { /** * Update the status type of the current user * - * @NoAdminRequired - * * @param string $statusType The new status type * @return DataResponse<Http::STATUS_OK, UserStatusPrivate, array{}> * @throws OCSBadRequestException The status type is invalid * * 200: The status was updated successfully */ + #[NoAdminRequired] #[ApiRoute(verb: 'PUT', url: '/api/v1/user_status/status')] public function setStatus(string $statusType): DataResponse { try { @@ -92,8 +91,6 @@ class UserStatusController extends OCSController { /** * Set the message to a predefined message for the current user * - * @NoAdminRequired - * * @param string $messageId ID of the predefined message * @param int|null $clearAt When the message should be cleared * @return DataResponse<Http::STATUS_OK, UserStatusPrivate, array{}> @@ -101,6 +98,7 @@ class UserStatusController extends OCSController { * * 200: The message was updated successfully */ + #[NoAdminRequired] #[ApiRoute(verb: 'PUT', url: '/api/v1/user_status/message/predefined')] public function setPredefinedMessage(string $messageId, ?int $clearAt): DataResponse { @@ -120,16 +118,16 @@ class UserStatusController extends OCSController { /** * Set the message to a custom message for the current user * - * @NoAdminRequired - * * @param string|null $statusIcon Icon of the status * @param string|null $message Message of the status * @param int|null $clearAt When the message should be cleared * @return DataResponse<Http::STATUS_OK, UserStatusPrivate, array{}> * @throws OCSBadRequestException The clearAt or icon is invalid or the message is too long + * @throws OCSNotFoundException No status for the current user * * 200: The message was updated successfully */ + #[NoAdminRequired] #[ApiRoute(verb: 'PUT', url: '/api/v1/user_status/message/custom')] public function setCustomMessage(?string $statusIcon, ?string $message, @@ -152,18 +150,19 @@ class UserStatusController extends OCSController { } catch (StatusMessageTooLongException $ex) { $this->logger->debug('New user-status for "' . $this->userId . '" was rejected due to a too long status message.'); throw new OCSBadRequestException($ex->getMessage(), $ex); + } catch (DoesNotExistException $ex) { + throw new OCSNotFoundException('No status for the current user'); } } /** * Clear the message of the current user * - * @NoAdminRequired - * - * @return DataResponse<Http::STATUS_OK, array<empty>, array{}> + * @return DataResponse<Http::STATUS_OK, list<empty>, array{}> * * 200: Message cleared successfully */ + #[NoAdminRequired] #[ApiRoute(verb: 'DELETE', url: '/api/v1/user_status/message')] public function clearMessage(): DataResponse { $this->service->clearMessage($this->userId); @@ -173,14 +172,13 @@ class UserStatusController extends OCSController { /** * Revert the status to the previous status * - * @NoAdminRequired - * * @param string $messageId ID of the message to delete * - * @return DataResponse<Http::STATUS_OK, UserStatusPrivate|array<empty>, array{}> + * @return DataResponse<Http::STATUS_OK, UserStatusPrivate|list<empty>, array{}> * * 200: Status reverted */ + #[NoAdminRequired] #[ApiRoute(verb: 'DELETE', url: '/api/v1/user_status/revert/{messageId}')] public function revertStatus(string $messageId): DataResponse { $backupStatus = $this->service->revertUserStatus($this->userId, $messageId, true); |