Use new Model extender

This commit is contained in:
Franz Liedke 2020-04-24 15:54:12 +02:00
parent 519fc3d970
commit 6fa5cc4408
2 changed files with 10 additions and 12 deletions

View File

@ -9,7 +9,9 @@
use Flarum\Approval\Access;
use Flarum\Approval\Listener;
use Flarum\Discussion\Discussion;
use Flarum\Extend;
use Flarum\Post\Post;
use Illuminate\Contracts\Events\Dispatcher;
return [
@ -20,6 +22,14 @@ return [
(new Extend\Frontend('admin'))
->js(__DIR__.'/js/dist/admin.js'),
// Discussions should be approved by default
(new Extend\Model(Discussion::class))
->default('is_approved', true),
// Posts should be approved by default
(new Extend\Model(Post::class))
->default('is_approved', true),
function (Dispatcher $events) {
$events->subscribe(Listener\AddPostApprovalAttributes::class);
$events->subscribe(Listener\ApproveContent::class);

View File

@ -10,7 +10,6 @@
namespace Flarum\Approval\Listener;
use Flarum\Discussion\Discussion;
use Flarum\Event\ConfigureModelDefaultAttributes;
use Flarum\Event\GetModelIsPrivate;
use Flarum\Flags\Flag;
use Flarum\Post\Event\Saving;
@ -24,21 +23,10 @@ class UnapproveNewContent
*/
public function subscribe(Dispatcher $events)
{
$events->listen(ConfigureModelDefaultAttributes::class, [$this, 'approveByDefault']);
$events->listen(Saving::class, [$this, 'unapproveNewPosts']);
$events->listen(GetModelIsPrivate::class, [$this, 'markUnapprovedContentAsPrivate']);
}
/**
* @param ConfigureModelDefaultAttributes $event
*/
public function approveByDefault(ConfigureModelDefaultAttributes $event)
{
if ($event->isModel(Post::class) || $event->isModel(Discussion::class)) {
$event->attributes['is_approved'] = true;
}
}
/**
* @param Saving $event
*/