diff options
Diffstat (limited to 'app/graphql/resolvers/alert_management/integrations_resolver.rb')
-rw-r--r-- | app/graphql/resolvers/alert_management/integrations_resolver.rb | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/app/graphql/resolvers/alert_management/integrations_resolver.rb b/app/graphql/resolvers/alert_management/integrations_resolver.rb index 4d1fe367277..cb7e73c2d1a 100644 --- a/app/graphql/resolvers/alert_management/integrations_resolver.rb +++ b/app/graphql/resolvers/alert_management/integrations_resolver.rb @@ -3,27 +3,60 @@ module Resolvers module AlertManagement class IntegrationsResolver < BaseResolver - alias_method :project, :synchronized_object + include ::Gitlab::Graphql::Laziness + + alias_method :project, :object + + argument :id, ::Types::GlobalIDType, + required: false, + description: 'ID of the integration.' type Types::AlertManagement::IntegrationType.connection_type, null: true - def resolve(**args) - http_integrations + prometheus_integrations + def resolve(id: nil) + if id + integrations_by(gid: id) + else + http_integrations + prometheus_integrations + end end private + def integrations_by(gid:) + object = GitlabSchema.object_from_id(gid, expected_type: expected_integration_types) + defer { object }.then do |integration| + ret = integration if project == integration&.project + Array.wrap(ret) + end + end + def prometheus_integrations - return [] unless Ability.allowed?(current_user, :admin_project, project) + return [] unless prometheus_integrations_allowed? Array(project.prometheus_service) end def http_integrations - return [] unless Ability.allowed?(current_user, :admin_operations, project) + return [] unless http_integrations_allowed? ::AlertManagement::HttpIntegrationsFinder.new(project, {}).execute end + + def prometheus_integrations_allowed? + Ability.allowed?(current_user, :admin_project, project) + end + + def http_integrations_allowed? + Ability.allowed?(current_user, :admin_operations, project) + end + + def expected_integration_types + [].tap do |types| + types << ::AlertManagement::HttpIntegration if http_integrations_allowed? + types << ::PrometheusService if prometheus_integrations_allowed? + end + end end end end |