mirror of
https://github.com/flarum/framework.git
synced 2025-03-31 20:55:15 +08:00
Only allow OP to add tags that they can start discussions without approval in
closes flarum/core#904
This commit is contained in:
parent
badd03f3a3
commit
d0c54cdbf9
@ -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);
|
||||
};
|
||||
|
37
extensions/approval/src/Access/TagPolicy.php
Executable file
37
extensions/approval/src/Access/TagPolicy.php
Executable 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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user