Skip to content

Commit

Permalink
Merge pull request #3980 from nextcloud/bugfix/noid/permission-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusknorr authored Aug 17, 2022
2 parents ab48ccc + 7c40172 commit e33dd15
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/Service/PermissionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace OCA\Deck\Service;

use OC\Cache\CappedMemoryCache;
use OCP\Cache\CappedMemoryCache;
use OCA\Circles\Model\Member;
use OCA\Deck\Db\Acl;
use OCA\Deck\Db\AclMapper;
Expand All @@ -33,7 +33,6 @@
use OCA\Deck\Db\User;
use OCA\Deck\NoPermissionException;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\IConfig;
use OCP\IGroupManager;
Expand Down Expand Up @@ -64,7 +63,8 @@ class PermissionService {
/** @var array */
private $users = [];

private $boardCache;
private CappedMemoryCache $boardCache;
private CappedMemoryCache $permissionCache;

public function __construct(
ILogger $logger,
Expand All @@ -88,6 +88,7 @@ public function __construct(
$this->userId = $userId;

$this->boardCache = new CappedMemoryCache();
$this->permissionCache = new CappedMemoryCache();
}

/**
Expand All @@ -97,15 +98,21 @@ public function __construct(
* @return bool|array
*/
public function getPermissions($boardId) {
if ($cached = $this->permissionCache->get($boardId)) {
return $cached;
}

$owner = $this->userIsBoardOwner($boardId);
$acls = $this->aclMapper->findAll($boardId);
return [
$permissions = [
Acl::PERMISSION_READ => $owner || $this->userCan($acls, Acl::PERMISSION_READ),
Acl::PERMISSION_EDIT => $owner || $this->userCan($acls, Acl::PERMISSION_EDIT),
Acl::PERMISSION_MANAGE => $owner || $this->userCan($acls, Acl::PERMISSION_MANAGE),
Acl::PERMISSION_SHARE => ($owner || $this->userCan($acls, Acl::PERMISSION_SHARE))
&& (!$this->shareManager->sharingDisabledForUser($this->userId))
];
$this->permissionCache->set($boardId, $permissions);
return $permissions;
}

/**
Expand Down Expand Up @@ -343,5 +350,6 @@ private function getGroupLimitList() {
*/
public function setUserId(string $userId): void {
$this->userId = $userId;
$this->permissionCache->clear();
}
}

0 comments on commit e33dd15

Please sign in to comment.