Fix not sending notification when adding an admin

Test Plan:
-navigate to /accounts/<user id with admin access>/settings
-add an admin by email
-navigate to /users/<new user id>/messages
-verify there is an message for

flag=none
fixes VICE-573

Change-Id: I5f3f5b4bae657a5449836cddc525310bef3e8682
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/244801
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Rob Orton <rob@instructure.com>
QA-Review: Rob Orton <rob@instructure.com>
Product-Review: Rob Orton <rob@instructure.com>
This commit is contained in:
Drake Harper 2020-08-11 15:04:13 -06:00
parent 789908d057
commit c337ad8a96
2 changed files with 14 additions and 1 deletions

View File

@ -257,7 +257,7 @@ class NotificationMessageCreator
# are already loaded so we are using the select :active? to not do another
# query to load them again.
users_from_to_list(to_list).each do |user|
to_user_channels[user] += user.communication_channels.select(&:active?)
to_user_channels[user] += user.communication_channels.select{ |cc| add_channel?(user, cc) }
end
# if the method gets communication channels, the user is loaded, and this
# allows all the methods in this file to behave the same as if it were users.
@ -268,6 +268,11 @@ class NotificationMessageCreator
to_user_channels
end
# only send emails to active channels or registration notifications to default users' channel
def add_channel?(user, channel)
channel.active? || (@notification.registration? && default_email?(user, channel))
end
def users_from_to_list(to_list)
to_list = [to_list] unless to_list.is_a? Enumerable

View File

@ -142,6 +142,14 @@ describe NotificationMessageCreator do
expect(messages.length).to eql(1)
end
it 'should send registration emails to unconfirmed communication_channels' do
notification_model({ subject: "test", name: "Test Name", category: "Registration" })
communication_channel(user_model, cc_state: 'unconfirmed')
account_user = account_model.account_users.create!(user: @user)
messages = NotificationMessageCreator.new(@notification, account_user, to_list: @user).create_message
expect(messages.length).to eql(1)
end
it 'does send other notifications when policy override is in effect' do
notification_set(notification_opts: { :category => "Registration" })
@course.root_account.enable_feature!(:mute_notifications_by_course)