Commit 55e8d950 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch 'use_resolve_path' into 'master'

Use ResolveResourceParent concern for iterations

See merge request gitlab-org/gitlab!52213
parents c0ae2dd8 9111404d
...@@ -5095,12 +5095,12 @@ input CreateIterationInput { ...@@ -5095,12 +5095,12 @@ input CreateIterationInput {
dueDate: String dueDate: String
""" """
The target group for the iteration. Full path of the group with which the resource is associated.
""" """
groupPath: ID groupPath: ID
""" """
The target project for the iteration. Full path of the project with which the resource is associated.
""" """
projectPath: ID projectPath: ID
......
...@@ -13827,8 +13827,8 @@ ...@@ -13827,8 +13827,8 @@
"fields": null, "fields": null,
"inputFields": [ "inputFields": [
{ {
"name": "groupPath", "name": "projectPath",
"description": "The target group for the iteration.", "description": "Full path of the project with which the resource is associated.",
"type": { "type": {
"kind": "SCALAR", "kind": "SCALAR",
"name": "ID", "name": "ID",
...@@ -13837,8 +13837,8 @@ ...@@ -13837,8 +13837,8 @@
"defaultValue": null "defaultValue": null
}, },
{ {
"name": "projectPath", "name": "groupPath",
"description": "The target project for the iteration.", "description": "Full path of the group with which the resource is associated.",
"type": { "type": {
"kind": "SCALAR", "kind": "SCALAR",
"name": "ID", "name": "ID",
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
module Mutations module Mutations
module Iterations module Iterations
class Create < BaseMutation class Create < BaseMutation
include Mutations::ResolvesGroup include Mutations::ResolvesResourceParent
include ResolvesProject
graphql_name 'CreateIteration' graphql_name 'CreateIteration'
...@@ -15,14 +14,6 @@ module Mutations ...@@ -15,14 +14,6 @@ module Mutations
null: true, null: true,
description: 'The created iteration.' 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, argument :title,
GraphQL::STRING_TYPE, GraphQL::STRING_TYPE,
required: false, required: false,
...@@ -46,7 +37,7 @@ module Mutations ...@@ -46,7 +37,7 @@ module Mutations
def resolve(args) def resolve(args)
validate_arguments!(args) validate_arguments!(args)
parent = find_parent(args) parent = authorized_resource_parent_find!(args)
response = ::Iterations::CreateService.new(parent, current_user, args).execute response = ::Iterations::CreateService.new(parent, current_user, args).execute
...@@ -61,40 +52,11 @@ module Mutations ...@@ -61,40 +52,11 @@ module Mutations
private 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) def validate_arguments!(args)
if args.except(:group_path, :project_path).empty? if args.except(:group_path, :project_path).empty?
raise Gitlab::Graphql::Errors::ArgumentError, raise Gitlab::Graphql::Errors::ArgumentError,
'The list of iteration attributes is empty' 'The list of iteration attributes is empty'
end 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 end
end end
......
...@@ -128,7 +128,7 @@ RSpec.describe 'Creating an Iteration' do ...@@ -128,7 +128,7 @@ RSpec.describe 'Creating an Iteration' do
let(:params) { {} } let(:params) { {} }
it_behaves_like 'a mutation that returns top-level errors', 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 it 'does not create the iteration' do
expect { post_graphql_mutation(mutation, current_user: current_user) }.not_to change(Iteration, :count) expect { post_graphql_mutation(mutation, current_user: current_user) }.not_to change(Iteration, :count)
...@@ -139,7 +139,7 @@ RSpec.describe 'Creating an Iteration' do ...@@ -139,7 +139,7 @@ RSpec.describe 'Creating an Iteration' do
let(:params) { { group_path: group.full_path, project_path: 'doesnotreallymatter' } } let(:params) { { group_path: group.full_path, project_path: 'doesnotreallymatter' } }
it_behaves_like 'a mutation that returns top-level errors', 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 it 'does not create the iteration' do
expect { post_graphql_mutation(mutation, current_user: current_user) }.not_to change(Iteration, :count) 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