Skip to content

Commit

Permalink
fixup! fix: Cache if no share is found for current poll in Acl
Browse files Browse the repository at this point in the history
  • Loading branch information
artonge committed Apr 24, 2024
1 parent 68439a5 commit 549f6e0
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/Model/Acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Acl implements JsonSerializable {
public const PERMISSION_ALL_ACCESS = 'allAccess';
private ?int $pollId = null;
private ?UserBase $currentUser = null;
// Cache whether the current poll has shares
private bool $noShare = false;


Expand Down Expand Up @@ -149,7 +150,7 @@ public function setPollId(?int $pollId = null, string $permission = self::PERMIS
} else {
$this->pollId = $pollId;
}

$this->loadPoll();
$this->request($permission);

Expand Down Expand Up @@ -187,7 +188,7 @@ public function getShare(): ?Share {

return $this->share;
}

/**
* load poll
* @throws NotFoundException Thrown if poll not found
Expand Down Expand Up @@ -222,10 +223,12 @@ private function loadShare(): void {
if (!$this->getToken()) {
if ($this->getCurrentUser()->getIsLoggedIn()) {
// search for logged in user's share, load it and return
$this->noShare = true;
$this->share = $this->shareMapper->findByPollAndUser($this->getPollId(), $this->getUserId());
/* If previous call did not throw, there is a share */
$this->noShare = false;
try {
$this->share = $this->shareMapper->findByPollAndUser($this->getPollId(), $this->getUserId());
} catch (\Throwable $ex) {
$this->noShare = true;
throw $ex;
}
// store share in session for further validations
// $this->session->set(AppConstants::SESSION_KEY_SHARE_TOKEN, $this->share->getToken());
return;
Expand Down Expand Up @@ -525,7 +528,7 @@ private function getAllowAddOptions(): bool {
* @return bool|null
*/
private function getAllowDeleteOption(?string $optionOwner, ?int $pollId) {

if (!$pollId) {
$this->logger->warning('Poll id missing');
return false;
Expand All @@ -542,7 +545,7 @@ private function getAllowDeleteOption(?string $optionOwner, ?int $pollId) {
$this->logger->warning('Option owner missing');
return false;
}


if ($this->matchUser($optionOwner)) {
return true;
Expand Down

0 comments on commit 549f6e0

Please sign in to comment.