FIX: Don't set notification level to `watching` when already watching.

This commit is contained in:
Guo Xiang Tan 2018-09-07 15:00:53 +08:00
parent 7663268584
commit ed1f942c52
2 changed files with 22 additions and 5 deletions

View File

@ -149,13 +149,20 @@ SQL
publish_topic_tracking_state(@topic, assign_to.id) publish_topic_tracking_state(@topic, assign_to.id)
TopicUser.change( if !TopicUser.exists?(
assign_to.id, user_id: assign_to.id,
@topic.id, topic_id: @topic.id,
notification_level: TopicUser.notification_levels[:watching], notification_level: TopicUser.notification_levels[:watching]
notifications_reason_id: TopicUser.notification_reasons[:plugin_changed]
) )
TopicUser.change(
assign_to.id,
@topic.id,
notification_level: TopicUser.notification_levels[:watching],
notifications_reason_id: TopicUser.notification_reasons[:plugin_changed]
)
end
if SiteSetting.assign_mailer_enabled if SiteSetting.assign_mailer_enabled
if !@topic.muted?(assign_to) if !@topic.muted?(assign_to)
message = AssignMailer.send_assignment(assign_to.email, @topic, @assigned_by) message = AssignMailer.send_assignment(assign_to.email, @topic, @assigned_by)

View File

@ -49,6 +49,16 @@ RSpec.describe TopicAssigner do
.to eq(TopicUser.notification_levels[:tracking]) .to eq(TopicUser.notification_levels[:tracking])
end end
it 'does not update notification level if already watching' do
TopicUser.change(moderator.id, topic.id,
notification_level: TopicUser.notification_levels[:watching]
)
expect do
assigner.assign(moderator)
end.to_not change { TopicUser.last.notifications_reason_id }
end
it 'does not update notification level if it is not set by the plugin' do it 'does not update notification level if it is not set by the plugin' do
assigner.assign(moderator) assigner.assign(moderator)