Skip to content

Commit

Permalink
Fix: Make out of office replacement nullable
Browse files Browse the repository at this point in the history
Signed-off-by: Hamza Mahjoubi <hamzamahjoubi221@gmail.com>
  • Loading branch information
hamza221 committed Jul 3, 2024
1 parent 8469904 commit 85a3b27
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 25 deletions.
10 changes: 5 additions & 5 deletions apps/dav/lib/Controller/OutOfOfficeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ public function getOutOfOffice(string $userId): DataResponse {
* @param string $lastDay Last day of the absence in format `YYYY-MM-DD`
* @param string $status Short text that is set as user status during the absence
* @param string $message Longer multiline message that is shown to others during the absence
* @param string $replacementUserId User id of the replacement user
* @param string $replacementUserDisplayName Display name of the replacement user
* @param ?string $replacementUserId User id of the replacement user
* @param ?string $replacementUserDisplayName Display name of the replacement user
* @return DataResponse<Http::STATUS_OK, DAVOutOfOfficeData, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: 'firstDay'}, array{}>|DataResponse<Http::STATUS_UNAUTHORIZED, null, array{}>|DataResponse<Http::STATUS_NOT_FOUND, null, array{}>
*
* 200: Absence data
Expand All @@ -120,16 +120,16 @@ public function setOutOfOffice(
string $lastDay,
string $status,
string $message,
string $replacementUserId = '',
string $replacementUserDisplayName = ''
?string $replacementUserId,
?string $replacementUserDisplayName

): DataResponse {
$user = $this->userSession?->getUser();
if ($user === null) {
return new DataResponse(null, Http::STATUS_UNAUTHORIZED);
}

if ($replacementUserId !== '') {
if ($replacementUserId !== null) {
$replacementUser = $this->userManager->get($replacementUserId);
if ($replacementUser === null) {
return new DataResponse(null, Http::STATUS_NOT_FOUND);
Expand Down
8 changes: 4 additions & 4 deletions apps/dav/lib/Db/Absence.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
* @method string getMessage()
* @method void setMessage(string $message)
* @method string getReplacementUserId()
* @method void setReplacementUserId(string $replacementUserId)
* @method void setReplacementUserId(?string $replacementUserId)
* @method string getReplacementUserDisplayName()
* @method void setReplacementUserDisplayName(string $replacementUserDisplayName)
* @method void setReplacementUserDisplayName(?string $replacementUserDisplayName)
*/
class Absence extends Entity implements JsonSerializable {
protected string $userId = '';
Expand All @@ -47,9 +47,9 @@ class Absence extends Entity implements JsonSerializable {

protected string $message = '';

protected string $replacementUserId = '';
protected ?string $replacementUserId = null;

protected string $replacementUserDisplayName = '';
protected ?string $replacementUserDisplayName = null;

public function __construct() {
$this->addType('userId', 'string');
Expand Down
4 changes: 2 additions & 2 deletions apps/dav/lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* @psalm-type DAVOutOfOfficeDataCommon = array{
* userId: string,
* message: string,
* replacementUserId: string,
* replacementUserDisplayName: string,
* replacementUserId: ?string,
* replacementUserDisplayName: ?string,
* }
*
* @psalm-type DAVOutOfOfficeData = DAVOutOfOfficeDataCommon&array{
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 @@ -61,8 +61,8 @@ public function createOrUpdateAbsence(
$absence->setLastDay($lastDay);
$absence->setStatus($status);
$absence->setMessage($message);
$absence->setReplacementUserId($replacementUserId ?? '');
$absence->setReplacementUserDisplayName($replacementUserDisplayName ?? '');
$absence->setReplacementUserId($replacementUserId);
$absence->setReplacementUserDisplayName($replacementUserDisplayName);

if ($absence->getId() === null) {
$absence = $this->absenceMapper->insert($absence);
Expand Down
10 changes: 6 additions & 4 deletions apps/dav/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,12 @@
"type": "string"
},
"replacementUserId": {
"type": "string"
"type": "string",
"nullable": true
},
"replacementUserDisplayName": {
"type": "string"
"type": "string",
"nullable": true
}
}
}
Expand Down Expand Up @@ -578,12 +580,12 @@
},
"replacementUserId": {
"type": "string",
"default": "",
"nullable": true,
"description": "User id of the replacement user"
},
"replacementUserDisplayName": {
"type": "string",
"default": "",
"nullable": true,
"description": "Display name of the replacement user"
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/private/User/OutOfOfficeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public function __construct(private string $id,
private int $endDate,
private string $shortMessage,
private string $message,
private string $replacementUserId,
private string $replacementUserDisplayName) {
private ?string $replacementUserId,
private ?string $replacementUserDisplayName) {
}

public function getId(): string {
Expand All @@ -47,11 +47,11 @@ public function getMessage(): string {
return $this->message;
}

public function getReplacementUserId(): string {
public function getReplacementUserId(): ?string {
return $this->replacementUserId;
}

public function getReplacementUserDisplayName(): string {
public function getReplacementUserDisplayName(): ?string {
return $this->replacementUserDisplayName;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/public/User/IOutOfOfficeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
* endDate: int,
* shortMessage: string,
* message: string,
* replacementUserId: string,
* replacementUserDisplayName: string
* replacementUserId: ?string,
* replacementUserDisplayName: ?string
* }
*
* @since 28.0.0
Expand Down Expand Up @@ -76,14 +76,14 @@ public function getMessage(): string;
*
* @since 30.0.0
*/
public function getReplacementUserId(): string;
public function getReplacementUserId(): ?string;

/**
* Get the replacement user displayName for auto responders and similar
*
* @since 30.0.0
*/
public function getReplacementUserDisplayName(): string;
public function getReplacementUserDisplayName(): ?string;

/**
* @return OutOfOfficeData
Expand Down

0 comments on commit 85a3b27

Please sign in to comment.