FIX: Create notification for group users when group has been invited.

https://meta.discourse.org/t/inviting-a-group-to-a-message-does-not-trigger-a-notification-mail/50509
This commit is contained in:
Guo Xiang Tan 2017-06-14 14:53:49 +09:00
parent 5ce8d7a8c5
commit 2fdf9068eb
2 changed files with 41 additions and 6 deletions

View File

@ -719,6 +719,21 @@ SQL
# ensure all the notifications are out
PostAlerter.new.after_save_post(last_post)
add_small_action(user, "invited_group", group.name)
group.users.where(
"group_users.notification_level > ?", NotificationLevels.all[:muted]
).find_each do |u|
u.notifications.create!(
notification_type: Notification.types[:invited_to_private_message],
topic_id: self.id,
post_number: 1,
data: {
topic_title: self.title,
display_username: user.username
}.to_json
)
end
end
true

View File

@ -439,22 +439,42 @@ describe Topic do
let(:walter) { Fabricate(:walter_white) }
context 'by group name' do
let(:group) { Fabricate(:group) }
it 'can add admin to allowed groups' do
admins = Group[:admins]
admins.alias_level = Group::ALIAS_LEVELS[:everyone]
admins.save
admins.update!(alias_level: Group::ALIAS_LEVELS[:everyone])
expect(topic.invite_group(topic.user, admins)).to eq(true)
expect(topic.allowed_groups.include?(admins)).to eq(true)
expect(topic.remove_allowed_group(topic.user, 'admins')).to eq(true)
topic.reload
expect(topic.allowed_groups.include?(admins)).to eq(false)
end
it 'creates a notification for each user in the group' do
user = Fabricate(:user)
user_2 = Fabricate(:user)
Fabricate(:post, topic: topic)
group.add(user)
group.add(user_2)
group.group_users.find_by(user: user_2).update!(
notification_level: NotificationLevels.all[:muted]
)
expect { topic.invite_group(topic.user, group) }
.to change { Notification.count }.by(1)
notification = Notification.last
expect(notification.user).to eq(user)
expect(notification.topic).to eq(topic)
expect(notification.notification_type)
.to eq(Notification.types[:invited_to_private_message])
end
end
context 'by username' do