From eb49e1d4e8eae819a62d6188441a99d9d22238d9 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 14 Oct 2015 16:12:10 +1030 Subject: [PATCH] Update references to `forum.` permissions ref flarum/core#425 --- .../js/admin/src/addTagsPermissionScope.js | 24 ++++++------------- .../tags/src/Access/DiscussionPolicy.php | 2 +- extensions/tags/src/Access/TagPolicy.php | 2 +- extensions/tags/src/Tag.php | 4 ++-- 4 files changed, 11 insertions(+), 21 deletions(-) diff --git a/extensions/tags/js/admin/src/addTagsPermissionScope.js b/extensions/tags/js/admin/src/addTagsPermissionScope.js index ebce05198..e816bbdb9 100644 --- a/extensions/tags/js/admin/src/addTagsPermissionScope.js +++ b/extensions/tags/js/admin/src/addTagsPermissionScope.js @@ -16,23 +16,13 @@ export default function() { label: tagLabel(tag), onremove: () => tag.save({isRestricted: false}), render: item => { - if (item.permission) { - let permission; - - if (item.permission === 'forum.view') { - permission = 'view'; - } else if (item.permission === 'forum.startDiscussion') { - permission = 'startDiscussion'; - } else if (item.permission.indexOf('discussion.') === 0) { - permission = item.permission; - } - - if (permission) { - return PermissionDropdown.component({ - permission: 'tag' + tag.id() + '.' + permission, - allowGuest: item.allowGuest - }); - } + if (item.permission === 'viewDiscussions' + || item.permission === 'startDiscussion' + || (item.permission && item.permission.indexOf('discussion.') === 0)) { + return PermissionDropdown.component({ + permission: 'tag' + tag.id() + '.' + item.permission, + allowGuest: item.allowGuest + }); } return ''; diff --git a/extensions/tags/src/Access/DiscussionPolicy.php b/extensions/tags/src/Access/DiscussionPolicy.php index 4d36ae5b3..f84c55707 100755 --- a/extensions/tags/src/Access/DiscussionPolicy.php +++ b/extensions/tags/src/Access/DiscussionPolicy.php @@ -81,7 +81,7 @@ class DiscussionPolicy extends AbstractPolicy $query->whereNotExists(function ($query) use ($actor) { return $query->select(new Expression(1)) ->from('discussions_tags') - ->whereIn('tag_id', Tag::getIdsWhereCannot($actor, 'view')) + ->whereIn('tag_id', Tag::getIdsWhereCannot($actor, 'viewDiscussions')) ->where('discussions.id', new Expression('discussion_id')); }); } diff --git a/extensions/tags/src/Access/TagPolicy.php b/extensions/tags/src/Access/TagPolicy.php index 055c395dc..c109335c7 100755 --- a/extensions/tags/src/Access/TagPolicy.php +++ b/extensions/tags/src/Access/TagPolicy.php @@ -29,7 +29,7 @@ class TagPolicy extends AbstractPolicy */ public function find(User $actor, Builder $query) { - $query->whereNotIn('id', Tag::getIdsWhereCannot($actor, 'view')); + $query->whereNotIn('id', Tag::getIdsWhereCannot($actor, 'viewDiscussions')); } /** diff --git a/extensions/tags/src/Tag.php b/extensions/tags/src/Tag.php index 37470b8db..d3ece4dd7 100644 --- a/extensions/tags/src/Tag.php +++ b/extensions/tags/src/Tag.php @@ -132,7 +132,7 @@ class Tag extends AbstractModel } $ids = []; - $hasGlobalPermission = $user->hasPermission($permission === 'view' ? 'forum.view' : $permission); + $hasGlobalPermission = $user->hasPermission($permission); foreach ($tags as $tag) { if (($hasGlobalPermission && ! $tag->is_restricted) || $user->hasPermission('tag' . $tag->id . '.' . $permission)) { @@ -157,7 +157,7 @@ class Tag extends AbstractModel } $ids = []; - $hasGlobalPermission = $user->hasPermission($permission === 'view' ? 'forum.view' : $permission); + $hasGlobalPermission = $user->hasPermission($permission); foreach ($tags as $tag) { if (($tag->is_restricted || ! $hasGlobalPermission) && ! $user->hasPermission('tag' . $tag->id . '.' . $permission)) {