Disallow editing if discussions are locked

Fixes flarum/core#1156.
This commit is contained in:
Franz Liedke 2017-04-13 08:22:08 +02:00
parent 268fe55565
commit ffa5e8b8c7
2 changed files with 38 additions and 0 deletions

View File

@ -21,4 +21,5 @@ return function (Dispatcher $events) {
$events->subscribe(Listener\SaveLockedToDatabase::class);
$events->subscribe(Access\DiscussionPolicy::class);
$events->subscribe(Access\PostPolicy::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\Lock\Access;
use Flarum\Core\Access\AbstractPolicy;
use Flarum\Core\User;
use Flarum\Core\Post;
class PostPolicy extends AbstractPolicy
{
/**
* {@inheritdoc}
*/
protected $model = Post::class;
/**
* @param User $actor
* @param Post $post
* @return bool
*/
public function edit(User $actor, Post $post)
{
$discussion = $post->discussion;
if ($discussion->is_locked && $actor->cannot('lock', $discussion)) {
return false;
}
}
}