Enforce forum.view permission

This commit is contained in:
Toby Zerner 2015-08-05 18:08:31 +09:30
parent 3f0089e8bb
commit ff8dc5ef25
3 changed files with 7 additions and 2 deletions

View File

@ -56,7 +56,7 @@ class ShowAction extends SerializeResourceAction
{ {
$forum = app('flarum.forum'); $forum = app('flarum.forum');
$forum->groups = Group::all(); $forum->groups = Group::whereVisibleTo($request->actor)->get();
return $forum; return $forum;
} }

View File

@ -29,6 +29,7 @@ class ForumSerializer extends Serializer
'welcomeTitle' => Core::config('welcome_title'), 'welcomeTitle' => Core::config('welcome_title'),
'welcomeMessage' => Core::config('welcome_message'), 'welcomeMessage' => Core::config('welcome_message'),
'themePrimaryColor' => Core::config('theme_primary_color'), 'themePrimaryColor' => Core::config('theme_primary_color'),
'canView' => $forum->can($this->actor, 'view'),
'canStartDiscussion' => $forum->can($this->actor, 'startDiscussion') 'canStartDiscussion' => $forum->can($this->actor, 'startDiscussion')
]; ];

View File

@ -14,6 +14,10 @@ trait VisibleScope
*/ */
public function scopeWhereVisibleTo(Builder $query, User $actor) public function scopeWhereVisibleTo(Builder $query, User $actor)
{ {
event(new ScopeModelVisibility($this, $query, $actor)); if (! app('flarum.forum')->can($actor, 'view')) {
$query->whereRaw('FALSE');
} else {
event(new ScopeModelVisibility($this, $query, $actor));
}
} }
} }