diff --git a/lib/topic_creator.rb b/lib/topic_creator.rb index 8ec4254f2ad..62f3ee2f022 100644 --- a/lib/topic_creator.rb +++ b/lib/topic_creator.rb @@ -30,8 +30,11 @@ class TopicCreator @topic.notifier.watch_topic!(@topic.user_id) end - @topic.topic_allowed_users.pluck(:user_id).reject{|id| id == @topic.user_id}.each do |id| - @topic.notifier.watch_topic!(id, nil) + user_ids = @topic.topic_allowed_users(true).pluck(:user_id) + user_ids += @topic.topic_allowed_groups(true).map { |t| t.group.users.pluck(:id) }.flatten + + user_ids.uniq.reject{ |id| id == @topic.user_id }.each do |user_id| + @topic.notifier.watch_topic!(user_id, nil) unless user_id == -1 end CategoryUser.auto_watch_new_topic(@topic) diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rb index d22e91931ac..e241917151e 100644 --- a/spec/models/post_action_spec.rb +++ b/spec/models/post_action_spec.rb @@ -18,6 +18,8 @@ describe PostAction do it "notify moderators integration test" do post = create_post mod = moderator + Group.refresh_automatic_groups! + action = PostAction.act(codinghorror, post, PostActionType.types[:notify_moderators], message: "this is my special long message"); posts = Post.joins(:topic) @@ -29,13 +31,15 @@ describe PostAction do action.related_post_id.should == posts[0].id.to_i posts[0].subtype.should == TopicSubtype.notify_moderators - # Moderators should be invited to the private topic, otherwise they're not permitted to see it - topic_user_ids = posts[0].topic.topic_users.map {|x| x.user_id} - topic_user_ids.should include(codinghorror.id) - topic_user_ids.should_not include(mod.id) + topic = posts[0].topic - # invite the moderator - posts[0].topic.allowed_users << mod + # Moderators should be invited to the private topic, otherwise they're not permitted to see it + topic_user_ids = topic.topic_users(true).map {|x| x.user_id} + topic_user_ids.should include(codinghorror.id) + topic_user_ids.should include(mod.id) + + # Notification level should be "Watching" for everyone + topic.topic_users(true).map(&:notification_level).uniq.should == [TopicUser.notification_levels[:watching]] # reply to PM should clear flag p = PostCreator.new(mod, topic_id: posts[0].topic_id, raw: "This is my test reply to the user, it should clear flags")