aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_status/lib/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'apps/user_status/lib/Controller')
-rw-r--r--apps/user_status/lib/Controller/HeartbeatController.php35
-rw-r--r--apps/user_status/lib/Controller/PredefinedStatusController.php20
-rw-r--r--apps/user_status/lib/Controller/StatusesController.php25
-rw-r--r--apps/user_status/lib/Controller/UserStatusController.php28
4 files changed, 44 insertions, 64 deletions
diff --git a/apps/user_status/lib/Controller/HeartbeatController.php b/apps/user_status/lib/Controller/HeartbeatController.php
index e8325617557..30f4af6572a 100644
--- a/apps/user_status/lib/Controller/HeartbeatController.php
+++ b/apps/user_status/lib/Controller/HeartbeatController.php
@@ -13,6 +13,7 @@ use OCA\UserStatus\ResponseDefinitions;
use OCA\UserStatus\Service\StatusService;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\ApiRoute;
+use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\AppFramework\Utility\ITimeFactory;
@@ -27,43 +28,29 @@ use OCP\UserStatus\IUserStatus;
*/
class HeartbeatController extends OCSController {
- /** @var IEventDispatcher */
- private $eventDispatcher;
-
- /** @var IUserSession */
- private $userSession;
-
- /** @var ITimeFactory */
- private $timeFactory;
-
- /** @var StatusService */
- private $service;
-
- public function __construct(string $appName,
+ public function __construct(
+ string $appName,
IRequest $request,
- IEventDispatcher $eventDispatcher,
- IUserSession $userSession,
- ITimeFactory $timeFactory,
- StatusService $service) {
+ private IEventDispatcher $eventDispatcher,
+ private IUserSession $userSession,
+ private ITimeFactory $timeFactory,
+ private StatusService $service,
+ ) {
parent::__construct($appName, $request);
- $this->eventDispatcher = $eventDispatcher;
- $this->userSession = $userSession;
- $this->timeFactory = $timeFactory;
- $this->service = $service;
}
/**
* Keep the status alive
*
- * @NoAdminRequired
- *
* @param string $status Only online, away
*
- * @return DataResponse<Http::STATUS_OK, UserStatusPrivate, array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NO_CONTENT, array<empty>, array{}>
+ * @return DataResponse<Http::STATUS_OK, UserStatusPrivate, array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NO_CONTENT, list<empty>, array{}>
+ *
* 200: Status successfully updated
* 204: User has no status to keep alive
* 400: Invalid status to update
*/
+ #[NoAdminRequired]
#[ApiRoute(verb: 'PUT', url: '/api/v1/heartbeat')]
public function heartbeat(string $status): DataResponse {
if (!\in_array($status, [IUserStatus::ONLINE, IUserStatus::AWAY], true)) {
diff --git a/apps/user_status/lib/Controller/PredefinedStatusController.php b/apps/user_status/lib/Controller/PredefinedStatusController.php
index 884bc1d2baa..70262d1108a 100644
--- a/apps/user_status/lib/Controller/PredefinedStatusController.php
+++ b/apps/user_status/lib/Controller/PredefinedStatusController.php
@@ -12,6 +12,7 @@ use OCA\UserStatus\ResponseDefinitions;
use OCA\UserStatus\Service\PredefinedStatusService;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\ApiRoute;
+use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\IRequest;
@@ -23,9 +24,6 @@ use OCP\IRequest;
*/
class PredefinedStatusController extends OCSController {
- /** @var PredefinedStatusService */
- private $predefinedStatusService;
-
/**
* AStatusController constructor.
*
@@ -33,27 +31,27 @@ class PredefinedStatusController extends OCSController {
* @param IRequest $request
* @param PredefinedStatusService $predefinedStatusService
*/
- public function __construct(string $appName,
+ public function __construct(
+ string $appName,
IRequest $request,
- PredefinedStatusService $predefinedStatusService) {
+ private PredefinedStatusService $predefinedStatusService,
+ ) {
parent::__construct($appName, $request);
- $this->predefinedStatusService = $predefinedStatusService;
}
/**
* Get all predefined messages
*
- * @NoAdminRequired
- *
- * @return DataResponse<Http::STATUS_OK, UserStatusPredefined[], array{}>
+ * @return DataResponse<Http::STATUS_OK, list<UserStatusPredefined>, array{}>
*
* 200: Predefined statuses returned
*/
+ #[NoAdminRequired]
#[ApiRoute(verb: 'GET', url: '/api/v1/predefined_statuses/')]
public function findAll():DataResponse {
// Filtering out the invisible one, that should only be set by API
- return new DataResponse(array_filter($this->predefinedStatusService->getDefaultStatuses(), function (array $status) {
+ return new DataResponse(array_values(array_filter($this->predefinedStatusService->getDefaultStatuses(), function (array $status) {
return !array_key_exists('visible', $status) || $status['visible'] === true;
- }));
+ })));
}
}
diff --git a/apps/user_status/lib/Controller/StatusesController.php b/apps/user_status/lib/Controller/StatusesController.php
index da942ed7d7c..44688c39023 100644
--- a/apps/user_status/lib/Controller/StatusesController.php
+++ b/apps/user_status/lib/Controller/StatusesController.php
@@ -14,6 +14,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\OCSNotFoundException;
use OCP\AppFramework\OCSController;
@@ -26,9 +27,6 @@ use OCP\UserStatus\IUserStatus;
*/
class StatusesController extends OCSController {
- /** @var StatusService */
- private $service;
-
/**
* StatusesController constructor.
*
@@ -36,44 +34,43 @@ class StatusesController extends OCSController {
* @param IRequest $request
* @param StatusService $service
*/
- public function __construct(string $appName,
+ public function __construct(
+ string $appName,
IRequest $request,
- StatusService $service) {
+ private StatusService $service,
+ ) {
parent::__construct($appName, $request);
- $this->service = $service;
}
/**
* Find statuses of users
*
- * @NoAdminRequired
- *
* @param int|null $limit Maximum number of statuses to find
- * @param int|null $offset Offset for finding statuses
- * @return DataResponse<Http::STATUS_OK, UserStatusPublic[], array{}>
+ * @param non-negative-int|null $offset Offset for finding statuses
+ * @return DataResponse<Http::STATUS_OK, list<UserStatusPublic>, array{}>
*
* 200: Statuses returned
*/
+ #[NoAdminRequired]
#[ApiRoute(verb: 'GET', url: '/api/v1/statuses')]
public function findAll(?int $limit = null, ?int $offset = null): DataResponse {
$allStatuses = $this->service->findAll($limit, $offset);
- return new DataResponse(array_map(function ($userStatus) {
+ return new DataResponse(array_values(array_map(function ($userStatus) {
return $this->formatStatus($userStatus);
- }, $allStatuses));
+ }, $allStatuses)));
}
/**
* Find the status of a user
*
- * @NoAdminRequired
- *
* @param string $userId ID of the user
* @return DataResponse<Http::STATUS_OK, UserStatusPublic, array{}>
* @throws OCSNotFoundException The user was not found
*
* 200: Status returned
*/
+ #[NoAdminRequired]
#[ApiRoute(verb: 'GET', url: '/api/v1/statuses/{userId}')]
public function find(string $userId): DataResponse {
try {
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);