Commit 10b32d0b authored by Alex Kalderimis's avatar Alex Kalderimis

Remove remaining indirect loads from DAST mutations

This removes a level of indirection, which is unnecessary since
mutations cannot make use of parallel loading.

`AuthorizesProject` is renamed to the more accurate `FindProject`
(authorization itself remains a property of the including class).
parent 27f26bdc
# frozen_string_literal: true
module Mutations
module AuthorizesProject
include ResolvesProject
def authorized_find_project!(full_path:)
authorized_find!(full_path: full_path)
end
private
def find_object(full_path:)
resolve_project(full_path: full_path)
end
end
end
# frozen_string_literal: true
module Mutations
module FindsProject
private
def find_object(full_path)
Project.find_by_full_path(full_path)
end
end
end
......@@ -3,9 +3,9 @@
module Mutations
module DastOnDemandScans
class Create < BaseMutation
InvalidGlobalID = Class.new(StandardError)
include FindsProject
include AuthorizesProject
InvalidGlobalID = Class.new(StandardError)
graphql_name 'DastOnDemandScanCreate'
......@@ -28,7 +28,7 @@ module Mutations
authorize :create_on_demand_dast_scan
def resolve(full_path:, dast_site_profile_id:, **args)
project = authorized_find_project!(full_path: full_path)
project = authorized_find!(full_path)
dast_site_profile = find_dast_site_profile(project, dast_site_profile_id)
dast_scanner_profile = find_dast_scanner_profile(project, args[:dast_scanner_profile_id])
......
......@@ -3,7 +3,7 @@
module Mutations
module DastScannerProfiles
class Create < BaseMutation
include AuthorizesProject
include FindsProject
graphql_name 'DastScannerProfileCreate'
......@@ -53,7 +53,7 @@ module Mutations
authorize :create_on_demand_dast_scan
def resolve(full_path:, profile_name:, spider_timeout: nil, target_timeout: nil, scan_type:, use_ajax_spider:, show_debug_messages:)
project = authorized_find_project!(full_path: full_path)
project = authorized_find!(full_path)
service = ::DastScannerProfiles::CreateService.new(project, current_user)
result = service.execute(
......
......@@ -3,7 +3,7 @@
module Mutations
module DastScannerProfiles
class Delete < BaseMutation
include AuthorizesProject
include FindsProject
graphql_name 'DastScannerProfileDelete'
......@@ -24,7 +24,7 @@ module Mutations
# See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883
id = ScannerProfileID.coerce_isolated_input(id)
project = authorized_find_project!(full_path: full_path)
project = authorized_find!(full_path)
service = ::DastScannerProfiles::DestroyService.new(project, current_user)
result = service.execute(id: id.model_id)
......
......@@ -3,7 +3,7 @@
module Mutations
module DastSiteProfiles
class Create < BaseMutation
include AuthorizesProject
include FindsProject
graphql_name 'DastSiteProfileCreate'
......@@ -26,7 +26,7 @@ module Mutations
authorize :create_on_demand_dast_scan
def resolve(full_path:, profile_name:, target_url: nil)
project = authorized_find_project!(full_path: full_path)
project = authorized_find!(full_path)
service = ::DastSiteProfiles::CreateService.new(project, current_user)
result = service.execute(name: profile_name, target_url: target_url)
......
......@@ -3,7 +3,7 @@
module Mutations
module DastSiteProfiles
class Update < BaseMutation
include AuthorizesProject
include FindsProject
graphql_name 'DastSiteProfileUpdate'
......@@ -33,7 +33,7 @@ module Mutations
# TODO: remove explicit coercion once compatibility layer has been removed
# See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883
service_args[:id] = ::Types::GlobalIDType[::DastSiteProfile].coerce_isolated_input(id).model_id
project = authorized_find_project!(full_path: full_path)
project = authorized_find!(full_path)
service = ::DastSiteProfiles::UpdateService.new(project, current_user)
result = service.execute(**service_args)
......
......@@ -3,7 +3,7 @@
module Mutations
module DastSiteTokens
class Create < BaseMutation
include AuthorizesProject
include FindsProject
graphql_name 'DastSiteTokenCreate'
......@@ -30,7 +30,7 @@ module Mutations
authorize :create_on_demand_dast_scan
def resolve(full_path:, target_url:)
project = authorized_find_project!(full_path: full_path)
project = authorized_find!(full_path)
raise Gitlab::Graphql::Errors::ResourceNotAvailable, 'Feature disabled' unless allowed?(project)
response = ::DastSiteTokens::CreateService.new(
......
......@@ -3,7 +3,7 @@
module Mutations
module DastSiteValidations
class Create < BaseMutation
include AuthorizesProject
include FindsProject
graphql_name 'DastSiteValidationCreate'
......@@ -34,7 +34,7 @@ module Mutations
authorize :create_on_demand_dast_scan
def resolve(full_path:, dast_site_token_id:, validation_path:, strategy: :text_file)
project = authorized_find_project!(full_path: full_path)
project = authorized_find!(full_path)
raise Gitlab::Graphql::Errors::ResourceNotAvailable, 'Feature disabled' unless allowed?(project)
dast_site_token = dast_site_token_id.find
......
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