Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable25] Fix sharing with group #1605

Merged
merged 6 commits into from
Jan 24, 2023
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
34 changes: 34 additions & 0 deletions lib/Album/AlbumMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,40 @@ public function getCollaborators(int $albumId): array {
return array_values(array_filter($collaborators, fn ($c) => $c !== null));
}


/**
* @param int $albumId
* @param string $userId
* @return bool
*/
public function isCollaborator(int $albumId, string $userId): bool {
$query = $this->connection->getQueryBuilder();
$query->select("collaborator_id", "collaborator_type")
->from("photos_albums_collabs")
->where($query->expr()->eq('album_id', $query->createNamedParameter($albumId, IQueryBuilder::PARAM_INT)));

$rows = $query->executeQuery()->fetchAll();

foreach ($rows as $row) {
switch ($row['collaborator_type']) {
case self::TYPE_USER:
if ($row['collaborator_id'] === $userId) {
return true;
}
break;
case self::TYPE_GROUP:
if ($this->groupManager->isInGroup($userId, $row['collaborator_id'])) {
return true;
}
break;
default:
break;
}
}

return false;
}

/**
* @param int $albumId
* @param array{'id': string, 'type': int} $collaborators
Expand Down
7 changes: 1 addition & 6 deletions lib/Sabre/Album/SharedAlbumRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\Conflict;
use OCA\Photos\Album\AlbumMapper;

class SharedAlbumRoot extends AlbumRoot {
/**
Expand All @@ -47,11 +46,7 @@ protected function addFile(int $sourceId, string $ownerUID): bool {
throw new Conflict("File $sourceId is already in the folder");
}

$collaboratorIds = array_map(
fn ($collaborator) => $collaborator['type'].':'.$collaborator['id'],
$this->albumMapper->getCollaborators($this->album->getAlbum()->getId()),
);
if (!in_array(AlbumMapper::TYPE_USER.':'.$this->userId, $collaboratorIds)) {
if (!$this->albumMapper->isCollaborator($this->album->getAlbum()->getId(), $this->userId)) {
return false;
}

Expand Down