REFACTOR: redo DiscourseTagging.filter_allowed_tags (PR #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

TODO: test performance

GitHub

You’ve signed the CLA, nlalonde. Thank you! This pull request is ready for review.