Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Correctly publish messages unconditionally to admins #13053

Merged
merged 1 commit into from May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/models/user_action.rb
Expand Up @@ -283,14 +283,14 @@ def self.log_action!(hash)
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
Expand Down
23 changes: 16 additions & 7 deletions spec/models/user_action_spec.rb
Expand Up @@ -35,15 +35,18 @@ def log_test_action(opts = {})
}.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
Expand All @@ -53,6 +56,12 @@ def stream(viewer = nil)
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

Expand Down