mirror of
https://github.com/discourse/discourse.git
synced 2025-01-04 10:53:55 +08:00
DEV: return full name in /notifications.json (#30335)
* wip: return full name in /notifications.json * DEV: test for full name * DEV: add test for enable_names=true * DEV: add notification6, cleanup * DEV: fix tests
This commit is contained in:
parent
d18bf67868
commit
3e8e861103
|
@ -371,13 +371,17 @@ class Notification < ActiveRecord::Base
|
||||||
(
|
(
|
||||||
notification.data_hash[:username] || notification.data_hash[:display_username] ||
|
notification.data_hash[:username] || notification.data_hash[:display_username] ||
|
||||||
notification.data_hash[:mentioned_by_username] ||
|
notification.data_hash[:mentioned_by_username] ||
|
||||||
notification.data_hash[:invited_by_username]
|
notification.data_hash[:invited_by_username] ||
|
||||||
|
notification.data_hash[:original_username]
|
||||||
)&.downcase
|
)&.downcase
|
||||||
end
|
end
|
||||||
|
|
||||||
users = User.where(username_lower: usernames.uniq).index_by(&:username_lower)
|
users = User.where(username_lower: usernames.uniq).index_by(&:username_lower)
|
||||||
notifications.each do |notification|
|
notifications.each do |notification|
|
||||||
notification.acting_user = users[notification.acting_username]
|
notification.acting_user = users[notification.acting_username]
|
||||||
|
notification.data_hash[
|
||||||
|
:original_name
|
||||||
|
] = notification.acting_user&.name if SiteSetting.enable_names
|
||||||
end
|
end
|
||||||
|
|
||||||
notifications
|
notifications
|
||||||
|
|
|
@ -809,10 +809,14 @@ RSpec.describe Notification do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".populate_acting_user" do
|
describe ".populate_acting_user" do
|
||||||
|
SiteSetting.enable_names = true
|
||||||
|
|
||||||
fab!(:user1) { Fabricate(:user) }
|
fab!(:user1) { Fabricate(:user) }
|
||||||
fab!(:user2) { Fabricate(:user) }
|
fab!(:user2) { Fabricate(:user) }
|
||||||
fab!(:user3) { Fabricate(:user) }
|
fab!(:user3) { Fabricate(:user) }
|
||||||
fab!(:user4) { Fabricate(:user) }
|
fab!(:user4) { Fabricate(:user) }
|
||||||
|
fab!(:user5) { Fabricate(:user) }
|
||||||
|
fab!(:user6) { Fabricate(:user) }
|
||||||
fab!(:notification1) do
|
fab!(:notification1) do
|
||||||
Fabricate(:notification, user: user, data: { username: user1.username }.to_json)
|
Fabricate(:notification, user: user, data: { username: user1.username }.to_json)
|
||||||
end
|
end
|
||||||
|
@ -825,16 +829,32 @@ RSpec.describe Notification do
|
||||||
fab!(:notification4) do
|
fab!(:notification4) do
|
||||||
Fabricate(:notification, user: user, data: { invited_by_username: user4.username }.to_json)
|
Fabricate(:notification, user: user, data: { invited_by_username: user4.username }.to_json)
|
||||||
end
|
end
|
||||||
|
fab!(:notification5) do
|
||||||
|
Fabricate(:notification, user: user, data: { original_username: user5.username }.to_json)
|
||||||
|
end
|
||||||
|
fab!(:notification6) do
|
||||||
|
Fabricate(:notification, user: user, data: { original_username: user6.username }.to_json)
|
||||||
|
end
|
||||||
|
|
||||||
it "Sets the acting_user correctly for each notification" do
|
it "Sets the acting_user correctly for each notification" do
|
||||||
Notification.populate_acting_user(
|
Notification.populate_acting_user(
|
||||||
[notification1, notification2, notification3, notification4],
|
[notification1, notification2, notification3, notification4, notification5],
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(notification1.acting_user).to eq(user1)
|
expect(notification1.acting_user).to eq(user1)
|
||||||
expect(notification2.acting_user).to eq(user2)
|
expect(notification2.acting_user).to eq(user2)
|
||||||
expect(notification3.acting_user).to eq(user3)
|
expect(notification3.acting_user).to eq(user3)
|
||||||
expect(notification4.acting_user).to eq(user4)
|
expect(notification4.acting_user).to eq(user4)
|
||||||
|
expect(notification5.acting_user).to eq(user5)
|
||||||
|
expect(notification5.data_hash[:original_name]).to eq user5.name
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with SiteSettings.enable_names=false" do
|
||||||
|
it "doesn't set the :original_name property" do
|
||||||
|
SiteSetting.enable_names = false
|
||||||
|
Notification.populate_acting_user([notification6])
|
||||||
|
expect(notification6.data_hash[:original_name]).to be_nil
|
||||||
|
SiteSetting.enable_names = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user