mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 20:04:42 +08:00
FIX: correctly uses private_email site setting in chat (#24528)
Chat will now check for the state of `SiteSetting.private_email` when sending the summary, when enabled, the mail will not display user information, channel information other than the ID and no message information, only the count of messages.
This commit is contained in:
@ -33,6 +33,22 @@ describe UserNotifications do
|
||||
end
|
||||
|
||||
describe "email subject" do
|
||||
context "when private_email setting is enabled" do
|
||||
before { SiteSetting.private_email = true }
|
||||
|
||||
it "has a generic subject" do
|
||||
Fabricate(:chat_message, user: sender, chat_channel: channel)
|
||||
email = described_class.chat_summary(user, {})
|
||||
|
||||
expect(email.subject).to eq(
|
||||
I18n.t(
|
||||
"user_notifications.chat_summary.subject.private_message",
|
||||
email_prefix: SiteSetting.email_prefix.presence || SiteSetting.title,
|
||||
),
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
it "includes the sender username in the subject" do
|
||||
expected_subject =
|
||||
I18n.t(
|
||||
@ -245,6 +261,21 @@ describe UserNotifications do
|
||||
)
|
||||
end
|
||||
|
||||
context "when private_email setting is enabled" do
|
||||
before { SiteSetting.private_email = true }
|
||||
|
||||
it "has a generic subject" do
|
||||
email = described_class.chat_summary(user, {})
|
||||
|
||||
expect(email.subject).to eq(
|
||||
I18n.t(
|
||||
"user_notifications.chat_summary.subject.private_message",
|
||||
email_prefix: SiteSetting.email_prefix.presence || SiteSetting.title,
|
||||
),
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
it "includes the sender username in the subject" do
|
||||
expected_subject =
|
||||
I18n.t(
|
||||
@ -500,6 +531,31 @@ describe UserNotifications do
|
||||
end
|
||||
|
||||
describe "mail contents" do
|
||||
context "when private_email setting is enabled" do
|
||||
before { SiteSetting.private_email = true }
|
||||
|
||||
it "has a generic channel title name" do
|
||||
email = described_class.chat_summary(user, {})
|
||||
|
||||
expect(email.html_part.body.to_s).to include(
|
||||
I18n.t("system_messages.private_channel_title", id: channel.id),
|
||||
)
|
||||
end
|
||||
|
||||
it "doesn’t include message content" do
|
||||
email = described_class.chat_summary(user, {})
|
||||
|
||||
expect(email.html_part.body.to_s).to_not include(chat_message.cooked_for_excerpt)
|
||||
end
|
||||
|
||||
it "doesn’t include user info" do
|
||||
email = described_class.chat_summary(user, {})
|
||||
|
||||
expect(email.html_part.body.to_s).to_not include(chat_message.user.small_avatar_url)
|
||||
expect(email.html_part.body.to_s).to_not include(chat_message.user.username)
|
||||
end
|
||||
end
|
||||
|
||||
it "returns an email when the user has unread mentions" do
|
||||
email = described_class.chat_summary(user, {})
|
||||
|
||||
@ -581,21 +637,49 @@ describe UserNotifications do
|
||||
expect(user_avatar.attribute("alt").value).to eq(sender.username)
|
||||
end
|
||||
|
||||
it "includes a view more link when there are more than two mentions" do
|
||||
2.times do
|
||||
msg = Fabricate(:chat_message, user: sender, chat_channel: channel)
|
||||
notification = Fabricate(:notification)
|
||||
Fabricate(:chat_mention, user: user, chat_message: msg, notification: notification)
|
||||
context "when there are more than two mentions" do
|
||||
it "includes a view more link " do
|
||||
2.times do
|
||||
msg = Fabricate(:chat_message, user: sender, chat_channel: channel)
|
||||
notification = Fabricate(:notification)
|
||||
Fabricate(:chat_mention, user: user, chat_message: msg, notification: notification)
|
||||
end
|
||||
|
||||
email = described_class.chat_summary(user, {})
|
||||
more_messages_channel_link =
|
||||
Nokogiri::HTML5.fragment(email.html_part.body.to_s).css(".more-messages-link")
|
||||
|
||||
expect(more_messages_channel_link.attribute("href").value).to eq(
|
||||
chat_message.full_url,
|
||||
)
|
||||
expect(more_messages_channel_link.text).to include(
|
||||
I18n.t("user_notifications.chat_summary.view_more", count: 1),
|
||||
)
|
||||
end
|
||||
|
||||
email = described_class.chat_summary(user, {})
|
||||
more_messages_channel_link =
|
||||
Nokogiri::HTML5.fragment(email.html_part.body.to_s).css(".more-messages-link")
|
||||
context "when private_email setting is enabled" do
|
||||
before { SiteSetting.private_email = true }
|
||||
|
||||
expect(more_messages_channel_link.attribute("href").value).to eq(chat_message.full_url)
|
||||
expect(more_messages_channel_link.text).to include(
|
||||
I18n.t("user_notifications.chat_summary.view_more", count: 1),
|
||||
)
|
||||
it "has only a link to view all messages" do
|
||||
2.times do
|
||||
msg = Fabricate(:chat_message, user: sender, chat_channel: channel)
|
||||
notification = Fabricate(:notification)
|
||||
Fabricate(
|
||||
:chat_mention,
|
||||
user: user,
|
||||
chat_message: msg,
|
||||
notification: notification,
|
||||
)
|
||||
end
|
||||
|
||||
email = described_class.chat_summary(user, {})
|
||||
more_messages_channel_link =
|
||||
Nokogiri::HTML5.fragment(email.html_part.body.to_s).css(".more-messages-link")
|
||||
expect(more_messages_channel_link.text).to include(
|
||||
I18n.t("user_notifications.chat_summary.view_messages", count: 3),
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "doesn't repeat mentions we already sent" do
|
||||
|
Reference in New Issue
Block a user