Skip to content

Commit 7ed31bd

Browse files
committed
chore(dav): clean up calendar placeholder handling
Signed-off-by: Jaggob <37583151+Jaggob@users.noreply.github.com>
1 parent 726f29c commit 7ed31bd

2 files changed

Lines changed: 20 additions & 13 deletions

File tree

lib/DAV/Calendar.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,10 @@ private function getBackendChildren() {
187187
return $this->children;
188188
}
189189

190-
if ($this->board) {
191-
if ($this->stack !== null) {
192-
$this->children = $this->stack->getCards() ?? [];
193-
} else {
194-
$this->children = $this->backend->getChildren($this->board->getId());
195-
}
190+
if ($this->stack !== null) {
191+
$this->children = $this->stack->getCards() ?? [];
196192
} else {
197-
$this->children = [];
193+
$this->children = $this->backend->getChildren($this->board->getId());
198194
}
199195

200196
return $this->children;
@@ -275,7 +271,7 @@ public function propPatch(PropPatch $propPatch) {
275271
* @inheritDoc
276272
*/
277273
public function getProperties($properties) {
278-
$displayName = 'Deck: ' . ($this->board ? $this->board->getTitle() : 'no board object provided');
274+
$displayName = 'Deck: ' . $this->board->getTitle();
279275
if ($this->stack !== null) {
280276
$displayName .= ' / ' . $this->stack->getTitle();
281277
}
@@ -289,7 +285,7 @@ public function getProperties($properties) {
289285

290286
private function extractUserIdFromPrincipalUri(): string {
291287
if (preg_match('#^/?principals/users/([^/]+)$#', $this->principalUri, $matches) !== 1) {
292-
throw new InvalidDataException('Invalid principal URI');
288+
throw new Forbidden('Invalid principal URI');
293289
}
294290

295291
return $matches[1];
@@ -398,7 +394,7 @@ private function buildPlaceholderCalendarObject(string $name) {
398394

399395
$placeholder = new Card();
400396
$placeholder->setId($cardId);
401-
$placeholder->setTitle('Deleted task');
397+
$placeholder->setTitle($this->translatePlaceholderTitle('Deleted task'));
402398
$placeholder->setDescription('');
403399
$placeholder->setDavUri($card->getDavUri());
404400
$placeholder->setStackId($this->stack?->getId() ?? $card->getStackId());
@@ -424,7 +420,7 @@ private function buildPlaceholderCalendarObject(string $name) {
424420

425421
$stack = new Stack();
426422
$stack->setId($stackId);
427-
$stack->setTitle('Deleted list');
423+
$stack->setTitle($this->translatePlaceholderTitle('Deleted list'));
428424
$stack->setBoardId($this->board->getId());
429425
$stack->setOrder(0);
430426
$stack->setDeletedAt(time());
@@ -462,4 +458,16 @@ private function isDirectObjectReadRequest(): bool {
462458
return false;
463459
}
464460
}
461+
462+
private function translatePlaceholderTitle(string $text): string {
463+
if (!class_exists('\OC')) {
464+
return $text;
465+
}
466+
467+
try {
468+
return \OC::$server->getL10N('deck')->t($text);
469+
} catch (\Throwable $e) {
470+
return $text;
471+
}
472+
}
465473
}

lib/DAV/DeckCalendarBackend.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ public function findCalendarObjectByName(string $name, ?int $boardId = null, ?in
159159
} catch (\Throwable $e) {
160160
return null;
161161
}
162-
163-
return null;
164162
}
165163

166164
public function getCalendarRevisionFingerprint(int $boardId, ?int $stackId = null): string {
@@ -456,6 +454,7 @@ private function updateStackFromCalendar(Stack $sourceItem, string $data): Stack
456454
$stack = $this->stackService->find($sourceItem->getId());
457455

458456
$title = trim((string)($todo->SUMMARY ?? ''));
457+
// Some clients serialize the synthetic stack VTODO summary as "List : <title>".
459458
if (mb_strpos($title, 'List : ') === 0) {
460459
$title = mb_substr($title, mb_strlen('List : '));
461460
}

0 commit comments

Comments
 (0)