diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-03 00:10:04 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-03 00:10:04 +0300 |
commit | 5fd6c937012b886c748e74b636c6188eae2645e2 (patch) | |
tree | 6b3c5a356c9e534b0e148147bb56209a9fba033b /app | |
parent | 0a22eaad01e62088ced6ed8d5111624be7decff0 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/graphql/mutations/concerns/mutations/assignable.rb | 52 | ||||
-rw-r--r-- | app/graphql/mutations/issues/set_assignees.rb | 15 | ||||
-rw-r--r-- | app/graphql/mutations/merge_requests/set_assignees.rb | 39 | ||||
-rw-r--r-- | app/graphql/types/mutation_type.rb | 1 |
4 files changed, 71 insertions, 36 deletions
diff --git a/app/graphql/mutations/concerns/mutations/assignable.rb b/app/graphql/mutations/concerns/mutations/assignable.rb new file mode 100644 index 00000000000..f6f4b744f4e --- /dev/null +++ b/app/graphql/mutations/concerns/mutations/assignable.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +module Mutations + module Assignable + extend ActiveSupport::Concern + + included do + argument :assignee_usernames, + [GraphQL::STRING_TYPE], + required: true, + description: 'The usernames to assign to the resource. Replaces existing assignees by default.' + + argument :operation_mode, + Types::MutationOperationModeEnum, + required: false, + description: 'The operation to perform. Defaults to REPLACE.' + end + + def resolve(project_path:, iid:, assignee_usernames:, operation_mode: Types::MutationOperationModeEnum.enum[:replace]) + resource = authorized_find!(project_path: project_path, iid: iid) + + Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab/issues/36098') if resource.is_a?(MergeRequest) + + update_service_class.new( + resource.project, + current_user, + assignee_ids: assignee_ids(resource, assignee_usernames, operation_mode) + ).execute(resource) + + { + resource.class.name.underscore.to_sym => resource, + errors: errors_on_object(resource) + } + end + + private + + def assignee_ids(resource, usernames, operation_mode) + assignee_ids = [] + assignee_ids += resource.assignees.map(&:id) if Types::MutationOperationModeEnum.enum.values_at(:remove, :append).include?(operation_mode) + user_ids = UsersFinder.new(current_user, username: usernames).execute.map(&:id) + + if operation_mode == Types::MutationOperationModeEnum.enum[:remove] + assignee_ids -= user_ids + else + assignee_ids |= user_ids + end + + assignee_ids + end + end +end diff --git a/app/graphql/mutations/issues/set_assignees.rb b/app/graphql/mutations/issues/set_assignees.rb new file mode 100644 index 00000000000..a4d1c755b53 --- /dev/null +++ b/app/graphql/mutations/issues/set_assignees.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Mutations + module Issues + class SetAssignees < Base + graphql_name 'IssueSetAssignees' + + include Assignable + + def update_service_class + ::Issues::UpdateService + end + end + end +end diff --git a/app/graphql/mutations/merge_requests/set_assignees.rb b/app/graphql/mutations/merge_requests/set_assignees.rb index de244b62d0f..548c6b55a85 100644 --- a/app/graphql/mutations/merge_requests/set_assignees.rb +++ b/app/graphql/mutations/merge_requests/set_assignees.rb @@ -5,43 +5,10 @@ module Mutations class SetAssignees < Base graphql_name 'MergeRequestSetAssignees' - argument :assignee_usernames, - [GraphQL::STRING_TYPE], - required: true, - description: <<~DESC - The usernames to assign to the merge request. Replaces existing assignees by default. - DESC + include Assignable - argument :operation_mode, - Types::MutationOperationModeEnum, - required: false, - description: <<~DESC - The operation to perform. Defaults to REPLACE. - DESC - - def resolve(project_path:, iid:, assignee_usernames:, operation_mode: Types::MutationOperationModeEnum.enum[:replace]) - Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab/issues/36098') - - merge_request = authorized_find!(project_path: project_path, iid: iid) - project = merge_request.project - - assignee_ids = [] - assignee_ids += merge_request.assignees.map(&:id) if Types::MutationOperationModeEnum.enum.values_at(:remove, :append).include?(operation_mode) - user_ids = UsersFinder.new(current_user, username: assignee_usernames).execute.map(&:id) - - if operation_mode == Types::MutationOperationModeEnum.enum[:remove] - assignee_ids -= user_ids - else - assignee_ids |= user_ids - end - - ::MergeRequests::UpdateService.new(project, current_user, assignee_ids: assignee_ids) - .execute(merge_request) - - { - merge_request: merge_request, - errors: errors_on_object(merge_request) - } + def update_service_class + ::MergeRequests::UpdateService end end end diff --git a/app/graphql/types/mutation_type.rb b/app/graphql/types/mutation_type.rb index 8b4ea5d21d4..2c58a19bd26 100644 --- a/app/graphql/types/mutation_type.rb +++ b/app/graphql/types/mutation_type.rb @@ -17,6 +17,7 @@ module Types mount_mutation Mutations::Branches::Create, calls_gitaly: true mount_mutation Mutations::Commits::Create, calls_gitaly: true mount_mutation Mutations::Discussions::ToggleResolve + mount_mutation Mutations::Issues::SetAssignees mount_mutation Mutations::Issues::SetConfidential mount_mutation Mutations::Issues::SetLocked mount_mutation Mutations::Issues::SetDueDate |