2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-03-04 01:36:36 +08:00
discourse/spec/fabricators/notification_fabricator.rb
Juan David Martínez Cubillos 88ce76bd16
DEV: Added the ability to use users' names in group mention notifications and mentions shown in emails (#33055)
**Description**
These changes were introduced in a previous PR but were reverted due to
a bug when several users were mentioned in a response. This PR
reintroduces the changes along with a fix to the issue.

This is part of a series of changes to allow customers to display users'
names instead of the user's username.

When a user belongs to a group that has been mentioned by another user.
It shows the name of the user that mentioned the group.

[Previous
commit](e147d2afe6)

**Before**


![imagen](https://github.com/user-attachments/assets/b62224fb-9b69-4603-be00-e7aa61d9b33c)

**After**


![imagen](https://github.com/user-attachments/assets/8495cb63-6530-4d86-a51c-f0510d48f6c7)

When a email is sent to the user when mentioned in a post 

**Before**



![imagen](https://github.com/user-attachments/assets/94e674da-085a-41cb-8145-ba6fbe3636ce)

**After**


![imagen](https://github.com/user-attachments/assets/490cb365-bf85-4745-93b9-e47048b2f02e)
2025-06-03 15:49:55 -05:00

125 lines
3.8 KiB
Ruby

# frozen_string_literal: true
Fabricator(:notification) do
transient :post
notification_type Notification.types[:mentioned]
high_priority false
user
topic { |attrs| attrs[:post]&.topic || Fabricate(:topic, user: attrs[:user]) }
post_number { |attrs| attrs[:post]&.post_number }
data '{"poison":"ivy","killer":"croc"}'
end
Fabricator(:quote_notification, from: :notification) do
notification_type Notification.types[:quoted]
user
topic { |attrs| Fabricate(:topic, user: attrs[:user]) }
end
Fabricator(:private_message_notification, from: :notification) do
notification_type Notification.types[:private_message]
high_priority true
data do |attrs|
post = attrs[:post] || Fabricate(:post, topic: attrs[:topic], user: attrs[:user])
{
topic_title: attrs[:topic].title,
original_post_id: post.id,
original_post_type: post.post_type,
original_username: post.user.username,
revision_number: nil,
display_username: post.user.username,
}.to_json
end
end
Fabricator(:bookmark_reminder_notification, from: :notification) do
notification_type Notification.types[:bookmark_reminder]
high_priority true
data do |attrs|
post = attrs[:post] || Fabricate(:post, topic: attrs[:topic], user: attrs[:user])
{
topic_title: attrs[:topic].title,
original_post_id: post.id,
original_post_type: post.post_type,
original_username: post.user.username,
revision_number: nil,
display_username: post.user.username,
bookmark_name: "Check out Mr Freeze's opinion here",
}.to_json
end
end
Fabricator(:replied_notification, from: :notification) do
notification_type Notification.types[:replied]
data do |attrs|
post = attrs[:post] || Fabricate(:post, topic: attrs[:topic], user: attrs[:user])
{
topic_title: attrs[:topic].title,
original_post_id: post.id,
original_username: post.user.username,
revision_number: nil,
display_username: post.user.username,
}.to_json
end
end
Fabricator(:posted_notification, from: :notification) do
notification_type Notification.types[:posted]
data do |attrs|
post = attrs[:post] || Fabricate(:post, topic: attrs[:topic], user: attrs[:user])
{
topic_title: attrs[:topic].title,
original_post_id: post.id,
original_post_type: post.post_type,
original_username: post.user.username,
revision_number: nil,
display_username: post.user.username,
}.to_json
end
end
Fabricator(:mentioned_notification, from: :notification) do
notification_type Notification.types[:mentioned]
data do |attrs|
{
topic_title: attrs[:topic].title,
original_post_id: attrs[:post].id,
original_post_type: attrs[:post].post_type,
original_username: attrs[:post].user.username,
revision_number: nil,
display_username: attrs[:post].user.username,
}.to_json
end
end
Fabricator(:group_mentioned_notification, from: :notification) do
transient :group
notification_type Notification.types[:group_mentioned]
data do |attrs|
{
topic_title: attrs[:topic].title,
original_post_id: attrs[:post].id,
original_post_type: attrs[:post].post_type,
original_username: attrs[:post].user.username,
revision_number: nil,
display_username: attrs[:post].user.username,
display_name: attrs[:user].name,
group_id: attrs[:group].id,
group_name: attrs[:group].name,
}.to_json
end
end
Fabricator(:watching_first_post_notification, from: :notification) do
notification_type Notification.types[:watching_first_post]
data do |attrs|
{
topic_title: attrs[:topic].title,
original_post_id: attrs[:post].id,
original_post_type: attrs[:post].post_type,
original_username: attrs[:post].user.username,
revision_number: nil,
display_username: attrs[:post].user.username,
}.to_json
end
end