FEATURE: Implement max_tags_per_email_subject (#22050)

* FEATURE: Implement max_tags_per_email_subject

* made it so only max_tags_per_email_subject is responsible for tags in emails when the feature is enabled

* added locales for implemented siteSettings

* reworded locale for enable_max_tags_per_email_subject

* added min value for max_tags_per_email_subject

* Implemented suggested changes to spec description
This commit is contained in:
Juan David Martínez Cubillos 2023-06-14 12:22:14 -05:00 committed by GitHub
parent b5d60da191
commit 8b39125985
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 15 deletions

View File

@ -601,12 +601,19 @@ class UserNotifications < ActionMailer::Base
# tag names
if opts[:show_tags_in_subject] && post.topic_id
max_tags =
if SiteSetting.enable_max_tags_per_email_subject
SiteSetting.max_tags_per_email_subject
else
SiteSetting.max_tags_per_topic
end
tags =
DiscourseTagging
.visible_tags(Guardian.new(user))
.joins(:topic_tags)
.where("topic_tags.topic_id = ?", post.topic_id)
.limit(SiteSetting.max_tags_per_topic)
.limit(max_tags)
.pluck(:name)
show_tags_in_subject = tags.any? ? tags.join(" ") : nil

View File

@ -2366,6 +2366,8 @@ en:
tagging_enabled: "Enable tags on topics?"
min_trust_to_create_tag: "The minimum trust level required to create a tag."
max_tags_per_topic: "The maximum tags that can be applied to a topic."
enable_max_tags_per_email_subject: "Use max_tags_per_email_subject when generating the subject of an email"
max_tags_per_email_subject: "The maximum tags that can be in the subject of an email"
max_tag_length: "The maximum amount of characters that can be used in a tag."
max_tag_search_results: "When searching for tags, the maximum number of results to show."
max_tags_in_filter_list: "Maximum number of tags to show in the filter dropdown. The most used tags will be shown."

View File

@ -2776,6 +2776,13 @@ tags:
max_tags_per_topic:
default: 5
client: true
enable_max_tags_per_email_subject:
default: false
client: true
max_tags_per_email_subject:
default: 5
client: true
min: 0
max_tag_length:
default: 20
client: true

View File

@ -445,6 +445,7 @@ RSpec.describe UserNotifications do
let(:category) { Fabricate(:category, name: "India") }
let(:tag1) { Fabricate(:tag, name: "Taggo") }
let(:tag2) { Fabricate(:tag, name: "Taggie") }
let(:tag3) { Fabricate(:tag, name: "Teggo") }
let(:hidden_tag) { Fabricate(:tag, name: "hidden") }
let!(:hidden_tag_group) do
@ -455,7 +456,7 @@ RSpec.describe UserNotifications do
Fabricate(
:topic,
category: category,
tags: [tag1, tag2, hidden_tag],
tags: [tag1, tag2, tag3, hidden_tag],
title: "Super cool topic",
)
end
@ -558,19 +559,49 @@ RSpec.describe UserNotifications do
expect(mail_html.scan(/>bobmarley/).count).to eq(1)
end
it "the number of tags shown in subject should match max_tags_per_topic" do
SiteSetting.email_subject =
"[%{site_name}] %{optional_pm}%{optional_cat}%{optional_tags}%{topic_title}"
SiteSetting.max_tags_per_topic = 1
mail =
UserNotifications.user_replied(
user,
post: response,
notification_type: notification.notification_type,
notification_data_hash: notification.data_hash,
)
expect(mail.subject).to match(/Taggo/)
expect(mail.subject).not_to match(/Taggie/)
describe "number of tags shown in subject line" do
describe "max_tags_per_email_subject siteSetting enabled" do
before { SiteSetting.enable_max_tags_per_email_subject = true }
it "should match max_tags_per_email_subject" do
SiteSetting.email_subject =
"[%{site_name}] %{optional_pm}%{optional_cat}%{optional_tags}%{topic_title}"
SiteSetting.max_tags_per_topic = 1
SiteSetting.max_tags_per_email_subject = 2
mail =
UserNotifications.user_replied(
user,
post: response,
notification_type: notification.notification_type,
notification_data_hash: notification.data_hash,
)
expect(mail.subject).to match(/Taggo/)
expect(mail.subject).to match(/Taggie/)
expect(mail.subject).not_to match(/Teggo/)
end
end
describe "max_tags_per_email_subject siteSetting disabled" do
before { SiteSetting.enable_max_tags_per_email_subject = false }
it "should match max_tags_per_topic" do
SiteSetting.email_subject =
"[%{site_name}] %{optional_pm}%{optional_cat}%{optional_tags}%{topic_title}"
SiteSetting.max_tags_per_topic = 2
SiteSetting.max_tags_per_email_subject = 1
mail =
UserNotifications.user_replied(
user,
post: response,
notification_type: notification.notification_type,
notification_data_hash: notification.data_hash,
)
expect(mail.subject).to match(/Taggo/)
expect(mail.subject).to match(/Taggie/)
expect(mail.subject).not_to match(/Teggo/)
end
end
end
it "doesn't include details when private_email is enabled" do