Commit e4ab3eff authored by Vitali Tatarintev's avatar Vitali Tatarintev

Use find_object instead of resolve_project

Use `include FindsProject` instead of `resolve_project`
in GraphQL mutations
parent 399fa5f7
......@@ -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,7 +3,7 @@
module Mutations
module JiraImport
class ImportUsers < BaseMutation
include ResolvesProject
include FindsProject
graphql_name 'JiraImportUsers'
......@@ -20,7 +20,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
......@@ -32,10 +32,6 @@ module Mutations
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
......
......@@ -3,7 +3,7 @@
module Mutations
module JiraImport
class Start < BaseMutation
include ResolvesProject
include FindsProject
graphql_name 'JiraImportStart'
......@@ -27,7 +27,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
......@@ -43,10 +43,6 @@ module Mutations
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
......
......@@ -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],
......
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