Skip to content

Commit

Permalink
constrain to within Q&A tags
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Nov 6, 2024
1 parent d947be9 commit 70f7178
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Search/BestAnswerPostFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

use Flarum\Filter\FilterInterface;
use Flarum\Filter\FilterState;
use Flarum\Tags\Tag;
use Flarum\User\User;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Collection;

class BestAnswerPostFilter implements FilterInterface
{
Expand Down Expand Up @@ -45,5 +47,20 @@ protected function constrain(Builder $query, User $actor, bool $negate)
$query->whereNotNull('discussions.best_answer_post_id')
->whereColumn('posts.id', '=', 'discussions.best_answer_post_id');
}

// Constrain to discussions within the allowed Q&A tags
$query->whereIn('discussions.id', function ($subQuery) use ($actor) {
$subQuery->select('discussion_id')
->from('discussion_tag')
->whereIn('tag_id', $this->allowedQnATags($actor));
});
}

protected function allowedQnATags(User $actor): Collection
{
return Tag::query()
->whereVisibleTo($actor)
->where('is_qna', true)
->pluck('id');
}
}

0 comments on commit 70f7178

Please sign in to comment.