FEATURE: categories can require topics have a tag from a tag group

In a category's settings, the Tags tab has two new fields to
specify the number of tags that must be added to a topic
from a tag group. When creating a new topic, an error will be
shown to the user if the requirement isn't met.
This commit is contained in:
Neil Lalonde
2019-10-30 14:49:00 -04:00
parent 091d058ff2
commit d777844ed6
15 changed files with 226 additions and 21 deletions

View File

@ -147,10 +147,10 @@ class TopicCreator
def setup_tags(topic)
if @opts[:tags].blank?
unless @guardian.is_staff? || !guardian.can_tag?(topic)
# Validate minimum required tags for a category
category = find_category
if category.present? && category.minimum_required_tags > 0
topic.errors.add(:base, I18n.t("tags.minimum_required_tags", count: category.minimum_required_tags))
if !DiscourseTagging.validate_min_required_tags_for_category(@guardian, topic, category) ||
!DiscourseTagging.validate_required_tags_from_group(@guardian, topic, category)
rollback_from_errors!(topic)
end
end