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/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/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