Skip to content

Commit

Permalink
Added new resend and cancel endpoints for user invite
Browse files Browse the repository at this point in the history
  • Loading branch information
gevorgmansuryan committed Sep 19, 2024
1 parent 51c1576 commit 6043b2f
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/<id:\d+>', 'route' => 'rest/user/invite/cancel', 'verb' => 'DELETE'],
['pattern' => 'user/invite/<id:\d+>', 'route' => 'rest/user/invite/resend', 'verb' => 'PATCH'],

// User: Session Controller
['pattern' => 'user/session/all/<id:\d+>', 'route' => 'rest/user/session/delete-from-user', 'verb' => 'DELETE'],
Expand Down
29 changes: 28 additions & 1 deletion controllers/user/InviteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions definitions/InviteDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace humhub\modules\rest\definitions;

use humhub\modules\rest\models\Invite;
use yii\helpers\Url;

class InviteDefinitions
{
Expand All @@ -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,
Expand Down
27 changes: 27 additions & 0 deletions docs/swagger/user.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tests/config/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

return [
'modules' => ['rest'],
'humhub_root' => '/app/humhub',
'fixtures' => [
'default',
'humhub\modules\rest\tests\codeception\fixtures\ActivityFixture',
Expand Down

0 comments on commit 6043b2f

Please sign in to comment.