Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(files_reminders): Only allow updating reminders if the file is accessible #50711

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/files_reminders/lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function get(int $fileId): DataResponse {
'dueDate' => $reminder->getDueDate()->format(DateTimeInterface::ATOM), // ISO 8601
];
return new DataResponse($reminderData, Http::STATUS_OK);
} catch (DoesNotExistException $e) {
} catch (NodeNotFoundException | DoesNotExistException $e) {
$reminderData = [
'dueDate' => null,
];
Expand Down Expand Up @@ -125,7 +125,7 @@ public function remove(int $fileId): DataResponse {
try {
$this->reminderService->remove($user, $fileId);
return new DataResponse([], Http::STATUS_OK);
} catch (DoesNotExistException $e) {
} catch (NodeNotFoundException | DoesNotExistException $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
}
Expand Down
20 changes: 16 additions & 4 deletions apps/files_reminders/lib/Service/ReminderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ public function get(int $id): RichReminder {
}

/**
* @throws NodeNotFoundException
* @throws DoesNotExistException
*/
public function getDueForUser(IUser $user, int $fileId): RichReminder {
$this->checkNode($user, $fileId);
$reminder = $this->reminderMapper->findDueForUser($user, $fileId);
return new RichReminder($reminder, $this->root);
}
Expand All @@ -74,17 +76,14 @@ public function getAll(?IUser $user = null) {
*/
public function createOrUpdate(IUser $user, int $fileId, DateTime $dueDate): bool {
$now = new DateTime('now', new DateTimeZone('UTC'));
$this->checkNode($user, $fileId);
try {
$reminder = $this->reminderMapper->findDueForUser($user, $fileId);
$reminder->setDueDate($dueDate);
$reminder->setUpdatedAt($now);
$this->reminderMapper->update($reminder);
return false;
} catch (DoesNotExistException $e) {
$node = $this->root->getUserFolder($user->getUID())->getFirstNodeById($fileId);
if (!$node) {
throw new NodeNotFoundException();
}
// Create new reminder if no reminder is found
$reminder = new Reminder();
$reminder->setUserId($user->getUID());
Expand All @@ -98,9 +97,11 @@ public function createOrUpdate(IUser $user, int $fileId, DateTime $dueDate): boo
}

/**
* @throws NodeNotFoundException
* @throws DoesNotExistException
*/
public function remove(IUser $user, int $fileId): void {
$this->checkNode($user, $fileId);
$reminder = $this->reminderMapper->findDueForUser($user, $fileId);
$this->reminderMapper->delete($reminder);
}
Expand Down Expand Up @@ -161,4 +162,15 @@ public function cleanUp(?int $limit = null): void {
$this->reminderMapper->delete($reminder);
}
}

/**
* @throws NodeNotFoundException
*/
private function checkNode(IUser $user, int $fileId): void {
$userFolder = $this->root->getUserFolder($user->getUID());
$node = $userFolder->getFirstNodeById($fileId);
if ($node === null) {
throw new NodeNotFoundException();
}
}
}
Loading