3232use OCA \Circles \Service \SearchService ;
3333use OCA \Circles \Tools \Traits \TDeserialize ;
3434use OCA \Circles \Tools \Traits \TNCLogger ;
35+ use OCP \AppFramework \Http ;
36+ use OCP \AppFramework \Http \Attribute \NoAdminRequired ;
37+ use OCP \AppFramework \Http \Attribute \UserRateLimit ;
3538use OCP \AppFramework \Http \DataResponse ;
3639use OCP \AppFramework \OCS \OCSException ;
3740use OCP \AppFramework \OCSController ;
@@ -591,13 +594,12 @@ public function link(string $circleId, string $singleId): DataResponse {
591594 }
592595
593596 /**
594- * @NoAdminRequired
595- *
596597 * @param string $circleId
597598 *
598599 * @return DataResponse
599600 * @throws OCSException
600601 */
602+ #[NoAdminRequired]
601603 public function createInvitation (string $ circleId ): DataResponse {
602604 try {
603605 $ this ->setCurrentFederatedUser ();
@@ -612,13 +614,12 @@ public function createInvitation(string $circleId): DataResponse {
612614 }
613615
614616 /**
615- * @NoAdminRequired
616- *
617617 * @param string $circleId
618618 *
619619 * @return DataResponse
620620 * @throws OCSException
621621 */
622+ #[NoAdminRequired]
622623 public function revokeInvitation (string $ circleId ): DataResponse {
623624 try {
624625 $ this ->setCurrentFederatedUser ();
@@ -632,6 +633,81 @@ public function revokeInvitation(string $circleId): DataResponse {
632633 }
633634 }
634635
636+ /**
637+ * @param string $invitationCode
638+ *
639+ * @return DataResponse
640+ * @throws OCSException
641+ */
642+ #[NoAdminRequired]
643+ #[UserRateLimit(limit: 10 , period: 3600 )]
644+ public function getInvitation (string $ invitationCode ): DataResponse {
645+ try {
646+ $ this ->setCurrentFederatedUser ();
647+
648+ $ circleProbe = (new CircleProbe ())
649+ ->includeSystemCircles ()
650+ ->includeHiddenCircles ()
651+ ->filterByInvitationCode ($ invitationCode );
652+
653+ $ circles = $ this ->circleService ->getCircles ($ circleProbe );
654+ if (empty ($ circles )) {
655+ return new DataResponse ([], Http::STATUS_NOT_FOUND );
656+ }
657+ $ circle = reset ($ circles );
658+
659+ $ membershipStatus = 'NOT_A_MEMBER ' ;
660+ if ($ circle ->hasInitiator ()) {
661+ if ($ circle ->getInitiator ()->getLevel () > Member::LEVEL_NONE ) {
662+ $ membershipStatus = 'MEMBER ' ;
663+ } elseif ($ circle ->getInitiator ()->getStatus () === Member::STATUS_INVITED ) {
664+ $ membershipStatus = 'REQUESTED_MEMBERSHIP ' ;
665+ }
666+ }
667+
668+ return new DataResponse ([
669+ 'circleId ' => $ circle ->getSingleId (),
670+ 'circleName ' => $ circle ->getName (),
671+ 'membershipStatus ' => $ membershipStatus ,
672+ ]);
673+ } catch (\Exception $ e ) {
674+ $ this ->e ($ e , ['circleId ' => $ invitationCode ]);
675+ throw new OCSException ($ e ->getMessage (), (int )$ e ->getCode (), $ e );
676+ }
677+ }
678+
679+ /**
680+ * @param string $invitationCode
681+ *
682+ * @return DataResponse
683+ * @throws OCSException
684+ */
685+ #[NoAdminRequired]
686+ #[UserRateLimit(limit: 10 , period: 3600 )]
687+ public function joinInvitation (string $ invitationCode ): DataResponse {
688+ try {
689+ $ this ->setCurrentFederatedUser ();
690+
691+ $ circleProbe = (new CircleProbe ())
692+ ->includeSystemCircles ()
693+ ->includeHiddenCircles ()
694+ ->filterByInvitationCode ($ invitationCode );
695+
696+ $ circles = $ this ->circleService ->getCircles ($ circleProbe );
697+ if (empty ($ circles )) {
698+ return new DataResponse ([], Http::STATUS_NOT_FOUND );
699+ }
700+ $ circle = reset ($ circles );
701+
702+ $ result = $ this ->circleService ->circleJoin ($ circle ->getSingleId (), $ invitationCode );
703+
704+ return new DataResponse ($ this ->serializeArray ($ result ));
705+ } catch (\Exception $ e ) {
706+ $ this ->e ($ e , ['circleId ' => $ invitationCode ]);
707+ throw new OCSException ($ e ->getMessage (), (int )$ e ->getCode (), $ e );
708+ }
709+ }
710+
635711 /**
636712 * @return void
637713 * @throws FederatedUserException
0 commit comments