@@ -238,6 +238,9 @@ protected function getFindChildrenQuery(string $type): IQueryBuilder {
238238 ->andWhere ($ qb ->expr ()->eq ('t.type ' , $ qb ->createNamedParameter ($ type )))
239239 ->andWhere ($ qb ->expr ()->isNull ('t.soft_deleted_at ' ))
240240 ->orderBy ('t.index ' , 'ASC ' );
241+ if ($ type === TreeMapper::TYPE_SHARE ) {
242+ $ this ->joinOriginalFolderNotSoftDeleted ($ qb );
243+ }
241244 return $ qb ;
242245 }
243246
@@ -249,9 +252,27 @@ protected function getFindSoftDeletedChildrenQuery(string $type): IQueryBuilder
249252 ->andWhere ($ qb ->expr ()->eq ('t.type ' , $ qb ->createNamedParameter ($ type )))
250253 ->andWhere ($ qb ->expr ()->isNotNull ('t.soft_deleted_at ' ))
251254 ->orderBy ('t.index ' , 'ASC ' );
255+ if ($ type === TreeMapper::TYPE_SHARE ) {
256+ $ this ->joinOriginalFolderNotSoftDeleted ($ qb );
257+ }
252258 return $ qb ;
253259 }
254260
261+ /**
262+ * Restricts a TYPE_SHARE query to shared folders whose underlying original
263+ * folder has not been soft-deleted by its owner. When the sharer trashes the
264+ * original folder, the share must disappear for sharees entirely — including
265+ * from their trash bin, since they cannot restore someone else's folder.
266+ */
267+ private function joinOriginalFolderNotSoftDeleted (IQueryBuilder $ qb ): void {
268+ $ qb
269+ ->innerJoin ('i ' , 'bookmarks_tree ' , 'ot ' , $ qb ->expr ()->andX (
270+ $ qb ->expr ()->eq ('ot.id ' , 'i.folder_id ' ),
271+ $ qb ->expr ()->eq ('ot.type ' , $ qb ->createNamedParameter (TreeMapper::TYPE_FOLDER ))
272+ ))
273+ ->andWhere ($ qb ->expr ()->isNull ('ot.soft_deleted_at ' ));
274+ }
275+
255276 /**
256277 * @param string $type
257278 * @psalm-param T $type
@@ -1006,6 +1027,9 @@ public function getSoftDeletedRootItems(string $userId, string $type): array {
10061027 $ qb ->expr ()->isNull ('t2.soft_deleted_at ' ),
10071028 $ qb ->expr ()->isNotNull ('r.folder_id ' ),
10081029 ));
1030+ if ($ type === TreeMapper::TYPE_SHARE ) {
1031+ $ this ->joinOriginalFolderNotSoftDeleted ($ qb );
1032+ }
10091033 return $ this ->findEntitiesWithType ($ qb , $ type );
10101034 }
10111035 if ($ type === TreeMapper::TYPE_BOOKMARK ) {
0 commit comments