1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
# frozen_string_literal: true
module Mutations
module Integrations
module Exclusions
class Create < BaseMutation
graphql_name 'IntegrationExclusionCreate'
include ResolvesIds
MAX_PROJECT_IDS = ::Integrations::Exclusions::CreateService::MAX_PROJECTS
MAX_GROUP_IDS = ::Integrations::Exclusions::CreateService::MAX_GROUPS
field :exclusions, [::Types::Integrations::ExclusionType],
null: true,
description: 'Integration exclusions created by the mutation.'
argument :integration_name,
::Types::Integrations::IntegrationTypeEnum,
required: true,
description: 'Type of integration to exclude.'
argument :project_ids,
[::Types::GlobalIDType[::Project]],
required: false,
validates: { length: { maximum: MAX_PROJECT_IDS } },
description: "IDs of projects to exclude up to a maximum of #{MAX_PROJECT_IDS}."
argument :group_ids,
[::Types::GlobalIDType[::Group]],
required: false,
validates: { length: { maximum: MAX_GROUP_IDS } },
description: "IDs of groups to exclude up to a maximum of #{MAX_GROUP_IDS}."
authorize :admin_all_resources
def resolve(integration_name:, project_ids: [], group_ids: [])
authorize!(:global)
result = ::Integrations::Exclusions::CreateService.new(
current_user: current_user,
projects: projects(project_ids),
groups: groups(group_ids),
integration_name: integration_name
).execute
{
exclusions: result.payload,
errors: result.errors
}
end
private
def groups(group_ids)
return [] unless group_ids.present?
Group.id_in(resolve_ids(group_ids)).limit(MAX_GROUP_IDS)
end
def projects(project_ids)
return [] unless project_ids.present?
Project.id_in(resolve_ids(project_ids)).with_group.limit(MAX_PROJECT_IDS)
end
end
end
end
end
|