mirror of
https://github.com/flarum/framework.git
synced 2024-12-01 05:53:45 +08:00
Merge upstream into master
This commit is contained in:
parent
88ab68af10
commit
cd8d747985
|
@ -29,7 +29,7 @@
|
|||
"flarum-extension": {
|
||||
"title": "Suspend",
|
||||
"icon": {
|
||||
"name": "ban",
|
||||
"name": "fas fa-ban",
|
||||
"backgroundColor": "#ddd",
|
||||
"color": "#666"
|
||||
}
|
||||
|
|
|
@ -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'
|
||||
});
|
||||
|
|
|
@ -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')
|
||||
}));
|
||||
|
|
32
extensions/suspend/src/Event/Suspended.php
Normal file
32
extensions/suspend/src/Event/Suspended.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
}
|
32
extensions/suspend/src/Event/Unsuspended.php
Normal file
32
extensions/suspend/src/Event/Unsuspended.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
}
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
namespace Flarum\Suspend\Event;
|
||||
|
||||
use Flarum\Core\User;
|
||||
use Flarum\User\User;
|
||||
|
||||
class UserWasSuspended
|
||||
{
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
namespace Flarum\Suspend\Event;
|
||||
|
||||
use Flarum\Core\User;
|
||||
use Flarum\User\User;
|
||||
|
||||
class UserWasUnsuspended
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user