mirror of
https://github.com/flarum/core.git
synced 2025-07-28 12:10:51 +02:00
Merge upstream into master
This commit is contained in:
@@ -29,7 +29,7 @@
|
|||||||
"flarum-extension": {
|
"flarum-extension": {
|
||||||
"title": "Suspend",
|
"title": "Suspend",
|
||||||
"icon": {
|
"icon": {
|
||||||
"name": "ban",
|
"name": "fas fa-ban",
|
||||||
"backgroundColor": "#ddd",
|
"backgroundColor": "#ddd",
|
||||||
"color": "#666"
|
"color": "#666"
|
||||||
}
|
}
|
||||||
|
@@ -5,7 +5,7 @@ import PermissionGrid from 'flarum/components/PermissionGrid';
|
|||||||
app.initializers.add('suspend', () => {
|
app.initializers.add('suspend', () => {
|
||||||
extend(PermissionGrid.prototype, 'moderateItems', items => {
|
extend(PermissionGrid.prototype, 'moderateItems', items => {
|
||||||
items.add('suspendUsers', {
|
items.add('suspendUsers', {
|
||||||
icon: 'ban',
|
icon: 'fas fa-ban',
|
||||||
label: app.translator.trans('flarum-suspend.admin.permissions.suspend_users_label'),
|
label: app.translator.trans('flarum-suspend.admin.permissions.suspend_users_label'),
|
||||||
permission: 'user.suspend'
|
permission: 'user.suspend'
|
||||||
});
|
});
|
||||||
|
@@ -21,7 +21,7 @@ app.initializers.add('flarum-suspend', () => {
|
|||||||
if (user.canSuspend()) {
|
if (user.canSuspend()) {
|
||||||
items.add('suspend', Button.component({
|
items.add('suspend', Button.component({
|
||||||
children: app.translator.trans('flarum-suspend.forum.user_controls.suspend_button'),
|
children: app.translator.trans('flarum-suspend.forum.user_controls.suspend_button'),
|
||||||
icon: 'ban',
|
icon: 'fas fa-ban',
|
||||||
onclick: () => app.modal.show(new SuspendUserModal({user}))
|
onclick: () => app.modal.show(new SuspendUserModal({user}))
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ app.initializers.add('flarum-suspend', () => {
|
|||||||
|
|
||||||
if (new Date() < until) {
|
if (new Date() < until) {
|
||||||
items.add('suspended', Badge.component({
|
items.add('suspended', Badge.component({
|
||||||
icon: 'ban',
|
icon: 'fas fa-ban',
|
||||||
type: 'suspended',
|
type: 'suspended',
|
||||||
label: app.translator.trans('flarum-suspend.forum.user_badge.suspended_tooltip')
|
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;
|
namespace Flarum\Suspend\Event;
|
||||||
|
|
||||||
use Flarum\Core\User;
|
use Flarum\User\User;
|
||||||
|
|
||||||
class UserWasSuspended
|
class UserWasSuspended
|
||||||
{
|
{
|
||||||
|
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
namespace Flarum\Suspend\Event;
|
namespace Flarum\Suspend\Event;
|
||||||
|
|
||||||
use Flarum\Core\User;
|
use Flarum\User\User;
|
||||||
|
|
||||||
class UserWasUnsuspended
|
class UserWasUnsuspended
|
||||||
{
|
{
|
||||||
|
@@ -12,9 +12,9 @@
|
|||||||
namespace Flarum\Suspend\Listener;
|
namespace Flarum\Suspend\Listener;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
use Flarum\Suspend\Event\Suspended;
|
||||||
|
use Flarum\Suspend\Event\Unsuspended;
|
||||||
use Flarum\Suspend\SuspendValidator;
|
use Flarum\Suspend\SuspendValidator;
|
||||||
use Flarum\Suspend\Event\UserWasSuspended;
|
|
||||||
use Flarum\Suspend\Event\UserWasUnsuspended;
|
|
||||||
use Flarum\User\AssertPermissionTrait;
|
use Flarum\User\AssertPermissionTrait;
|
||||||
use Flarum\User\Event\Saving;
|
use Flarum\User\Event\Saving;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
@@ -29,13 +29,19 @@ class SaveSuspensionToDatabase
|
|||||||
* @var SuspendValidator
|
* @var SuspendValidator
|
||||||
*/
|
*/
|
||||||
protected $validator;
|
protected $validator;
|
||||||
|
/**
|
||||||
|
* @var Dispatcher
|
||||||
|
*/
|
||||||
|
protected $events;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param SuspendValidator $validator
|
* @param SuspendValidator $validator
|
||||||
|
* @param Dispatcher $events
|
||||||
*/
|
*/
|
||||||
public function __construct(SuspendValidator $validator)
|
public function __construct(SuspendValidator $validator, Dispatcher $events)
|
||||||
{
|
{
|
||||||
$this->validator = $validator;
|
$this->validator = $validator;
|
||||||
|
$this->events = $events;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,10 +71,12 @@ class SaveSuspensionToDatabase
|
|||||||
? new DateTime($attributes['suspendUntil'])
|
? new DateTime($attributes['suspendUntil'])
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
if (isset($attributes['suspendUntil'])) {
|
if ($user->isDirty('suspend_until')) {
|
||||||
$user->raise(new UserWasSuspended($user, $actor));
|
$this->events->dispatch(
|
||||||
} else {
|
$user->suspend_until === null ?
|
||||||
$user->raise(new UserWasUnsuspended($user, $actor));
|
new Unsuspended($user, $actor) :
|
||||||
|
new Suspended($user, $actor)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,15 +11,16 @@
|
|||||||
|
|
||||||
namespace Flarum\Suspend\Listener;
|
namespace Flarum\Suspend\Listener;
|
||||||
|
|
||||||
use DateTime;
|
use Flarum\Api\Serializer\BasicUserSerializer;
|
||||||
use Flarum\Api\Serializer\UserBasicSerializer;
|
|
||||||
use Flarum\Core\Notification\NotificationSyncer;
|
|
||||||
use Flarum\Core\User;
|
|
||||||
use Flarum\Event\ConfigureNotificationTypes;
|
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\UserWasSuspended;
|
||||||
use Flarum\Suspend\Event\UserWasUnsuspended;
|
use Flarum\Suspend\Event\UserWasUnsuspended;
|
||||||
use Flarum\Suspend\Notification\UserSuspendedBlueprint;
|
use Flarum\Suspend\Notification\UserSuspendedBlueprint;
|
||||||
use Flarum\Suspend\Notification\UserUnsuspendedBlueprint;
|
use Flarum\Suspend\Notification\UserUnsuspendedBlueprint;
|
||||||
|
use Flarum\User\User;
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
|
|
||||||
class SendNotificationWhenUserIsSuspended
|
class SendNotificationWhenUserIsSuspended
|
||||||
@@ -43,8 +44,8 @@ class SendNotificationWhenUserIsSuspended
|
|||||||
public function subscribe(Dispatcher $events)
|
public function subscribe(Dispatcher $events)
|
||||||
{
|
{
|
||||||
$events->listen(ConfigureNotificationTypes::class, [$this, 'registerNotificationType']);
|
$events->listen(ConfigureNotificationTypes::class, [$this, 'registerNotificationType']);
|
||||||
$events->listen(UserWasSuspended::class, [$this, 'whenUserWasSuspended']);
|
$events->listen(Suspended::class, [$this, 'whenSuspended']);
|
||||||
$events->listen(UserWasUnsuspended::class, [$this, 'whenUserWasUnsuspended']);
|
$events->listen(Unsuspended::class, [$this, 'whenUnsuspended']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,43 +53,29 @@ class SendNotificationWhenUserIsSuspended
|
|||||||
*/
|
*/
|
||||||
public function registerNotificationType(ConfigureNotificationTypes $event)
|
public function registerNotificationType(ConfigureNotificationTypes $event)
|
||||||
{
|
{
|
||||||
$event->add(UserSuspendedBlueprint::class, UserBasicSerializer::class, ['alert', 'email']);
|
$event->add(UserSuspendedBlueprint::class, BasicUserSerializer::class, ['alert', 'email']);
|
||||||
$event->add(UserUnsuspendedBlueprint::class, UserBasicSerializer::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]);
|
$this->notifications->sync(
|
||||||
}
|
new UserUnsuspendedBlueprint($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
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
namespace Flarum\Suspend\Notification;
|
namespace Flarum\Suspend\Notification;
|
||||||
|
|
||||||
use Flarum\Core\Notification\BlueprintInterface;
|
use Flarum\Notification\Blueprint\BlueprintInterface;
|
||||||
use Flarum\Core\User;
|
use Flarum\User\User;
|
||||||
|
|
||||||
class UserSuspendedBlueprint implements BlueprintInterface
|
class UserSuspendedBlueprint implements BlueprintInterface
|
||||||
{
|
{
|
||||||
|
@@ -11,8 +11,8 @@
|
|||||||
|
|
||||||
namespace Flarum\Suspend\Notification;
|
namespace Flarum\Suspend\Notification;
|
||||||
|
|
||||||
use Flarum\Core\Notification\BlueprintInterface;
|
use Flarum\Notification\Blueprint\BlueprintInterface;
|
||||||
use Flarum\Core\User;
|
use Flarum\User\User;
|
||||||
|
|
||||||
class UserUnsuspendedBlueprint implements BlueprintInterface
|
class UserUnsuspendedBlueprint implements BlueprintInterface
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user