REFACTOR: redo DiscourseTagging.filter_allowed_tags (#8328)

This method had grown into a monster. Its query had bugs
that I couldn't fix, and new features would be hard to add.
Also I don't understand how it all works anymore...
Replace it with common table expressions that can be queried
to generate the results we need, instead of subtracting
results using lots of "NOT IN" clauses.

Fixed are bugs with tag schemas that use combinations of
tag groups, parent tags, and one-tag-per-topic restrictions.
For example: https://meta.discourse.org/t/130991/6
This commit is contained in:
Neil Lalonde
2019-11-12 14:28:44 -05:00
committed by GitHub
parent 4422d9a4bf
commit 7711df40e6
6 changed files with 294 additions and 233 deletions

View File

@ -327,10 +327,9 @@ class TopicsController < ApplicationController
if category && topic_tags = (params[:tags] || topic.tags.pluck(:name)).reject { |c| c.empty? }
if topic_tags.present?
allowed_tags = DiscourseTagging.filter_allowed_tags(
Tag.all,
guardian,
category: category
).pluck("tags.name")
).map(&:name)
invalid_tags = topic_tags - allowed_tags