mirror of
https://github.com/flarum/framework.git
synced 2025-04-26 14:44:03 +08:00
Use new extenders (#23)
This commit is contained in:
parent
def0faa7c3
commit
bebced2d53
@ -7,6 +7,8 @@
|
|||||||
* LICENSE file that was distributed with this source code.
|
* LICENSE file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Flarum\Api\Serializer\BasicDiscussionSerializer;
|
||||||
|
use Flarum\Api\Serializer\PostSerializer;
|
||||||
use Flarum\Approval\Access;
|
use Flarum\Approval\Access;
|
||||||
use Flarum\Approval\Listener;
|
use Flarum\Approval\Listener;
|
||||||
use Flarum\Discussion\Discussion;
|
use Flarum\Discussion\Discussion;
|
||||||
@ -30,10 +32,21 @@ return [
|
|||||||
(new Extend\Model(Post::class))
|
(new Extend\Model(Post::class))
|
||||||
->default('is_approved', true),
|
->default('is_approved', true),
|
||||||
|
|
||||||
|
(new Extend\ApiSerializer(BasicDiscussionSerializer::class))
|
||||||
|
->attribute('isApproved', function ($serializer, Discussion $discussion) {
|
||||||
|
return (bool) $discussion->is_approved;
|
||||||
|
}),
|
||||||
|
|
||||||
|
(new Extend\ApiSerializer(PostSerializer::class))
|
||||||
|
->attribute('isApproved', function ($serializer, Post $post) {
|
||||||
|
return (bool) $post->is_approved;
|
||||||
|
})->attribute('canApprove', function (PostSerializer $serializer, Post $post) {
|
||||||
|
return (bool) $serializer->getActor()->can('approvePosts', $post->discussion);
|
||||||
|
}),
|
||||||
|
|
||||||
new Extend\Locales(__DIR__.'/locale'),
|
new Extend\Locales(__DIR__.'/locale'),
|
||||||
|
|
||||||
function (Dispatcher $events) {
|
function (Dispatcher $events) {
|
||||||
$events->subscribe(Listener\AddPostApprovalAttributes::class);
|
|
||||||
$events->subscribe(Listener\ApproveContent::class);
|
$events->subscribe(Listener\ApproveContent::class);
|
||||||
$events->subscribe(Listener\UnapproveNewContent::class);
|
$events->subscribe(Listener\UnapproveNewContent::class);
|
||||||
|
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Flarum.
|
|
||||||
*
|
|
||||||
* For detailed copyright and license information, please view the
|
|
||||||
* LICENSE file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Flarum\Approval\Listener;
|
|
||||||
|
|
||||||
use Flarum\Api\Event\Serializing;
|
|
||||||
use Flarum\Api\Serializer\BasicDiscussionSerializer;
|
|
||||||
use Flarum\Api\Serializer\PostSerializer;
|
|
||||||
use Illuminate\Contracts\Events\Dispatcher;
|
|
||||||
|
|
||||||
class AddPostApprovalAttributes
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @param Dispatcher $events
|
|
||||||
*/
|
|
||||||
public function subscribe(Dispatcher $events)
|
|
||||||
{
|
|
||||||
$events->listen(Serializing::class, [$this, 'addApiAttributes']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Serializing $event
|
|
||||||
*/
|
|
||||||
public function addApiAttributes(Serializing $event)
|
|
||||||
{
|
|
||||||
if ($event->isSerializer(BasicDiscussionSerializer::class)
|
|
||||||
|| $event->isSerializer(PostSerializer::class)) {
|
|
||||||
$event->attributes['isApproved'] = (bool) $event->model->is_approved;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($event->isSerializer(PostSerializer::class)) {
|
|
||||||
$event->attributes['canApprove'] = (bool) $event->actor->can('approvePosts', $event->model->discussion);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user