From 6043b2f30f81cc56aaf466cecd2fd87e4fb0d548 Mon Sep 17 00:00:00 2001 From: gevorgmansuryan Date: Fri, 20 Sep 2024 02:23:01 +0400 Subject: [PATCH 1/3] Added new `resend` and `cancel` endpoints for user invite --- Events.php | 2 ++ controllers/user/InviteController.php | 29 ++++++++++++++++++++++++++- definitions/InviteDefinitions.php | 2 ++ docs/swagger/user.yaml | 27 +++++++++++++++++++++++++ module.json | 2 +- tests/config/test.php | 1 + 6 files changed, 61 insertions(+), 2 deletions(-) diff --git a/Events.php b/Events.php index e7ee16a..bb68b85 100644 --- a/Events.php +++ b/Events.php @@ -84,6 +84,8 @@ public static function onBeforeRequest($event) // User: Invite Controller ['pattern' => 'user/invite', 'route' => 'rest/user/invite/index', 'verb' => 'POST'], ['pattern' => 'user/invite', 'route' => 'rest/user/invite/list', 'verb' => 'GET'], + ['pattern' => 'user/invite/', 'route' => 'rest/user/invite/cancel', 'verb' => 'DELETE'], + ['pattern' => 'user/invite/', 'route' => 'rest/user/invite/resend', 'verb' => 'PATCH'], // User: Session Controller ['pattern' => 'user/session/all/', 'route' => 'rest/user/session/delete-from-user', 'verb' => 'DELETE'], diff --git a/controllers/user/InviteController.php b/controllers/user/InviteController.php index 2736826..51b2825 100644 --- a/controllers/user/InviteController.php +++ b/controllers/user/InviteController.php @@ -30,7 +30,7 @@ protected function getAccessRules() public function actionIndex() { - $emails = (array)Yii::$app->request->post('emails'); + $emails = (array) Yii::$app->request->post('emails'); if (!$emails) { return $this->returnError(404, 'Please provide an array of emails in the json format'); } @@ -70,6 +70,33 @@ public function actionList() return $this->returnPagination($query, $pagination, $results); } + public function actionResend($id) + { + $userInvite = Invite::find()->where(['id' => $id, 'source' => Invite::SOURCE_INVITE])->one(); + + if (!$userInvite) { + return $this->returnError(404, 'Invite not found!'); + } + + $userInvite->save(); + $userInvite->sendInviteMail(); + + return $this->returnSuccess('Invite has been resent.'); + } + + public function actionCancel($id) + { + $userInvite = Invite::find()->where(['id' => $id, 'source' => Invite::SOURCE_INVITE])->one(); + + if (!$userInvite) { + return $this->returnError(404, 'Invite not found!'); + } + + $userInvite->delete(); + + return $this->returnSuccess('Invite has been canceled.'); + } + protected function createInvite($email) { $userInvite = new Invite(); diff --git a/definitions/InviteDefinitions.php b/definitions/InviteDefinitions.php index bac3dec..568dbe3 100644 --- a/definitions/InviteDefinitions.php +++ b/definitions/InviteDefinitions.php @@ -3,6 +3,7 @@ namespace humhub\modules\rest\definitions; use humhub\modules\rest\models\Invite; +use yii\helpers\Url; class InviteDefinitions { @@ -15,6 +16,7 @@ public static function getInvite(Invite $invite) 'lastname' => $invite->lastname, 'language' => $invite->language, 'space' => $invite->space ? SpaceDefinitions::getSpaceShort($invite->space) : null, + 'invitationUrl' => Url::to(['/user/registration', 'token' => $invite->token], true), 'originator' => $invite->originator ? UserDefinitions::getUserShort($invite->originator) : null, 'createdBy' => $invite->createdBy ? UserDefinitions::getUserShort($invite->createdBy) : null, 'updatedBy' => $invite->updatedBy ? UserDefinitions::getUserShort($invite->updatedBy) : null, diff --git a/docs/swagger/user.yaml b/docs/swagger/user.yaml index 945d698..4429e84 100644 --- a/docs/swagger/user.yaml +++ b/docs/swagger/user.yaml @@ -516,6 +516,29 @@ paths: type: array items: $ref: "user.yaml#/definitions/Invite" + '/user/invite/{id}': + patch: + tags: + - Invite + summary: Resend invite + description: Resends invitation email + produces: + - application/json + - application/xml + responses: + '200': + description: Successful operation + delete: + tags: + - Invite + summary: Cancel invite + description: Cancels the invite, making the invitation URL no longer valid. + produces: + - application/json + - application/xml + responses: + '200': + description: Successful operation #----------------------------------------------------------------------------------------------------------------------- # Begin Session @@ -789,6 +812,10 @@ definitions: space: readOnly: true $ref: "space.yaml#/definitions/SpaceShort" + invitationUrl: + type: string + readOnly: true + example: "http://example.com/user/registration?token=cK4FCaopFHNP" originator: readOnly: true $ref: "user.yaml#/definitions/UserShort" diff --git a/module.json b/module.json index cfee703..41f7c1c 100644 --- a/module.json +++ b/module.json @@ -5,7 +5,7 @@ "keywords": [ "api", "rest" ], - "version": "0.10.3", + "version": "0.10.4", "homepage": "https://github.com/humhub/rest", "humhub": { "minVersion": "1.16" diff --git a/tests/config/test.php b/tests/config/test.php index 726273e..9970bed 100644 --- a/tests/config/test.php +++ b/tests/config/test.php @@ -8,6 +8,7 @@ return [ 'modules' => ['rest'], + 'humhub_root' => '/app/humhub', 'fixtures' => [ 'default', 'humhub\modules\rest\tests\codeception\fixtures\ActivityFixture', From 291c3958a5e5ba1f71468e6e4d264aa3daf31c83 Mon Sep 17 00:00:00 2001 From: gevorgmansuryan Date: Fri, 20 Sep 2024 02:25:11 +0400 Subject: [PATCH 2/3] Added new `resend` and `cancel` endpoints for user invite --- docs/CHANGELOG.md | 4 ++++ tests/config/test.php | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 2087b88..df5e298 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog ========= +0.10.4 (Unreleased) +--------------------------- +- Enh #179: Added new `resend` and `cancel` endpoints for user invite + 0.10.3 (September 13, 2024) --------------------------- - Enh #177: Collect user data for Legal module diff --git a/tests/config/test.php b/tests/config/test.php index 9970bed..726273e 100644 --- a/tests/config/test.php +++ b/tests/config/test.php @@ -8,7 +8,6 @@ return [ 'modules' => ['rest'], - 'humhub_root' => '/app/humhub', 'fixtures' => [ 'default', 'humhub\modules\rest\tests\codeception\fixtures\ActivityFixture', From 7934e70f081903c0f66b416623a56c48b661494c Mon Sep 17 00:00:00 2001 From: gevorgmansuryan Date: Sat, 21 Sep 2024 04:18:03 +0400 Subject: [PATCH 3/3] Added new `resend` and `cancel` endpoints for user invite --- docs/html/user.html | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/html/user.html b/docs/html/user.html index 40fa5a2..1e20c68 100644 --- a/docs/html/user.html +++ b/docs/html/user.html @@ -331,7 +331,8 @@ .ldMUmp{font-size:0.929em;line-height:20px;background-color:#186FAF;color:#ffffff;padding:3px 10px;text-transform:uppercase;font-family:Montserrat,sans-serif;margin:0;}/*!sc*/ .blNLGm{font-size:0.929em;line-height:20px;background-color:#95507c;color:#ffffff;padding:3px 10px;text-transform:uppercase;font-family:Montserrat,sans-serif;margin:0;}/*!sc*/ .bJzUtf{font-size:0.929em;line-height:20px;background-color:#cc3333;color:#ffffff;padding:3px 10px;text-transform:uppercase;font-family:Montserrat,sans-serif;margin:0;}/*!sc*/ -data-styled.g115[id="sc-fmdNqN"]{content:"ihNycv,ldMUmp,blNLGm,bJzUtf,"}/*!sc*/ +.cDAiVX{font-size:0.929em;line-height:20px;background-color:#bf581d;color:#ffffff;padding:3px 10px;text-transform:uppercase;font-family:Montserrat,sans-serif;margin:0;}/*!sc*/ +data-styled.g115[id="sc-fmdNqN"]{content:"ihNycv,ldMUmp,blNLGm,bJzUtf,cDAiVX,"}/*!sc*/ .flIrdF{position:absolute;width:100%;z-index:100;background:#fafafa;color:#263238;box-sizing:border-box;box-shadow:0px 0px 6px rgba(0,0,0,0.33);overflow:hidden;border-bottom-left-radius:4px;border-bottom-right-radius:4px;-webkit-transition:all 0.25s ease;transition:all 0.25s ease;visibility:hidden;-webkit-transform:translateY(-50%) scaleY(0);-ms-transform:translateY(-50%) scaleY(0);transform:translateY(-50%) scaleY(0);}/*!sc*/ data-styled.g116[id="sc-ljsmAU"]{content:"flIrdF,"}/*!sc*/ .fQkroN{padding:10px;}/*!sc*/ @@ -391,7 +392,7 @@ -
Responses

Request samples

Content type
application/json
{
  • "emails": [
    ]
}

Pending invites

Returns list of pending invites

Responses

Response samples

Content type
{
  • "total": 76,
  • "page": 1,
  • "results": [
    ]
}

Session

User sessions

+

Response samples

Content type
{}

Resend invite

Resends invitation email

+

Responses

Cancel invite

Cancels the invite, making the invitation URL no longer valid.

+

Responses

Session

User sessions

Deletes all sessions for a particular user

path Parameters
id
required
integer

The id of user

Responses