From 59de5cceac7ebadf99955301bea29c51dcc1dd41 Mon Sep 17 00:00:00 2001 From: David Sevilla Martin Date: Thu, 18 May 2017 20:32:23 -0400 Subject: [PATCH 1/7] add alert & email notifications for suspend & unsuspend --- extensions/suspend/bootstrap.php | 1 + extensions/suspend/js/forum/dist/extension.js | 116 +++++++++++++++++- .../components/UserSuspendedNotification.js | 25 ++++ .../components/UserUnsuspendedNotification.js | 22 ++++ extensions/suspend/js/forum/src/main.js | 5 + .../suspend/src/Event/UserWasSuspended.php | 38 ++++++ .../suspend/src/Event/UserWasUnsuspended.php | 38 ++++++ .../src/Listener/SaveSuspensionToDatabase.php | 8 ++ .../SendNotificationWhenUserIsSuspended.php | 95 ++++++++++++++ .../Notification/UserSuspendedBlueprint.php | 78 ++++++++++++ .../Notification/UserUnsuspendedBlueprint.php | 77 ++++++++++++ 11 files changed, 501 insertions(+), 2 deletions(-) create mode 100644 extensions/suspend/js/forum/src/components/UserSuspendedNotification.js create mode 100644 extensions/suspend/js/forum/src/components/UserUnsuspendedNotification.js create mode 100644 extensions/suspend/src/Event/UserWasSuspended.php create mode 100644 extensions/suspend/src/Event/UserWasUnsuspended.php create mode 100644 extensions/suspend/src/Listener/SendNotificationWhenUserIsSuspended.php create mode 100644 extensions/suspend/src/Notification/UserSuspendedBlueprint.php create mode 100644 extensions/suspend/src/Notification/UserUnsuspendedBlueprint.php diff --git a/extensions/suspend/bootstrap.php b/extensions/suspend/bootstrap.php index 74d3f0c8a..9c15afe7f 100644 --- a/extensions/suspend/bootstrap.php +++ b/extensions/suspend/bootstrap.php @@ -18,6 +18,7 @@ return function (Dispatcher $events) { $events->subscribe(Listener\AddUserSuspendAttributes::class); $events->subscribe(Listener\RevokeAccessFromSuspendedUsers::class); $events->subscribe(Listener\SaveSuspensionToDatabase::class); + $events->subscribe(Listener\SendNotificationWhenUserIsSuspended::class); $events->subscribe(Access\UserPolicy::class); }; diff --git a/extensions/suspend/js/forum/dist/extension.js b/extensions/suspend/js/forum/dist/extension.js index 0bf8c06f4..2ba4fb221 100644 --- a/extensions/suspend/js/forum/dist/extension.js +++ b/extensions/suspend/js/forum/dist/extension.js @@ -152,10 +152,115 @@ System.register('flarum/suspend/components/SuspendUserModal', ['flarum/component });; 'use strict'; -System.register('flarum/suspend/main', ['flarum/extend', 'flarum/app', 'flarum/utils/UserControls', 'flarum/components/Button', 'flarum/components/Badge', 'flarum/Model', 'flarum/models/User', 'flarum/suspend/components/SuspendUserModal'], function (_export, _context) { +System.register('flarum/suspend/components/UserSuspendedNotification', ['flarum/components/Notification', 'flarum/helpers/username', 'flarum/helpers/humanTime'], function (_export, _context) { "use strict"; - var extend, app, UserControls, Button, Badge, Model, User, SuspendUserModal; + var Notification, username, humanTime, UserSuspendedNotification; + return { + setters: [function (_flarumComponentsNotification) { + Notification = _flarumComponentsNotification.default; + }, function (_flarumHelpersUsername) { + username = _flarumHelpersUsername.default; + }, function (_flarumHelpersHumanTime) { + humanTime = _flarumHelpersHumanTime.default; + }], + execute: function () { + UserSuspendedNotification = function (_Notification) { + babelHelpers.inherits(UserSuspendedNotification, _Notification); + + function UserSuspendedNotification() { + babelHelpers.classCallCheck(this, UserSuspendedNotification); + return babelHelpers.possibleConstructorReturn(this, (UserSuspendedNotification.__proto__ || Object.getPrototypeOf(UserSuspendedNotification)).apply(this, arguments)); + } + + babelHelpers.createClass(UserSuspendedNotification, [{ + key: 'icon', + value: function icon() { + return 'ban'; + } + }, { + key: 'href', + value: function href() { + return app.route.user(this.props.notification.subject()); + } + }, { + key: 'content', + value: function content() { + var notification = this.props.notification; + var actor = notification.sender(); + var suspendUntil = notification.content(); + var timeReadable = moment(suspendUntil.date).from(notification.time(), true); + + return app.translator.transChoice('flarum-suspend.forum.notifications.user_suspended_text', { + actor: actor, + timeReadable: timeReadable + }); + } + }]); + return UserSuspendedNotification; + }(Notification); + + _export('default', UserSuspendedNotification); + } + }; +});; +'use strict'; + +System.register('flarum/suspend/components/UserUnsuspendedNotification', ['flarum/components/Notification', 'flarum/helpers/username', 'flarum/helpers/humanTime'], function (_export, _context) { + "use strict"; + + var Notification, username, humanTime, UserUnsuspendedNotification; + return { + setters: [function (_flarumComponentsNotification) { + Notification = _flarumComponentsNotification.default; + }, function (_flarumHelpersUsername) { + username = _flarumHelpersUsername.default; + }, function (_flarumHelpersHumanTime) { + humanTime = _flarumHelpersHumanTime.default; + }], + execute: function () { + UserUnsuspendedNotification = function (_Notification) { + babelHelpers.inherits(UserUnsuspendedNotification, _Notification); + + function UserUnsuspendedNotification() { + babelHelpers.classCallCheck(this, UserUnsuspendedNotification); + return babelHelpers.possibleConstructorReturn(this, (UserUnsuspendedNotification.__proto__ || Object.getPrototypeOf(UserUnsuspendedNotification)).apply(this, arguments)); + } + + babelHelpers.createClass(UserUnsuspendedNotification, [{ + key: 'icon', + value: function icon() { + return 'ban'; + } + }, { + key: 'href', + value: function href() { + return app.route.user(this.props.notification.subject()); + } + }, { + key: 'content', + value: function content() { + var notification = this.props.notification; + var actor = notification.sender(); + + return app.translator.transChoice('flarum-suspend.forum.notifications.user_unsuspended_text', { + actor: actor + }); + } + }]); + return UserUnsuspendedNotification; + }(Notification); + + _export('default', UserUnsuspendedNotification); + } + }; +});; +'use strict'; + +System.register('flarum/suspend/main', ['flarum/extend', 'flarum/app', 'flarum/utils/UserControls', 'flarum/components/Button', 'flarum/components/Badge', 'flarum/Model', 'flarum/models/User', 'flarum/suspend/components/SuspendUserModal', 'flarum/suspend/components/UserSuspendedNotification', 'flarum/suspend/components/UserUnsuspendedNotification'], function (_export, _context) { + "use strict"; + + var extend, app, UserControls, Button, Badge, Model, User, SuspendUserModal, UserSuspendedNotification, UserUnsuspendedNotification; return { setters: [function (_flarumExtend) { extend = _flarumExtend.extend; @@ -173,10 +278,17 @@ System.register('flarum/suspend/main', ['flarum/extend', 'flarum/app', 'flarum/u User = _flarumModelsUser.default; }, function (_flarumSuspendComponentsSuspendUserModal) { SuspendUserModal = _flarumSuspendComponentsSuspendUserModal.default; + }, function (_flarumSuspendComponentsUserSuspendedNotification) { + UserSuspendedNotification = _flarumSuspendComponentsUserSuspendedNotification.default; + }, function (_flarumSuspendComponentsUserUnsuspendedNotification) { + UserUnsuspendedNotification = _flarumSuspendComponentsUserUnsuspendedNotification.default; }], execute: function () { app.initializers.add('flarum-suspend', function () { + app.notificationComponents.userSuspended = UserSuspendedNotification; + app.notificationComponents.userUnsuspended = UserUnsuspendedNotification; + User.prototype.canSuspend = Model.attribute('canSuspend'); User.prototype.suspendUntil = Model.attribute('suspendUntil', Model.transformDate); diff --git a/extensions/suspend/js/forum/src/components/UserSuspendedNotification.js b/extensions/suspend/js/forum/src/components/UserSuspendedNotification.js new file mode 100644 index 000000000..008c83b7d --- /dev/null +++ b/extensions/suspend/js/forum/src/components/UserSuspendedNotification.js @@ -0,0 +1,25 @@ +import Notification from 'flarum/components/Notification'; +import username from 'flarum/helpers/username'; +import humanTime from 'flarum/helpers/humanTime'; + +export default class UserSuspendedNotification extends Notification { + icon() { + return 'ban'; + } + + href() { + return app.route.user(this.props.notification.subject()); + } + + content() { + const notification = this.props.notification; + const actor = notification.sender(); + const suspendUntil = notification.content(); + const timeReadable = moment(suspendUntil.date).from(notification.time(), true); + + return app.translator.transChoice('flarum-suspend.forum.notifications.user_suspended_text', { + actor, + timeReadable, + }); + } +} diff --git a/extensions/suspend/js/forum/src/components/UserUnsuspendedNotification.js b/extensions/suspend/js/forum/src/components/UserUnsuspendedNotification.js new file mode 100644 index 000000000..3a92009c6 --- /dev/null +++ b/extensions/suspend/js/forum/src/components/UserUnsuspendedNotification.js @@ -0,0 +1,22 @@ +import Notification from 'flarum/components/Notification'; +import username from 'flarum/helpers/username'; +import humanTime from 'flarum/helpers/humanTime'; + +export default class UserUnsuspendedNotification extends Notification { + icon() { + return 'ban'; + } + + href() { + return app.route.user(this.props.notification.subject()); + } + + content() { + const notification = this.props.notification; + const actor = notification.sender(); + + return app.translator.transChoice('flarum-suspend.forum.notifications.user_unsuspended_text', { + actor, + }); + } +} diff --git a/extensions/suspend/js/forum/src/main.js b/extensions/suspend/js/forum/src/main.js index 6998fbcea..34715bf0e 100644 --- a/extensions/suspend/js/forum/src/main.js +++ b/extensions/suspend/js/forum/src/main.js @@ -7,8 +7,13 @@ import Model from 'flarum/Model'; import User from 'flarum/models/User'; import SuspendUserModal from 'flarum/suspend/components/SuspendUserModal'; +import UserSuspendedNotification from 'flarum/suspend/components/UserSuspendedNotification'; +import UserUnsuspendedNotification from 'flarum/suspend/components/UserUnsuspendedNotification'; app.initializers.add('flarum-suspend', () => { + app.notificationComponents.userSuspended = UserSuspendedNotification; + app.notificationComponents.userUnsuspended = UserUnsuspendedNotification; + User.prototype.canSuspend = Model.attribute('canSuspend'); User.prototype.suspendUntil = Model.attribute('suspendUntil', Model.transformDate); diff --git a/extensions/suspend/src/Event/UserWasSuspended.php b/extensions/suspend/src/Event/UserWasSuspended.php new file mode 100644 index 000000000..6b7ee7749 --- /dev/null +++ b/extensions/suspend/src/Event/UserWasSuspended.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Suspend\Event; + +use Flarum\Core\Post; +use Flarum\Core\User; + +class UserWasSuspended +{ + /** + * @var User + */ + public $user; + + /** + * @var User + */ + public $actor; + + /** + * @param User $user + * @param User $actor + */ + public function __construct(User $user, User $actor) + { + $this->user = $user; + $this->actor = $actor; + } +} diff --git a/extensions/suspend/src/Event/UserWasUnsuspended.php b/extensions/suspend/src/Event/UserWasUnsuspended.php new file mode 100644 index 000000000..c54511d28 --- /dev/null +++ b/extensions/suspend/src/Event/UserWasUnsuspended.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Suspend\Event; + +use Flarum\Core\Post; +use Flarum\Core\User; + +class UserWasUnsuspended +{ + /** + * @var User + */ + public $user; + + /** + * @var User + */ + public $actor; + + /** + * @param User $user + * @param User $actor + */ + public function __construct(User $user, User $actor) + { + $this->user = $user; + $this->actor = $actor; + } +} diff --git a/extensions/suspend/src/Listener/SaveSuspensionToDatabase.php b/extensions/suspend/src/Listener/SaveSuspensionToDatabase.php index 8c90fcdbe..70cee6e82 100755 --- a/extensions/suspend/src/Listener/SaveSuspensionToDatabase.php +++ b/extensions/suspend/src/Listener/SaveSuspensionToDatabase.php @@ -15,6 +15,8 @@ use DateTime; use Flarum\Core\Access\AssertPermissionTrait; use Flarum\Event\UserWillBeSaved; use Flarum\Suspend\SuspendValidator; +use Flarum\Suspend\Event\UserWasSuspended; +use Flarum\Suspend\Event\UserWasUnsuspended; use Illuminate\Contracts\Events\Dispatcher; class SaveSuspensionToDatabase @@ -60,6 +62,12 @@ class SaveSuspensionToDatabase $this->assertCan($actor, 'suspend', $user); $user->suspend_until = new DateTime($attributes['suspendUntil']); + + if (isset($attributes['suspendUntil'])) { + $user->raise(new UserWasSuspended($user, $actor)); + } else { + $user->raise(new UserWasUnsuspended($user, $actor)); + } } } } diff --git a/extensions/suspend/src/Listener/SendNotificationWhenUserIsSuspended.php b/extensions/suspend/src/Listener/SendNotificationWhenUserIsSuspended.php new file mode 100644 index 000000000..163dc3d76 --- /dev/null +++ b/extensions/suspend/src/Listener/SendNotificationWhenUserIsSuspended.php @@ -0,0 +1,95 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Suspend\Listener; + +use DateTime; +use Flarum\Api\Serializer\UserBasicSerializer; +use Flarum\Core\Notification\NotificationSyncer; +use Flarum\Core\Post; +use Flarum\Core\User; +use Flarum\Event\ConfigureNotificationTypes; +use Flarum\Suspend\Event\UserWasSuspended; +use Flarum\Suspend\Event\UserWasUnsuspended; +use Flarum\Suspend\Notification\UserSuspendedBlueprint; +use Flarum\Suspend\Notification\UserUnsuspendedBlueprint; +use Illuminate\Contracts\Events\Dispatcher; + +class SendNotificationWhenUserIsSuspended +{ + /** + * @var NotificationSyncer + */ + protected $notifications; + + /** + * @param NotificationSyncer $notifications + */ + public function __construct(NotificationSyncer $notifications) + { + $this->notifications = $notifications; + } + + /** + * @param Dispatcher $events + */ + public function subscribe(Dispatcher $events) + { + $events->listen(ConfigureNotificationTypes::class, [$this, 'registerNotificationType']); + $events->listen(UserWasSuspended::class, [$this, 'whenUserWasSuspended']); + $events->listen(UserWasUnsuspended::class, [$this, 'whenUserWasUnsuspended']); + } + + /** + * @param ConfigureNotificationTypes $event + */ + public function registerNotificationType(ConfigureNotificationTypes $event) + { + $event->add(UserSuspendedBlueprint::class, UserBasicSerializer::class, ['alert', 'email']); + $event->add(UserUnsuspendedBlueprint::class, UserBasicSerializer::class, ['alert', 'email']); + } + + /** + * @param UserWasSuspended $event + */ + public function whenUserWasSuspended(UserWasSuspended $event) + { + $this->sync($event->user, $event->actor, [$event->user]); + } + + /** + * @param UserWasSuspended $event + */ + public function whenUserWasUnsuspended(UserWasUnsuspended $event) + { + $this->sync($event->user, $event->actor, [$event->user]); + } + + /** + * @param User $user + * @param User $actor + * @param array $recipients + */ + public function sync(User $user, User $actor, array $recipients) + { + if ($user->suspend_until > new DateTime()) { + $this->notifications->sync( + new UserSuspendedBlueprint($user, $actor), + $recipients + ); + } else { + $this->notifications->sync( + new UserUnsuspendedBlueprint($user, $actor), + $recipients + ); + } + } +} diff --git a/extensions/suspend/src/Notification/UserSuspendedBlueprint.php b/extensions/suspend/src/Notification/UserSuspendedBlueprint.php new file mode 100644 index 000000000..cd6269b84 --- /dev/null +++ b/extensions/suspend/src/Notification/UserSuspendedBlueprint.php @@ -0,0 +1,78 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Suspend\Notification; + +use Flarum\Core\Notification\BlueprintInterface; +use Flarum\Core\User; + +class UserSuspendedBlueprint implements BlueprintInterface +{ + /** + * @var User + */ + public $user; + + /** + * @var User + */ + public $actor; + + /** + * @param User $user + * @param User $actor + */ + public function __construct(User $user, User $actor) + { + $this->user = $user; + $this->actor = $actor; + } + + /** + * {@inheritdoc} + */ + public function getSubject() + { + return $this->user; + } + + /** + * {@inheritdoc} + */ + public function getSender() + { + return $this->actor; + } + + /** + * {@inheritdoc} + */ + public function getData() + { + return $this->user['suspend_until']; + } + + /** + * {@inheritdoc} + */ + public static function getType() + { + return 'userSuspended'; + } + + /** + * {@inheritdoc} + */ + public static function getSubjectModel() + { + return User::class; + } +} diff --git a/extensions/suspend/src/Notification/UserUnsuspendedBlueprint.php b/extensions/suspend/src/Notification/UserUnsuspendedBlueprint.php new file mode 100644 index 000000000..adf79df32 --- /dev/null +++ b/extensions/suspend/src/Notification/UserUnsuspendedBlueprint.php @@ -0,0 +1,77 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Suspend\Notification; + +use Flarum\Core\Notification\BlueprintInterface; +use Flarum\Core\User; + +class UserUnsuspendedBlueprint implements BlueprintInterface +{ + /** + * @var User + */ + public $user; + + /** + * @var User + */ + public $actor; + + /** + * @param User $user + * @param User $actor + */ + public function __construct(User $user, User $actor) + { + $this->user = $user; + $this->actor = $actor; + } + + /** + * {@inheritdoc} + */ + public function getSubject() + { + return $this->user; + } + + /** + * {@inheritdoc} + */ + public function getSender() + { + return $this->actor; + } + + /** + * {@inheritdoc} + */ + public function getData() + { + } + + /** + * {@inheritdoc} + */ + public static function getType() + { + return 'userUnsuspended'; + } + + /** + * {@inheritdoc} + */ + public static function getSubjectModel() + { + return User::class; + } +} From 01124e5c59ecad9fcbf078667cd80650806d658e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sevilla=20Mart=C3=ADn?= Date: Fri, 19 May 2017 08:12:52 -0400 Subject: [PATCH 2/7] Apply fixes from StyleCI (#1) --- extensions/suspend/src/Event/UserWasSuspended.php | 1 - extensions/suspend/src/Event/UserWasUnsuspended.php | 1 - extensions/suspend/src/Listener/SaveSuspensionToDatabase.php | 2 +- .../src/Listener/SendNotificationWhenUserIsSuspended.php | 1 - 4 files changed, 1 insertion(+), 4 deletions(-) diff --git a/extensions/suspend/src/Event/UserWasSuspended.php b/extensions/suspend/src/Event/UserWasSuspended.php index 6b7ee7749..0f6904ea6 100644 --- a/extensions/suspend/src/Event/UserWasSuspended.php +++ b/extensions/suspend/src/Event/UserWasSuspended.php @@ -11,7 +11,6 @@ namespace Flarum\Suspend\Event; -use Flarum\Core\Post; use Flarum\Core\User; class UserWasSuspended diff --git a/extensions/suspend/src/Event/UserWasUnsuspended.php b/extensions/suspend/src/Event/UserWasUnsuspended.php index c54511d28..90983f413 100644 --- a/extensions/suspend/src/Event/UserWasUnsuspended.php +++ b/extensions/suspend/src/Event/UserWasUnsuspended.php @@ -11,7 +11,6 @@ namespace Flarum\Suspend\Event; -use Flarum\Core\Post; use Flarum\Core\User; class UserWasUnsuspended diff --git a/extensions/suspend/src/Listener/SaveSuspensionToDatabase.php b/extensions/suspend/src/Listener/SaveSuspensionToDatabase.php index 70cee6e82..e0f414423 100755 --- a/extensions/suspend/src/Listener/SaveSuspensionToDatabase.php +++ b/extensions/suspend/src/Listener/SaveSuspensionToDatabase.php @@ -14,9 +14,9 @@ namespace Flarum\Suspend\Listener; use DateTime; use Flarum\Core\Access\AssertPermissionTrait; use Flarum\Event\UserWillBeSaved; -use Flarum\Suspend\SuspendValidator; use Flarum\Suspend\Event\UserWasSuspended; use Flarum\Suspend\Event\UserWasUnsuspended; +use Flarum\Suspend\SuspendValidator; use Illuminate\Contracts\Events\Dispatcher; class SaveSuspensionToDatabase diff --git a/extensions/suspend/src/Listener/SendNotificationWhenUserIsSuspended.php b/extensions/suspend/src/Listener/SendNotificationWhenUserIsSuspended.php index 163dc3d76..33b92aab4 100644 --- a/extensions/suspend/src/Listener/SendNotificationWhenUserIsSuspended.php +++ b/extensions/suspend/src/Listener/SendNotificationWhenUserIsSuspended.php @@ -14,7 +14,6 @@ namespace Flarum\Suspend\Listener; use DateTime; use Flarum\Api\Serializer\UserBasicSerializer; use Flarum\Core\Notification\NotificationSyncer; -use Flarum\Core\Post; use Flarum\Core\User; use Flarum\Event\ConfigureNotificationTypes; use Flarum\Suspend\Event\UserWasSuspended; From 62d30f140b887d5caab23a77f5f7019cd72f13d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sevilla=20Mart=C3=ADn?= Date: Mon, 12 Feb 2018 08:30:27 -0500 Subject: [PATCH 3/7] fix issues, revert js dist --- extensions/suspend/js/forum/dist/extension.js | 116 +----------------- .../SendNotificationWhenUserIsSuspended.php | 4 +- .../Notification/UserSuspendedBlueprint.php | 2 +- 3 files changed, 5 insertions(+), 117 deletions(-) diff --git a/extensions/suspend/js/forum/dist/extension.js b/extensions/suspend/js/forum/dist/extension.js index 2ba4fb221..0bf8c06f4 100644 --- a/extensions/suspend/js/forum/dist/extension.js +++ b/extensions/suspend/js/forum/dist/extension.js @@ -152,115 +152,10 @@ System.register('flarum/suspend/components/SuspendUserModal', ['flarum/component });; 'use strict'; -System.register('flarum/suspend/components/UserSuspendedNotification', ['flarum/components/Notification', 'flarum/helpers/username', 'flarum/helpers/humanTime'], function (_export, _context) { +System.register('flarum/suspend/main', ['flarum/extend', 'flarum/app', 'flarum/utils/UserControls', 'flarum/components/Button', 'flarum/components/Badge', 'flarum/Model', 'flarum/models/User', 'flarum/suspend/components/SuspendUserModal'], function (_export, _context) { "use strict"; - var Notification, username, humanTime, UserSuspendedNotification; - return { - setters: [function (_flarumComponentsNotification) { - Notification = _flarumComponentsNotification.default; - }, function (_flarumHelpersUsername) { - username = _flarumHelpersUsername.default; - }, function (_flarumHelpersHumanTime) { - humanTime = _flarumHelpersHumanTime.default; - }], - execute: function () { - UserSuspendedNotification = function (_Notification) { - babelHelpers.inherits(UserSuspendedNotification, _Notification); - - function UserSuspendedNotification() { - babelHelpers.classCallCheck(this, UserSuspendedNotification); - return babelHelpers.possibleConstructorReturn(this, (UserSuspendedNotification.__proto__ || Object.getPrototypeOf(UserSuspendedNotification)).apply(this, arguments)); - } - - babelHelpers.createClass(UserSuspendedNotification, [{ - key: 'icon', - value: function icon() { - return 'ban'; - } - }, { - key: 'href', - value: function href() { - return app.route.user(this.props.notification.subject()); - } - }, { - key: 'content', - value: function content() { - var notification = this.props.notification; - var actor = notification.sender(); - var suspendUntil = notification.content(); - var timeReadable = moment(suspendUntil.date).from(notification.time(), true); - - return app.translator.transChoice('flarum-suspend.forum.notifications.user_suspended_text', { - actor: actor, - timeReadable: timeReadable - }); - } - }]); - return UserSuspendedNotification; - }(Notification); - - _export('default', UserSuspendedNotification); - } - }; -});; -'use strict'; - -System.register('flarum/suspend/components/UserUnsuspendedNotification', ['flarum/components/Notification', 'flarum/helpers/username', 'flarum/helpers/humanTime'], function (_export, _context) { - "use strict"; - - var Notification, username, humanTime, UserUnsuspendedNotification; - return { - setters: [function (_flarumComponentsNotification) { - Notification = _flarumComponentsNotification.default; - }, function (_flarumHelpersUsername) { - username = _flarumHelpersUsername.default; - }, function (_flarumHelpersHumanTime) { - humanTime = _flarumHelpersHumanTime.default; - }], - execute: function () { - UserUnsuspendedNotification = function (_Notification) { - babelHelpers.inherits(UserUnsuspendedNotification, _Notification); - - function UserUnsuspendedNotification() { - babelHelpers.classCallCheck(this, UserUnsuspendedNotification); - return babelHelpers.possibleConstructorReturn(this, (UserUnsuspendedNotification.__proto__ || Object.getPrototypeOf(UserUnsuspendedNotification)).apply(this, arguments)); - } - - babelHelpers.createClass(UserUnsuspendedNotification, [{ - key: 'icon', - value: function icon() { - return 'ban'; - } - }, { - key: 'href', - value: function href() { - return app.route.user(this.props.notification.subject()); - } - }, { - key: 'content', - value: function content() { - var notification = this.props.notification; - var actor = notification.sender(); - - return app.translator.transChoice('flarum-suspend.forum.notifications.user_unsuspended_text', { - actor: actor - }); - } - }]); - return UserUnsuspendedNotification; - }(Notification); - - _export('default', UserUnsuspendedNotification); - } - }; -});; -'use strict'; - -System.register('flarum/suspend/main', ['flarum/extend', 'flarum/app', 'flarum/utils/UserControls', 'flarum/components/Button', 'flarum/components/Badge', 'flarum/Model', 'flarum/models/User', 'flarum/suspend/components/SuspendUserModal', 'flarum/suspend/components/UserSuspendedNotification', 'flarum/suspend/components/UserUnsuspendedNotification'], function (_export, _context) { - "use strict"; - - var extend, app, UserControls, Button, Badge, Model, User, SuspendUserModal, UserSuspendedNotification, UserUnsuspendedNotification; + var extend, app, UserControls, Button, Badge, Model, User, SuspendUserModal; return { setters: [function (_flarumExtend) { extend = _flarumExtend.extend; @@ -278,17 +173,10 @@ System.register('flarum/suspend/main', ['flarum/extend', 'flarum/app', 'flarum/u User = _flarumModelsUser.default; }, function (_flarumSuspendComponentsSuspendUserModal) { SuspendUserModal = _flarumSuspendComponentsSuspendUserModal.default; - }, function (_flarumSuspendComponentsUserSuspendedNotification) { - UserSuspendedNotification = _flarumSuspendComponentsUserSuspendedNotification.default; - }, function (_flarumSuspendComponentsUserUnsuspendedNotification) { - UserUnsuspendedNotification = _flarumSuspendComponentsUserUnsuspendedNotification.default; }], execute: function () { app.initializers.add('flarum-suspend', function () { - app.notificationComponents.userSuspended = UserSuspendedNotification; - app.notificationComponents.userUnsuspended = UserUnsuspendedNotification; - User.prototype.canSuspend = Model.attribute('canSuspend'); User.prototype.suspendUntil = Model.attribute('suspendUntil', Model.transformDate); diff --git a/extensions/suspend/src/Listener/SendNotificationWhenUserIsSuspended.php b/extensions/suspend/src/Listener/SendNotificationWhenUserIsSuspended.php index 33b92aab4..869c33938 100644 --- a/extensions/suspend/src/Listener/SendNotificationWhenUserIsSuspended.php +++ b/extensions/suspend/src/Listener/SendNotificationWhenUserIsSuspended.php @@ -65,7 +65,7 @@ class SendNotificationWhenUserIsSuspended } /** - * @param UserWasSuspended $event + * @param UserWasUnsuspended $event */ public function whenUserWasUnsuspended(UserWasUnsuspended $event) { @@ -79,7 +79,7 @@ class SendNotificationWhenUserIsSuspended */ public function sync(User $user, User $actor, array $recipients) { - if ($user->suspend_until > new DateTime()) { + if (isset($user->suspend_until) && $user->suspend_until > new DateTime()) { $this->notifications->sync( new UserSuspendedBlueprint($user, $actor), $recipients diff --git a/extensions/suspend/src/Notification/UserSuspendedBlueprint.php b/extensions/suspend/src/Notification/UserSuspendedBlueprint.php index cd6269b84..d27e811f2 100644 --- a/extensions/suspend/src/Notification/UserSuspendedBlueprint.php +++ b/extensions/suspend/src/Notification/UserSuspendedBlueprint.php @@ -57,7 +57,7 @@ class UserSuspendedBlueprint implements BlueprintInterface */ public function getData() { - return $this->user['suspend_until']; + return $this->user->suspend_until; } /** From cc285f6fc869fdebe1df22564ea87f352c167e41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sevilla=20Mart=C3=ADn?= Date: Mon, 12 Feb 2018 08:34:36 -0500 Subject: [PATCH 4/7] fix merge conflicts --- extensions/suspend/bootstrap.php | 26 +++++++++++++------ .../src/Listener/SaveSuspensionToDatabase.php | 10 ++++--- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/extensions/suspend/bootstrap.php b/extensions/suspend/bootstrap.php index 9c15afe7f..98d44bdcc 100644 --- a/extensions/suspend/bootstrap.php +++ b/extensions/suspend/bootstrap.php @@ -9,16 +9,26 @@ * file that was distributed with this source code. */ +use Flarum\Extend; use Flarum\Suspend\Access; use Flarum\Suspend\Listener; use Illuminate\Contracts\Events\Dispatcher; -return function (Dispatcher $events) { - $events->subscribe(Listener\AddClientAssets::class); - $events->subscribe(Listener\AddUserSuspendAttributes::class); - $events->subscribe(Listener\RevokeAccessFromSuspendedUsers::class); - $events->subscribe(Listener\SaveSuspensionToDatabase::class); - $events->subscribe(Listener\SendNotificationWhenUserIsSuspended::class); +return [ + (new Extend\Assets('forum')) + ->asset(__DIR__.'/js/forum/dist/extension.js') + ->asset(__DIR__.'/less/forum/extension.less') + ->bootstrapper('flarum/suspend/main'), + (new Extend\Assets('admin')) + ->asset(__DIR__.'/js/admin/dist/extension.js') + ->asset(__DIR__.'/less/admin/extension.less') + ->bootstrapper('flarum/suspend/main'), + function (Dispatcher $events) { + $events->subscribe(Listener\AddUserSuspendAttributes::class); + $events->subscribe(Listener\RevokeAccessFromSuspendedUsers::class); + $events->subscribe(Listener\SaveSuspensionToDatabase::class); + $events->subscribe(Listener\SendNotificationWhenUserIsSuspended::class); - $events->subscribe(Access\UserPolicy::class); -}; + $events->subscribe(Access\UserPolicy::class); + } +]; diff --git a/extensions/suspend/src/Listener/SaveSuspensionToDatabase.php b/extensions/suspend/src/Listener/SaveSuspensionToDatabase.php index e0f414423..5a8e089f3 100755 --- a/extensions/suspend/src/Listener/SaveSuspensionToDatabase.php +++ b/extensions/suspend/src/Listener/SaveSuspensionToDatabase.php @@ -12,11 +12,11 @@ namespace Flarum\Suspend\Listener; use DateTime; -use Flarum\Core\Access\AssertPermissionTrait; -use Flarum\Event\UserWillBeSaved; +use Flarum\Suspend\SuspendValidator; use Flarum\Suspend\Event\UserWasSuspended; use Flarum\Suspend\Event\UserWasUnsuspended; -use Flarum\Suspend\SuspendValidator; +use Flarum\User\AssertPermissionTrait; +use Flarum\User\Event\Saving; use Illuminate\Contracts\Events\Dispatcher; class SaveSuspensionToDatabase @@ -61,7 +61,9 @@ class SaveSuspensionToDatabase $this->assertCan($actor, 'suspend', $user); - $user->suspend_until = new DateTime($attributes['suspendUntil']); + $user->suspend_until = $attributes['suspendUntil'] + ? new DateTime($attributes['suspendUntil']) + : null; if (isset($attributes['suspendUntil'])) { $user->raise(new UserWasSuspended($user, $actor)); From cd8d7479851df917687202c148c095858541fb36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sevilla=20Mart=C3=ADn?= Date: Mon, 12 Feb 2018 08:36:37 -0500 Subject: [PATCH 5/7] Merge upstream into master --- extensions/suspend/composer.json | 2 +- extensions/suspend/js/admin/src/main.js | 2 +- extensions/suspend/js/forum/src/main.js | 4 +- extensions/suspend/src/Event/Suspended.php | 32 +++++++++++ extensions/suspend/src/Event/Unsuspended.php | 32 +++++++++++ .../suspend/src/Event/UserWasSuspended.php | 2 +- .../suspend/src/Event/UserWasUnsuspended.php | 2 +- .../src/Listener/SaveSuspensionToDatabase.php | 22 +++++--- .../SendNotificationWhenUserIsSuspended.php | 55 +++++++------------ .../Notification/UserSuspendedBlueprint.php | 4 +- .../Notification/UserUnsuspendedBlueprint.php | 4 +- 11 files changed, 110 insertions(+), 51 deletions(-) create mode 100644 extensions/suspend/src/Event/Suspended.php create mode 100644 extensions/suspend/src/Event/Unsuspended.php diff --git a/extensions/suspend/composer.json b/extensions/suspend/composer.json index 33b2830d7..ef0ed66cc 100644 --- a/extensions/suspend/composer.json +++ b/extensions/suspend/composer.json @@ -29,7 +29,7 @@ "flarum-extension": { "title": "Suspend", "icon": { - "name": "ban", + "name": "fas fa-ban", "backgroundColor": "#ddd", "color": "#666" } diff --git a/extensions/suspend/js/admin/src/main.js b/extensions/suspend/js/admin/src/main.js index d81b74f8d..87b9e41fd 100644 --- a/extensions/suspend/js/admin/src/main.js +++ b/extensions/suspend/js/admin/src/main.js @@ -5,7 +5,7 @@ import PermissionGrid from 'flarum/components/PermissionGrid'; app.initializers.add('suspend', () => { extend(PermissionGrid.prototype, 'moderateItems', items => { items.add('suspendUsers', { - icon: 'ban', + icon: 'fas fa-ban', label: app.translator.trans('flarum-suspend.admin.permissions.suspend_users_label'), permission: 'user.suspend' }); diff --git a/extensions/suspend/js/forum/src/main.js b/extensions/suspend/js/forum/src/main.js index 34715bf0e..248f531f1 100644 --- a/extensions/suspend/js/forum/src/main.js +++ b/extensions/suspend/js/forum/src/main.js @@ -21,7 +21,7 @@ app.initializers.add('flarum-suspend', () => { if (user.canSuspend()) { items.add('suspend', Button.component({ children: app.translator.trans('flarum-suspend.forum.user_controls.suspend_button'), - icon: 'ban', + icon: 'fas fa-ban', onclick: () => app.modal.show(new SuspendUserModal({user})) })); } @@ -32,7 +32,7 @@ app.initializers.add('flarum-suspend', () => { if (new Date() < until) { items.add('suspended', Badge.component({ - icon: 'ban', + icon: 'fas fa-ban', type: 'suspended', label: app.translator.trans('flarum-suspend.forum.user_badge.suspended_tooltip') })); diff --git a/extensions/suspend/src/Event/Suspended.php b/extensions/suspend/src/Event/Suspended.php new file mode 100644 index 000000000..f855410fb --- /dev/null +++ b/extensions/suspend/src/Event/Suspended.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Suspend\Event; + +use Flarum\User\User; + +class Suspended +{ + /** + * @var User + */ + public $user; + /** + * @var User + */ + public $actor; + + public function __construct(User $user, User $actor) + { + $this->user = $user; + $this->actor = $actor; + } +} diff --git a/extensions/suspend/src/Event/Unsuspended.php b/extensions/suspend/src/Event/Unsuspended.php new file mode 100644 index 000000000..4051f15be --- /dev/null +++ b/extensions/suspend/src/Event/Unsuspended.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flarum\Suspend\Event; + +use Flarum\User\User; + +class Unsuspended +{ + /** + * @var User + */ + public $user; + /** + * @var User + */ + public $actor; + + public function __construct(User $user, User $actor) + { + $this->user = $user; + $this->actor = $actor; + } +} diff --git a/extensions/suspend/src/Event/UserWasSuspended.php b/extensions/suspend/src/Event/UserWasSuspended.php index 0f6904ea6..459f21606 100644 --- a/extensions/suspend/src/Event/UserWasSuspended.php +++ b/extensions/suspend/src/Event/UserWasSuspended.php @@ -11,7 +11,7 @@ namespace Flarum\Suspend\Event; -use Flarum\Core\User; +use Flarum\User\User; class UserWasSuspended { diff --git a/extensions/suspend/src/Event/UserWasUnsuspended.php b/extensions/suspend/src/Event/UserWasUnsuspended.php index 90983f413..c766647d8 100644 --- a/extensions/suspend/src/Event/UserWasUnsuspended.php +++ b/extensions/suspend/src/Event/UserWasUnsuspended.php @@ -11,7 +11,7 @@ namespace Flarum\Suspend\Event; -use Flarum\Core\User; +use Flarum\User\User; class UserWasUnsuspended { diff --git a/extensions/suspend/src/Listener/SaveSuspensionToDatabase.php b/extensions/suspend/src/Listener/SaveSuspensionToDatabase.php index 24c56d8a6..c9961defb 100755 --- a/extensions/suspend/src/Listener/SaveSuspensionToDatabase.php +++ b/extensions/suspend/src/Listener/SaveSuspensionToDatabase.php @@ -12,9 +12,9 @@ namespace Flarum\Suspend\Listener; use DateTime; +use Flarum\Suspend\Event\Suspended; +use Flarum\Suspend\Event\Unsuspended; use Flarum\Suspend\SuspendValidator; -use Flarum\Suspend\Event\UserWasSuspended; -use Flarum\Suspend\Event\UserWasUnsuspended; use Flarum\User\AssertPermissionTrait; use Flarum\User\Event\Saving; use Illuminate\Contracts\Events\Dispatcher; @@ -29,13 +29,19 @@ class SaveSuspensionToDatabase * @var SuspendValidator */ protected $validator; + /** + * @var Dispatcher + */ + protected $events; /** * @param SuspendValidator $validator + * @param Dispatcher $events */ - public function __construct(SuspendValidator $validator) + public function __construct(SuspendValidator $validator, Dispatcher $events) { $this->validator = $validator; + $this->events = $events; } /** @@ -65,10 +71,12 @@ class SaveSuspensionToDatabase ? new DateTime($attributes['suspendUntil']) : null; - if (isset($attributes['suspendUntil'])) { - $user->raise(new UserWasSuspended($user, $actor)); - } else { - $user->raise(new UserWasUnsuspended($user, $actor)); + if ($user->isDirty('suspend_until')) { + $this->events->dispatch( + $user->suspend_until === null ? + new Unsuspended($user, $actor) : + new Suspended($user, $actor) + ); } } } diff --git a/extensions/suspend/src/Listener/SendNotificationWhenUserIsSuspended.php b/extensions/suspend/src/Listener/SendNotificationWhenUserIsSuspended.php index 869c33938..1f925c033 100644 --- a/extensions/suspend/src/Listener/SendNotificationWhenUserIsSuspended.php +++ b/extensions/suspend/src/Listener/SendNotificationWhenUserIsSuspended.php @@ -11,15 +11,16 @@ namespace Flarum\Suspend\Listener; -use DateTime; -use Flarum\Api\Serializer\UserBasicSerializer; -use Flarum\Core\Notification\NotificationSyncer; -use Flarum\Core\User; +use Flarum\Api\Serializer\BasicUserSerializer; use Flarum\Event\ConfigureNotificationTypes; +use Flarum\Notification\NotificationSyncer; +use Flarum\Suspend\Event\Suspended; +use Flarum\Suspend\Event\Unsuspended; use Flarum\Suspend\Event\UserWasSuspended; use Flarum\Suspend\Event\UserWasUnsuspended; use Flarum\Suspend\Notification\UserSuspendedBlueprint; use Flarum\Suspend\Notification\UserUnsuspendedBlueprint; +use Flarum\User\User; use Illuminate\Contracts\Events\Dispatcher; class SendNotificationWhenUserIsSuspended @@ -43,8 +44,8 @@ class SendNotificationWhenUserIsSuspended public function subscribe(Dispatcher $events) { $events->listen(ConfigureNotificationTypes::class, [$this, 'registerNotificationType']); - $events->listen(UserWasSuspended::class, [$this, 'whenUserWasSuspended']); - $events->listen(UserWasUnsuspended::class, [$this, 'whenUserWasUnsuspended']); + $events->listen(Suspended::class, [$this, 'whenSuspended']); + $events->listen(Unsuspended::class, [$this, 'whenUnsuspended']); } /** @@ -52,43 +53,29 @@ class SendNotificationWhenUserIsSuspended */ public function registerNotificationType(ConfigureNotificationTypes $event) { - $event->add(UserSuspendedBlueprint::class, UserBasicSerializer::class, ['alert', 'email']); - $event->add(UserUnsuspendedBlueprint::class, UserBasicSerializer::class, ['alert', 'email']); + $event->add(UserSuspendedBlueprint::class, BasicUserSerializer::class, ['alert', 'email']); + $event->add(UserUnsuspendedBlueprint::class, BasicUserSerializer::class, ['alert', 'email']); } /** - * @param UserWasSuspended $event + * @param Suspended $event */ - public function whenUserWasSuspended(UserWasSuspended $event) + public function whenSuspended(Suspended $event) { - $this->sync($event->user, $event->actor, [$event->user]); + $this->notifications->sync( + new UserSuspendedBlueprint($event->user, $event->actor), + [$event->user] + ); } /** - * @param UserWasUnsuspended $event + * @param Unsuspended $event */ - public function whenUserWasUnsuspended(UserWasUnsuspended $event) + public function whenUnsuspended(Unsuspended $event) { - $this->sync($event->user, $event->actor, [$event->user]); - } - - /** - * @param User $user - * @param User $actor - * @param array $recipients - */ - public function sync(User $user, User $actor, array $recipients) - { - if (isset($user->suspend_until) && $user->suspend_until > new DateTime()) { - $this->notifications->sync( - new UserSuspendedBlueprint($user, $actor), - $recipients - ); - } else { - $this->notifications->sync( - new UserUnsuspendedBlueprint($user, $actor), - $recipients - ); - } + $this->notifications->sync( + new UserUnsuspendedBlueprint($event->user, $event->actor), + [$event->user] + ); } } diff --git a/extensions/suspend/src/Notification/UserSuspendedBlueprint.php b/extensions/suspend/src/Notification/UserSuspendedBlueprint.php index d27e811f2..52ac92d4a 100644 --- a/extensions/suspend/src/Notification/UserSuspendedBlueprint.php +++ b/extensions/suspend/src/Notification/UserSuspendedBlueprint.php @@ -11,8 +11,8 @@ namespace Flarum\Suspend\Notification; -use Flarum\Core\Notification\BlueprintInterface; -use Flarum\Core\User; +use Flarum\Notification\Blueprint\BlueprintInterface; +use Flarum\User\User; class UserSuspendedBlueprint implements BlueprintInterface { diff --git a/extensions/suspend/src/Notification/UserUnsuspendedBlueprint.php b/extensions/suspend/src/Notification/UserUnsuspendedBlueprint.php index adf79df32..d9e1806a8 100644 --- a/extensions/suspend/src/Notification/UserUnsuspendedBlueprint.php +++ b/extensions/suspend/src/Notification/UserUnsuspendedBlueprint.php @@ -11,8 +11,8 @@ namespace Flarum\Suspend\Notification; -use Flarum\Core\Notification\BlueprintInterface; -use Flarum\Core\User; +use Flarum\Notification\Blueprint\BlueprintInterface; +use Flarum\User\User; class UserUnsuspendedBlueprint implements BlueprintInterface { From c3c1672993e3b2d8ad83f40fcab70691454d4083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sevilla=20Mart=C3=ADn?= Date: Sat, 12 May 2018 10:28:36 -0400 Subject: [PATCH 6/7] Delete old event files --- .../suspend/src/Event/UserWasSuspended.php | 37 ------------------- .../suspend/src/Event/UserWasUnsuspended.php | 37 ------------------- 2 files changed, 74 deletions(-) delete mode 100644 extensions/suspend/src/Event/UserWasSuspended.php delete mode 100644 extensions/suspend/src/Event/UserWasUnsuspended.php diff --git a/extensions/suspend/src/Event/UserWasSuspended.php b/extensions/suspend/src/Event/UserWasSuspended.php deleted file mode 100644 index 459f21606..000000000 --- a/extensions/suspend/src/Event/UserWasSuspended.php +++ /dev/null @@ -1,37 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Flarum\Suspend\Event; - -use Flarum\User\User; - -class UserWasSuspended -{ - /** - * @var User - */ - public $user; - - /** - * @var User - */ - public $actor; - - /** - * @param User $user - * @param User $actor - */ - public function __construct(User $user, User $actor) - { - $this->user = $user; - $this->actor = $actor; - } -} diff --git a/extensions/suspend/src/Event/UserWasUnsuspended.php b/extensions/suspend/src/Event/UserWasUnsuspended.php deleted file mode 100644 index c766647d8..000000000 --- a/extensions/suspend/src/Event/UserWasUnsuspended.php +++ /dev/null @@ -1,37 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Flarum\Suspend\Event; - -use Flarum\User\User; - -class UserWasUnsuspended -{ - /** - * @var User - */ - public $user; - - /** - * @var User - */ - public $actor; - - /** - * @param User $user - * @param User $actor - */ - public function __construct(User $user, User $actor) - { - $this->user = $user; - $this->actor = $actor; - } -} From 83cdd63737f3e2153fae189f741e68a3af3a5d6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sevilla=20Mart=C3=ADn?= Date: Sat, 12 May 2018 10:50:28 -0400 Subject: [PATCH 7/7] Apply fixes from StyleCI (#3) --- .../src/Listener/SendNotificationWhenUserIsSuspended.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/extensions/suspend/src/Listener/SendNotificationWhenUserIsSuspended.php b/extensions/suspend/src/Listener/SendNotificationWhenUserIsSuspended.php index 1f925c033..b73fbe4dd 100644 --- a/extensions/suspend/src/Listener/SendNotificationWhenUserIsSuspended.php +++ b/extensions/suspend/src/Listener/SendNotificationWhenUserIsSuspended.php @@ -16,11 +16,8 @@ use Flarum\Event\ConfigureNotificationTypes; use Flarum\Notification\NotificationSyncer; use Flarum\Suspend\Event\Suspended; use Flarum\Suspend\Event\Unsuspended; -use Flarum\Suspend\Event\UserWasSuspended; -use Flarum\Suspend\Event\UserWasUnsuspended; use Flarum\Suspend\Notification\UserSuspendedBlueprint; use Flarum\Suspend\Notification\UserUnsuspendedBlueprint; -use Flarum\User\User; use Illuminate\Contracts\Events\Dispatcher; class SendNotificationWhenUserIsSuspended