Update references to forum. permissions

ref flarum/core#425
This commit is contained in:
Toby Zerner 2015-10-14 16:12:10 +10:30
parent 67c1d79c5c
commit eb49e1d4e8
4 changed files with 11 additions and 21 deletions

View File

@ -16,23 +16,13 @@ export default function() {
label: tagLabel(tag), label: tagLabel(tag),
onremove: () => tag.save({isRestricted: false}), onremove: () => tag.save({isRestricted: false}),
render: item => { render: item => {
if (item.permission) { if (item.permission === 'viewDiscussions'
let permission; || item.permission === 'startDiscussion'
|| (item.permission && item.permission.indexOf('discussion.') === 0)) {
if (item.permission === 'forum.view') { return PermissionDropdown.component({
permission = 'view'; permission: 'tag' + tag.id() + '.' + item.permission,
} else if (item.permission === 'forum.startDiscussion') { allowGuest: item.allowGuest
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
});
}
} }
return ''; return '';

View File

@ -81,7 +81,7 @@ class DiscussionPolicy extends AbstractPolicy
$query->whereNotExists(function ($query) use ($actor) { $query->whereNotExists(function ($query) use ($actor) {
return $query->select(new Expression(1)) return $query->select(new Expression(1))
->from('discussions_tags') ->from('discussions_tags')
->whereIn('tag_id', Tag::getIdsWhereCannot($actor, 'view')) ->whereIn('tag_id', Tag::getIdsWhereCannot($actor, 'viewDiscussions'))
->where('discussions.id', new Expression('discussion_id')); ->where('discussions.id', new Expression('discussion_id'));
}); });
} }

View File

@ -29,7 +29,7 @@ class TagPolicy extends AbstractPolicy
*/ */
public function find(User $actor, Builder $query) public function find(User $actor, Builder $query)
{ {
$query->whereNotIn('id', Tag::getIdsWhereCannot($actor, 'view')); $query->whereNotIn('id', Tag::getIdsWhereCannot($actor, 'viewDiscussions'));
} }
/** /**

View File

@ -132,7 +132,7 @@ class Tag extends AbstractModel
} }
$ids = []; $ids = [];
$hasGlobalPermission = $user->hasPermission($permission === 'view' ? 'forum.view' : $permission); $hasGlobalPermission = $user->hasPermission($permission);
foreach ($tags as $tag) { foreach ($tags as $tag) {
if (($hasGlobalPermission && ! $tag->is_restricted) || $user->hasPermission('tag' . $tag->id . '.' . $permission)) { if (($hasGlobalPermission && ! $tag->is_restricted) || $user->hasPermission('tag' . $tag->id . '.' . $permission)) {
@ -157,7 +157,7 @@ class Tag extends AbstractModel
} }
$ids = []; $ids = [];
$hasGlobalPermission = $user->hasPermission($permission === 'view' ? 'forum.view' : $permission); $hasGlobalPermission = $user->hasPermission($permission);
foreach ($tags as $tag) { foreach ($tags as $tag) {
if (($tag->is_restricted || ! $hasGlobalPermission) && ! $user->hasPermission('tag' . $tag->id . '.' . $permission)) { if (($tag->is_restricted || ! $hasGlobalPermission) && ! $user->hasPermission('tag' . $tag->id . '.' . $permission)) {