Skip to content

Commit

Permalink
Merge branch 'master' into enh/profile-image-banner
Browse files Browse the repository at this point in the history
  • Loading branch information
luke- authored Sep 23, 2024
2 parents b257818 + 6204832 commit 3cc32cd
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 5 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
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
0.10.4 (Unreleased)
---------------------------
- Enh #181: Added user profile `image_url` and `banner_url`
- Enh #179: Added new `resend` and `cancel` endpoints for user invite

0.10.3 (September 13, 2024)
---------------------------
Expand Down
Loading

0 comments on commit 3cc32cd

Please sign in to comment.