diff --git a/apps/dav/lib/Controller/OutOfOfficeController.php b/apps/dav/lib/Controller/OutOfOfficeController.php index ec2e3c9583386..b9e87b60964a8 100644 --- a/apps/dav/lib/Controller/OutOfOfficeController.php +++ b/apps/dav/lib/Controller/OutOfOfficeController.php @@ -99,7 +99,7 @@ public function getCurrentOutOfOfficeData(string $userId): DataResponse { * 404: No out-of-office data was found */ #[NoAdminRequired] - public function getOutOfOfficeData(string $userId): DataResponse { + public function getOutOfOffice(string $userId): DataResponse { try { $data = $this->absenceService->getAbsence($userId); if ($data === null) { diff --git a/apps/dav/lib/Service/AbsenceService.php b/apps/dav/lib/Service/AbsenceService.php index 81eb2a322f162..3e2a218d52b47 100644 --- a/apps/dav/lib/Service/AbsenceService.php +++ b/apps/dav/lib/Service/AbsenceService.php @@ -145,7 +145,7 @@ public function getAbsence(string $userId): ?Absence { } } - public function getCurrentAbsence(IUser $user): ?Absence { + public function getCurrentAbsence(IUser $user): ?IOutOfOfficeData { try { $absence = $this->absenceMapper->findByUserId($user->getUID()); $oooData = $absence->toOutOufOfficeData( @@ -153,7 +153,7 @@ public function getCurrentAbsence(IUser $user): ?Absence { $this->timezoneService->getUserTimezone($user->getUID()) ?? $this->timezoneService->getDefaultTimezone(), ); if ($this->isInEffect($oooData)) { - return $absence; + return $oooData; } } catch (DoesNotExistException) { // Nothing there to process diff --git a/apps/dav/openapi.json b/apps/dav/openapi.json index a235e3bff1d6b..b0f72d8387a47 100644 --- a/apps/dav/openapi.json +++ b/apps/dav/openapi.json @@ -219,7 +219,7 @@ } } }, - "/ocs/v2.php/apps/dav/api/v1/outOfOffice/{userId}": { + "/ocs/v2.php/apps/dav/api/v1/outOfOffice/{userId}/now": { "get": { "operationId": "out_of_office-get-current-out-of-office-data", "summary": "Get the currently configured out-of-office data of a user.", @@ -317,6 +317,106 @@ } } } + } + }, + "/ocs/v2.php/apps/dav/api/v1/outOfOffice/{userId}": { + "get": { + "operationId": "out_of_office-get-out-of-office", + "summary": "Get the configured out-of-office data of a user.", + "tags": [ + "out_of_office" + ], + "security": [ + { + "bearer_auth": [] + }, + { + "basic_auth": [] + } + ], + "parameters": [ + { + "name": "userId", + "in": "path", + "description": "The user id to get out-of-office data for.", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "OCS-APIRequest", + "in": "header", + "description": "Required to be true for the API request to pass", + "required": true, + "schema": { + "type": "boolean", + "default": true + } + } + ], + "responses": { + "200": { + "description": "Out-of-office data", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": { + "$ref": "#/components/schemas/OutOfOfficeData" + } + } + } + } + } + } + } + }, + "404": { + "description": "No out-of-office data was found", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": { + "nullable": true + } + } + } + } + } + } + } + } + } }, "post": { "operationId": "out_of_office-set-out-of-office", diff --git a/lib/private/User/OutOfOfficeData.php b/lib/private/User/OutOfOfficeData.php index 12b7e03a0ae84..72e42afab6ae6 100644 --- a/lib/private/User/OutOfOfficeData.php +++ b/lib/private/User/OutOfOfficeData.php @@ -60,4 +60,15 @@ public function getShortMessage(): string { public function getMessage(): string { return $this->message; } + + public function jsonSerialize(): array { + return [ + 'id' => $this->getId(), + 'userId' => $this->getUser()->getUID(), + 'startDate' => $this->getStartDate(), + 'endDate' => $this->getEndDate(), + 'shortMessage' => $this->getShortMessage(), + 'message' => $this->getMessage(), + ]; + } } diff --git a/lib/public/User/IOutOfOfficeData.php b/lib/public/User/IOutOfOfficeData.php index 03444449d58f9..baabb269367a4 100644 --- a/lib/public/User/IOutOfOfficeData.php +++ b/lib/public/User/IOutOfOfficeData.php @@ -25,6 +25,7 @@ namespace OCP\User; +use JsonSerializable; use OCP\IUser; /** @@ -32,7 +33,7 @@ * * @since 28.0.0 */ -interface IOutOfOfficeData { +interface IOutOfOfficeData extends JsonSerializable { /** * Get the unique token assigned to the current out-of-office event * @@ -74,4 +75,18 @@ public function getShortMessage(): string; * @since 28.0.0 */ public function getMessage(): string; + + /** + * @return array { + * id: int, + * userId: string, + * startDate: int, + * endDate: int, + * shortMessage: string, + * message: string, + * } + * + * @since 28.0.0 + */ + public function jsonSerialize(): array; }