Database changes (#19)

* Rename suspend_until column

* Missed one!

* Update core attribute names

* Rename user.suspendUntil
This commit is contained in:
Toby Zerner 2018-09-17 04:27:13 +09:30 committed by Franz Liedke
parent 3f37d68314
commit 1b3a432c41
11 changed files with 38 additions and 24 deletions

View File

@ -5,7 +5,7 @@ export default class SuspendUserModal extends Modal {
init() {
super.init();
let until = this.props.user.suspendUntil();
let until = this.props.user.suspendedUntil();
let status = null;
if (new Date() > until) until = null;
@ -81,21 +81,21 @@ export default class SuspendUserModal extends Modal {
this.loading = true;
let suspendUntil = null;
let suspendedUntil = null;
switch (this.status()) {
case 'indefinitely':
suspendUntil = new Date('2038-01-01');
suspendedUntil = new Date('2038-01-01');
break;
case 'limited':
suspendUntil = moment().add(this.daysRemaining(), 'days').toDate();
suspendedUntil = moment().add(this.daysRemaining(), 'days').toDate();
break;
default:
// no default
}
this.props.user.save({suspendUntil}).then(
this.props.user.save({suspendedUntil}).then(
() => this.hide(),
this.loaded.bind(this)
);

View File

@ -13,11 +13,11 @@ export default class UserSuspendedNotification extends Notification {
content() {
const notification = this.props.notification;
const suspendUntil = notification.content();
const timeReadable = moment(suspendUntil.date).from(notification.time(), true);
const suspendedUntil = notification.content();
const timeReadable = moment(suspendedUntil.date).from(notification.createdAt(), true);
return app.translator.trans('flarum-suspend.forum.notifications.user_suspended_text', {
user: notification.sender(),
user: notification.fromUser(),
timeReadable,
});
}

View File

@ -15,7 +15,7 @@ export default class UserUnsuspendedNotification extends Notification {
const notification = this.props.notification;
return app.translator.trans('flarum-suspend.forum.notifications.user_unsuspended_text', {
user: notification.sender(),
user: notification.fromUser(),
});
}
}

View File

@ -15,7 +15,7 @@ app.initializers.add('flarum-suspend', () => {
app.notificationComponents.userUnsuspended = UserUnsuspendedNotification;
User.prototype.canSuspend = Model.attribute('canSuspend');
User.prototype.suspendUntil = Model.attribute('suspendUntil', Model.transformDate);
User.prototype.suspendedUntil = Model.attribute('suspendedUntil', Model.transformDate);
extend(UserControls, 'moderationControls', (items, user) => {
if (user.canSuspend()) {
@ -28,7 +28,7 @@ app.initializers.add('flarum-suspend', () => {
});
extend(User.prototype, 'badges', function(items) {
const until = this.suspendUntil();
const until = this.suspendedUntil();
if (new Date() < until) {
items.add('suspended', Badge.component({

View File

@ -0,0 +1,14 @@
<?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.
*/
use Flarum\Database\Migration;
return Migration::renameColumn('users', 'suspend_until', 'suspended_until');

View File

@ -34,7 +34,7 @@ class AddUserSuspendAttributes
public function addDates(ConfigureModelDates $event)
{
if ($event->isModel(User::class)) {
$event->dates[] = 'suspend_until';
$event->dates[] = 'suspended_until';
}
}
@ -47,7 +47,7 @@ class AddUserSuspendAttributes
$canSuspend = $event->actor->can('suspend', $event->model);
if ($canSuspend) {
$event->attributes['suspendUntil'] = $event->formatDate($event->model->suspend_until);
$event->attributes['suspendedUntil'] = $event->formatDate($event->model->suspended_until);
}
$event->attributes['canSuspend'] = $canSuspend;

View File

@ -31,9 +31,9 @@ class RevokeAccessFromSuspendedUsers
*/
public function prepareUserGroups(PrepareUserGroups $event)
{
$suspendUntil = $event->user->suspend_until;
$suspendedUntil = $event->user->suspended_until;
if ($suspendUntil && $suspendUntil->gt(Carbon::now())) {
if ($suspendedUntil && $suspendedUntil->gt(Carbon::now())) {
$event->groupIds = [Group::GUEST_ID];
}
}

View File

@ -59,7 +59,7 @@ class SaveSuspensionToDatabase
{
$attributes = array_get($event->data, 'attributes', []);
if (array_key_exists('suspendUntil', $attributes)) {
if (array_key_exists('suspendedUntil', $attributes)) {
$this->validator->assertValid($attributes);
$user = $event->user;
@ -67,13 +67,13 @@ class SaveSuspensionToDatabase
$this->assertCan($actor, 'suspend', $user);
$user->suspend_until = $attributes['suspendUntil']
? new DateTime($attributes['suspendUntil'])
$user->suspended_until = $attributes['suspendedUntil']
? new DateTime($attributes['suspendedUntil'])
: null;
if ($user->isDirty('suspend_until')) {
if ($user->isDirty('suspended_until')) {
$this->events->dispatch(
$user->suspend_until === null ?
$user->suspended_until === null ?
new Unsuspended($user, $actor) :
new Suspended($user, $actor)
);

View File

@ -47,7 +47,7 @@ class UserSuspendedBlueprint implements BlueprintInterface
/**
* {@inheritdoc}
*/
public function getSender()
public function getFromUser()
{
return $this->actor;
}
@ -57,7 +57,7 @@ class UserSuspendedBlueprint implements BlueprintInterface
*/
public function getData()
{
return $this->user->suspend_until;
return $this->user->suspended_until;
}
/**

View File

@ -47,7 +47,7 @@ class UserUnsuspendedBlueprint implements BlueprintInterface
/**
* {@inheritdoc}
*/
public function getSender()
public function getFromUser()
{
return $this->actor;
}

View File

@ -19,6 +19,6 @@ class SuspendValidator extends AbstractValidator
* {@inheritdoc}
*/
protected $rules = [
'suspendUntil' => ['nullable', 'date'],
'suspendedUntil' => ['nullable', 'date'],
];
}