debian-mirror-gitlab/app/graphql/resolvers/alert_management/http_integrations_resolver.rb

44 lines
1.1 KiB
Ruby
Raw Normal View History

2021-04-17 20:07:23 +05:30
# frozen_string_literal: true
module Resolvers
module AlertManagement
class HttpIntegrationsResolver < BaseResolver
2021-04-29 21:17:54 +05:30
include ::Gitlab::Graphql::Laziness
alias_method :project, :object
argument :id, Types::GlobalIDType[::AlertManagement::HttpIntegration],
required: false,
description: 'ID of the integration.'
2021-04-17 20:07:23 +05:30
type Types::AlertManagement::HttpIntegrationType.connection_type, null: true
2021-04-29 21:17:54 +05:30
def resolve(id: nil)
return [] unless Ability.allowed?(current_user, :admin_operations, project)
if id
integrations_by(gid: id)
else
http_integrations
end
2021-04-17 20:07:23 +05:30
end
private
2021-04-29 21:17:54 +05:30
def integrations_by(gid:)
id = Types::GlobalIDType[::AlertManagement::HttpIntegration].coerce_isolated_input(gid)
object = GitlabSchema.find_by_gid(id)
defer { object }.then do |integration|
ret = integration if project == integration&.project
Array.wrap(ret)
end
end
2021-04-17 20:07:23 +05:30
2021-04-29 21:17:54 +05:30
def http_integrations
2021-04-17 20:07:23 +05:30
::AlertManagement::HttpIntegrationsFinder.new(project, {}).execute
end
end
end
end