Reverse tag visibility logic

So that discussions with non-existent tags are still visible
This commit is contained in:
Toby Zerner 2015-06-19 17:26:46 +09:30
parent 6aff8ebca5
commit 0d1d61922f
2 changed files with 4 additions and 4 deletions

View File

@ -57,7 +57,7 @@ class Tag extends Model
return $this;
}
public static function getVisibleTo($user)
public static function getNotVisibleTo($user)
{
static $tags;
if (! $tags) {
@ -66,7 +66,7 @@ class Tag extends Model
$ids = [];
foreach ($tags as $tag) {
if (! $tag->is_restricted || $user->hasPermission('tag'.$tag->id.'.view')) {
if ($tag->is_restricted && ! $user->hasPermission('tag'.$tag->id.'.view')) {
$ids[] = $tag->id;
}
}

View File

@ -39,7 +39,7 @@ class TagsServiceProvider extends ServiceProvider
(new Extend\Model('Flarum\Tags\Tag'))
// Hide tags that the user doesn't have permission to see.
->scopeVisible(function ($query, User $user) {
$query->whereIn('id', Tag::getVisibleTo($user));
$query->whereNotIn('id', Tag::getNotVisibleTo($user));
})
// Allow the user to start discussions in tags which aren't
@ -76,7 +76,7 @@ class TagsServiceProvider extends ServiceProvider
$query->whereNotExists(function ($query) use ($user) {
return $query->select(app('db')->raw(1))
->from('discussions_tags')
->whereNotIn('tag_id', Tag::getVisibleTo($user))
->whereIn('tag_id', Tag::getNotVisibleTo($user))
->whereRaw('discussion_id = discussions.id');
});
})