@@ -75,18 +75,20 @@ public function __construct(
7575 /**
7676 * Search for recipients that can be added to a share.
7777 *
78- * @param ?list<class-string<IShareRecipientType>> $recipientTypeClasses Type class of recipients to filter by
78+ * @param ?list<class-string<IShareRecipientType>> $filterRecipientTypeClasses Type classes of recipients to filter by
7979 * @param string $query The query to search for
8080 * @param int<1, 100> $limit The maximum number of participants
8181 * @param non-negative-int $offset The offset of the participants
82- * @return DataResponse<Http::STATUS_OK, list<SharingRecipient>, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, string, array{}>
82+ * @param ?string $id If provided, recipients that are already part of the share will not be returned.
83+ * @return DataResponse<Http::STATUS_OK, list<SharingRecipient>, array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND, string, array{}>
8384 *
8485 * 200: Recipients returned
8586 * 400: Invalid recipient search parameters
87+ * 404: Share used for filtering existing recipients does not exist
8688 */
8789 #[NoAdminRequired]
8890 #[ApiRoute(verb: 'GET ' , url: '/api/v1/recipients ' )]
89- public function searchRecipients (?array $ recipientTypeClasses , string $ query , int $ limit = 10 , int $ offset = 0 ): DataResponse {
91+ public function searchRecipients (?array $ filterRecipientTypeClasses , string $ query , int $ limit = 10 , int $ offset = 0 , ? string $ id = null ): DataResponse {
9092 /** @psalm-suppress DocblockTypeContradiction */
9193 if ($ limit < 1 ) {
9294 return new DataResponse ('The limit is too low. ' , Http::STATUS_BAD_REQUEST );
@@ -103,10 +105,17 @@ public function searchRecipients(?array $recipientTypeClasses, string $query, in
103105 }
104106
105107 try {
106- $ recipients = $ this ->manager ->searchRecipients ($ this ->accessContext , $ recipientTypeClasses , $ query , $ limit , $ offset );
107- return new DataResponse (ShareRecipient::formatMultiple ($ this ->registry , $ this ->l10nFactory , $ this ->urlGenerator , $ this ->userManager , $ recipients ));
108- } catch (ShareInvalidException $ shareInvalidException ) {
109- return new DataResponse ($ shareInvalidException ->getHint (), Http::STATUS_BAD_REQUEST );
108+ try {
109+ $ this ->dbConnection ->beginTransaction ();
110+ $ recipients = $ this ->manager ->searchRecipients ($ this ->accessContext , $ filterRecipientTypeClasses , $ query , $ limit , $ offset , $ id );
111+ $ this ->dbConnection ->commit ();
112+ return new DataResponse (ShareRecipient::formatMultiple ($ this ->registry , $ this ->l10nFactory , $ this ->urlGenerator , $ this ->userManager , $ recipients ));
113+ } catch (Exception $ exception ) {
114+ $ this ->dbConnection ->rollBack ();
115+ throw $ exception ;
116+ }
117+ } catch (ShareNotFoundException $ shareNotFoundException ) {
118+ return new DataResponse ($ shareNotFoundException ->getHint (), Http::STATUS_NOT_FOUND );
110119 }
111120 }
112121
@@ -519,10 +528,9 @@ public function deleteShare(string $id): DataResponse {
519528 * @param string $id ID of the share
520529 * @param ?string $secret Secret of the share
521530 * @param array<class-string<IShareRecipientType|ISharePropertyTypeFilter>, mixed> $arguments Arguments for accessing the share
522- * @return DataResponse<Http::STATUS_OK, SharingShare, array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http:: STATUS_NOT_FOUND, string, array{}>
531+ * @return DataResponse<Http::STATUS_OK, SharingShare, array{}>|DataResponse<Http::STATUS_NOT_FOUND, string, array{}>
523532 *
524533 * 200: Share returned
525- * 400: Invalid arguments
526534 * 404: Share not found
527535 */
528536 #[PublicPage]
@@ -540,8 +548,6 @@ public function getShare(string $id, ?string $secret = null, array $arguments =
540548 $ this ->dbConnection ->rollBack ();
541549 throw $ exception ;
542550 }
543- } catch (ShareInvalidException $ shareInvalidException ) {
544- return new DataResponse ($ shareInvalidException ->getHint (), Http::STATUS_BAD_REQUEST );
545551 } catch (ShareNotFoundException $ shareNotFoundException ) {
546552 return new DataResponse ($ shareNotFoundException ->getHint (), Http::STATUS_NOT_FOUND );
547553 }
0 commit comments