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 ...@@ -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,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Mutations module Mutations
module JiraImport module JiraImport
class ImportUsers < BaseMutation class ImportUsers < BaseMutation
include ResolvesProject include FindsProject
graphql_name 'JiraImportUsers' graphql_name 'JiraImportUsers'
...@@ -20,7 +20,7 @@ module Mutations ...@@ -20,7 +20,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
...@@ -32,10 +32,6 @@ module Mutations ...@@ -32,10 +32,6 @@ module Mutations
private private
def find_object(full_path:)
resolve_project(full_path: full_path)
end
def authorized_resource?(project) def authorized_resource?(project)
Ability.allowed?(context[:current_user], :admin_project, project) Ability.allowed?(context[:current_user], :admin_project, project)
end end
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Mutations module Mutations
module JiraImport module JiraImport
class Start < BaseMutation class Start < BaseMutation
include ResolvesProject include FindsProject
graphql_name 'JiraImportStart' graphql_name 'JiraImportStart'
...@@ -27,7 +27,7 @@ module Mutations ...@@ -27,7 +27,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
...@@ -43,10 +43,6 @@ module Mutations ...@@ -43,10 +43,6 @@ module Mutations
private private
def find_object(full_path:)
resolve_project(full_path: full_path)
end
def authorized_resource?(project) def authorized_resource?(project)
Ability.allowed?(context[:current_user], :admin_project, project) Ability.allowed?(context[:current_user], :admin_project, project)
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],
......
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