Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endpoint for pending invites #170

Merged
merged 4 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public static function onBeforeRequest($event)
['pattern' => 'user/group/<id:\d+>/member', 'route' => 'rest/user/group/members', 'verb' => ['GET', 'HEAD']],
['pattern' => 'user/group/<id:\d+>/member', 'route' => 'rest/user/group/member-add', 'verb' => ['PUT', 'PATCH']],
['pattern' => 'user/group/<id:\d+>/member', 'route' => 'rest/user/group/member-remove', 'verb' => ['DELETE']],
['pattern' => 'user/invite', 'route' => 'rest/user/invite/index', 'verb' => 'POST'],

// User: Invite Controller
//['pattern' => 'user/invite', 'route' => 'api/user/invite/index', 'verb' => 'POST'],
['pattern' => 'user/invite', 'route' => 'rest/user/invite/index', 'verb' => 'POST'],
['pattern' => 'user/invite', 'route' => 'rest/user/invite/list', 'verb' => 'GET'],

// User: Session Controller
['pattern' => 'user/session/all/<id:\d+>', 'route' => 'rest/user/session/delete-from-user', 'verb' => 'DELETE'],
Expand Down
22 changes: 22 additions & 0 deletions controllers/user/InviteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,25 @@

use humhub\modules\rest\components\BaseController;
use humhub\modules\user\models\Invite;
use humhub\modules\rest\definitions\InviteDefinitions;
use humhub\modules\user\models\User;
use Yii;
use yii\validators\EmailValidator;
use yii\helpers\ArrayHelper;


/**
* Class InviteController
*/
class InviteController extends BaseController
{
protected function getAccessRules()
{
return [
['permissions' => [ManageUsers::class]],
];
}

public function actionIndex()
{
$emails = (array)Yii::$app->request->post('emails');
Expand Down Expand Up @@ -46,6 +55,19 @@ public function actionIndex()
return $this->returnSuccess(count($emails) . ' users have been invited.');
}

public function actionList()
{
$query = Invite::find()->where(['source' => Invite::SOURCE_INVITE]);

$pagination = $this->handlePagination($query, 10);

$results = ArrayHelper::getColumn($query->all(), function(Invite $invite) {
return InviteDefinitions::getInvite($invite);
});

return $this->returnPagination($query, $pagination, $results);
}

protected function createInvite($email)
{
$userInvite = new Invite();
Expand Down
16 changes: 16 additions & 0 deletions definitions/InviteDefinitions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace humhub\modules\rest\definitions;

use humhub\modules\user\models\Invite;

class InviteDefinitions
{
public static function getInvite(Invite $invite)
{
return [
'id' => $invite->id,
'email' => $invite->email,
];
}
}
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
------------------------
- Enh #155: Add `requirements.php`
- Fix #164: Disable `mustChangePassword` check for impersonated access tokens
- Enh #170: Added new endpoint `GET /user/invite` for user pending invites

0.9.3 (December 8, 2023)
------------------------
Expand Down
Loading
Loading