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