mirror of
https://github.com/flarum/framework.git
synced 2024-12-02 06:53:47 +08:00
Simplify discussion/tag permission logic
A user now must have a permission to act for *all* tags assigned to a discussion, rather than just one of them. This is consistent with the way the permissions are worked out for visibility.
This commit is contained in:
parent
e3278070ac
commit
01e776e2be
|
@ -57,30 +57,13 @@ class DiscussionPolicy extends AbstractPolicy
|
||||||
* @param Discussion $discussion
|
* @param Discussion $discussion
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function before(User $actor, $ability, Discussion $discussion)
|
public function after(User $actor, $ability, Discussion $discussion)
|
||||||
{
|
{
|
||||||
// Wrap all discussion permission checks with some logic pertaining to
|
// Wrap all discussion permission checks with some logic pertaining to
|
||||||
// the discussion's tags. If the discussion has a tag that has been
|
// the discussion's tags. If the discussion has any tags that are
|
||||||
// restricted, and the user has this permission for that tag, then they
|
// restricted, then the user *must* have permission for all of them.
|
||||||
// are allowed. If the discussion only has tags that have been
|
foreach ($discussion->tags as $tag) {
|
||||||
// restricted, then the user *must* have permission for at least one of
|
if ($tag->is_restricted && ! $actor->hasPermission('tag' . $tag->id . '.discussion.' . $ability)) {
|
||||||
// them.
|
|
||||||
$tags = $discussion->tags;
|
|
||||||
|
|
||||||
if (count($tags)) {
|
|
||||||
$restricted = true;
|
|
||||||
|
|
||||||
foreach ($tags as $tag) {
|
|
||||||
if ($tag->is_restricted) {
|
|
||||||
if ($actor->hasPermission('tag'.$tag->id.'.discussion.'.$ability)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$restricted = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($restricted) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user