Commit 9111404d authored by Jan Provaznik's avatar Jan Provaznik

Use ResolveResourceParent mixing for iterations

This dries a little bit the code by reusing same logic from mixin.
parent 405e447b
......@@ -5095,12 +5095,12 @@ input CreateIterationInput {
dueDate: String
"""
The target group for the iteration.
Full path of the group with which the resource is associated.
"""
groupPath: ID
"""
The target project for the iteration.
Full path of the project with which the resource is associated.
"""
projectPath: ID
......
......@@ -13827,8 +13827,8 @@
"fields": null,
"inputFields": [
{
"name": "groupPath",
"description": "The target group for the iteration.",
"name": "projectPath",
"description": "Full path of the project with which the resource is associated.",
"type": {
"kind": "SCALAR",
"name": "ID",
......@@ -13837,8 +13837,8 @@
"defaultValue": null
},
{
"name": "projectPath",
"description": "The target project for the iteration.",
"name": "groupPath",
"description": "Full path of the group with which the resource is associated.",
"type": {
"kind": "SCALAR",
"name": "ID",
......@@ -3,8 +3,7 @@
module Mutations
module Iterations
class Create < BaseMutation
include Mutations::ResolvesGroup
include ResolvesProject
include Mutations::ResolvesResourceParent
graphql_name 'CreateIteration'
......@@ -15,14 +14,6 @@ module Mutations
null: true,
description: 'The created iteration.'
argument :group_path, GraphQL::ID_TYPE,
required: false,
description: "The target group for the iteration."
argument :project_path, GraphQL::ID_TYPE,
required: false,
description: "The target project for the iteration."
argument :title,
GraphQL::STRING_TYPE,
required: false,
......@@ -46,7 +37,7 @@ module Mutations
def resolve(args)
validate_arguments!(args)
parent = find_parent(args)
parent = authorized_resource_parent_find!(args)
response = ::Iterations::CreateService.new(parent, current_user, args).execute
......@@ -61,40 +52,11 @@ module Mutations
private
def find_object(group_path: nil, project_path: nil)
if group_path
resolve_group(full_path: group_path)
elsif project_path
resolve_project(full_path: project_path)
end
end
def find_parent(args)
group_path = args.delete(:group_path)
project_path = args.delete(:project_path)
if group_path
authorized_find!(group_path: group_path)
elsif project_path
authorized_find!(project_path: project_path)
end
end
def validate_arguments!(args)
if args.except(:group_path, :project_path).empty?
raise Gitlab::Graphql::Errors::ArgumentError,
'The list of iteration attributes is empty'
end
if args[:group_path].present? && args[:project_path].present?
raise Gitlab::Graphql::Errors::ArgumentError,
'Only one of group_path or project_path can be provided'
end
if args[:group_path].nil? && args[:project_path].nil?
raise Gitlab::Graphql::Errors::ArgumentError,
'Either group_path or project_path is required'
end
end
end
end
......
......@@ -128,7 +128,7 @@ RSpec.describe 'Creating an Iteration' do
let(:params) { {} }
it_behaves_like 'a mutation that returns top-level errors',
errors: ['Either group_path or project_path is required']
errors: ['Exactly one of group_path or project_path arguments is required']
it 'does not create the iteration' do
expect { post_graphql_mutation(mutation, current_user: current_user) }.not_to change(Iteration, :count)
......@@ -139,7 +139,7 @@ RSpec.describe 'Creating an Iteration' do
let(:params) { { group_path: group.full_path, project_path: 'doesnotreallymatter' } }
it_behaves_like 'a mutation that returns top-level errors',
errors: ['Only one of group_path or project_path can be provided']
errors: ['Exactly one of group_path or project_path arguments is required']
it 'does not create the iteration' do
expect { post_graphql_mutation(mutation, current_user: current_user) }.not_to change(Iteration, :count)
......
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