diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-13 15:10:03 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-13 15:10:03 +0000 |
commit | 6df7943512ca90323c69b926404cc561b6305ce2 (patch) | |
tree | 5dbdb697f641358516ddae9b45ab8bae5d58de81 /app/graphql/mutations | |
parent | 5605efec12c99adf88f641391cb879dedf8fa05e (diff) | |
download | gitlab-ce-6df7943512ca90323c69b926404cc561b6305ce2.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/graphql/mutations')
-rw-r--r-- | app/graphql/mutations/boards/lists/base.rb | 28 | ||||
-rw-r--r-- | app/graphql/mutations/boards/lists/create.rb | 73 |
2 files changed, 101 insertions, 0 deletions
diff --git a/app/graphql/mutations/boards/lists/base.rb b/app/graphql/mutations/boards/lists/base.rb new file mode 100644 index 00000000000..34b271ba3b8 --- /dev/null +++ b/app/graphql/mutations/boards/lists/base.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +module Mutations + module Boards + module Lists + class Base < BaseMutation + include Mutations::ResolvesIssuable + + argument :board_id, ::Types::GlobalIDType[::Board], + required: true, + description: 'The Global ID of the issue board to mutate' + + field :list, + Types::BoardListType, + null: true, + description: 'List of the issue board' + + authorize :admin_list + + private + + def find_object(id:) + GitlabSchema.object_from_id(id, expected_type: ::Board) + end + end + end + end +end diff --git a/app/graphql/mutations/boards/lists/create.rb b/app/graphql/mutations/boards/lists/create.rb new file mode 100644 index 00000000000..4f545709ee9 --- /dev/null +++ b/app/graphql/mutations/boards/lists/create.rb @@ -0,0 +1,73 @@ +# frozen_string_literal: true + +module Mutations + module Boards + module Lists + class Create < Base + graphql_name 'BoardListCreate' + + argument :backlog, GraphQL::BOOLEAN_TYPE, + required: false, + description: 'Create the backlog list' + + argument :label_id, ::Types::GlobalIDType[::Label], + required: false, + description: 'ID of an existing label' + + def ready?(**args) + if args.slice(*mutually_exclusive_args).size != 1 + arg_str = mutually_exclusive_args.map { |x| x.to_s.camelize(:lower) }.join(' or ') + raise Gitlab::Graphql::Errors::ArgumentError, "one and only one of #{arg_str} is required" + end + + super + end + + def resolve(**args) + board = authorized_find!(id: args[:board_id]) + params = create_list_params(args) + + authorize_list_type_resource!(board, params) + + list = create_list(board, params) + + { + list: list.valid? ? list : nil, + errors: errors_on_object(list) + } + end + + private + + def authorize_list_type_resource!(board, params) + return unless params[:label_id] + + labels = ::Labels::AvailableLabelsService.new(current_user, board.resource_parent, params) + .filter_labels_ids_in_param(:label_id) + + unless labels.present? + raise Gitlab::Graphql::Errors::ArgumentError, 'Label not found!' + end + end + + def create_list(board, params) + create_list_service = + ::Boards::Lists::CreateService.new(board.resource_parent, current_user, params) + + create_list_service.execute(board) + end + + def create_list_params(args) + params = args.slice(*mutually_exclusive_args).with_indifferent_access + params[:label_id] = GitlabSchema.parse_gid(params[:label_id]).model_id if params[:label_id] + + params + end + + def mutually_exclusive_args + [:backlog, :label_id] + end + end + end + end +end |