diff options
-rw-r--r-- | core/Migrations/Version16000Date20190207141427.php | 9 | ||||
-rw-r--r-- | lib/private/Collaboration/Resources/Manager.php | 25 | ||||
-rw-r--r-- | lib/public/Collaboration/Resources/IManager.php | 13 |
3 files changed, 44 insertions, 3 deletions
diff --git a/core/Migrations/Version16000Date20190207141427.php b/core/Migrations/Version16000Date20190207141427.php index bc1c7e24a8c..c74c3ee1c36 100644 --- a/core/Migrations/Version16000Date20190207141427.php +++ b/core/Migrations/Version16000Date20190207141427.php @@ -85,6 +85,11 @@ class Version16000Date20190207141427 extends SimpleMigrationStep { 'notnull' => false, 'default' => 0, ]); + $table->addColumn('resource_type', Type::STRING, [ + 'notnull' => false, + 'length' => 64, + 'default' => '', + ]); $table->addColumn('resource_id', Type::STRING, [ 'notnull' => false, 'length' => 64, @@ -95,8 +100,8 @@ class Version16000Date20190207141427 extends SimpleMigrationStep { 'default' => 0, ]); - $table->addUniqueIndex(['user_id', 'collection_id', 'resource_id'], 'collres_unique_user'); - $table->addIndex(['user_id', 'resource_id'], 'collres_user_res'); + $table->addUniqueIndex(['user_id', 'collection_id', 'resource_type', 'resource_id'], 'collres_unique_user'); + $table->addIndex(['user_id', 'resource_type', 'resource_id'], 'collres_user_res'); $table->addIndex(['user_id', 'collection_id'], 'collres_user_coll'); } diff --git a/lib/private/Collaboration/Resources/Manager.php b/lib/private/Collaboration/Resources/Manager.php index b95747c61de..3c2714b76a6 100644 --- a/lib/private/Collaboration/Resources/Manager.php +++ b/lib/private/Collaboration/Resources/Manager.php @@ -200,6 +200,7 @@ class Manager implements IManager { 'r', self::TABLE_ACCESS_CACHE, 'a', $query->expr()->andX( $query->expr()->eq('r.resource_id', 'a.resource_id'), + $query->expr()->eq('r.resource_type', 'a.resource_type'), $query->expr()->eq('a.user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR)) ) ) @@ -237,6 +238,7 @@ class Manager implements IManager { 'r', self::TABLE_ACCESS_CACHE, 'a', $query->expr()->andX( $query->expr()->eq('r.resource_id', 'a.resource_id'), + $query->expr()->eq('r.resource_type', 'a.resource_type'), $query->expr()->eq('a.user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR)) ) ) @@ -362,6 +364,7 @@ class Manager implements IManager { $query->select('access') ->from(self::TABLE_ACCESS_CACHE) ->where($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId(), IQueryBuilder::PARAM_STR))) + ->andWhere($query->expr()->eq('resource_type', $query->createNamedParameter($resource->getType(), IQueryBuilder::PARAM_STR))) ->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR))) ->setMaxResults(1); @@ -403,6 +406,7 @@ class Manager implements IManager { ->values([ 'user_id' => $query->createNamedParameter($userId), 'resource_id' => $query->createNamedParameter($resource->getId()), + 'resource_type' => $query->createNamedParameter($resource->getType()), 'access' => $query->createNamedParameter($access), ]); try { @@ -440,7 +444,8 @@ class Manager implements IManager { $query = $this->connection->getQueryBuilder(); $query->delete(self::TABLE_ACCESS_CACHE) - ->where($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId()))); + ->where($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId()))) + ->andWhere($query->expr()->eq('resource_type', $query->createNamedParameter($resource->getType(), IQueryBuilder::PARAM_STR))); $query->execute(); foreach ($resource->getCollections() as $collection) { @@ -456,6 +461,14 @@ class Manager implements IManager { $query->execute(); } + public function invalidateAccessCacheForProvider(IProvider $provider): void { + $query = $this->connection->getQueryBuilder(); + + $query->delete(self::TABLE_ACCESS_CACHE) + ->where($query->expr()->eq('resource_type', $query->createNamedParameter($provider->getType(), IQueryBuilder::PARAM_STR))); + $query->execute(); + } + public function invalidateAccessCacheForResourceByUser(IResource $resource, ?IUser $user): void { $query = $this->connection->getQueryBuilder(); $userId = $user instanceof IUser ? $user->getUID() : ''; @@ -480,6 +493,16 @@ class Manager implements IManager { $query->execute(); } + public function invalidateAccessCacheForProviderByUser(IProvider $provider, ?IUser $user): void { + $query = $this->connection->getQueryBuilder(); + $userId = $user instanceof IUser ? $user->getUID() : ''; + + $query->delete(self::TABLE_ACCESS_CACHE) + ->where($query->expr()->eq('resource_type', $query->createNamedParameter($provider->getType(), IQueryBuilder::PARAM_STR))) + ->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId))); + $query->execute(); + } + /** * @param IProvider $provider */ diff --git a/lib/public/Collaboration/Resources/IManager.php b/lib/public/Collaboration/Resources/IManager.php index 050326d91c4..a04edaf9f8c 100644 --- a/lib/public/Collaboration/Resources/IManager.php +++ b/lib/public/Collaboration/Resources/IManager.php @@ -83,6 +83,19 @@ interface IManager extends IProvider { public function invalidateAccessCacheForResourceByUser(IResource $resource, ?IUser $user): void; /** + * @param IProvider $provider + * @since 16.0.0 + */ + public function invalidateAccessCacheForProvider(IProvider $provider): void; + + /** + * @param IProvider $provider + * @param IUser|null $user + * @since 16.0.0 + */ + public function invalidateAccessCacheForProviderByUser(IProvider $provider, ?IUser $user): void; + + /** * @param string $type * @param string $id * @return IResource |