mirror of
https://github.com/discourse/discourse.git
synced 2026-08-11 02:59:07 +08:00
Previously, picking a group in the bulk assign modal always failed with a bodyless 500: the client only sent `username`, `group_name` was not a permitted bulk action parameter, and the bulk operation only ever resolved a `User` — so `Assigner` received `nil`, treated it as a `Group`, and crashed dereferencing it. This change routes both the bulk and single-topic paths through one `DiscourseAssign::AssigneeResolver`, makes `Assigner#assign` return a reason instead of raising for caller-supplied input, and surfaces per-topic refusals through `@errors` so a partially applied bulk assign explains itself instead of reporting success. Ref - t/188206
20 lines
617 B
Ruby
Vendored
20 lines
617 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
module DiscourseAssign
|
|
module AssigneeResolver
|
|
def self.resolve!(guardian, username: nil, group_name: nil)
|
|
username = username.to_s.strip.presence
|
|
group_name = group_name.to_s.strip.presence
|
|
|
|
raise Discourse::InvalidParameters.new(:assignee) if username.blank? && group_name.blank?
|
|
|
|
return User.find_by_username(username) || raise(Discourse::NotFound) if username
|
|
|
|
group = Group.find_by("LOWER(name) = ?", group_name.downcase)
|
|
raise Discourse::NotFound if group.blank?
|
|
guardian.ensure_can_see_group!(group)
|
|
|
|
group
|
|
end
|
|
end
|
|
end
|