mirror of https://github.com/nextcloud/photos
Merge pull request #1600 from simonspa/p/fix-group-sharing
Fix sharing with group
This commit is contained in:
commit
cb6acf8588
|
@ -332,6 +332,40 @@ class AlbumMapper {
|
||||||
return array_values(array_filter($collaborators, fn ($c) => $c !== null));
|
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 int $albumId
|
||||||
* @param array{'id': string, 'type': int} $collaborators
|
* @param array{'id': string, 'type': int} $collaborators
|
||||||
|
|
|
@ -25,7 +25,6 @@ namespace OCA\Photos\Sabre\Album;
|
||||||
|
|
||||||
use Sabre\DAV\Exception\Forbidden;
|
use Sabre\DAV\Exception\Forbidden;
|
||||||
use Sabre\DAV\Exception\Conflict;
|
use Sabre\DAV\Exception\Conflict;
|
||||||
use OCA\Photos\Album\AlbumMapper;
|
|
||||||
|
|
||||||
class SharedAlbumRoot extends AlbumRoot {
|
class SharedAlbumRoot extends AlbumRoot {
|
||||||
/**
|
/**
|
||||||
|
@ -47,11 +46,7 @@ class SharedAlbumRoot extends AlbumRoot {
|
||||||
throw new Conflict("File $sourceId is already in the folder");
|
throw new Conflict("File $sourceId is already in the folder");
|
||||||
}
|
}
|
||||||
|
|
||||||
$collaboratorIds = array_map(
|
if (!$this->albumMapper->isCollaborator($this->album->getAlbum()->getId(), $this->userId)) {
|
||||||
fn ($collaborator) => $collaborator['type'].':'.$collaborator['id'],
|
|
||||||
$this->albumMapper->getCollaborators($this->album->getAlbum()->getId()),
|
|
||||||
);
|
|
||||||
if (!in_array(AlbumMapper::TYPE_USER.':'.$this->userId, $collaboratorIds)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue