2626use NCU \Sharing \Share ;
2727use NCU \Sharing \ShareAccessContext ;
2828use NCU \Sharing \ShareState ;
29+ use NCU \Sharing \ShareUserStatus ;
2930use NCU \Sharing \Source \IShareSourceType ;
3031use NCU \Sharing \Source \ShareSource ;
3132use OCA \Sharing \ResponseDefinitions ;
5152 * @psalm-import-type SharingShare from ResponseDefinitions
5253 * @psalm-import-type SharingRecipient from ResponseDefinitions
5354 * @psalm-import-type SharingState from ResponseDefinitions
55+ * @psalm-import-type SharingUserStatus from ResponseDefinitions
5456 * @psalm-import-type SharingPermissionPreset from ResponseDefinitions
5557 */
5658final class ApiV1Controller extends OCSController {
@@ -186,8 +188,7 @@ public function updateShareState(string $id, string $state): DataResponse {
186188 $ this ->dbConnection ->beginTransaction ();
187189
188190 $ share = $ this ->manager ->getShare ($ this ->accessContext , $ id );
189- $ this ->manager ->updateShareState ($ this ->accessContext , $ share , $ shareState );
190- $ share = $ this ->manager ->getShare ($ this ->accessContext , $ id );
191+ $ share = $ this ->manager ->updateShareState ($ this ->accessContext , $ share , $ shareState );
191192 $ this ->dbConnection ->commit ();
192193 return new DataResponse ($ share ->format ($ this ->registry , $ this ->l10nFactory , $ this ->urlGenerator , $ this ->userManager ));
193194 } catch (Exception $ exception ) {
@@ -201,6 +202,43 @@ public function updateShareState(string $id, string $state): DataResponse {
201202 }
202203 }
203204
205+ /**
206+ * Update the user status for a share.
207+ *
208+ * @param string $id ID of the share
209+ * @param SharingUserStatus $userStatus New user status for the share
210+ * @return DataResponse<Http::STATUS_OK, SharingShare, array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND, string, array{}>
211+ *
212+ * 200: User status for share updated successfully
213+ * 400: Invalid share user status
214+ * 404: Share not found
215+ */
216+ #[NoAdminRequired]
217+ #[ApiRoute(verb: 'PUT ' , url: '/api/v1/share/{id}/user-status ' )]
218+ public function updateShareUserStatus (string $ id , string $ userStatus ): DataResponse {
219+ try {
220+ $ shareUserStatus = ShareUserStatus::from ($ userStatus );
221+ } catch (ValueError $ valueError ) {
222+ return new DataResponse ($ valueError ->getMessage (), Http::STATUS_BAD_REQUEST );
223+ }
224+
225+ try {
226+ try {
227+ $ this ->dbConnection ->beginTransaction ();
228+
229+ $ share = $ this ->manager ->getShare ($ this ->accessContext , $ id );
230+ $ share = $ this ->manager ->updateShareUserStatus ($ this ->accessContext , $ share , $ shareUserStatus );
231+ $ this ->dbConnection ->commit ();
232+ return new DataResponse ($ share ->format ($ this ->registry , $ this ->l10nFactory , $ this ->urlGenerator , $ this ->userManager ));
233+ } catch (Exception $ exception ) {
234+ $ this ->dbConnection ->rollBack ();
235+ throw $ exception ;
236+ }
237+ } catch (ShareNotFoundException $ shareNotFoundException ) {
238+ return new DataResponse ($ shareNotFoundException ->getHint (), Http::STATUS_NOT_FOUND );
239+ }
240+ }
241+
204242 /**
205243 * Add a new source to a share.
206244 *
@@ -561,6 +599,7 @@ public function getShare(string $id, ?string $secret = null, array $arguments =
561599 * @param ?class-string<IShareSourceType> $filterSourceTypeClass Source type class to filter by.
562600 * @param ?non-empty-string $filterSourceTypeValue Source type value to filter by.
563601 * @param ?SharingState $filterState State to filter by.
602+ * @param ?SharingUserStatus $filterUserStatus User status to filter by.
564603 * @param ?string $lastShareID The ID of the previous share. This is used as an offset and only shares with higher IDs are returned.
565604 * @param int<1, 100> $limit The number of shares to return.
566605 * @return DataResponse<Http::STATUS_OK, list<SharingShare>, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, string, array{}>
@@ -570,7 +609,7 @@ public function getShare(string $id, ?string $secret = null, array $arguments =
570609 */
571610 #[NoAdminRequired]
572611 #[ApiRoute(verb: 'GET ' , url: '/api/v1/shares ' )]
573- public function getShares (?string $ filterSourceTypeClass , ?string $ filterSourceTypeValue , ?string $ filterState , ?string $ lastShareID , int $ limit = 100 ): DataResponse {
612+ public function getShares (?string $ filterSourceTypeClass , ?string $ filterSourceTypeValue , ?string $ filterState , ?string $ filterUserStatus , ? string $ lastShareID , int $ limit = 100 ): DataResponse {
574613 /** @psalm-suppress DocblockTypeContradiction */
575614 if ($ limit < 1 ) {
576615 return new DataResponse ('The limit is too low. ' , Http::STATUS_BAD_REQUEST );
@@ -598,10 +637,18 @@ public function getShares(?string $filterSourceTypeClass, ?string $filterSourceT
598637 }
599638 }
600639
640+ if ($ filterUserStatus !== null ) {
641+ try {
642+ $ filterUserStatus = ShareUserStatus::from ($ filterUserStatus );
643+ } catch (ValueError $ valueError ) {
644+ return new DataResponse ($ valueError ->getMessage (), Http::STATUS_BAD_REQUEST );
645+ }
646+ }
647+
601648 try {
602649 $ this ->dbConnection ->beginTransaction ();
603650
604- $ shares = $ this ->manager ->getShares ($ this ->accessContext , $ filterSourceTypeClass , $ filterSourceTypeValue , $ filterState , $ lastShareID , $ limit );
651+ $ shares = $ this ->manager ->getShares ($ this ->accessContext , $ filterSourceTypeClass , $ filterSourceTypeValue , $ filterState , $ filterUserStatus , $ lastShareID , $ limit );
605652 $ this ->dbConnection ->commit ();
606653 return new DataResponse (Share::formatMultiple ($ this ->registry , $ this ->l10nFactory , $ this ->urlGenerator , $ this ->userManager , $ shares ));
607654 } catch (Exception $ exception ) {
0 commit comments