FIX: Correctly publish messages unconditionally to admins (#13053)
Under certain conditions admins would miss messages when posting action in topics where they have permission. This also fixes an error where we would sometimes explode when publishing to an empty group.
This commit is contained in:
parent
f1b14a7f71
commit
058b5310c1
|
@ -283,14 +283,14 @@ class UserAction < ActiveRecord::Base
|
|||
update_like_count(user_id, hash[:action_type], 1)
|
||||
end
|
||||
|
||||
# move into Topic perhaps
|
||||
group_ids = nil
|
||||
if topic && topic.category && topic.category.read_restricted
|
||||
group_ids = topic.category.groups.pluck("groups.id")
|
||||
group_ids = [Group::AUTO_GROUPS[:admins]]
|
||||
group_ids.concat(topic.category.groups.pluck("groups.id"))
|
||||
end
|
||||
|
||||
if action.user
|
||||
MessageBus.publish("/u/#{action.user.username.downcase}", action.id, user_ids: [user_id], group_ids: group_ids)
|
||||
MessageBus.publish("/u/#{action.user.username_lower}", action.id, user_ids: [user_id], group_ids: group_ids)
|
||||
end
|
||||
|
||||
action
|
||||
|
|
|
@ -35,15 +35,18 @@ describe UserAction do
|
|||
}.merge(opts))
|
||||
end
|
||||
|
||||
describe "integration" do
|
||||
before do
|
||||
# Create some test data using a helper
|
||||
log_test_action
|
||||
log_test_action(action_type: UserAction::GOT_PRIVATE_MESSAGE)
|
||||
log_test_action(action_type: UserAction::NEW_TOPIC, target_topic_id: public_topic.id, target_post_id: public_post.id)
|
||||
log_test_action(action_type: UserAction::BOOKMARK)
|
||||
it "allows publishing when group is deleted" do
|
||||
public_topic.category.update!(read_restricted: true)
|
||||
|
||||
m = MessageBus.track_publish("/u/#{user.username_lower}") do
|
||||
log_test_action(target_topic_id: public_topic.id, target_post_id: public_post.id)
|
||||
end
|
||||
|
||||
expect(m[0].group_ids).to eq([Group::AUTO_GROUPS[:admins]])
|
||||
expect(m[0].user_ids).to eq([user.id])
|
||||
end
|
||||
|
||||
describe "integration" do
|
||||
def stats_for_user(viewer = nil)
|
||||
UserAction.stats(user.id, Guardian.new(viewer)).map { |r| r.action_type.to_i }.sort
|
||||
end
|
||||
|
@ -53,6 +56,12 @@ describe UserAction do
|
|||
end
|
||||
|
||||
it 'includes the events correctly' do
|
||||
# Create some test data using a helper
|
||||
log_test_action
|
||||
log_test_action(action_type: UserAction::GOT_PRIVATE_MESSAGE)
|
||||
log_test_action(action_type: UserAction::NEW_TOPIC, target_topic_id: public_topic.id, target_post_id: public_post.id)
|
||||
log_test_action(action_type: UserAction::BOOKMARK)
|
||||
|
||||
Jobs.run_immediately!
|
||||
PostActionNotifier.enable
|
||||
|
||||
|
|
Loading…
Reference in New Issue