Commit 5b5fb566 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch '298688-use-find-object-in-graphql-resolvers' into 'master'

Use include FindsProject instead of resolve_project

See merge request gitlab-org/gitlab!52569
parents e18fff6f 585602a1
...@@ -4,7 +4,7 @@ module Mutations ...@@ -4,7 +4,7 @@ module Mutations
module AlertManagement module AlertManagement
module HttpIntegration module HttpIntegration
class Create < HttpIntegrationBase class Create < HttpIntegrationBase
include ResolvesProject include FindsProject
graphql_name 'HttpIntegrationCreate' graphql_name 'HttpIntegrationCreate'
...@@ -21,7 +21,7 @@ module Mutations ...@@ -21,7 +21,7 @@ module Mutations
description: 'Whether the integration is receiving alerts.' description: 'Whether the integration is receiving alerts.'
def resolve(args) def resolve(args)
project = authorized_find!(full_path: args[:project_path]) project = authorized_find!(args[:project_path])
response ::AlertManagement::HttpIntegrations::CreateService.new( response ::AlertManagement::HttpIntegrations::CreateService.new(
project, project,
...@@ -29,12 +29,6 @@ module Mutations ...@@ -29,12 +29,6 @@ module Mutations
http_integration_params(project, args) http_integration_params(project, args)
).execute ).execute
end end
private
def find_object(full_path:)
resolve_project(full_path: full_path)
end
end end
end end
end end
......
...@@ -4,7 +4,7 @@ module Mutations ...@@ -4,7 +4,7 @@ module Mutations
module AlertManagement module AlertManagement
module PrometheusIntegration module PrometheusIntegration
class Create < PrometheusIntegrationBase class Create < PrometheusIntegrationBase
include ResolvesProject include FindsProject
graphql_name 'PrometheusIntegrationCreate' graphql_name 'PrometheusIntegrationCreate'
...@@ -21,7 +21,7 @@ module Mutations ...@@ -21,7 +21,7 @@ module Mutations
description: 'Endpoint at which prometheus can be queried.' description: 'Endpoint at which prometheus can be queried.'
def resolve(args) def resolve(args)
project = authorized_find!(full_path: args[:project_path]) project = authorized_find!(args[:project_path])
return integration_exists if project.prometheus_service return integration_exists if project.prometheus_service
...@@ -37,10 +37,6 @@ module Mutations ...@@ -37,10 +37,6 @@ module Mutations
private private
def find_object(full_path:)
resolve_project(full_path: full_path)
end
def integration_exists def integration_exists
response(nil, message: _('Multiple Prometheus integrations are not supported')) response(nil, message: _('Multiple Prometheus integrations are not supported'))
end end
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Mutations module Mutations
module Branches module Branches
class Create < BaseMutation class Create < BaseMutation
include ResolvesProject include FindsProject
graphql_name 'CreateBranch' graphql_name 'CreateBranch'
...@@ -28,7 +28,7 @@ module Mutations ...@@ -28,7 +28,7 @@ module Mutations
authorize :push_code authorize :push_code
def resolve(project_path:, name:, ref:) def resolve(project_path:, name:, ref:)
project = authorized_find!(full_path: project_path) project = authorized_find!(project_path)
context.scoped_set!(:branch_project, project) context.scoped_set!(:branch_project, project)
...@@ -40,12 +40,6 @@ module Mutations ...@@ -40,12 +40,6 @@ module Mutations
errors: Array.wrap(result[:message]) errors: Array.wrap(result[:message])
} }
end end
private
def find_object(full_path:)
resolve_project(full_path: full_path)
end
end end
end end
end end
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Mutations module Mutations
module Commits module Commits
class Create < BaseMutation class Create < BaseMutation
include ResolvesProject include FindsProject
graphql_name 'CommitCreate' graphql_name 'CommitCreate'
...@@ -37,7 +37,7 @@ module Mutations ...@@ -37,7 +37,7 @@ module Mutations
authorize :push_code authorize :push_code
def resolve(project_path:, branch:, message:, actions:, **args) def resolve(project_path:, branch:, message:, actions:, **args)
project = authorized_find!(full_path: project_path) project = authorized_find!(project_path)
attributes = { attributes = {
commit_message: message, commit_message: message,
...@@ -53,12 +53,6 @@ module Mutations ...@@ -53,12 +53,6 @@ module Mutations
errors: Array.wrap(result[:message]) errors: Array.wrap(result[:message])
} }
end end
private
def find_object(full_path:)
resolve_project(full_path: full_path)
end
end end
end end
end end
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Mutations module Mutations
module ContainerExpirationPolicies module ContainerExpirationPolicies
class Update < Mutations::BaseMutation class Update < Mutations::BaseMutation
include ResolvesProject include FindsProject
graphql_name 'UpdateContainerExpirationPolicy' graphql_name 'UpdateContainerExpirationPolicy'
...@@ -50,7 +50,7 @@ module Mutations ...@@ -50,7 +50,7 @@ module Mutations
description: 'The container expiration policy after mutation.' description: 'The container expiration policy after mutation.'
def resolve(project_path:, **args) def resolve(project_path:, **args)
project = authorized_find!(full_path: project_path) project = authorized_find!(project_path)
result = ::ContainerExpirationPolicies::UpdateService result = ::ContainerExpirationPolicies::UpdateService
.new(container: project, current_user: current_user, params: args) .new(container: project, current_user: current_user, params: args)
...@@ -61,12 +61,6 @@ module Mutations ...@@ -61,12 +61,6 @@ module Mutations
errors: result.errors errors: result.errors
} }
end end
private
def find_object(full_path:)
resolve_project(full_path: full_path)
end
end end
end end
end end
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Mutations module Mutations
module Issues module Issues
class Create < BaseMutation class Create < BaseMutation
include ResolvesProject include FindsProject
graphql_name 'CreateIssue' graphql_name 'CreateIssue'
authorize :create_issue authorize :create_issue
...@@ -70,7 +70,7 @@ module Mutations ...@@ -70,7 +70,7 @@ module Mutations
end end
def resolve(project_path:, **attributes) def resolve(project_path:, **attributes)
project = authorized_find!(full_path: project_path) project = authorized_find!(project_path)
params = build_create_issue_params(attributes.merge(author_id: current_user.id)) params = build_create_issue_params(attributes.merge(author_id: current_user.id))
issue = ::Issues::CreateService.new(project, current_user, params).execute issue = ::Issues::CreateService.new(project, current_user, params).execute
...@@ -98,10 +98,6 @@ module Mutations ...@@ -98,10 +98,6 @@ module Mutations
def mutually_exclusive_label_args def mutually_exclusive_label_args
[:labels, :label_ids] [:labels, :label_ids]
end end
def find_object(full_path:)
resolve_project(full_path: full_path)
end
end end
end end
end end
......
...@@ -3,10 +3,12 @@ ...@@ -3,10 +3,12 @@
module Mutations module Mutations
module JiraImport module JiraImport
class ImportUsers < BaseMutation class ImportUsers < BaseMutation
include ResolvesProject include FindsProject
graphql_name 'JiraImportUsers' graphql_name 'JiraImportUsers'
authorize :admin_project
field :jira_users, field :jira_users,
[Types::JiraUserType], [Types::JiraUserType],
null: true, null: true,
...@@ -20,7 +22,7 @@ module Mutations ...@@ -20,7 +22,7 @@ module Mutations
description: 'The index of the record the import should started at, default 0 (50 records returned).' description: 'The index of the record the import should started at, default 0 (50 records returned).'
def resolve(project_path:, start_at: 0) def resolve(project_path:, start_at: 0)
project = authorized_find!(full_path: project_path) project = authorized_find!(project_path)
service_response = ::JiraImport::UsersImporter.new(context[:current_user], project, start_at.to_i).execute service_response = ::JiraImport::UsersImporter.new(context[:current_user], project, start_at.to_i).execute
...@@ -29,16 +31,6 @@ module Mutations ...@@ -29,16 +31,6 @@ module Mutations
errors: service_response.errors errors: service_response.errors
} }
end end
private
def find_object(full_path:)
resolve_project(full_path: full_path)
end
def authorized_resource?(project)
Ability.allowed?(context[:current_user], :admin_project, project)
end
end end
end end
end end
...@@ -3,10 +3,12 @@ ...@@ -3,10 +3,12 @@
module Mutations module Mutations
module JiraImport module JiraImport
class Start < BaseMutation class Start < BaseMutation
include ResolvesProject include FindsProject
graphql_name 'JiraImportStart' graphql_name 'JiraImportStart'
authorize :admin_project
field :jira_import, field :jira_import,
Types::JiraImportType, Types::JiraImportType,
null: true, null: true,
...@@ -27,7 +29,7 @@ module Mutations ...@@ -27,7 +29,7 @@ module Mutations
description: 'The mapping of Jira to GitLab users.' description: 'The mapping of Jira to GitLab users.'
def resolve(project_path:, jira_project_key:, users_mapping:) def resolve(project_path:, jira_project_key:, users_mapping:)
project = authorized_find!(full_path: project_path) project = authorized_find!(project_path)
mapping = users_mapping.to_ary.map { |map| map.to_hash } mapping = users_mapping.to_ary.map { |map| map.to_hash }
service_response = ::JiraImport::StartImportService service_response = ::JiraImport::StartImportService
...@@ -40,16 +42,6 @@ module Mutations ...@@ -40,16 +42,6 @@ module Mutations
errors: service_response.errors errors: service_response.errors
} }
end end
private
def find_object(full_path:)
resolve_project(full_path: full_path)
end
def authorized_resource?(project)
Ability.allowed?(context[:current_user], :admin_project, project)
end
end end
end end
end end
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Mutations module Mutations
module MergeRequests module MergeRequests
class Create < BaseMutation class Create < BaseMutation
include ResolvesProject include FindsProject
graphql_name 'MergeRequestCreate' graphql_name 'MergeRequestCreate'
...@@ -39,7 +39,7 @@ module Mutations ...@@ -39,7 +39,7 @@ module Mutations
authorize :create_merge_request_from authorize :create_merge_request_from
def resolve(project_path:, **attributes) def resolve(project_path:, **attributes)
project = authorized_find!(full_path: project_path) project = authorized_find!(project_path)
params = attributes.merge(author_id: current_user.id) params = attributes.merge(author_id: current_user.id)
merge_request = ::MergeRequests::CreateService.new(project, current_user, params).execute merge_request = ::MergeRequests::CreateService.new(project, current_user, params).execute
...@@ -49,12 +49,6 @@ module Mutations ...@@ -49,12 +49,6 @@ module Mutations
errors: errors_on_object(merge_request) errors: errors_on_object(merge_request)
} }
end end
private
def find_object(full_path:)
resolve_project(full_path: full_path)
end
end end
end end
end end
...@@ -3,17 +3,11 @@ ...@@ -3,17 +3,11 @@
module Mutations module Mutations
module Releases module Releases
class Base < BaseMutation class Base < BaseMutation
include ResolvesProject include FindsProject
argument :project_path, GraphQL::ID_TYPE, argument :project_path, GraphQL::ID_TYPE,
required: true, required: true,
description: 'Full path of the project the release is associated with.' description: 'Full path of the project the release is associated with.'
private
def find_object(full_path:)
resolve_project(full_path: full_path)
end
end end
end end
end end
...@@ -41,7 +41,7 @@ module Mutations ...@@ -41,7 +41,7 @@ module Mutations
authorize :create_release authorize :create_release
def resolve(project_path:, assets: nil, **scalars) def resolve(project_path:, assets: nil, **scalars)
project = authorized_find!(full_path: project_path) project = authorized_find!(project_path)
params = { params = {
**scalars, **scalars,
......
...@@ -17,7 +17,7 @@ module Mutations ...@@ -17,7 +17,7 @@ module Mutations
authorize :destroy_release authorize :destroy_release
def resolve(project_path:, tag:) def resolve(project_path:, tag:)
project = authorized_find!(full_path: project_path) project = authorized_find!(project_path)
params = { tag: tag }.with_indifferent_access params = { tag: tag }.with_indifferent_access
......
...@@ -47,7 +47,7 @@ module Mutations ...@@ -47,7 +47,7 @@ module Mutations
end end
def resolve(project_path:, **scalars) def resolve(project_path:, **scalars)
project = authorized_find!(full_path: project_path) project = authorized_find!(project_path)
params = scalars.with_indifferent_access params = scalars.with_indifferent_access
......
...@@ -4,7 +4,7 @@ module Mutations ...@@ -4,7 +4,7 @@ module Mutations
module Security module Security
module CiConfiguration module CiConfiguration
class ConfigureSast < BaseMutation class ConfigureSast < BaseMutation
include ResolvesProject include FindsProject
graphql_name 'ConfigureSast' graphql_name 'ConfigureSast'
...@@ -25,7 +25,7 @@ module Mutations ...@@ -25,7 +25,7 @@ module Mutations
authorize :push_code authorize :push_code
def resolve(project_path:, configuration:) def resolve(project_path:, configuration:)
project = authorized_find!(full_path: project_path) project = authorized_find!(project_path)
result = ::Security::CiConfiguration::SastCreateService.new(project, current_user, configuration).execute result = ::Security::CiConfiguration::SastCreateService.new(project, current_user, configuration).execute
prepare_response(result) prepare_response(result)
...@@ -33,10 +33,6 @@ module Mutations ...@@ -33,10 +33,6 @@ module Mutations
private private
def find_object(full_path:)
resolve_project(full_path: full_path)
end
def prepare_response(result) def prepare_response(result)
{ {
status: result[:status], status: result[:status],
......
...@@ -4,7 +4,7 @@ module Mutations ...@@ -4,7 +4,7 @@ module Mutations
module Clusters module Clusters
module Agents module Agents
class Create < BaseMutation class Create < BaseMutation
include ResolvesProject include FindsProject
authorize :create_cluster authorize :create_cluster
...@@ -24,7 +24,7 @@ module Mutations ...@@ -24,7 +24,7 @@ module Mutations
description: 'Cluster agent created after mutation.' description: 'Cluster agent created after mutation.'
def resolve(project_path:, name:) def resolve(project_path:, name:)
project = authorized_find!(full_path: project_path) project = authorized_find!(project_path)
result = ::Clusters::Agents::CreateService.new(project, current_user).execute(name: name) result = ::Clusters::Agents::CreateService.new(project, current_user).execute(name: name)
{ {
...@@ -32,12 +32,6 @@ module Mutations ...@@ -32,12 +32,6 @@ module Mutations
errors: Array.wrap(result[:message]) errors: Array.wrap(result[:message])
} }
end end
private
def find_object(full_path:)
resolve_project(full_path: full_path)
end
end end
end end
end end
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Mutations module Mutations
module DastScannerProfiles module DastScannerProfiles
class Update < BaseMutation class Update < BaseMutation
include ResolvesProject include FindsProject
graphql_name 'DastScannerProfileUpdate' graphql_name 'DastScannerProfileUpdate'
...@@ -53,7 +53,7 @@ module Mutations ...@@ -53,7 +53,7 @@ module Mutations
# See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883 # See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883
gid = ::Types::GlobalIDType[::DastScannerProfile].coerce_isolated_input(service_args[:id]) gid = ::Types::GlobalIDType[::DastScannerProfile].coerce_isolated_input(service_args[:id])
project = authorized_find!(full_path: full_path) project = authorized_find!(full_path)
service = ::DastScannerProfiles::UpdateService.new(project, current_user) service = ::DastScannerProfiles::UpdateService.new(project, current_user)
result = service.execute(**service_args, id: gid.model_id) result = service.execute(**service_args, id: gid.model_id)
...@@ -64,12 +64,6 @@ module Mutations ...@@ -64,12 +64,6 @@ module Mutations
{ errors: result.errors } { errors: result.errors }
end end
end end
private
def find_object(full_path:)
resolve_project(full_path: full_path)
end
end end
end end
end end
...@@ -4,7 +4,7 @@ module Mutations ...@@ -4,7 +4,7 @@ module Mutations
module IncidentManagement module IncidentManagement
module OncallSchedule module OncallSchedule
class Create < OncallScheduleBase class Create < OncallScheduleBase
include ResolvesProject include FindsProject
graphql_name 'OncallScheduleCreate' graphql_name 'OncallScheduleCreate'
...@@ -25,7 +25,7 @@ module Mutations ...@@ -25,7 +25,7 @@ module Mutations
description: 'The timezone of the on-call schedule.' description: 'The timezone of the on-call schedule.'
def resolve(args) def resolve(args)
project = authorized_find!(full_path: args[:project_path]) project = authorized_find!(args[:project_path])
response ::IncidentManagement::OncallSchedules::CreateService.new( response ::IncidentManagement::OncallSchedules::CreateService.new(
project, project,
...@@ -33,12 +33,6 @@ module Mutations ...@@ -33,12 +33,6 @@ module Mutations
args.slice(:name, :description, :timezone) args.slice(:name, :description, :timezone)
).execute ).execute
end end
private
def find_object(full_path:)
resolve_project(full_path: full_path)
end
end end
end end
end end
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Mutations module Mutations
module Pipelines module Pipelines
class RunDastScan < BaseMutation class RunDastScan < BaseMutation
include ResolvesProject include FindsProject
graphql_name 'RunDASTScan' graphql_name 'RunDASTScan'
...@@ -30,7 +30,7 @@ module Mutations ...@@ -30,7 +30,7 @@ module Mutations
authorize :create_on_demand_dast_scan authorize :create_on_demand_dast_scan
def resolve(project_path:, target_url:, branch:, scan_type:) def resolve(project_path:, target_url:, branch:, scan_type:)
project = authorized_find!(full_path: project_path) project = authorized_find!(project_path)
service = ::Ci::RunDastScanService.new(project, current_user) service = ::Ci::RunDastScanService.new(project, current_user)
result = service.execute(branch: branch, target_url: target_url) result = service.execute(branch: branch, target_url: target_url)
...@@ -44,10 +44,6 @@ module Mutations ...@@ -44,10 +44,6 @@ module Mutations
private private
def find_object(full_path:)
resolve_project(full_path: full_path)
end
def success_response(project:, pipeline:) def success_response(project:, pipeline:)
pipeline_url = Rails.application.routes.url_helpers.project_pipeline_url( pipeline_url = Rails.application.routes.url_helpers.project_pipeline_url(
project, project,
......
...@@ -4,7 +4,7 @@ module Mutations ...@@ -4,7 +4,7 @@ module Mutations
module QualityManagement module QualityManagement
module TestCases module TestCases
class Create < BaseMutation class Create < BaseMutation
include ResolvesProject include FindsProject
graphql_name 'CreateTestCase' graphql_name 'CreateTestCase'
...@@ -33,7 +33,7 @@ module Mutations ...@@ -33,7 +33,7 @@ module Mutations
def resolve(args) def resolve(args)
project_path = args.delete(:project_path) project_path = args.delete(:project_path)
project = authorized_find!(full_path: project_path) project = authorized_find!(project_path)
result = ::QualityManagement::TestCases::CreateService.new( result = ::QualityManagement::TestCases::CreateService.new(
project, project,
...@@ -48,12 +48,6 @@ module Mutations ...@@ -48,12 +48,6 @@ module Mutations
errors: Array.wrap(result.message) errors: Array.wrap(result.message)
} }
end end
private
def find_object(full_path:)
resolve_project(full_path: full_path)
end
end end
end end
end end
......
...@@ -3,13 +3,15 @@ ...@@ -3,13 +3,15 @@
module Mutations module Mutations
module RequirementsManagement module RequirementsManagement
class CreateRequirement < BaseRequirement class CreateRequirement < BaseRequirement
include FindsProject
graphql_name 'CreateRequirement' graphql_name 'CreateRequirement'
authorize :create_requirement authorize :create_requirement
def resolve(args) def resolve(args)
project_path = args.delete(:project_path) project_path = args.delete(:project_path)
project = authorized_find!(full_path: project_path) project = authorized_find!(project_path)
requirement = ::RequirementsManagement::CreateRequirementService.new( requirement = ::RequirementsManagement::CreateRequirementService.new(
project, project,
...@@ -22,12 +24,6 @@ module Mutations ...@@ -22,12 +24,6 @@ module Mutations
errors: errors_on_object(requirement) errors: errors_on_object(requirement)
} }
end end
private
def find_object(full_path:)
resolve_project(full_path: full_path)
end
end end
end end
end end
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Mutations module Mutations
module RequirementsManagement module RequirementsManagement
class ExportRequirements < BaseMutation class ExportRequirements < BaseMutation
include ResolvesProject include FindsProject
include CommonRequirementArguments include CommonRequirementArguments
graphql_name 'ExportRequirements' graphql_name 'ExportRequirements'
...@@ -16,19 +16,13 @@ module Mutations ...@@ -16,19 +16,13 @@ module Mutations
def resolve(args) def resolve(args)
project_path = args.delete(:project_path) project_path = args.delete(:project_path)
project = authorized_find!(full_path: project_path) project = authorized_find!(project_path)
IssuableExportCsvWorker.perform_async(:requirement, current_user.id, project.id, args) IssuableExportCsvWorker.perform_async(:requirement, current_user.id, project.id, args)
{ {
errors: [] errors: []
} }
end end
private
def find_object(full_path:)
resolve_project(full_path: full_path)
end
end end
end end
end end
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