1
0
mirror of https://github.com/flarum/core.git synced 2025-08-09 18:07:02 +02:00

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; return $this;
} }
public static function getVisibleTo($user) public static function getNotVisibleTo($user)
{ {
static $tags; static $tags;
if (! $tags) { if (! $tags) {
@@ -66,7 +66,7 @@ class Tag extends Model
$ids = []; $ids = [];
foreach ($tags as $tag) { 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; $ids[] = $tag->id;
} }
} }

View File

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