Use db schema for tags instead of plugin store and custom fields

This commit is contained in:
Neil Lalonde
2016-05-26 14:29:48 -04:00
parent ebd4b45771
commit f13470b96b
33 changed files with 726 additions and 186 deletions
+7 -43
View File
@@ -72,51 +72,15 @@ class PostRevisor
tc.check_result(tc.topic.change_category_to_id(category_id))
end
track_topic_field(:tags_empty_array) do |tc, val|
if val.present?
unless tc.guardian.is_staff?
old_tags = tc.topic.tags || []
staff_tags = DiscourseTagging.staff_only_tags(old_tags)
if staff_tags.present?
tc.topic.errors[:base] << I18n.t("tags.staff_tag_remove_disallowed", tag: staff_tags.join(" "))
tc.check_result(false)
next
end
end
tc.record_change(DiscourseTagging::TAGS_FIELD_NAME, tc.topic.custom_fields[DiscourseTagging::TAGS_FIELD_NAME], nil)
tc.topic.custom_fields.delete(DiscourseTagging::TAGS_FIELD_NAME)
end
end
track_topic_field(:tags) do |tc, tags|
if tags.present? && tc.guardian.can_tag_topics?
tags = DiscourseTagging.tags_for_saving(tags, tc.guardian)
old_tags = tc.topic.tags || []
new_tags = tags - old_tags
removed_tags = old_tags - tags
unless tc.guardian.is_staff?
staff_tags = DiscourseTagging.staff_only_tags(new_tags)
if staff_tags.present?
tc.topic.errors[:base] << I18n.t("tags.staff_tag_disallowed", tag: staff_tags.join(" "))
tc.check_result(false)
next
end
staff_tags = DiscourseTagging.staff_only_tags(removed_tags)
if staff_tags.present?
tc.topic.errors[:base] << I18n.t("tags.staff_tag_remove_disallowed", tag: staff_tags.join(" "))
tc.check_result(false)
next
end
if tc.guardian.can_tag_topics?
prev_tags = tc.topic.tags.map(&:name)
next if tags.blank? && prev_tags.blank?
if !DiscourseTagging.tag_topic_by_names(tc.topic, tc.guardian, tags)
tc.check_result(false)
next
end
tc.record_change(DiscourseTagging::TAGS_FIELD_NAME, tc.topic.custom_fields[DiscourseTagging::TAGS_FIELD_NAME], tags)
tc.topic.custom_fields.update(DiscourseTagging::TAGS_FIELD_NAME => tags)
DiscourseTagging.auto_notify_for(new_tags, tc.topic) if new_tags.present?
tc.record_change('tags', prev_tags, tags)
end
end