-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39133 from nextcloud/feature/openapi/user_status
user_status: Add OpenAPI spec
- Loading branch information
Showing
10 changed files
with
167 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
* @copyright Copyright (c) 2020, Georg Ehrke | ||
* | ||
* @author Georg Ehrke <[email protected]> | ||
* @author Kate Döen <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
|
@@ -40,6 +41,9 @@ public function __construct(IEmojiHelper $emojiHelper) { | |
$this->emojiHelper = $emojiHelper; | ||
} | ||
|
||
/** | ||
* @return array{user_status: array{enabled: bool, restore: bool, supports_emoji: bool}} | ||
*/ | ||
public function getCapabilities() { | ||
return [ | ||
'user_status' => [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
* @copyright Copyright (c) 2020, Georg Ehrke | ||
* | ||
* @author Georg Ehrke <[email protected]> | ||
* @author Kate Döen <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
|
@@ -26,6 +27,7 @@ | |
namespace OCA\UserStatus\Controller; | ||
|
||
use OCA\UserStatus\Db\UserStatus; | ||
use OCA\UserStatus\ResponseDefinitions; | ||
use OCA\UserStatus\Service\StatusService; | ||
use OCP\AppFramework\Controller; | ||
use OCP\AppFramework\Db\DoesNotExistException; | ||
|
@@ -39,6 +41,9 @@ | |
use OCP\User\Events\UserLiveStatusEvent; | ||
use OCP\UserStatus\IUserStatus; | ||
|
||
/** | ||
* @psalm-import-type UserStatusPrivate from ResponseDefinitions | ||
*/ | ||
class HeartbeatController extends OCSController { | ||
|
||
/** @var IEventDispatcher */ | ||
|
@@ -67,10 +72,16 @@ public function __construct(string $appName, | |
} | ||
|
||
/** | ||
* Keep the status alive | ||
* | ||
* @NoAdminRequired | ||
* | ||
* @param string $status | ||
* @return DataResponse | ||
* @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{}> | ||
* 200: Status successfully updated | ||
* 204: User has no status to keep alive | ||
* 400: Invalid status to update | ||
*/ | ||
public function heartbeat(string $status): DataResponse { | ||
if (!\in_array($status, [IUserStatus::ONLINE, IUserStatus::AWAY], true)) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
* @copyright Copyright (c) 2020, Georg Ehrke | ||
* | ||
* @author Georg Ehrke <[email protected]> | ||
* @author Kate Döen <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
|
@@ -25,15 +26,17 @@ | |
*/ | ||
namespace OCA\UserStatus\Controller; | ||
|
||
use OCA\UserStatus\ResponseDefinitions; | ||
use OCA\UserStatus\Service\PredefinedStatusService; | ||
use OCP\AppFramework\Http; | ||
use OCP\AppFramework\Http\DataResponse; | ||
use OCP\AppFramework\OCSController; | ||
use OCP\IRequest; | ||
|
||
/** | ||
* Class DefaultStatusController | ||
* | ||
* @package OCA\UserStatus\Controller | ||
* | ||
* @psalm-import-type UserStatusPredefined from ResponseDefinitions | ||
*/ | ||
class PredefinedStatusController extends OCSController { | ||
|
||
|
@@ -55,9 +58,11 @@ public function __construct(string $appName, | |
} | ||
|
||
/** | ||
* Get all predefined messages | ||
* | ||
* @NoAdminRequired | ||
* | ||
* @return DataResponse | ||
* @return DataResponse<Http::STATUS_OK, UserStatusPredefined[], array{}> | ||
*/ | ||
public function findAll():DataResponse { | ||
// Filtering out the invisible one, that should only be set by API | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
* | ||
* @author Christoph Wurst <[email protected]> | ||
* @author Georg Ehrke <[email protected]> | ||
* @author Kate Döen <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
|
@@ -27,14 +28,19 @@ | |
namespace OCA\UserStatus\Controller; | ||
|
||
use OCA\UserStatus\Db\UserStatus; | ||
use OCA\UserStatus\ResponseDefinitions; | ||
use OCA\UserStatus\Service\StatusService; | ||
use OCP\AppFramework\Db\DoesNotExistException; | ||
use OCP\AppFramework\Http; | ||
use OCP\AppFramework\Http\DataResponse; | ||
use OCP\AppFramework\OCS\OCSNotFoundException; | ||
use OCP\AppFramework\OCSController; | ||
use OCP\IRequest; | ||
use OCP\UserStatus\IUserStatus; | ||
|
||
/** | ||
* @psalm-import-type UserStatusPublic from ResponseDefinitions | ||
*/ | ||
class StatusesController extends OCSController { | ||
|
||
/** @var StatusService */ | ||
|
@@ -55,11 +61,13 @@ public function __construct(string $appName, | |
} | ||
|
||
/** | ||
* Find statuses of users | ||
* | ||
* @NoAdminRequired | ||
* | ||
* @param int|null $limit | ||
* @param int|null $offset | ||
* @return DataResponse | ||
* @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{}> | ||
*/ | ||
public function findAll(?int $limit = null, ?int $offset = null): DataResponse { | ||
$allStatuses = $this->service->findAll($limit, $offset); | ||
|
@@ -70,11 +78,15 @@ public function findAll(?int $limit = null, ?int $offset = null): DataResponse { | |
} | ||
|
||
/** | ||
* Find the status of a user | ||
* | ||
* @NoAdminRequired | ||
* | ||
* @param string $userId | ||
* @return DataResponse | ||
* @throws OCSNotFoundException | ||
* @param string $userId ID of the user | ||
* @return DataResponse<Http::STATUS_OK, UserStatusPublic, array{}> | ||
* @throws OCSNotFoundException The user was not found | ||
* | ||
* 200: The status was found successfully | ||
*/ | ||
public function find(string $userId): DataResponse { | ||
try { | ||
|
@@ -88,7 +100,7 @@ public function find(string $userId): DataResponse { | |
|
||
/** | ||
* @param UserStatus $status | ||
* @return array{userId: string, message: string, icon: string, clearAt: int, status: string} | ||
* @return UserStatusPublic | ||
*/ | ||
private function formatStatus(UserStatus $status): array { | ||
$visibleStatus = $status->getStatus(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
* @author Georg Ehrke <[email protected]> | ||
* @author Joas Schilling <[email protected]> | ||
* @author Simon Spannagel <[email protected]> | ||
* @author Kate Döen <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
|
@@ -33,15 +34,20 @@ | |
use OCA\UserStatus\Exception\InvalidStatusIconException; | ||
use OCA\UserStatus\Exception\InvalidStatusTypeException; | ||
use OCA\UserStatus\Exception\StatusMessageTooLongException; | ||
use OCA\UserStatus\ResponseDefinitions; | ||
use OCA\UserStatus\Service\StatusService; | ||
use OCP\AppFramework\Db\DoesNotExistException; | ||
use OCP\AppFramework\Http; | ||
use OCP\AppFramework\Http\DataResponse; | ||
use OCP\AppFramework\OCS\OCSBadRequestException; | ||
use OCP\AppFramework\OCS\OCSNotFoundException; | ||
use OCP\AppFramework\OCSController; | ||
use OCP\ILogger; | ||
use OCP\IRequest; | ||
|
||
/** | ||
* @psalm-import-type UserStatusPrivate from ResponseDefinitions | ||
*/ | ||
class UserStatusController extends OCSController { | ||
|
||
/** @var string */ | ||
|
@@ -74,10 +80,14 @@ public function __construct(string $appName, | |
} | ||
|
||
/** | ||
* Get the status of the current user | ||
* | ||
* @NoAdminRequired | ||
* | ||
* @return DataResponse | ||
* @throws OCSNotFoundException | ||
* @return DataResponse<Http::STATUS_OK, UserStatusPrivate, array{}> | ||
* @throws OCSNotFoundException The user was not found | ||
* | ||
* 200: The status was found successfully | ||
*/ | ||
public function getStatus(): DataResponse { | ||
try { | ||
|
@@ -90,11 +100,15 @@ public function getStatus(): DataResponse { | |
} | ||
|
||
/** | ||
* Update the status type of the current user | ||
* | ||
* @NoAdminRequired | ||
* | ||
* @param string $statusType | ||
* @return DataResponse | ||
* @throws OCSBadRequestException | ||
* @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 | ||
*/ | ||
public function setStatus(string $statusType): DataResponse { | ||
try { | ||
|
@@ -109,12 +123,16 @@ public function setStatus(string $statusType): DataResponse { | |
} | ||
|
||
/** | ||
* Set the message to a predefined message for the current user | ||
* | ||
* @NoAdminRequired | ||
* | ||
* @param string $messageId | ||
* @param int|null $clearAt | ||
* @return DataResponse | ||
* @throws OCSBadRequestException | ||
* @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{}> | ||
* @throws OCSBadRequestException The clearAt or message-id is invalid | ||
* | ||
* 200: The message was updated successfully | ||
*/ | ||
public function setPredefinedMessage(string $messageId, | ||
?int $clearAt): DataResponse { | ||
|
@@ -132,13 +150,17 @@ public function setPredefinedMessage(string $messageId, | |
} | ||
|
||
/** | ||
* Set the message to a custom message for the current user | ||
* | ||
* @NoAdminRequired | ||
* | ||
* @param string|null $statusIcon | ||
* @param string|null $message | ||
* @param int|null $clearAt | ||
* @return DataResponse | ||
* @throws OCSBadRequestException | ||
* @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 | ||
* | ||
* 200: The message was updated successfully | ||
*/ | ||
public function setCustomMessage(?string $statusIcon, | ||
?string $message, | ||
|
@@ -165,19 +187,27 @@ public function setCustomMessage(?string $statusIcon, | |
} | ||
|
||
/** | ||
* Clear the message of the current user | ||
* | ||
* @NoAdminRequired | ||
* | ||
* @return DataResponse | ||
* @return DataResponse<Http::STATUS_OK, array<empty>, array{}> | ||
*/ | ||
public function clearMessage(): DataResponse { | ||
$this->service->clearMessage($this->userId); | ||
return new DataResponse([]); | ||
} | ||
|
||
/** | ||
* Revert the status to the previous status | ||
* | ||
* @NoAdminRequired | ||
* | ||
* @return DataResponse | ||
* @param string $messageId ID of the message to delete | ||
* | ||
* @return DataResponse<Http::STATUS_OK, UserStatusPrivate|array<empty>, array{}> | ||
* | ||
* 200: Status reverted | ||
*/ | ||
public function revertStatus(string $messageId): DataResponse { | ||
$backupStatus = $this->service->revertUserStatus($this->userId, $messageId, true); | ||
|
@@ -189,7 +219,7 @@ public function revertStatus(string $messageId): DataResponse { | |
|
||
/** | ||
* @param UserStatus $status | ||
* @return array | ||
* @return UserStatusPrivate | ||
*/ | ||
private function formatStatus(UserStatus $status): array { | ||
return [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.