diff options
Diffstat (limited to 'app/graphql/mutations/issues')
-rw-r--r-- | app/graphql/mutations/issues/set_crm_contacts.rb | 9 | ||||
-rw-r--r-- | app/graphql/mutations/issues/set_escalation_status.rb | 46 |
2 files changed, 54 insertions, 1 deletions
diff --git a/app/graphql/mutations/issues/set_crm_contacts.rb b/app/graphql/mutations/issues/set_crm_contacts.rb index 4e49a45d52a..62990fc67f1 100644 --- a/app/graphql/mutations/issues/set_crm_contacts.rb +++ b/app/graphql/mutations/issues/set_crm_contacts.rb @@ -18,7 +18,8 @@ module Mutations def resolve(project_path:, iid:, contact_ids:, operation_mode: Types::MutationOperationModeEnum.enum[:replace]) issue = authorized_find!(project_path: project_path, iid: iid) project = issue.project - raise Gitlab::Graphql::Errors::ResourceNotAvailable, 'Feature disabled' unless Feature.enabled?(:customer_relations, project.group, default_enabled: :yaml) + + raise Gitlab::Graphql::Errors::ResourceNotAvailable, 'Feature disabled' unless feature_enabled?(project) contact_ids = contact_ids.compact.map do |contact_id| raise Gitlab::Graphql::Errors::ArgumentError, "Contact #{contact_id} is invalid." unless contact_id.respond_to?(:model_id) @@ -43,6 +44,12 @@ module Mutations errors: response.errors } end + + private + + def feature_enabled?(project) + Feature.enabled?(:customer_relations, project.group, default_enabled: :yaml) && project.group&.crm_enabled? + end end end end diff --git a/app/graphql/mutations/issues/set_escalation_status.rb b/app/graphql/mutations/issues/set_escalation_status.rb new file mode 100644 index 00000000000..6073b73277b --- /dev/null +++ b/app/graphql/mutations/issues/set_escalation_status.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +module Mutations + module Issues + class SetEscalationStatus < Base + graphql_name 'IssueSetEscalationStatus' + + argument :status, Types::IncidentManagement::EscalationStatusEnum, + required: true, + description: 'Set the escalation status.' + + def resolve(project_path:, iid:, status:) + issue = authorized_find!(project_path: project_path, iid: iid) + project = issue.project + + authorize_escalation_status!(project) + check_feature_availability!(project, issue) + + ::Issues::UpdateService.new( + project: project, + current_user: current_user, + params: { escalation_status: { status: status } } + ).execute(issue) + + { + issue: issue, + errors: errors_on_object(issue) + } + end + + private + + def authorize_escalation_status!(project) + return if Ability.allowed?(current_user, :update_escalation_status, project) + + raise_resource_not_available_error! + end + + def check_feature_availability!(project, issue) + return if Feature.enabled?(:incident_escalations, project) && issue.supports_escalation? + + raise Gitlab::Graphql::Errors::ResourceNotAvailable, 'Feature unavailable for provided issue' + end + end + end +end |