diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-11 09:08:22 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-11 09:08:22 +0300 |
commit | 1b3eb6f388e2c376cc95adbd4babd8bad76eb4d6 (patch) | |
tree | a39034626ee95bed60ce943dcc44cc13102d793b /app/graphql | |
parent | 7b0ffedd699f02990b1af3e6d84f914cb72659b1 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/graphql')
-rw-r--r-- | app/graphql/mutations/alert_management/alerts/set_assignees.rb | 56 | ||||
-rw-r--r-- | app/graphql/types/mutation_type.rb | 1 |
2 files changed, 57 insertions, 0 deletions
diff --git a/app/graphql/mutations/alert_management/alerts/set_assignees.rb b/app/graphql/mutations/alert_management/alerts/set_assignees.rb new file mode 100644 index 00000000000..1e0c9fdeeaf --- /dev/null +++ b/app/graphql/mutations/alert_management/alerts/set_assignees.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +module Mutations + module AlertManagement + module Alerts + class SetAssignees < Base + graphql_name 'AlertSetAssignees' + + argument :assignee_usernames, + [GraphQL::STRING_TYPE], + required: true, + description: 'The usernames to assign to the alert. Replaces existing assignees by default.' + + argument :operation_mode, + Types::MutationOperationModeEnum, + required: false, + description: 'The operation to perform. Defaults to REPLACE.' + + def resolve(args) + alert = authorized_find!(project_path: args[:project_path], iid: args[:iid]) + result = set_assignees(alert, args[:assignee_usernames], args[:operation_mode]) + + prepare_response(result) + end + + private + + def set_assignees(alert, assignee_usernames, operation_mode) + operation_mode ||= Types::MutationOperationModeEnum.enum[:replace] + + original_assignees = alert.assignees + target_users = find_target_users(assignee_usernames) + + assignees = case Types::MutationOperationModeEnum.enum.key(operation_mode).to_sym + when :replace then target_users.uniq + when :append then (original_assignees + target_users).uniq + when :remove then (original_assignees - target_users) + end + + ::AlertManagement::Alerts::UpdateService.new(alert, current_user, assignees: assignees).execute + end + + def find_target_users(assignee_usernames) + UsersFinder.new(current_user, username: assignee_usernames).execute + end + + def prepare_response(result) + { + alert: result.payload[:alert], + errors: result.error? ? [result.message] : [] + } + end + end + end + end +end diff --git a/app/graphql/types/mutation_type.rb b/app/graphql/types/mutation_type.rb index 8d4368cc30a..8874c56dfdb 100644 --- a/app/graphql/types/mutation_type.rb +++ b/app/graphql/types/mutation_type.rb @@ -9,6 +9,7 @@ module Types mount_mutation Mutations::Admin::SidekiqQueues::DeleteJobs mount_mutation Mutations::AlertManagement::CreateAlertIssue mount_mutation Mutations::AlertManagement::UpdateAlertStatus + mount_mutation Mutations::AlertManagement::Alerts::SetAssignees mount_mutation Mutations::AwardEmojis::Add mount_mutation Mutations::AwardEmojis::Remove mount_mutation Mutations::AwardEmojis::Toggle |