Skip to content

Commit

Permalink
FIX: Don't set notification level to watching when already watching.
Browse files Browse the repository at this point in the history
  • Loading branch information
tgxworld committed Sep 7, 2018
1 parent 7663268 commit ed1f942
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/topic_assigner.rb
Expand Up @@ -149,13 +149,20 @@ def assign(assign_to, silent: false)

publish_topic_tracking_state(@topic, assign_to.id)

TopicUser.change(
assign_to.id,
@topic.id,
notification_level: TopicUser.notification_levels[:watching],
notifications_reason_id: TopicUser.notification_reasons[:plugin_changed]
if !TopicUser.exists?(
user_id: assign_to.id,
topic_id: @topic.id,
notification_level: TopicUser.notification_levels[:watching]
)

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 !@topic.muted?(assign_to)
message = AssignMailer.send_assignment(assign_to.email, @topic, @assigned_by)
Expand Down
10 changes: 10 additions & 0 deletions spec/lib/topic_assigner_spec.rb
Expand Up @@ -49,6 +49,16 @@ def assert_publish_topic_state(topic, user)
.to eq(TopicUser.notification_levels[:tracking])
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
assigner.assign(moderator)

Expand Down

0 comments on commit ed1f942

Please sign in to comment.