Skip to content

Commit

Permalink
fixup! fix(dav): Make current ooo info time-dependent
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
  • Loading branch information
ChristophWurst committed Dec 1, 2023
1 parent 929dcea commit 169026c
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 5 deletions.
2 changes: 1 addition & 1 deletion apps/dav/lib/Controller/OutOfOfficeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions apps/dav/lib/Service/AbsenceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ 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(
$user,
$this->timezoneService->getUserTimezone($user->getUID()) ?? $this->timezoneService->getDefaultTimezone(),
);
if ($this->isInEffect($oooData)) {
return $absence;
return $oooData;
}
} catch (DoesNotExistException) {
// Nothing there to process
Expand Down
102 changes: 101 additions & 1 deletion apps/dav/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions lib/private/User/OutOfOfficeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
];
}
}
17 changes: 16 additions & 1 deletion lib/public/User/IOutOfOfficeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@

namespace OCP\User;

use JsonSerializable;
use OCP\IUser;

/**
* DTO to hold out-of-office information of a user
*
* @since 28.0.0
*/
interface IOutOfOfficeData {
interface IOutOfOfficeData extends JsonSerializable {
/**
* Get the unique token assigned to the current out-of-office event
*
Expand Down Expand Up @@ -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;
}

0 comments on commit 169026c

Please sign in to comment.