Only allow OP to add tags that they can start discussions without approval in

closes flarum/core#904
This commit is contained in:
Toby Zerner 2016-05-28 09:52:47 +09:30
parent badd03f3a3
commit d0c54cdbf9
2 changed files with 40 additions and 0 deletions

View File

@ -10,6 +10,7 @@
*/
use Flarum\Approval\Listener;
use Flarum\Approval\Access;
use Illuminate\Contracts\Events\Dispatcher;
return function (Dispatcher $events) {
@ -18,4 +19,6 @@ return function (Dispatcher $events) {
$events->subscribe(Listener\ApproveContent::class);
$events->subscribe(Listener\HideUnapprovedContent::class);
$events->subscribe(Listener\UnapproveNewContent::class);
$events->subscribe(Access\TagPolicy::class);
};

View File

@ -0,0 +1,37 @@
<?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\Approval\Access;
use Flarum\Core\Access\AbstractPolicy;
use Flarum\Core\User;
use Flarum\Tags\Tag;
class TagPolicy extends AbstractPolicy
{
/**
* {@inheritdoc}
*/
protected $model = Tag::class;
/**
* @param User $actor
* @param Tag $tag
* @return bool|null
*/
public function addToDiscussion(User $actor, Tag $tag)
{
$disallowedTags = Tag::getIdsWhereCannot($actor, 'discussion.startWithoutApproval');
if (in_array($tag->id, $disallowedTags)) {
return false;
}
}
}