Skip to content

Commit

Permalink
[#57264] fixed callback href for not persisted models
Browse files Browse the repository at this point in the history
  • Loading branch information
Kharonus committed Oct 7, 2024
1 parent 80765dd commit b0693bc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
10 changes: 6 additions & 4 deletions lib/api/v3/utilities/custom_field_injector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,16 @@ def allowed_users_href_callback
static_filters = allowed_users_static_filters
instance_filters = method(:allowed_users_instance_filter)

represented_is_clazz = lambda do |represented, clazz|
represented.respond_to?(:model) && represented.model.is_a?(clazz)
represented_is_existent_instance = lambda do |represented, clazz|
represented.respond_to?(:model) &&
represented.model.is_a?(clazz) &&
represented.model.id.present?
end

->(*) {
if represented_is_clazz.(represented, Project)
if represented_is_existent_instance.(represented, Project)
api_v3_paths.available_assignees_in_project(represented.id)
elsif represented_is_clazz.(represented, WorkPackage)
elsif represented_is_existent_instance.(represented, WorkPackage)
api_v3_paths.available_assignees_in_work_package(represented.id)
else
filters = static_filters + instance_filters.call(represented)
Expand Down
24 changes: 13 additions & 11 deletions spec/lib/api/v3/utilities/custom_field_injector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@
is_required: true)
end

before do
allow(schema)
.to receive(:id)
.and_return(model.id)
end

it_behaves_like "has basic schema properties" do
let(:path) { cf_path }
let(:type) { "User" }
Expand All @@ -278,17 +284,7 @@

it_behaves_like "links to allowed values via collection link" do
let(:path) { cf_path }
let(:href) do
params = [
{ status: { operator: "!", values: [Principal.statuses[:locked].to_s] } },
{ type: { operator: "=", values: %w[User Group PlaceholderUser] } },
{ member: { operator: "=", values: [schema.project_id.to_s] } }
]

query = CGI.escape(JSON.dump(params))

"#{api_v3_paths.principals}?filters=#{query}&pageSize=-1"
end
let(:href) { api_v3_paths.available_assignees_in_work_package(model.id) }
end
end

Expand All @@ -305,6 +301,12 @@
is_required: true)
end

before do
allow(schema)
.to receive(:project_id)
.and_return(nil)
end

it_behaves_like "links to allowed values via collection link" do
let(:path) { cf_path }
let(:href) do
Expand Down

0 comments on commit b0693bc

Please sign in to comment.