Commit ac235c10 authored by Alex Kalderimis's avatar Alex Kalderimis

Ensure that existing usages of GlobalIDType continue to work

Early adopters need to have the coercion added to their code.

In the case of dast_site_profiles/update_service, I have also changed
the service code from operating on global-ids to integer ids, since no
use was being made of advanced features (#model_id was called
unconditionally, which meant you could have passed in any kind of ID).
parent 37748122
......@@ -29,11 +29,15 @@ module Mutations
private
def parameters(**args)
args.transform_values { |id| GitlabSchema.find_by_gid(id) }.transform_values(&:sync).tap do |hash|
args.transform_values { |id| find_design(id) }.transform_values(&:sync).tap do |hash|
hash.each { |k, design| not_found(args[k]) unless current_user.can?(:read_design, design) }
end
end
def find_design(id)
GitlabSchema.object_from_id(DesignID.coerce_isolated_input(id))
end
def not_found(gid)
raise Gitlab::Graphql::Errors::ResourceNotAvailable, "Resource not available: #{gid}"
end
......
......@@ -49,8 +49,7 @@ module Types
field :milestone, ::Types::MilestoneType,
null: true,
description: 'Find a milestone',
resolve: -> (_obj, args, _ctx) { GitlabSchema.find_by_gid(args[:id]) } do
description: 'Find a milestone' do
argument :id, ::Types::GlobalIDType[Milestone],
required: true,
description: 'Find a milestone by its ID'
......@@ -86,7 +85,13 @@ module Types
end
def issue(id:)
GitlabSchema.object_from_id(id, expected_type: ::Issue)
id = ::Types::GlobalIDType[::Issue].coerce_isolated_input(id)
GitlabSchema.find_by_gid(id)
end
def milestone(id:)
id = ::Types::GlobalIDType[Milestone].coerce_isolated_input(id)
GitlabSchema.find_by_gid(id)
end
end
end
......
......@@ -8,7 +8,6 @@ module EE
prepended do
field :iteration, ::Types::IterationType,
null: true,
resolve: -> (_obj, args, _ctx) { ::GitlabSchema.find_by_gid(args[:id]) },
description: 'Find an iteration' do
argument :id, ::Types::GlobalIDType[::Iteration],
required: true,
......@@ -54,6 +53,10 @@ module EE
resolver: ::Resolvers::InstanceSecurityDashboardResolver,
description: 'Fields related to Instance Security Dashboard'
end
def iteration(id:)
::GitlabSchema.find_by_gid(::Types::GlobalIDType[Iteration].coerce_isolated_input(id))
end
end
end
end
......@@ -30,6 +30,8 @@ module Mutations
def resolve(full_path:, dast_site_profile_id:, **args)
project = authorized_find_project!(full_path: full_path)
# TODO: remove explicit coercion once compatibility layer is removed
dast_site_profile_id = ::Types::GlobalIDType[::DastSiteProfile].coerce_isolated_input(dast_site_profile_id)
dast_site_profile = find_dast_site_profile(project: project, dast_site_profile_id: dast_site_profile_id)
dast_site = dast_site_profile.dast_site
dast_scanner_profile = find_dast_scanner_profile(project: project, dast_scanner_profile_id: args[:dast_scanner_profile_id])
......
......@@ -19,6 +19,9 @@ module Mutations
def resolve(full_path:, id:)
project = authorized_find_project!(full_path: full_path)
# TODO: remove explicit coercion once compatibility layer is removed
id = ::Types::GlobalIDType[::DastSiteProfile].coerce_isolated_input(id)
dast_site_profile = find_dast_site_profile(project: project, global_id: id)
return { errors: dast_site_profile.errors.full_messages } unless dast_site_profile.destroy
......
......@@ -29,7 +29,9 @@ module Mutations
authorize :create_on_demand_dast_scan
def resolve(full_path:, **service_args)
def resolve(full_path:, id:, **service_args)
# TODO: remove explicit coercion once compatibility layer has been removed
service_args[:id] = ::Types::GlobalIDType[::DastSiteProfile].coerce_isolated_input(id).model_id
project = authorized_find_project!(full_path: full_path)
service = ::DastSiteProfiles::UpdateService.new(project, current_user)
......
......@@ -30,7 +30,7 @@ module DastSiteProfiles
# rubocop: disable CodeReuse/ActiveRecord
def find_dast_site_profile!(id)
DastSiteProfilesFinder.new(project_id: project.id, id: id.model_id).execute.first!
DastSiteProfilesFinder.new(project_id: project.id, id: id).execute.first!
end
# rubocop: enable CodeReuse/ActiveRecord
end
......
......@@ -17,7 +17,7 @@ RSpec.describe DastSiteProfiles::UpdateService do
describe '#execute' do
subject do
described_class.new(project, user).execute(
id: dast_site_profile.to_global_id,
id: dast_site_profile.id,
profile_name: new_profile_name,
target_url: new_target_url
)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment