FEATURE: Assigning a user to a topic will make user watch the topic.

This commit is contained in:
Guo Xiang Tan 2018-08-03 16:24:59 +08:00
parent 6e7f01e5d4
commit 9bea971196
2 changed files with 29 additions and 2 deletions

View File

@ -144,6 +144,13 @@ SQL
publish_topic_tracking_state(@topic, assign_to.id) 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 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)
@ -201,6 +208,13 @@ SQL
post.publish_change_to_clients!(:revised, reload_topic: true) post.publish_change_to_clients!(:revised, reload_topic: true)
TopicUser.change(
assigned_to_id,
@topic.id,
notification_level: TopicUser.notification_levels[:tracking],
notifications_reason_id: TopicUser.notification_reasons[:plugin_changed]
)
assigned_user = User.find_by(id: assigned_to_id) assigned_user = User.find_by(id: assigned_to_id)
MessageBus.publish( MessageBus.publish(
"/staff/topic-assignment", "/staff/topic-assignment",

View File

@ -31,9 +31,22 @@ RSpec.describe TopicAssigner do
it "can assign and unassign correctly" do it "can assign and unassign correctly" do
assigner.assign(moderator) assigner.assign(moderator)
expect(TopicQuery.new(moderator, assigned: moderator.username).list_latest.topics).to be_present
expect(TopicQuery.new(
moderator, assigned: moderator.username
).list_latest.topics).to eq([topic])
expect(TopicUser.find_by(user: moderator).notification_level)
.to eq(TopicUser.notification_levels[:watching])
assigner.unassign assigner.unassign
expect(TopicQuery.new(moderator, assigned: moderator.username).list_latest.topics).to be_blank
expect(TopicQuery.new(
moderator, assigned: moderator.username
).list_latest.topics).to eq([])
expect(TopicUser.find_by(user: moderator).notification_level)
.to eq(TopicUser.notification_levels[:tracking])
end end
it "can unassign all a user's topics at once" do it "can unassign all a user's topics at once" do