Skip to content

A platform for community discussion. Free, open, simple.

FIX: Publish "/staff/topic-assignment" on topic re-open (#39542)

Jarek Radoszf207f79b71d5
diff --git a/plugins/discourse-assign/app/models/assignment.rb b/plugins/discourse-assign/app/models/assignment.rb
index bf28baf34b5..078bfd3901c 100644
--- a/plugins/discourse-assign/app/models/assignment.rb
+++ b/plugins/discourse-assign/app/models/assignment.rb
@@ -81,6 +81,7 @@ class Assignment < ActiveRecord::Base
return unless target
update!(active: true)
Jobs.enqueue(:assign_notification, assignment_id: id)
+ publish_topic_assignment
end
def deactivate!
@@ -94,6 +95,26 @@ class Assignment < ActiveRecord::Base
)
end
+ def publish_topic_assignment
+ return if !assigned_to
+
+ serializer_class = assigned_to_user? ? BasicUserSerializer : BasicGroupSerializer
+ MessageBus.publish(
+ "/staff/topic-assignment",
+ {
+ type: "assigned",
+ topic_id: topic_id,
+ post_id: target.is_a?(Post) && target.id,
+ post_number: target.is_a?(Post) && target.post_number,
+ assigned_type: assigned_to_type,
+ assigned_to: serializer_class.new(assigned_to, scope: Guardian.new, root: false).as_json,
+ assignment_note: note,
+ assignment_status: status,
+ },
+ user_ids: User.assign_allowed.pluck(:id),
+ )
+ end
+
private
def default_status
diff --git a/plugins/discourse-assign/lib/assigner.rb b/plugins/discourse-assign/lib/assigner.rb
index 71c05d8f1f3..170695461f8 100644
--- a/plugins/discourse-assign/lib/assigner.rb
+++ b/plugins/discourse-assign/lib/assigner.rb
@@ -241,7 +241,7 @@ class ::Assigner
@target.assignment.update!(note: note, status: status)
queue_notification(@target.assignment) if should_notify
- publish_assignment(@target.assignment, assign_to, note, status)
+ @target.assignment.publish_topic_assignment
# email is skipped, for now
@@ -326,7 +326,7 @@ class ::Assigner
# This assignment should never be notified
SilencedAssignment.create!(assignment_id: assignment.id) if !should_notify
- publish_assignment(assignment, assign_to, note, status)
+ assignment.publish_topic_assignment
if assignment.assigned_to_user?
if !assign_to.user_option.do_nothing_when_assigned?
@@ -523,24 +523,6 @@ class ::Assigner
)
end
- def publish_assignment(assignment, assign_to, note, status)
- serializer = assignment.assigned_to_user? ? BasicUserSerializer : BasicGroupSerializer
- MessageBus.publish(
- "/staff/topic-assignment",
- {
- type: "assigned",
- topic_id: topic.id,
- post_id: post_target? && @target.id,
- post_number: post_target? && @target.post_number,
- assigned_type: assignment.assigned_to_type,
- assigned_to: serializer.new(assign_to, scope: Guardian.new, root: false).as_json,
- assignment_note: note,
- assignment_status: status,
- },
- user_ids: allowed_user_ids,
- )
- end
-
def moderator_post_assign_action_code(assignment, action_code)
if assignment.target.is_a?(Post)
# posts do not have to handle conditions of 'assign' or 'reassign'
diff --git a/plugins/discourse-assign/spec/system/assign_post_spec.rb b/plugins/discourse-assign/spec/system/assign_post_spec.rb
index dece8221eb0..0f1e1c3bbc4 100644
--- a/plugins/discourse-assign/spec/system/assign_post_spec.rb
+++ b/plugins/discourse-assign/spec/system/assign_post_spec.rb
@@ -13,8 +13,6 @@ describe "Assign | Assigning posts" do
SiteSetting.assign_enabled = true
SiteSetting.whispers_allowed_groups = "#{Group::AUTO_GROUPS[:staff]}"
SiteSetting.prioritize_full_name_in_ux = false
- # The system tests in this file are flaky and auth token related so turning this on
- SiteSetting.verbose_auth_token_logging = true
sign_in(admin)
end
@@ -74,9 +72,7 @@ describe "Assign | Assigning posts" do
it "show the user's username if there is no name" do
visit "/t/#{topic.id}"
- staff_user.name = nil
- staff_user.save
- staff_user.reload
+ staff_user.update!(name: nil)
assign_post(post2, staff_user)
diff --git a/plugins/discourse-assign/spec/system/assign_topic_spec.rb b/plugins/discourse-assign/spec/system/assign_topic_spec.rb
index 16af06531c6..43682eb9935 100644
--- a/plugins/discourse-assign/spec/system/assign_topic_spec.rb
+++ b/plugins/discourse-assign/spec/system/assign_topic_spec.rb
@@ -78,9 +78,7 @@ describe "Assign | Assigning topics" do
it "show the user's username if there is no name" do
visit "/t/#{topic.id}"
- admin2.name = nil
- admin2.save!
- admin2.reload
+ admin2.update!(name: nil)
topic_page.click_assign_topic
assign_modal.assignee = admin2
@@ -163,7 +161,6 @@ describe "Assign | Assigning topics" do
before { SiteSetting.reassign_on_open = true }
it "reassigns the topic on open" do
- skip_on_ci!("Flaky test - reassigning topic on open")
visit "/t/#{topic.id}"
topic_page.click_assign_topic
@@ -189,10 +186,7 @@ describe "Assign | Assigning topics" do
I18n.t("js.action_codes.closed.disabled", when: "just now"),
)
expect(page).to have_no_css("#post_5")
-
- try_until_success(reason: "Relies on MessageBus updates") do
- expect(find("#topic .assigned-to")).to have_content(admin2.username)
- end
+ expect(find("#topic .assigned-to")).to have_content(admin2.username)
end
end
end