]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(dav): Allow apps to get unshares for DAV resources 47512/head
authorJoas Schilling <coding@schilljs.com>
Mon, 26 Aug 2024 16:58:32 +0000 (18:58 +0200)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Tue, 27 Aug 2024 09:25:39 +0000 (09:25 +0000)
Signed-off-by: Joas Schilling <coding@schilljs.com>
apps/dav/lib/DAV/Sharing/SharingMapper.php
apps/dav/lib/DAV/Sharing/SharingService.php

index 3bffddabd9c761e1aaef65cc4a3cf97a2c84370b..59483ac9471a9167151dca7942592e6dcb5c06a8 100644 (file)
@@ -14,21 +14,34 @@ class SharingMapper {
        public function __construct(private IDBConnection $db) {
        }
 
-       public function getSharesForId(int $resourceId, string $resourceType): array {
+       protected function getSharesForIdByAccess(int $resourceId, string $resourceType, bool $sharesWithAccess): array {
                $query = $this->db->getQueryBuilder();
-               $result = $query->select(['principaluri', 'access'])
+               $query->select(['principaluri', 'access'])
                        ->from('dav_shares')
                        ->where($query->expr()->eq('resourceid', $query->createNamedParameter($resourceId, IQueryBuilder::PARAM_INT)))
                        ->andWhere($query->expr()->eq('type', $query->createNamedParameter($resourceType, IQueryBuilder::PARAM_STR)))
-                       ->andWhere($query->expr()->neq('access', $query->createNamedParameter(Backend::ACCESS_UNSHARED, IQueryBuilder::PARAM_INT)))
-                       ->groupBy(['principaluri', 'access'])
-                       ->executeQuery();
+                       ->groupBy(['principaluri', 'access']);
 
+               if ($sharesWithAccess) {
+                       $query->andWhere($query->expr()->neq('access', $query->createNamedParameter(Backend::ACCESS_UNSHARED, IQueryBuilder::PARAM_INT)));
+               } else {
+                       $query->andWhere($query->expr()->eq('access', $query->createNamedParameter(Backend::ACCESS_UNSHARED, IQueryBuilder::PARAM_INT)));
+               }
+
+               $result = $query->executeQuery();
                $rows = $result->fetchAll();
                $result->closeCursor();
                return $rows;
        }
 
+       public function getSharesForId(int $resourceId, string $resourceType): array {
+               return $this->getSharesForIdByAccess($resourceId, $resourceType, true);
+       }
+
+       public function getUnsharesForId(int $resourceId, string $resourceType): array {
+               return $this->getSharesForIdByAccess($resourceId, $resourceType, false);
+       }
+
        public function getSharesForIds(array $resourceIds, string $resourceType): array {
                $query = $this->db->getQueryBuilder();
                $result = $query->select(['resourceid', 'principaluri', 'access'])
index a5a0f96ba59207057a5cf754068d5d8c9639a454..de280d2c34712ac5b31f63b9239d1dc22be1532e 100644 (file)
@@ -41,6 +41,10 @@ abstract class SharingService {
                return $this->mapper->getSharesForId($resourceId, $this->getResourceType());
        }
 
+       public function getUnshares(int $resourceId): array {
+               return $this->mapper->getUnsharesForId($resourceId, $this->getResourceType());
+       }
+
        public function getSharesForIds(array $resourceIds): array {
                return $this->mapper->getSharesForIds($resourceIds, $this->getResourceType());
        }