FIX: Change notification_level back to tracking only if set by plugin.

This commit is contained in:
Guo Xiang Tan 2018-09-04 15:30:53 +08:00
parent 8ad7304bdd
commit 7663268584
2 changed files with 28 additions and 4 deletions

View File

@ -232,13 +232,21 @@ SQL
post.publish_change_to_clients!(:revised, reload_topic: true)
TopicUser.change(
assigned_to_id,
@topic.id,
notification_level: TopicUser.notification_levels[:tracking],
if TopicUser.exists?(
user_id: assigned_to_id,
topic: @topic,
notification_level: TopicUser.notification_levels[:watching],
notifications_reason_id: TopicUser.notification_reasons[:plugin_changed]
)
TopicUser.change(
assigned_to_id,
@topic.id,
notification_level: TopicUser.notification_levels[:tracking],
notifications_reason_id: TopicUser.notification_reasons[:plugin_changed]
)
end
assigned_user = User.find_by(id: assigned_to_id)
MessageBus.publish(
"/staff/topic-assignment",

View File

@ -49,6 +49,22 @@ RSpec.describe TopicAssigner do
.to eq(TopicUser.notification_levels[:tracking])
end
it 'does not update notification level if it is not set by the plugin' do
assigner.assign(moderator)
expect(TopicUser.find_by(user: moderator).notification_level)
.to eq(TopicUser.notification_levels[:watching])
TopicUser.change(moderator.id, topic.id,
notification_level: TopicUser.notification_levels[:muted]
)
assigner.unassign
expect(TopicUser.find_by(user: moderator, topic: topic).notification_level)
.to eq(TopicUser.notification_levels[:muted])
end
it "can unassign all a user's topics at once" do
assigner.assign(moderator)
TopicAssigner.unassign_all(moderator, moderator)