3232use OCP \Share \Exceptions \GenericShareException ;
3333use OCP \Share \Exceptions \ShareNotFound ;
3434use OCP \Share \IManager ;
35+ use OCP \Share \IPartialShareProvider ;
3536use OCP \Share \IShare ;
3637
3738/** Taken from the talk shareapicontroller helper */
@@ -42,7 +43,7 @@ public function formatShare(IShare $share): array;
4243 public function canAccessShare (IShare $ share , string $ user ): bool ;
4344}
4445
45- class DeckShareProvider implements \OCP \Share \IShareProvider {
46+ class DeckShareProvider implements \OCP \Share \IShareProvider, IPartialShareProvider {
4647 public const DECK_FOLDER = '/Deck ' ;
4748 public const DECK_FOLDER_PLACEHOLDER = '/{DECK_PLACEHOLDER} ' ;
4849
@@ -702,6 +703,34 @@ public function getSharesByPath(Node $path): array {
702703 * @return IShare[]
703704 */
704705 public function getSharedWith ($ userId , $ shareType , $ node , $ limit , $ offset ): array {
706+ return $ this ->_getSharedWith ($ userId , $ limit , $ offset , $ node );
707+ }
708+
709+ public function getSharedWithByPath (
710+ string $ userId ,
711+ int $ shareType ,
712+ string $ path ,
713+ bool $ forChildren ,
714+ int $ limit ,
715+ int $ offset ,
716+ ): iterable {
717+ return $ this ->_getSharedWith ($ userId , $ limit , $ offset , null , $ path , $ forChildren );
718+ }
719+
720+ /**
721+ * Get received shared for the given user.
722+ * You can optionally provide a node or a path to filter the shares.
723+ *
724+ * @return IShare[]
725+ */
726+ private function _getSharedWith (
727+ string $ userId ,
728+ int $ limit ,
729+ int $ offset ,
730+ ?Node $ node = null ,
731+ ?string $ path = null ,
732+ ?bool $ forChildren = false ,
733+ ): array {
705734 $ allBoards = $ this ->boardMapper ->findBoardIds ($ userId );
706735
707736 /** @var IShare[] $shares */
@@ -740,6 +769,17 @@ public function getSharedWith($userId, $shareType, $node, $limit, $offset): arra
740769 $ qb ->andWhere ($ qb ->expr ()->eq ('s.file_source ' , $ qb ->createNamedParameter ($ node ->getId ())));
741770 }
742771
772+ if ($ path !== null ) {
773+ $ qb ->leftJoin ('s ' , 'share ' , 'sc ' , $ qb ->expr ()->eq ('s.parent ' , 'sc.id ' ))
774+ ->andWhere ($ qb ->expr ()->eq ('sc.share_type ' , $ qb ->createNamedParameter (IShare::TYPE_DECK_USER )));
775+
776+ if ($ forChildren ) {
777+ $ qb ->andWhere ($ qb ->expr ()->like ('sc.file_target ' , $ qb ->createNamedParameter ($ this ->dbConnection ->escapeLikeParameter ($ path ) . '_% ' )));
778+ } else {
779+ $ qb ->andWhere ($ qb ->expr ()->eq ('sc.file_target ' , $ qb ->createNamedParameter ($ path )));
780+ }
781+ }
782+
743783 $ qb ->andWhere ($ qb ->expr ()->eq ('s.share_type ' , $ qb ->createNamedParameter (IShare::TYPE_DECK )))
744784 ->andWhere ($ qb ->expr ()->in ('db.id ' , $ qb ->createNamedParameter (
745785 $ boards ,
0 commit comments