Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(dav): Allow apps to get unshares for DAV resources
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen authored and backportbot[bot] committed Aug 27, 2024
commit 36aff9e8e480af982ff26b1ac7d9c5001a573a63
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