Enh: Added possibility to disable mail summary feature

This commit is contained in:
Lucas Bartholemy 2020-01-27 14:24:19 +01:00
parent 5ba4740365
commit 39408a76fa
7 changed files with 78 additions and 21 deletions

View File

@ -39,6 +39,8 @@ HumHub Change Log (DEVELOP)
- Enh #3822 Added content id to notification urls as fallback in case notification was deleted
- Fix: Settings cli rewrite dynamic config when required
- Fix #3806: Using `Receive notifications for new content` will not include the space to the notification setting view until settings are saved
- Enh: Added possibility to disable mail summary feature
1.4.0-beta.2
------------

View File

@ -11,6 +11,10 @@ namespace humhub\modules\activity;
use humhub\modules\activity\components\MailSummary;
use humhub\modules\activity\jobs\SendMailSummary;
use humhub\modules\activity\models\Activity;
use humhub\modules\admin\permissions\ManageSettings;
use humhub\modules\admin\widgets\SettingsMenu;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\user\widgets\AccountMenu;
use Yii;
use yii\base\BaseObject;
use yii\base\Event;
@ -32,7 +36,9 @@ class Events extends BaseObject
*/
public static function onCronHourlyRun($event)
{
Yii::$app->queue->push(new SendMailSummary(['interval' => MailSummary::INTERVAL_HOURLY]));
if (static::getModule()->enableMailSummaries) {
Yii::$app->queue->push(new SendMailSummary(['interval' => MailSummary::INTERVAL_HOURLY]));
}
}
/**
@ -42,9 +48,11 @@ class Events extends BaseObject
*/
public static function onCronDailyRun($event)
{
Yii::$app->queue->push(new SendMailSummary(['interval' => MailSummary::INTERVAL_DAILY]));
if (date('w') == Yii::$app->getModule('activity')->weeklySummaryDay) {
Yii::$app->queue->push(new SendMailSummary(['interval' => MailSummary::INTERVAL_WEEKLY]));
if (static::getModule()->enableMailSummaries) {
Yii::$app->queue->push(new SendMailSummary(['interval' => MailSummary::INTERVAL_DAILY]));
if (date('w') == Yii::$app->getModule('activity')->weeklySummaryDay) {
Yii::$app->queue->push(new SendMailSummary(['interval' => MailSummary::INTERVAL_WEEKLY]));
}
}
}
@ -75,10 +83,46 @@ class Events extends BaseObject
}
}
public static function onAccountMenuInit($event)
{
if (static::getModule()->enableMailSummaries) {
/** @var AccountMenu $menu */
$menu = $event->sender;
$menu->addEntry(new MenuLink([
'label' => Yii::t('ActivityModule.account', 'E-Mail Summaries'),
'id' => 'account-settings-emailsummary',
'icon' => 'envelope',
'url' => ['/activity/user'],
'sortOrder' => 105,
'isActive' => MenuLink::isActiveState('activity')
]));
}
}
public static function onSettingsMenuInit($event)
{
if (static::getModule()->enableMailSummaries) {
/** @var SettingsMenu $menu */
$menu = $event->sender;
$menu->addEntry(new MenuLink([
'label' => Yii::t('ActivityModule.base', 'E-Mail Summaries'),
'url' => ['/activity/admin/defaults'],
'sortOrder' => 300,
'isActive' => MenuLink::isActiveState('activity', 'admin', 'defaults'),
'isVisible' => Yii::$app->user->can(ManageSettings::class)
]));
}
}
/**
* Callback to validate module database records.
*
* @param Event $event
* @throws \Throwable
* @throws \yii\db\StaleObjectException
*/
public static function onIntegrityCheck($event)
{
@ -116,4 +160,13 @@ class Events extends BaseObject
}
}
/**
* @return Module
*/
private static function getModule()
{
return Yii::$app->getModule('activity');
}
}

View File

@ -30,6 +30,13 @@ class Module extends \humhub\components\Module
*/
public $weeklySummaryDay = 0;
/**
* @var boolean enable mail summary feature
* @since 1.4
*/
public $enableMailSummaries = true;
/**
* Returns all configurable Activitiess
*

View File

@ -11,7 +11,10 @@ use humhub\modules\activity\Events;
use humhub\components\ActiveRecord;
use humhub\commands\IntegrityController;
use humhub\modules\activity\Module;
use humhub\modules\admin\widgets\SettingsMenu;
use humhub\modules\user\widgets\AccountMenu;
/** @noinspection MissedFieldInspection */
return [
'id' => 'activity',
'class' => Module::class,
@ -21,5 +24,7 @@ return [
['class' => IntegrityController::class, 'event' => IntegrityController::EVENT_ON_RUN, 'callback' => [Events::class, 'onIntegrityCheck']],
['class' => CronController::class, 'event' => CronController::EVENT_ON_HOURLY_RUN, 'callback' => [Events::class, 'onCronHourlyRun']],
['class' => CronController::class, 'event' => CronController::EVENT_ON_DAILY_RUN, 'callback' => [Events::class, 'onCronDailyRun']],
['class' => AccountMenu::class, 'event' => AccountMenu::EVENT_INIT, 'callback' => [Events::class, 'onAccountMenuInit']],
['class' => SettingsMenu::class, 'event' => SettingsMenu::EVENT_INIT, 'callback' => [Events::class, 'onSettingsMenuInit']]
],
];

View File

@ -8,6 +8,7 @@
namespace humhub\modules\activity\jobs;
use humhub\modules\activity\Module;
use Yii;
use humhub\modules\queue\ActiveJob;
use humhub\modules\activity\components\MailSummaryProcessor;
@ -32,6 +33,12 @@ class SendMailSummary extends ActiveJob
*/
public function run()
{
/** @var Module $module */
$module = Yii::$app->getModule('activity');
if ($module->enableMailSummaries) {
return;
}
if ($this->interval === MailSummary::INTERVAL_DAILY || $this->interval === MailSummary::INTERVAL_HOURLY || $this->interval === MailSummary::INTERVAL_WEEKLY) {
MailSummaryProcessor::process($this->interval);
} else {

View File

@ -42,14 +42,6 @@ class SettingsMenu extends TabMenu
'isVisible' => $canEditSettings
]));
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.base', 'E-Mail summaries'),
'url' => ['/activity/admin/defaults'],
'sortOrder' => 300,
'isActive' => MenuLink::isActiveState('activity', 'admin', 'defaults'),
'isVisible' => $canEditSettings
]));
$this->addEntry(new MenuLink([
'label' => Yii::t('AdminModule.base', 'Notifications'),
'url' => ['/notification/admin/defaults'],

View File

@ -38,15 +38,6 @@ class AccountMenu extends LeftNavigation
'isActive' => MenuLink::isActiveState('user', 'account', ['edit', 'change-email', 'change-password', 'delete'])
]));
$this->addEntry(new MenuLink([
'label' => Yii::t('UserModule.account', 'E-Mail Summaries'),
'id' => 'account-settings-emailsummary',
'icon' => 'envelope',
'url' => ['/activity/user'],
'sortOrder' => 105,
'isActive' => MenuLink::isActiveState('activity')
]));
$this->addEntry(new MenuLink([
'label' => Yii::t('UserModule.account', 'Notifications'),
'id' => 'account-settings-notifications',