diff options
author | Joas Schilling <coding@schilljs.com> | 2019-02-11 14:57:38 +0300 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2019-03-01 22:56:19 +0300 |
commit | 59c92a75139b9db1cc1171f41bac971c2c528873 (patch) | |
tree | c897e2fcec33a4c3509539f67198a90c17efc307 | |
parent | ece471de360ebbebee6b098a20d65042dd69928c (diff) |
Further work on the access cache
Searching for all is still a problem
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | apps/files/lib/Collaboration/Resources/ResourceProvider.php | 2 | ||||
-rw-r--r-- | core/Controller/CollaborationResourcesController.php | 28 | ||||
-rw-r--r-- | lib/private/Collaboration/Resources/Collection.php | 94 | ||||
-rw-r--r-- | lib/private/Collaboration/Resources/Manager.php | 184 | ||||
-rw-r--r-- | lib/private/Collaboration/Resources/Resource.php | 42 | ||||
-rw-r--r-- | lib/public/Collaboration/Resources/ICollection.php | 14 | ||||
-rw-r--r-- | lib/public/Collaboration/Resources/IManager.php | 31 | ||||
-rw-r--r-- | lib/public/Collaboration/Resources/IProvider.php | 4 | ||||
-rw-r--r-- | lib/public/Collaboration/Resources/IResource.php | 4 |
9 files changed, 305 insertions, 98 deletions
diff --git a/apps/files/lib/Collaboration/Resources/ResourceProvider.php b/apps/files/lib/Collaboration/Resources/ResourceProvider.php index 1a6089b4856..4338156c0ad 100644 --- a/apps/files/lib/Collaboration/Resources/ResourceProvider.php +++ b/apps/files/lib/Collaboration/Resources/ResourceProvider.php @@ -77,7 +77,7 @@ class ResourceProvider implements IProvider { * @return bool * @since 15.0.0 */ - public function canAccess(IResource $resource, IUser $user = null): bool { + public function canAccessResource(IResource $resource, IUser $user = null): bool { if (!$user instanceof IUser) { return false; } diff --git a/core/Controller/CollaborationResourcesController.php b/core/Controller/CollaborationResourcesController.php index ae306d8aea8..77f47a9f0a1 100644 --- a/core/Controller/CollaborationResourcesController.php +++ b/core/Controller/CollaborationResourcesController.php @@ -59,7 +59,7 @@ class CollaborationResourcesController extends OCSController { * @throws CollectionException when the collection was not found for the user */ protected function getCollection(int $collectionId): ICollection { - $collection = $this->manager->getCollection($collectionId); + $collection = $this->manager->getCollectionForUser($collectionId, $this->userSession->getUser()); if (!$collection->canAccess($this->userSession->getUser())) { throw new CollectionException('Not found'); @@ -115,9 +115,9 @@ class CollaborationResourcesController extends OCSController { return new DataResponse([], Http::STATUS_NOT_FOUND); } - try { - $resource = $this->manager->getResource($resourceType, $resourceId); - } catch (ResourceException $e) { + $resource = $this->manager->createResource($resourceType, $resourceId); + + if (!$resource->canAccess($this->userSession->getUser())) { return new DataResponse([], Http::STATUS_NOT_FOUND); } @@ -145,7 +145,7 @@ class CollaborationResourcesController extends OCSController { } try { - $resource = $this->manager->getResource($resourceType, $resourceId); + $resource = $this->manager->getResourceForUser($resourceType, $resourceId, $this->userSession->getUser()); } catch (CollectionException $e) { return new DataResponse([], Http::STATUS_NOT_FOUND); } @@ -164,8 +164,8 @@ class CollaborationResourcesController extends OCSController { */ public function getCollectionsByResource(string $resourceType, string $resourceId): DataResponse { try { - $resource = $this->manager->getResource($resourceType, $resourceId); - } catch (CollectionException $e) { + $resource = $this->manager->getResourceForUser($resourceType, $resourceId, $this->userSession->getUser()); + } catch (ResourceException $e) { return new DataResponse([], Http::STATUS_NOT_FOUND); } @@ -190,7 +190,7 @@ class CollaborationResourcesController extends OCSController { } try { - $resource = $this->manager->getResource($baseResourceType, $baseResourceId); + $resource = $this->manager->createResource($baseResourceType, $baseResourceId); } catch (CollectionException $e) { return new DataResponse([], Http::STATUS_NOT_FOUND); } @@ -214,19 +214,13 @@ class CollaborationResourcesController extends OCSController { */ public function renameCollection(int $collectionId, string $collectionName): DataResponse { try { - $collection = $this->manager->getCollection($collectionId); - if (!$collection->canAccess($this->userSession->getUser())) { - throw new CollectionException('Not found'); - } + $collection = $this->getCollection($collectionId); } catch (CollectionException $exception) { return new DataResponse([], Http::STATUS_NOT_FOUND); } - try { - $collection = $this->manager->renameCollection($collectionId, $collectionName); - } catch (CollectionException $e) { - return new DataResponse([], Http::STATUS_NOT_FOUND); - } + $collection->setName($collectionName); + return new DataResponse($this->prepareCollection($collection)); } diff --git a/lib/private/Collaboration/Resources/Collection.php b/lib/private/Collaboration/Resources/Collection.php index c538580b8f8..6d37cebdc2f 100644 --- a/lib/private/Collaboration/Resources/Collection.php +++ b/lib/private/Collaboration/Resources/Collection.php @@ -34,7 +34,7 @@ use OCP\IUser; class Collection implements ICollection { - /** @var IManager */ + /** @var IManager|Manager */ protected $manager; /** @var IDBConnection */ @@ -46,6 +46,9 @@ class Collection implements ICollection { /** @var string */ protected $name; + /** @var IUser|null */ + protected $userForAccess; + /** @var bool|null */ protected $access; @@ -57,12 +60,14 @@ class Collection implements ICollection { IDBConnection $connection, int $id, string $name, - ?bool $access + ?IUser $userForAccess = null, + ?bool $access = null ) { $this->manager = $manager; $this->connection = $connection; $this->id = $id; $this->name = $name; + $this->userForAccess = $userForAccess; $this->access = $access; $this->resources = []; } @@ -84,21 +89,26 @@ class Collection implements ICollection { } /** + * @param string $name + * @since 16.0.0 + */ + public function setName(string $name): void { + $query = $this->connection->getQueryBuilder(); + $query->update(Manager::TABLE_COLLECTIONS) + ->set('name', $query->createNamedParameter($name)) + ->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT))); + $query->execute(); + + $this->name = $name; + } + + /** * @return IResource[] * @since 16.0.0 */ public function getResources(): array { if (empty($this->resources)) { - $query = $this->connection->getQueryBuilder(); - $query->select('resource_type', 'resource_id') - ->from('collres_resources') - ->where($query->expr()->eq('collection_id', $query->createNamedParameter($this->id, IQueryBuilder::PARAM_INT))); - - $result = $query->execute(); - while ($row = $result->fetch()) { - $this->resources[] = $this->manager->getResource($row['resource_type'], $row['resource_id']); - } - $result->closeCursor(); + $this->resources = $this->manager->getResourcesByCollectionForUser($this, $this->userForAccess); } return $this->resources; @@ -111,17 +121,17 @@ class Collection implements ICollection { * @throws ResourceException when the resource is already part of the collection * @since 16.0.0 */ - public function addResource(IResource $resource) { + public function addResource(IResource $resource): void { array_map(function(IResource $r) use ($resource) { if ($this->isSameResource($r, $resource)) { throw new ResourceException('Already part of the collection'); } - }, $this->resources); + }, $this->getResources()); $this->resources[] = $resource; $query = $this->connection->getQueryBuilder(); - $query->insert('collres_resources') + $query->insert(Manager::TABLE_RESOURCES) ->values([ 'collection_id' => $query->createNamedParameter($this->id, IQueryBuilder::PARAM_INT), 'resource_type' => $query->createNamedParameter($resource->getType()), @@ -133,6 +143,8 @@ class Collection implements ICollection { } catch (ConstraintViolationException $e) { throw new ResourceException('Already part of the collection'); } + + $this->manager->invalidateAccessCacheForCollection($this); } /** @@ -141,13 +153,13 @@ class Collection implements ICollection { * @param IResource $resource * @since 16.0.0 */ - public function removeResource(IResource $resource) { - $this->resources = array_filter($this->resources, function(IResource $r) use ($resource) { + public function removeResource(IResource $resource): void { + $this->resources = array_filter($this->getResources(), function(IResource $r) use ($resource) { return !$this->isSameResource($r, $resource); }); $query = $this->connection->getQueryBuilder(); - $query->delete('collres_resources') + $query->delete(Manager::TABLE_RESOURCES) ->where($query->expr()->eq('collection_id', $query->createNamedParameter($this->id, IQueryBuilder::PARAM_INT))) ->andWhere($query->expr()->eq('resource_type', $query->createNamedParameter($resource->getType()))) ->andWhere($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId()))); @@ -155,27 +167,48 @@ class Collection implements ICollection { if (empty($this->resources)) { $this->removeCollection(); + } else { + $this->manager->invalidateAccessCacheForCollection($this); } + } /** * Can a user/guest access the collection * - * @param IUser $user + * @param IUser|null $user * @return bool * @since 16.0.0 */ - public function canAccess(IUser $user = null): bool { - if ($this->access === null) { - $this->access = false; - foreach ($this->getResources() as $resource) { - if ($resource->canAccess($user)) { - $this->access = true; - } - } + public function canAccess(?IUser $user): bool { + if ($user instanceof IUser) { + return $this->canUserAccess($user); + } + return $this->canGuestAccess(); + } + + protected function canUserAccess(IUser $user): bool { + if (\is_bool($this->access) && $this->userForAccess instanceof IUser && $user->getUID() === $this->userForAccess->getUID()) { + return $this->access; } - return $this->access; + $access = $this->manager->canAccessCollection($this, $user); + if ($this->userForAccess instanceof IUser && $user->getUID() === $this->userForAccess->getUID()) { + $this->access = $access; + } + return $access; + } + + protected function canGuestAccess(): bool { + if (\is_bool($this->access) && !$this->userForAccess instanceof IUser) { + return $this->access; + } + + $access = $this->manager->canAccessCollection($this, null); + if (!$this->userForAccess instanceof IUser) { + $this->access = $access; + } + return $access; } protected function isSameResource(IResource $resource1, IResource $resource2): bool { @@ -183,12 +216,13 @@ class Collection implements ICollection { $resource1->getId() === $resource2->getId(); } - protected function removeCollection() { + protected function removeCollection(): void { $query = $this->connection->getQueryBuilder(); - $query->delete('collres_collections') + $query->delete(Manager::TABLE_COLLECTIONS) ->where($query->expr()->eq('id', $query->createNamedParameter($this->id, IQueryBuilder::PARAM_INT))); $query->execute(); + $this->manager->invalidateAccessCacheForCollection($this); $this->id = 0; } } diff --git a/lib/private/Collaboration/Resources/Manager.php b/lib/private/Collaboration/Resources/Manager.php index ae42f272c05..b7aeb221d88 100644 --- a/lib/private/Collaboration/Resources/Manager.php +++ b/lib/private/Collaboration/Resources/Manager.php @@ -35,6 +35,10 @@ use OCP\IUser; class Manager implements IManager { + public const TABLE_COLLECTIONS = 'collres_collections'; + public const TABLE_RESOURCES = 'collres_resources'; + public const TABLE_ACCESS_CACHE = 'collres_accesscache'; + /** @var IDBConnection */ protected $connection; @@ -54,7 +58,7 @@ class Manager implements IManager { public function getCollection(int $id): ICollection { $query = $this->connection->getQueryBuilder(); $query->select('*') - ->from('collres_collections') + ->from(self::TABLE_COLLECTIONS) ->where($query->expr()->eq('id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT))); $result = $query->execute(); $row = $result->fetch(); @@ -68,6 +72,45 @@ class Manager implements IManager { } /** + * @param int $id + * @param IUser|null $user + * @return ICollection + * @throws CollectionException when the collection could not be found + * @since 16.0.0 + */ + public function getCollectionForUser(int $id, ?IUser $user): ICollection { + $query = $this->connection->getQueryBuilder(); + $userId = $user instanceof IUser ? $user->getUID() : ''; + + $query->select('*') + ->from(self::TABLE_COLLECTIONS) + ->leftJoin( + 'r', self::TABLE_ACCESS_CACHE, 'a', + $query->expr()->andX( + $query->expr()->eq('c.id', 'a.resource_id'), + $query->expr()->eq('a.user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR)) + ) + ) + ->where($query->expr()->eq('c.id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT))); + $result = $query->execute(); + $row = $result->fetch(); + $result->closeCursor(); + + if (!$row) { + throw new CollectionException('Collection not found'); + } + + + $access = $row['access'] === null ? null : (bool) $row['access']; + if ($user instanceof IUser) { + $access = [$user->getUID() => $access]; + return new Collection($this, $this->connection, (int) $row['id'], (string) $row['name'], $access, null); + } + + return new Collection($this, $this->connection, (int) $row['id'], (string) $row['name'], [], $access); + } + + /** * @param IUser $user * @param string $filter * @param int $limit @@ -78,7 +121,7 @@ class Manager implements IManager { public function searchCollections(IUser $user, string $filter, int $limit = 50, int $start = 0): array { $query = $this->connection->getQueryBuilder(); $query->select('*') - ->from('collres_collections') + ->from(self::TABLE_COLLECTIONS) ->where($query->expr()->iLike('name', $query->createNamedParameter($filter, IQueryBuilder::PARAM_STR))) ->setMaxResults($limit) ->setFirstResult($start); @@ -105,7 +148,7 @@ class Manager implements IManager { */ public function newCollection(string $name): ICollection { $query = $this->connection->getQueryBuilder(); - $query->insert('collres_collections') + $query->insert(self::TABLE_COLLECTIONS) ->values([ 'name' => $query->createNamedParameter($name), ]); @@ -120,11 +163,82 @@ class Manager implements IManager { * @return IResource * @since 16.0.0 */ - public function getResource(string $type, string $id): IResource { + public function createResource(string $type, string $id): IResource { return new Resource($this, $this->connection, $type, $id); } /** + * @param string $type + * @param string $id + * @param IUser|null $user + * @return IResource + * @throws ResourceException + * @since 16.0.0 + */ + public function getResourceForUser(string $type, string $id, ?IUser $user): IResource { + $query = $this->connection->getQueryBuilder(); + $userId = $user instanceof IUser ? $user->getUID() : ''; + + $query->select('r.*', 'a.access') + ->from(self::TABLE_RESOURCES, 'r') + ->leftJoin( + 'r', self::TABLE_ACCESS_CACHE, 'a', + $query->expr()->andX( + $query->expr()->eq('r.id', 'a.resource_id'), + $query->expr()->eq('a.user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR)) + ) + ) + ->where($query->expr()->eq('r.resource_type', $query->createNamedParameter($type, IQueryBuilder::PARAM_STR))) + ->andWhere($query->expr()->eq('r.resource_id', $query->createNamedParameter($id, IQueryBuilder::PARAM_STR))); + $result = $query->execute(); + $row = $result; + $result->closeCursor(); + + if (!$row) { + throw new ResourceException('Resource not found'); + } + + $access = $row['access'] === null ? null : (bool) $row['access']; + if ($user instanceof IUser) { + return new Resource($this, $this->connection, $type, $id, $user, $access); + } + + return new Resource($this, $this->connection, $type, $id, null, $access); + } + + /** + * @param ICollection $collection + * @param IUser|null $user + * @return IResource[] + * @since 16.0.0 + */ + public function getResourcesByCollectionForUser(ICollection $collection, ?IUser $user): array { + $query = $this->connection->getQueryBuilder(); + $userId = $user instanceof IUser ? $user->getUID() : ''; + + $query->select('r.*', 'a.access') + ->from(self::TABLE_RESOURCES, 'r') + ->leftJoin( + 'r', self::TABLE_ACCESS_CACHE, 'a', + $query->expr()->andX( + $query->expr()->eq('r.id', 'a.resource_id'), + $query->expr()->eq('a.user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR)) + ) + ) + ->where($query->expr()->eq('r.collection_id', $query->createNamedParameter($collection->getId(), IQueryBuilder::PARAM_INT))); + + $resources = []; + $result = $query->execute(); + while ($row = $result->fetch()) { + $access = $row['access'] === null ? null : (bool) $row['access']; + $resources[] = new Resource($this, $this->connection, $row['resource_type'], $row['resource_id'], $user, $access); + } + $result->closeCursor(); + + return $resources; + } + + /** * @return IProvider[] * @since 16.0.0 */ @@ -174,30 +288,53 @@ class Manager implements IManager { * Can a user/guest access the collection * * @param IResource $resource - * @param IUser $user + * @param IUser|null $user * @return bool * @since 16.0.0 */ - public function canAccess(IResource $resource, IUser $user = null): bool { + public function canAccessResource(IResource $resource, ?IUser $user): bool { + $access = false; foreach ($this->getProviders() as $provider) { if ($provider->getType() === $resource->getType()) { try { if ($provider->canAccess($resource, $user)) { - return true; + $access = true; + break; } } catch (ResourceException $e) { } } } - return false; + $this->cacheAccessForResource($resource, $user, $access); + return $access; + } + + /** + * Can a user/guest access the collection + * + * @param ICollection $collection + * @param IUser|null $user + * @return bool + * @since 16.0.0 + */ + public function canAccessCollection(ICollection $collection, ?IUser $user): bool { + $access = false; + foreach ($collection->getResources() as $resource) { + if ($resource->canAccess($user)) { + $access = true; + } + } + + $this->cacheAccessForCollection($collection, $user, $access); + return $access; } public function cacheAccessForResource(IResource $resource, ?IUser $user, bool $access): void { $query = $this->connection->getQueryBuilder(); $userId = $user instanceof IUser ? $user->getUID() : ''; - $query->insert('collres_accesscache') + $query->insert(self::TABLE_ACCESS_CACHE) ->values([ 'user_id' => $query->createNamedParameter($userId), 'resource_id' => $query->createNamedParameter($resource->getId()), @@ -210,7 +347,7 @@ class Manager implements IManager { $query = $this->connection->getQueryBuilder(); $userId = $user instanceof IUser ? $user->getUID() : ''; - $query->insert('collres_accesscache') + $query->insert(self::TABLE_ACCESS_CACHE) ->values([ 'user_id' => $query->createNamedParameter($userId), 'collection_id' => $query->createNamedParameter($collection->getId()), @@ -223,7 +360,7 @@ class Manager implements IManager { $query = $this->connection->getQueryBuilder(); $userId = $user instanceof IUser ? $user->getUID() : ''; - $query->delete('collres_accesscache') + $query->delete(self::TABLE_ACCESS_CACHE) ->where($query->expr()->eq('user_id', $query->createNamedParameter($userId))); $query->execute(); } @@ -231,7 +368,7 @@ class Manager implements IManager { public function invalidateAccessCacheForResource(IResource $resource): void { $query = $this->connection->getQueryBuilder(); - $query->delete('collres_accesscache') + $query->delete(self::TABLE_ACCESS_CACHE) ->where($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId()))); $query->execute(); @@ -240,10 +377,10 @@ class Manager implements IManager { } } - protected function invalidateAccessCacheForCollection(ICollection $collection): void { + public function invalidateAccessCacheForCollection(ICollection $collection): void { $query = $this->connection->getQueryBuilder(); - $query->delete('collres_accesscache') + $query->delete(self::TABLE_ACCESS_CACHE) ->where($query->expr()->eq('collection_id', $query->createNamedParameter($collection->getId()))); $query->execute(); } @@ -252,7 +389,7 @@ class Manager implements IManager { $query = $this->connection->getQueryBuilder(); $userId = $user instanceof IUser ? $user->getUID() : ''; - $query->delete('collres_accesscache') + $query->delete(self::TABLE_ACCESS_CACHE) ->where($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId()))) ->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId))); $query->execute(); @@ -266,7 +403,7 @@ class Manager implements IManager { $query = $this->connection->getQueryBuilder(); $userId = $user instanceof IUser ? $user->getUID() : ''; - $query->delete('collres_accesscache') + $query->delete(self::TABLE_ACCESS_CACHE) ->where($query->expr()->eq('collection_id', $query->createNamedParameter($collection->getId()))) ->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId))); $query->execute(); @@ -309,19 +446,4 @@ class Manager implements IManager { return ''; } - - /** - * @param string $name - * @return ICollection - * @since 16.0.0 - */ - public function renameCollection(int $id, string $name): ICollection { - $query = $this->connection->getQueryBuilder(); - $query->update('collres_collections') - ->set('name', $query->createNamedParameter($name)) - ->where($query->expr()->eq('id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT))); - $query->execute(); - - return new Collection($this, $this->connection, $id, $name); - } } diff --git a/lib/private/Collaboration/Resources/Resource.php b/lib/private/Collaboration/Resources/Resource.php index bfc63fefdfc..d9c72ca2039 100644 --- a/lib/private/Collaboration/Resources/Resource.php +++ b/lib/private/Collaboration/Resources/Resource.php @@ -43,6 +43,9 @@ class Resource implements IResource { /** @var string */ protected $id; + /** @var IUser|null */ + protected $userForAccess; + /** @var bool|null */ protected $access; @@ -60,12 +63,14 @@ class Resource implements IResource { IDBConnection $connection, string $type, string $id, - ?bool $access + ?IUser $userForAccess = null, + ?bool $access = null ) { $this->manager = $manager; $this->connection = $connection; $this->type = $type; $this->id = $id; + $this->userForAccess = $userForAccess; $this->access = $access; } @@ -117,19 +122,42 @@ class Resource implements IResource { return $this->link; } - /** * Can a user/guest access the resource * - * @param IUser $user + * @param IUser|null $user * @return bool * @since 16.0.0 */ - public function canAccess(IUser $user = null): bool { - if ($this->access === null) { - $this->access = $this->manager->canAccess($this, $user); + public function canAccess(?IUser $user): bool { + if ($user instanceof IUser) { + return $this->canUserAccess($user); + } + return $this->canGuestAccess(); + } + + protected function canUserAccess(IUser $user): bool { + if (\is_bool($this->access) && $this->userForAccess instanceof IUser && $user->getUID() === $this->userForAccess->getUID()) { + return $this->access; + } + + $access = $this->manager->canAccessResource($this, $user); + if ($this->userForAccess instanceof IUser && $user->getUID() === $this->userForAccess->getUID()) { + $this->access = $access; + } + return $access; + } + + protected function canGuestAccess(): bool { + if (\is_bool($this->access) && !$this->userForAccess instanceof IUser) { + return $this->access; + } + + $access = $this->manager->canAccessResource($this, null); + if (!$this->userForAccess instanceof IUser) { + $this->access = $access; } - return $this->access; + return $access; } /** diff --git a/lib/public/Collaboration/Resources/ICollection.php b/lib/public/Collaboration/Resources/ICollection.php index cd59a7d3e5a..8cdc7b87939 100644 --- a/lib/public/Collaboration/Resources/ICollection.php +++ b/lib/public/Collaboration/Resources/ICollection.php @@ -42,6 +42,12 @@ interface ICollection { public function getName(): string; /** + * @param string $name + * @since 16.0.0 + */ + public function setName(string $name): void; + + /** * @return IResource[] * @since 16.0.0 */ @@ -54,7 +60,7 @@ interface ICollection { * @throws ResourceException when the resource is already part of the collection * @since 16.0.0 */ - public function addResource(IResource $resource); + public function addResource(IResource $resource): void; /** * Removes a resource from a collection @@ -62,14 +68,14 @@ interface ICollection { * @param IResource $resource * @since 16.0.0 */ - public function removeResource(IResource $resource); + public function removeResource(IResource $resource): void; /** * Can a user/guest access the collection * - * @param IUser $user + * @param IUser|null $user * @return bool * @since 16.0.0 */ - public function canAccess(IUser $user = null): bool; + public function canAccess(?IUser $user): bool; } diff --git a/lib/public/Collaboration/Resources/IManager.php b/lib/public/Collaboration/Resources/IManager.php index 77f958e513a..af371f7b4f0 100644 --- a/lib/public/Collaboration/Resources/IManager.php +++ b/lib/public/Collaboration/Resources/IManager.php @@ -22,6 +22,8 @@ declare(strict_types=1); namespace OCP\Collaboration\Resources; +use OCP\IUser; + /** * @since 16.0.0 */ @@ -36,27 +38,48 @@ interface IManager extends IProvider { public function getCollection(int $id): ICollection; /** + * @param int $id + * @param IUser|null $user + * @return ICollection + * @throws CollectionException when the collection could not be found + * @since 16.0.0 + */ + public function getCollectionForUser(int $id, ?IUser $user): ICollection; + + /** * @param string $name * @return ICollection * @since 16.0.0 */ public function newCollection(string $name): ICollection; + /** + * Can a user/guest access the collection + * + * @param ICollection $collection + * @param IUser|null $user + * @return bool + * @since 16.0.0 + */ + public function canAccessCollection(ICollection $collection, ?IUser $user): bool; /** - * @param string $name - * @return ICollection + * @param string $type + * @param string $id + * @return IResource * @since 16.0.0 */ - public function renameCollection(int $id, string $name): ICollection; + public function createResource(string $type, string $id): IResource; /** * @param string $type * @param string $id + * @param IUser|null $user * @return IResource + * @throws ResourceException * @since 16.0.0 */ - public function getResource(string $type, string $id): IResource; + public function getResourceForUser(string $type, string $id, ?IUser $user): IResource; /** * @param IProvider $provider diff --git a/lib/public/Collaboration/Resources/IProvider.php b/lib/public/Collaboration/Resources/IProvider.php index 52ad2305cfe..3014305106f 100644 --- a/lib/public/Collaboration/Resources/IProvider.php +++ b/lib/public/Collaboration/Resources/IProvider.php @@ -69,10 +69,10 @@ interface IProvider { * Can a user/guest access the collection * * @param IResource $resource - * @param IUser $user + * @param IUser|null $user * @return bool * @since 16.0.0 */ - public function canAccess(IResource $resource, IUser $user = null): bool; + public function canAccessResource(IResource $resource, ?IUser $user): bool; } diff --git a/lib/public/Collaboration/Resources/IResource.php b/lib/public/Collaboration/Resources/IResource.php index 34969dabd0d..609a283c2d8 100644 --- a/lib/public/Collaboration/Resources/IResource.php +++ b/lib/public/Collaboration/Resources/IResource.php @@ -62,11 +62,11 @@ interface IResource { /** * Can a user/guest access the resource * - * @param IUser $user + * @param IUser|null $user * @return bool * @since 16.0.0 */ - public function canAccess(IUser $user = null): bool; + public function canAccess(?IUser $user): bool; /** * @return ICollection[] |