mirror of
https://github.com/humhub/humhub.git
synced 2025-01-17 14:18:27 +01:00
Add an event trigger after send an invitation email (#7229)
* Add an event trigger after send an invitation email * Hide invitations with unknown sources * Fix resending to all core invitations
This commit is contained in:
parent
590238d1a2
commit
74b57663f0
@ -49,6 +49,7 @@ HumHub Changelog
|
|||||||
- Fix #7222: Fix rendering of checkbox on MacOS and iOS
|
- Fix #7222: Fix rendering of checkbox on MacOS and iOS
|
||||||
- Fix #7225: Fix module JS config initialisation on AJAX request
|
- Fix #7225: Fix module JS config initialisation on AJAX request
|
||||||
- Fix #7227: Fix search reindexing after create new content
|
- Fix #7227: Fix search reindexing after create new content
|
||||||
|
- Enh #7229: Hide invitations with unknown sources
|
||||||
|
|
||||||
1.16.2 (September 5, 2024)
|
1.16.2 (September 5, 2024)
|
||||||
--------------------------
|
--------------------------
|
||||||
|
@ -53,9 +53,6 @@ class PendingRegistrationsController extends Controller
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritdoc
|
|
||||||
*/
|
|
||||||
public function actionIndex()
|
public function actionIndex()
|
||||||
{
|
{
|
||||||
$searchModel = new PendingRegistrationSearch();
|
$searchModel = new PendingRegistrationSearch();
|
||||||
@ -64,12 +61,7 @@ class PendingRegistrationsController extends Controller
|
|||||||
return $this->render('index', [
|
return $this->render('index', [
|
||||||
'dataProvider' => $dataProvider,
|
'dataProvider' => $dataProvider,
|
||||||
'searchModel' => $searchModel,
|
'searchModel' => $searchModel,
|
||||||
'types' => [
|
'types' => [null => null] + $searchModel->getAllowedSources(),
|
||||||
null => null,
|
|
||||||
PendingRegistrationSearch::SOURCE_INVITE => Yii::t('AdminModule.base', 'Invite by email'),
|
|
||||||
PendingRegistrationSearch::SOURCE_INVITE_BY_LINK => Yii::t('AdminModule.base', 'Invite by link'),
|
|
||||||
PendingRegistrationSearch::SOURCE_SELF => Yii::t('AdminModule.base', 'Sign up'),
|
|
||||||
],
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +92,7 @@ class PendingRegistrationsController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resend a invite
|
* Resend an invitation
|
||||||
*
|
*
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return string
|
* @return string
|
||||||
@ -111,18 +103,18 @@ class PendingRegistrationsController extends Controller
|
|||||||
$this->forcePostRequest();
|
$this->forcePostRequest();
|
||||||
$invite = $this->findInviteById($id);
|
$invite = $this->findInviteById($id);
|
||||||
if (Yii::$app->request->isPost) {
|
if (Yii::$app->request->isPost) {
|
||||||
$invite->sendInviteMail();
|
if ($invite->sendInviteMail()) {
|
||||||
$this->view->success(Yii::t(
|
$this->view->success(Yii::t('AdminModule.user', 'Resend invitation email'));
|
||||||
'AdminModule.user',
|
} else {
|
||||||
'Resend invitation email',
|
$this->view->error(Yii::t('AdminModule.user', 'Cannot resend invitation email!'));
|
||||||
));
|
}
|
||||||
return $this->redirect(['index']);
|
return $this->redirect(['index']);
|
||||||
}
|
}
|
||||||
return $this->render('resend', ['model' => $invite]);
|
return $this->render('resend', ['model' => $invite]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete an invite
|
* Delete an invitation
|
||||||
*
|
*
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return string
|
* @return string
|
||||||
@ -134,20 +126,20 @@ class PendingRegistrationsController extends Controller
|
|||||||
$this->forcePostRequest();
|
$this->forcePostRequest();
|
||||||
$invite = $this->findInviteById($id);
|
$invite = $this->findInviteById($id);
|
||||||
if (Yii::$app->request->isPost) {
|
if (Yii::$app->request->isPost) {
|
||||||
$invite->delete();
|
if ($invite->delete()) {
|
||||||
$this->view->success(Yii::t(
|
$this->view->success(Yii::t(
|
||||||
'AdminModule.user',
|
'AdminModule.user',
|
||||||
'Deleted invitation',
|
'Deleted invitation',
|
||||||
));
|
));
|
||||||
|
}
|
||||||
return $this->redirect(['index']);
|
return $this->redirect(['index']);
|
||||||
}
|
}
|
||||||
return $this->render('delete', ['model' => $invite]);
|
return $this->render('delete', ['model' => $invite]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete all invitations
|
* Resend all invitations
|
||||||
*
|
*
|
||||||
* @param int $id
|
|
||||||
* @return string
|
* @return string
|
||||||
* @throws HttpException
|
* @throws HttpException
|
||||||
* @throws Throwable
|
* @throws Throwable
|
||||||
@ -155,7 +147,7 @@ class PendingRegistrationsController extends Controller
|
|||||||
public function actionResendAll()
|
public function actionResendAll()
|
||||||
{
|
{
|
||||||
if (Yii::$app->request->isPost) {
|
if (Yii::$app->request->isPost) {
|
||||||
foreach (Invite::find()->each() as $invite) {
|
foreach (Invite::find()->where(Invite::filterSource())->each() as $invite) {
|
||||||
$invite->sendInviteMail();
|
$invite->sendInviteMail();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,7 +170,7 @@ class PendingRegistrationsController extends Controller
|
|||||||
public function actionDeleteAll()
|
public function actionDeleteAll()
|
||||||
{
|
{
|
||||||
if (Yii::$app->request->isPost) {
|
if (Yii::$app->request->isPost) {
|
||||||
Invite::deleteAll();
|
Invite::deleteAll(Invite::filterSource());
|
||||||
|
|
||||||
$this->view->success(Yii::t(
|
$this->view->success(Yii::t(
|
||||||
'AdminModule.user',
|
'AdminModule.user',
|
||||||
@ -189,9 +181,8 @@ class PendingRegistrationsController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete all or selected invitation
|
* Resend all or selected invitation
|
||||||
*
|
*
|
||||||
* @param int $id
|
|
||||||
* @return string
|
* @return string
|
||||||
* @throws HttpException
|
* @throws HttpException
|
||||||
* @throws Throwable
|
* @throws Throwable
|
||||||
@ -202,7 +193,7 @@ class PendingRegistrationsController extends Controller
|
|||||||
|
|
||||||
$ids = Yii::$app->request->post('id');
|
$ids = Yii::$app->request->post('id');
|
||||||
if (!empty($ids)) {
|
if (!empty($ids)) {
|
||||||
foreach (Invite::findAll(['id' => $ids]) as $invite) {
|
foreach (Invite::findAll(['id' => $ids] + Invite::filterSource()) as $invite) {
|
||||||
$invite->sendInviteMail();
|
$invite->sendInviteMail();
|
||||||
}
|
}
|
||||||
$this->view->success(Yii::t(
|
$this->view->success(Yii::t(
|
||||||
@ -217,7 +208,6 @@ class PendingRegistrationsController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Delete all or selected invitation
|
* Delete all or selected invitation
|
||||||
*
|
*
|
||||||
* @param int $id
|
|
||||||
* @return string
|
* @return string
|
||||||
* @throws HttpException
|
* @throws HttpException
|
||||||
* @throws Throwable
|
* @throws Throwable
|
||||||
@ -227,7 +217,7 @@ class PendingRegistrationsController extends Controller
|
|||||||
if (Yii::$app->request->isPost) {
|
if (Yii::$app->request->isPost) {
|
||||||
$ids = Yii::$app->request->post('id');
|
$ids = Yii::$app->request->post('id');
|
||||||
if (!empty($ids)) {
|
if (!empty($ids)) {
|
||||||
foreach (Invite::findAll(['id' => $ids]) as $invite) {
|
foreach (Invite::findAll(['id' => $ids] + Invite::filterSource()) as $invite) {
|
||||||
$invite->delete();
|
$invite->delete();
|
||||||
}
|
}
|
||||||
$this->view->success(Yii::t(
|
$this->view->success(Yii::t(
|
||||||
@ -275,7 +265,7 @@ class PendingRegistrationsController extends Controller
|
|||||||
*/
|
*/
|
||||||
private function findInviteById($id)
|
private function findInviteById($id)
|
||||||
{
|
{
|
||||||
$invite = Invite::findOne(['id' => $id]);
|
$invite = Invite::findOne(['id' => $id] + Invite::filterSource());
|
||||||
if ($invite === null) {
|
if ($invite === null) {
|
||||||
throw new HttpException(404, Yii::t(
|
throw new HttpException(404, Yii::t(
|
||||||
'AdminModule.user',
|
'AdminModule.user',
|
||||||
|
@ -85,7 +85,8 @@ class UserController extends Controller
|
|||||||
$searchModel = new UserSearch();
|
$searchModel = new UserSearch();
|
||||||
$searchModel->status = User::STATUS_ENABLED;
|
$searchModel->status = User::STATUS_ENABLED;
|
||||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||||
$showPendingRegistrations = (Invite::find()->count() > 0 && Yii::$app->user->can([new ManageUsers(), new ManageGroups()]));
|
$showPendingRegistrations = Invite::find()->where(Invite::filterSource())->exists() &&
|
||||||
|
Yii::$app->user->can([ManageUsers::class, ManageGroups::class]);
|
||||||
|
|
||||||
return $this->render('list', [
|
return $this->render('list', [
|
||||||
'dataProvider' => $dataProvider,
|
'dataProvider' => $dataProvider,
|
||||||
|
@ -50,7 +50,9 @@ class PendingRegistrationSearch extends Invite
|
|||||||
*/
|
*/
|
||||||
public function search($params = [])
|
public function search($params = [])
|
||||||
{
|
{
|
||||||
$query = self::find()->joinWith(['originator']);
|
$query = self::find()
|
||||||
|
->joinWith(['originator'])
|
||||||
|
->andWhere(self::filterSource());
|
||||||
|
|
||||||
$dataProvider = new ActiveDataProvider([
|
$dataProvider = new ActiveDataProvider([
|
||||||
'query' => $query,
|
'query' => $query,
|
||||||
|
@ -57,6 +57,8 @@ class Invite extends ActiveRecord
|
|||||||
*/
|
*/
|
||||||
public $skipCaptchaValidation = false;
|
public $skipCaptchaValidation = false;
|
||||||
|
|
||||||
|
protected ?array $allowedSources = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
@ -325,4 +327,22 @@ class Invite extends ActiveRecord
|
|||||||
{
|
{
|
||||||
return $this->hasOne(User::class, ['id' => 'updated_by']);
|
return $this->hasOne(User::class, ['id' => 'updated_by']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAllowedSources(): array
|
||||||
|
{
|
||||||
|
if ($this->allowedSources === null) {
|
||||||
|
$this->allowedSources = [
|
||||||
|
self::SOURCE_INVITE => Yii::t('AdminModule.base', 'Invite by email'),
|
||||||
|
self::SOURCE_INVITE_BY_LINK => Yii::t('AdminModule.base', 'Invite by link'),
|
||||||
|
self::SOURCE_SELF => Yii::t('AdminModule.base', 'Sign up'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->allowedSources;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function filterSource(): array
|
||||||
|
{
|
||||||
|
return ['source' => array_keys((new static())->getAllowedSources())];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user