diff options
Diffstat (limited to 'app/graphql/mutations/work_items/create.rb')
-rw-r--r-- | app/graphql/mutations/work_items/create.rb | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/app/graphql/mutations/work_items/create.rb b/app/graphql/mutations/work_items/create.rb index 9f124de7ab2..dfd2d5d1f88 100644 --- a/app/graphql/mutations/work_items/create.rb +++ b/app/graphql/mutations/work_items/create.rb @@ -6,13 +6,15 @@ module Mutations graphql_name 'WorkItemCreate' include Mutations::SpamProtection - include FindsProject + include FindsNamespace include Mutations::WorkItems::Widgetable description "Creates a work item." authorize :create_work_item + MUTUALLY_EXCLUSIVE_ARGUMENTS_ERROR = 'Please provide either projectPath or namespacePath argument, but not both.' + argument :confidential, GraphQL::Types::Boolean, required: false, description: 'Sets the work item confidentiality.' @@ -25,9 +27,16 @@ module Mutations argument :milestone_widget, ::Types::WorkItems::Widgets::MilestoneInputType, required: false, description: 'Input for milestone widget.' + argument :namespace_path, GraphQL::Types::ID, + required: false, + description: 'Full path of the namespace(project or group) the work item is created in.' argument :project_path, GraphQL::Types::ID, - required: true, - description: 'Full path of the project the work item is associated with.' + required: false, + description: 'Full path of the project the work item is associated with.', + deprecated: { + reason: 'Please use namespace_path instead. That will cover for both projects and groups', + milestone: '15.10' + } argument :title, GraphQL::Types::String, required: true, description: copy_field_description(Types::WorkItemType, :title) @@ -39,8 +48,17 @@ module Mutations null: true, description: 'Created work item.' - def resolve(project_path:, **attributes) - project = authorized_find!(project_path) + def ready?(**args) + if args.slice(:project_path, :namespace_path)&.length != 1 + raise Gitlab::Graphql::Errors::ArgumentError, MUTUALLY_EXCLUSIVE_ARGUMENTS_ERROR + end + + super + end + + def resolve(project_path: nil, namespace_path: nil, **attributes) + container_path = project_path || namespace_path + container = authorized_find!(container_path) spam_params = ::Spam::SpamParams.new_from_request(request: context[:request]) params = global_id_compatibility_params(attributes).merge(author_id: current_user.id) @@ -48,7 +66,7 @@ module Mutations widget_params = extract_widget_params!(type, params) create_result = ::WorkItems::CreateService.new( - container: project, + container: container, current_user: current_user, params: params, spam_params: spam_params, |