Skip to content

Commit

Permalink
Merge pull request #47512 from nextcloud/backport/47494/stable30
Browse files Browse the repository at this point in the history
[stable30] fix(dav): Allow apps to get unshares for DAV resources
  • Loading branch information
nickvergessen authored Aug 27, 2024
2 parents fc9da19 + 36aff9e commit 4ea8417
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
23 changes: 18 additions & 5 deletions apps/dav/lib/DAV/Sharing/SharingMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
4 changes: 4 additions & 0 deletions apps/dav/lib/DAV/Sharing/SharingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public function getShares(int $resourceId): array {
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());
}
Expand Down

0 comments on commit 4ea8417

Please sign in to comment.