Enh #7068: Bulk re-send email invites (#7147)

Co-authored-by: Lucas Bartholemy <luke-@users.noreply.github.com>
This commit is contained in:
Marc Farré 2024-09-02 14:26:17 +01:00 committed by GitHub
parent db36b12657
commit f94c7b83ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 107 additions and 21 deletions

View File

@ -12,6 +12,8 @@ HumHub Changelog
- Enh #7129: Link `wall-entry-controls`- color to `--text-color-soft`
- Chg #7136: When opening a modal box, don't autofocus automatically on the first form input
- Enh #7138: Added missing DB relations to UserInvite model
- Enh #7139: Export `confirmUnload` function from `humhub.client.js`
- Enh #7068: Bulk re-send email invites
- Enh #7139 : Export `confirmUnload` function from `humhub.client.js`
- Enh #7144: Add `DeviceDetectorHelper` class to detect devices such as the mobile app
- Fix #7149: Fixed dropdown issue on mobile

View File

@ -144,6 +144,29 @@ class PendingRegistrationsController extends Controller
return $this->render('delete', ['model' => $invite]);
}
/**
* Delete all invitations
*
* @param int $id
* @return string
* @throws HttpException
* @throws Throwable
*/
public function actionResendAll()
{
if (Yii::$app->request->isPost) {
foreach (Invite::find()->each() as $invite) {
$invite->sendInviteMail();
}
$this->view->success(Yii::t(
'AdminModule.user',
'All open registration invitations were successfully re-sent.',
));
}
return $this->redirect(['index']);
}
/**
* Delete all invitations
*
@ -173,15 +196,39 @@ class PendingRegistrationsController extends Controller
* @throws HttpException
* @throws Throwable
*/
public function actionDeleteAllSelected()
public function actionResendAllSelected()
{
if (Yii::$app->request->isPost) {
$ids = Yii::$app->request->post('id');
if (!empty($ids)) {
foreach ($ids as $id) {
$invitation = Invite::findOne(['id' => $id]);
$invitation->delete();
foreach (Invite::findAll(['id' => $ids]) as $invite) {
$invite->sendInviteMail();
}
$this->view->success(Yii::t(
'AdminModule.user',
'The selected invitations have been successfully re-sent!',
));
}
}
return $this->redirect(['index']);
}
/**
* Delete all or selected invitation
*
* @param int $id
* @return string
* @throws HttpException
* @throws Throwable
*/
public function actionDeleteAllSelected()
{
if (Yii::$app->request->isPost) {
$ids = Yii::$app->request->post('id');
if (!empty($ids)) {
foreach (Invite::findAll(['id' => $ids]) as $invite) {
$invite->delete();
}
$this->view->success(Yii::t(
'AdminModule.user',

View File

@ -5,6 +5,20 @@ humhub.module('admin.PendingRegistrations', function (module, require, $) {
var PendingRegistrations = Widget.extend();
PendingRegistrations.prototype.resendAllSelected = function (evt) {
var that = this;
client.post(evt).then(function () {
var keys = $("#grid").yiiGridView("getSelectedRows");
$.ajax({
url: that.options.urlResendSelected,
type: "POST",
data: {id: keys},
})
}).catch(function (e) {
module.log.error(e, true);
})
};
PendingRegistrations.prototype.deleteAllSelected = function (evt) {
var that = this;
client.post(evt).then(function () {
@ -19,6 +33,12 @@ humhub.module('admin.PendingRegistrations', function (module, require, $) {
})
};
PendingRegistrations.prototype.resendAll = function (evt) {
client.post(evt).catch(function () {
module.log.error(e, true);
})
};
PendingRegistrations.prototype.deleteAll = function (evt) {
client.post(evt).catch(function () {
module.log.error(e, true);
@ -30,10 +50,16 @@ humhub.module('admin.PendingRegistrations', function (module, require, $) {
this.$.find("input").change(function () {
var $selection = that.$.find(':checked')
if ($selection.length > 1) {
$('.resend-all').html(that.options.noteResendSelected);
$('.resend-all').attr('data-action-click', 'resendAllSelected');
$('.resend-all').attr('data-action-click-url', that.options.urlResendSelected);
$('.delete-all').html(that.options.noteDeleteSelected);
$('.delete-all').attr('data-action-click', 'deleteAllSelected');
$('.delete-all').attr('data-action-click-url', that.options.urlDeleteSelected);
} else {
$('.resend-all').html(that.options.noteResendAll);
$('.resend-all').attr('data-action-click', 'resendAll');
$('.resend-all').attr('data-action-click-url', that.options.urlResendAll);
$('.delete-all').html(that.options.noteDeleteAll);
$('.delete-all').attr('data-action-click', 'deleteAll');
$('.delete-all').attr('data-action-click-url', that.options.urlDeleteAll);

View File

@ -9,10 +9,10 @@
namespace humhub\modules\admin\widgets;
use humhub\modules\admin\models\PendingRegistrationSearch;
use yii\helpers\Url;
use humhub\widgets\JsWidget;
use Yii;
use yii\data\ActiveDataProvider;
use yii\helpers\Url;
/**
* PendingRegistrations shows a grid view of all open/pending UserInvites
@ -80,6 +80,10 @@ class PendingRegistrations extends JsWidget
public function getData()
{
return [
'url-resend-selected' => Url::to(['pending-registrations/resend-all-selected']),
'url-resend-all' => Url::to(['pending-registrations/resend-all']),
'note-resend-selected' => Yii::t('AdminModule.base', 'Resend to selected rows'),
'note-resend-all' => Yii::t('AdminModule.base', 'Resend to all'),
'url-delete-selected' => Url::to(['pending-registrations/delete-all-selected']),
'url-delete-all' => Url::to(['pending-registrations/delete-all']),
'note-delete-selected' => Yii::t('AdminModule.base', 'Delete selected rows'),

View File

@ -15,28 +15,33 @@ use yii\helpers\Url;
AdminPendingRegistrationsAsset::register($this);
?>
<?= Html::beginTag('div', $options); ?>
<h4><?= Yii::t('AdminModule.base', 'Pending user registrations') ?></h4>
<div class="help-block">
<?= Yii::t(
'AdminModule.user',
'The following list contains all pending sign-ups and invites.'
) ?>
</div>
<div class="pull-right">
<h4>
<?= humhub\libs\Html::backButton(
['/admin/user/index'],
[
'label' => Yii::t('AdminModule.base', 'Back to user overview'),
'class' => 'btn-sm'
]
'class' => 'btn-sm pull-right',
],
) ?>
<?= Yii::t('AdminModule.base', 'Pending user registrations') ?>
</h4>
<div class="help-block">
<?= Yii::t('AdminModule.user', 'The following list contains all pending sign-ups and invites.') ?>
</div>
<div class="pull-right">
<?php if ($dataProvider->totalCount > 0): ?>
<?= Button::primary(Yii::t('AdminModule.user', 'Re-send to all'))
->icon('paper-plane')
->action('resendAll', Url::toRoute(['/admin/pending-registrations/resend-all']))
->cssClass('resend-all btn-sm')->
confirm(Yii::t('AdminModule.user', 'Resend invitations?'), Yii::t('AdminModule.user', 'Do you really want to re-send the invitations to pending registration users?')) ?>
<?= Button::danger(Yii::t('AdminModule.user', 'Delete All'))
->icon('trash')
->action('deleteAll', Url::toRoute(['/admin/pending-registrations/delete-all']))
->cssClass('delete-all btn-sm')->
confirm('<b>Delete</b> pending registrations?', 'Do you really want to delete pending registrations?'); ?>
confirm(Yii::t('AdminModule.user', 'Delete pending registrations?'), Yii::t('AdminModule.user', 'Do you really want to delete pending registrations?')) ?>
<?php endif; ?>
<?= ExportButton::widget(['filter' => 'PendingRegistrationSearch']) ?>
</div>
@ -82,19 +87,21 @@ AdminPendingRegistrationsAsset::register($this);
'resend' => function ($url, $model, $key) {
return Button::primary()
->action('client.post', Url::to(['resend', 'id' => $model->id]))
->icon('envelope')
->icon('paper-plane')
->confirm(Yii::t('AdminModule.user', 'Resend invitation?'))
->xs();
},
'delete' => function ($url, $model, $key) {
return
Button::primary()
Button::danger()
->action('client.post', Url::to(['delete', 'id' => $model->id]))
->icon('trash')
->confirm(Yii::t('AdminModule.user', 'Delete pending registrations?'))
->xs();
},
],
],
]
],
]) ?>
<?= Html::endTag('div');