diff --git a/.github/workflows/integration-pgsql.yml b/.github/workflows/integration-pgsql.yml index 1d757796621..3ca3dcaa26f 100644 --- a/.github/workflows/integration-pgsql.yml +++ b/.github/workflows/integration-pgsql.yml @@ -69,7 +69,7 @@ jobs: - 'sharing-3' - 'sharing-4' php-versions: ['8.3'] - server-versions: ['master'] + server-versions: ['share-update-check-single'] guests-versions: ['main'] circles-versions: ['master'] notifications-versions: ['master'] diff --git a/lib/Share/RoomShareProvider.php b/lib/Share/RoomShareProvider.php index 88f76b527c3..cf63c5c7b8b 100644 --- a/lib/Share/RoomShareProvider.php +++ b/lib/Share/RoomShareProvider.php @@ -10,6 +10,7 @@ use OC\Files\Cache\Cache; use OC\User\LazyUser; +use OCA\Talk\Config; use OCA\Talk\Events\BeforeDuplicateShareSentEvent; use OCA\Talk\Exceptions\ParticipantNotFoundException; use OCA\Talk\Exceptions\RoomNotFoundException; @@ -71,6 +72,7 @@ public function __construct( private IL10N $l, private IMimeTypeLoader $mimeTypeLoader, private IUserManager $userManager, + protected Config $config, ) { $this->sharesByIdCache = new CappedMemoryCache(); } @@ -717,7 +719,7 @@ public function getSharesByIds(array $ids, ?string $recipientId = null): array { * @param bool $allRoomShares indicates that the passed in shares are all room shares for the user * @return list */ - private function resolveSharesForRecipient(array $shareMap, string $userId, bool $allRoomShares = false): array { + private function resolveSharesForRecipient(array $shareMap, string $userId, ?string $path = null, bool $forChildren = false): array { $qb = $this->dbConnection->getQueryBuilder(); $query = $qb->select('parent', 'permissions', 'file_target') @@ -730,7 +732,17 @@ private function resolveSharesForRecipient(array $shareMap, string $userId, bool $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) )); - if ($allRoomShares) { + if ($path !== null) { + $path = str_replace('/' . $userId . '/files', '', $path); + $path = rtrim($path, '/'); + + if ($forChildren) { + $qb->andWhere($qb->expr()->like('file_target', $qb->createNamedParameter($this->dbConnection->escapeLikeParameter($path) . '/_%'))); + } else { + $nonChildPath = $path === '' ? '/' : $path; + $qb->andWhere($qb->expr()->eq('file_target', $qb->createNamedParameter($nonChildPath))); + } + $stmt = $query->executeQuery(); while ($data = $stmt->fetchAssociative()) { @@ -831,6 +843,9 @@ private function _getSharedWith( return []; } + /** @var ?string $attachmentFolder */ + $attachmentFolder = null; + /** @var IShare[] $shares */ $shares = []; @@ -857,15 +872,47 @@ private function _getSharedWith( $qb->andWhere($qb->expr()->eq('s.file_source', $qb->createNamedParameter($node->getId()))); } + $onClause = $qb->expr()->andX( + $qb->expr()->eq('sc.parent', 's.id'), + $qb->expr()->eq('sc.share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERROOM)), + $qb->expr()->eq('sc.share_with', $qb->createNamedParameter($userId)), + ); + $qb->leftJoin('s', 'share', 'sc', $onClause) + ->selectAlias('sc.file_target', 'sc_file_target') + ->selectAlias('sc.permissions', 'sc_permissions'); + if ($path !== null) { - $qb->leftJoin('s', 'share', 'sc', $qb->expr()->eq('s.id', 'sc.parent')) - ->andWhere($qb->expr()->eq('sc.share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERROOM))) - ->andWhere($qb->expr()->eq('sc.share_with', $qb->createNamedParameter($userId))); + $path = str_replace('/' . $userId . '/files', '', $path); + $path = rtrim($path, '/'); if ($forChildren) { - $qb->andWhere($qb->expr()->like('sc.file_target', $qb->createNamedParameter($this->dbConnection->escapeLikeParameter($path) . '_%'))); + $userAttachmentFolder = $this->config->getAttachmentFolder($userId); + $escapedUserAttachmentFolder = preg_quote($userAttachmentFolder, '/'); + $pathWithPlaceholder = preg_replace("/^$escapedUserAttachmentFolder/", self::TALK_FOLDER_PLACEHOLDER, $path); + + $childPathTemplate = $this->dbConnection->escapeLikeParameter($path) . '/_%'; + $childPathTemplatePlaceholder = $this->dbConnection->escapeLikeParameter($pathWithPlaceholder) . '/_%'; + + $qb->andWhere( + $qb->expr()->orX( + $qb->expr()->like('sc.file_target', $qb->createNamedParameter($childPathTemplate, IQueryBuilder::PARAM_STR)), + $qb->expr()->andX( + $qb->expr()->isNull('sc.file_target'), + $qb->expr()->like('s.file_target', $qb->createNamedParameter($childPathTemplatePlaceholder, IQueryBuilder::PARAM_STR)), + ), + ), + ); } else { - $qb->andWhere($qb->expr()->eq('sc.file_target', $qb->createNamedParameter($path))); + $nonChildPath = $path === '' ? '/' : $path; + $qb->andWhere( + $qb->expr()->orX( + $qb->expr()->eq('sc.file_target', $qb->createNamedParameter($nonChildPath, IQueryBuilder::PARAM_STR)), + $qb->expr()->andX( + $qb->expr()->isNull('sc.file_target'), + $qb->expr()->eq('s.file_target', $qb->createNamedParameter($nonChildPath, IQueryBuilder::PARAM_STR)), + ), + ), + ); } } @@ -891,13 +938,22 @@ private function _getSharedWith( } $share = $this->createShareObject($data); + + if (array_key_exists('sc_file_target', $data) && $data['sc_file_target'] === null) { + $attachmentFolder ??= $this->config->getAttachmentFolder($userId); + $share->setTarget(str_replace(self::TALK_FOLDER_PLACEHOLDER, $attachmentFolder, $share->getTarget())); + $share->setPermissions((int)$data['sc_permissions']); + $this->move($share, $userId); + } else { + $share->setTarget($data['sc_file_target']); + $share->setPermissions((int)$data['sc_permissions']); + } + $shares[$share->getId()] = $share; } $cursor->closeCursor(); } - $shares = $this->resolveSharesForRecipient($shares, $userId, true); - return $shares; } diff --git a/tests/integration/features/sharing-1/create.feature b/tests/integration/features/sharing-1/create.feature index 56ec7538efd..3a0f9342ec5 100644 --- a/tests/integration/features/sharing-1/create.feature +++ b/tests/integration/features/sharing-1/create.feature @@ -350,7 +350,7 @@ Feature: sharing-1/create | item_type | file | | mimetype | text/plain | | storage_id | home::participant2 | - | file_target | /{TALK_PLACEHOLDER}/welcome (2).txt | + | file_target | /Talk/welcome (2).txt | | share_with | group room | | share_with_displayname | Group room | And user "participant3" gets last share