FIX: Make autotag watched words case insensitive (#13043)

* FIX: Hide tag watched words if tagging is disabled

These 'autotag' words were shown even if tagging was disabled.

* FIX: Make autotag watched words case insensitive

This commit also fixes the bug when no tag was applied if no other tag
was already present.
This commit is contained in:
Bianca Nenciu
2021-05-14 16:52:10 +03:00
committed by GitHub
parent 0e6a8757fe
commit 3a1b05f219
5 changed files with 26 additions and 27 deletions

View File

@ -169,23 +169,23 @@ class TopicCreator
end
def setup_tags(topic)
return if @opts[:tags].blank?
valid_tags = DiscourseTagging.tag_topic_by_names(topic, @guardian, @opts[:tags])
unless valid_tags
topic.errors.add(:base, :unable_to_tag)
rollback_from_errors!(topic)
end
guardian = Guardian.new(Discourse.system_user)
word_watcher = WordWatcher.new("#{@opts[:title]} #{@opts[:raw]}")
word_watcher_tags = topic.tags.map(&:name)
WordWatcher.words_for_action(:tag).each do |word, tags|
if word_watcher.matches?(word)
word_watcher_tags += tags.split(",")
if @opts[:tags].present?
valid_tags = DiscourseTagging.tag_topic_by_names(topic, @guardian, @opts[:tags])
unless valid_tags
topic.errors.add(:base, :unable_to_tag)
rollback_from_errors!(topic)
end
end
DiscourseTagging.tag_topic_by_names(topic, guardian, word_watcher_tags)
watched_words = WordWatcher.words_for_action(:tag)
if watched_words.present?
word_watcher = WordWatcher.new("#{@opts[:title]} #{@opts[:raw]}")
word_watcher_tags = topic.tags.map(&:name)
watched_words.each do |word, tags|
word_watcher_tags += tags.split(",") if word_watcher.word_matches?(word)
end
DiscourseTagging.tag_topic_by_names(topic, Discourse.system_user.guardian, word_watcher_tags)
end
end
def setup_auto_close_time(topic)