mirror of
https://github.com/flarum/framework.git
synced 2025-02-21 03:59:39 +08:00
Reverse tag visibility logic
So that discussions with non-existent tags are still visible
This commit is contained in:
parent
6aff8ebca5
commit
0d1d61922f
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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');
|
||||
});
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user