Skip to content

Commit

Permalink
Merge pull request #49797 from nextcloud/fix/user_status/harden-api
Browse files Browse the repository at this point in the history
Harden user_status API
  • Loading branch information
sorbaugh authored Dec 18, 2024
2 parents 5198ef2 + e8e5bd6 commit 407ac7f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion apps/user_status/lib/Controller/StatusesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(
* Find statuses of users
*
* @param int|null $limit Maximum number of statuses to find
* @param int|null $offset Offset for finding statuses
* @param non-negative-int|null $offset Offset for finding statuses
* @return DataResponse<Http::STATUS_OK, list<UserStatusPublic>, array{}>
*
* 200: Statuses returned
Expand Down
5 changes: 4 additions & 1 deletion apps/user_status/lib/Controller/UserStatusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,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,
Expand Down Expand Up @@ -123,6 +123,7 @@ public function setPredefinedMessage(string $messageId,
* @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
*/
Expand All @@ -149,6 +150,8 @@ public function setCustomMessage(?string $statusIcon,
} 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');
}
}

Expand Down
1 change: 0 additions & 1 deletion apps/user_status/lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
* icon: string,
* message: string,
* clearAt: ?UserStatusClearAt,
* visible: ?bool,
* }
*
* @psalm-type UserStatusType = "online"|"away"|"dnd"|"busy"|"offline"|"invisible"
Expand Down
38 changes: 31 additions & 7 deletions apps/user_status/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@
"id",
"icon",
"message",
"clearAt",
"visible"
"clearAt"
],
"properties": {
"id": {
Expand All @@ -127,10 +126,6 @@
"clearAt": {
"$ref": "#/components/schemas/ClearAt",
"nullable": true
},
"visible": {
"type": "boolean",
"nullable": true
}
}
},
Expand Down Expand Up @@ -442,7 +437,8 @@
"schema": {
"type": "integer",
"format": "int64",
"nullable": true
"nullable": true,
"minimum": 0
}
},
{
Expand Down Expand Up @@ -1015,6 +1011,34 @@
}
}
}
},
"404": {
"description": "No status for the current user",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {}
}
}
}
}
}
}
}
}
}
Expand Down

0 comments on commit 407ac7f

Please sign in to comment.