diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 23:50:22 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-20 23:50:22 +0000 |
commit | 9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch) | |
tree | 70467ae3692a0e35e5ea56bcb803eb512a10bedb /app/graphql/resolvers/alert_management | |
parent | 4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff) | |
download | gitlab-ce-9dc93a4519d9d5d7be48ff274127136236a3adb3.tar.gz |
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'app/graphql/resolvers/alert_management')
-rw-r--r-- | app/graphql/resolvers/alert_management/http_integrations_resolver.rb | 30 | ||||
-rw-r--r-- | app/graphql/resolvers/alert_management/integrations_resolver.rb | 43 |
2 files changed, 63 insertions, 10 deletions
diff --git a/app/graphql/resolvers/alert_management/http_integrations_resolver.rb b/app/graphql/resolvers/alert_management/http_integrations_resolver.rb index 94a72bca7c7..abc54614a59 100644 --- a/app/graphql/resolvers/alert_management/http_integrations_resolver.rb +++ b/app/graphql/resolvers/alert_management/http_integrations_resolver.rb @@ -3,19 +3,39 @@ module Resolvers module AlertManagement class HttpIntegrationsResolver < BaseResolver - alias_method :project, :synchronized_object + include ::Gitlab::Graphql::Laziness + + alias_method :project, :object + + argument :id, Types::GlobalIDType[::AlertManagement::HttpIntegration], + required: false, + description: 'ID of the integration.' type Types::AlertManagement::HttpIntegrationType.connection_type, null: true - def resolve(**args) - http_integrations + def resolve(id: nil) + return [] unless Ability.allowed?(current_user, :admin_operations, project) + + if id + integrations_by(gid: id) + else + http_integrations + end end private - def http_integrations - return [] unless Ability.allowed?(current_user, :admin_operations, project) + 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 + def http_integrations ::AlertManagement::HttpIntegrationsFinder.new(project, {}).execute end end 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 |