Skip to content

Commit

Permalink
FEATURE: watch title for automatic tagging (discourse#12782)
Browse files Browse the repository at this point in the history
Previously watched words ignored topic titles when applying auto tagging rules.

Also copy has been improved to reflect how the system behaves.

The text hints that we are only watching first post now
  • Loading branch information
SamSaffron authored Apr 21, 2021
1 parent 3e6c392 commit e4f1760
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/jobs/regular/process_post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def extract_links(post)
end

def auto_tag(post)
word_watcher = WordWatcher.new(post.raw)
word_watcher = WordWatcher.new("#{post.topic.title} #{post.raw}")

old_tags = post.topic.tags.pluck(:name).to_set
new_tags = old_tags.dup
Expand Down
2 changes: 1 addition & 1 deletion app/services/word_watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def self.word_matcher_regexp(action, raise_errors: false)
end
Regexp.new(regexp, Regexp::IGNORECASE)
end
rescue RegexpError => e
rescue RegexpError
raise if raise_errors
nil # Admin will be alerted via admin_dashboard_data.rb
end
Expand Down
6 changes: 3 additions & 3 deletions config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4684,16 +4684,16 @@ en:
require_approval: "Require Approval"
flag: "Flag"
replace: "Replace"
tag: "Auto-tag"
tag: "Tag"
action_descriptions:
block: "Prevent posts containing these words from being posted. The user will see an error message when they try to submit their post."
censor: "Allow posts containing these words, but replace them with characters that hide the censored words."
require_approval: "Posts containing these words will require approval by staff before they can be seen."
flag: "Allow posts containing these words, but flag them as inappropriate so moderators can review them."
replace: "Replace words in posts with other words or links"
tag: "Automatically tag posts with these words"
tag: "Automatically tag topics based on first post"
form:
label: "New Word"
label: "Has the word"
placeholder: "full word or * as wildcard"
placeholder_regexp: "regular expression"
replacement_label: "Replacement"
Expand Down
6 changes: 6 additions & 0 deletions spec/jobs/process_post_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@
post = Fabricate(:post, raw: "Greetings?", cooked: "")
Jobs::ProcessPost.new.execute(post_id: post.id)
expect(post.topic.reload.tags.pluck(:name)).to contain_exactly("hello", "world")

topic = Fabricate(:topic, title: "Greetings? People")
post = Fabricate(:post, topic: topic, raw: "nothing yet", cooked: "")

Jobs::ProcessPost.new.execute(post_id: post.id)
expect(post.topic.reload.tags.pluck(:name)).to contain_exactly("hello", "world")
end

it "automatically tags first posts (regex)" do
Expand Down

0 comments on commit e4f1760

Please sign in to comment.