From 557a65aadd7a9ed2bb90935e7e178ea409178570 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Tue, 30 Jan 2018 11:14:25 +1030 Subject: [PATCH] Grant users permission to view empty discussions if they can edit posts This fixes an issue where unapproved discussions (via flarum-ext-approval) that were rejected became invisible to the user. This solution is imperfect and some more substantial thought into how flarum-ext-approval works is required in the future. --- src/Discussion/DiscussionPolicy.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Discussion/DiscussionPolicy.php b/src/Discussion/DiscussionPolicy.php index fca8f6c70..9a4a03019 100644 --- a/src/Discussion/DiscussionPolicy.php +++ b/src/Discussion/DiscussionPolicy.php @@ -103,16 +103,18 @@ class DiscussionPolicy extends AbstractPolicy } // Hide discussions with no comments, unless they are authored by the - // current user. - $query->where(function ($query) use ($actor) { - $query->where('comments_count', '>', 0) - ->orWhere('start_user_id', $actor->id) - ->orWhere(function ($query) use ($actor) { - $this->events->fire( - new ScopeModelVisibility($query, $actor, 'viewEmpty') - ); - }); - }); + // current user, or the user is allowed to edit the discussion's posts. + if (! $actor->hasPermission('discussion.editPosts')) { + $query->where(function ($query) use ($actor) { + $query->where('comments_count', '>', 0) + ->orWhere('start_user_id', $actor->id) + ->orWhere(function ($query) use ($actor) { + $this->events->fire( + new ScopeModelVisibility($query, $actor, 'editPosts') + ); + }); + }); + } } /**