diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-08 06:09:54 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-08 06:09:54 +0000 |
commit | f6cdec670b9b757fc2225a2c6627ab79765e5b8a (patch) | |
tree | 7a1fde030f117b69332d01b22deefd1c81fff458 /app/graphql | |
parent | e2ee1eec50aa8df8543d7ecc585ec0ba5ee544ac (diff) | |
download | gitlab-ce-f6cdec670b9b757fc2225a2c6627ab79765e5b8a.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/graphql')
-rw-r--r-- | app/graphql/resolvers/projects/services_resolver.rb | 39 | ||||
-rw-r--r-- | app/graphql/types/project_type.rb | 6 | ||||
-rw-r--r-- | app/graphql/types/projects/service_type.rb | 29 | ||||
-rw-r--r-- | app/graphql/types/projects/service_type_enum.rb | 13 | ||||
-rw-r--r-- | app/graphql/types/projects/services/base_service_type.rb | 15 | ||||
-rw-r--r-- | app/graphql/types/projects/services/jira_service_type.rb | 18 |
6 files changed, 120 insertions, 0 deletions
diff --git a/app/graphql/resolvers/projects/services_resolver.rb b/app/graphql/resolvers/projects/services_resolver.rb new file mode 100644 index 00000000000..40c64c24513 --- /dev/null +++ b/app/graphql/resolvers/projects/services_resolver.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +module Resolvers + module Projects + class ServicesResolver < BaseResolver + include Gitlab::Graphql::Authorize::AuthorizeResource + + argument :active, + GraphQL::BOOLEAN_TYPE, + required: false, + description: 'Indicates if the service is active' + argument :type, + Types::Projects::ServiceTypeEnum, + required: false, + description: 'Class name of the service' + + alias_method :project, :object + + def resolve(**args) + authorize!(project) + + services(args[:active], args[:type]) + end + + def authorized_resource?(project) + Ability.allowed?(context[:current_user], :admin_project, project) + end + + private + + def services(active, type) + servs = project.services + servs = servs.by_active_flag(active) unless active.nil? + servs = servs.by_type(type) unless type.blank? + servs + end + end + end +end diff --git a/app/graphql/types/project_type.rb b/app/graphql/types/project_type.rb index d82feffe441..3115a53e053 100644 --- a/app/graphql/types/project_type.rb +++ b/app/graphql/types/project_type.rb @@ -199,6 +199,12 @@ module Types null: true, description: 'Jira imports into the project', resolver: Resolvers::Projects::JiraImportsResolver + + field :services, + Types::Projects::ServiceType.connection_type, + null: true, + description: 'Project services', + resolver: Resolvers::Projects::ServicesResolver end end diff --git a/app/graphql/types/projects/service_type.rb b/app/graphql/types/projects/service_type.rb new file mode 100644 index 00000000000..55dd828d4b8 --- /dev/null +++ b/app/graphql/types/projects/service_type.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module Types + module Projects + module ServiceType + include Types::BaseInterface + graphql_name 'Service' + + # TODO: Add all the fields that we want to expose for the project services intergrations + # https://gitlab.com/gitlab-org/gitlab/-/issues/213088 + field :type, GraphQL::STRING_TYPE, null: true, + description: 'Class name of the service' + field :active, GraphQL::BOOLEAN_TYPE, null: true, + description: 'Indicates if the service is active' + + definition_methods do + def resolve_type(object, context) + if object.is_a?(::JiraService) + Types::Projects::Services::JiraServiceType + else + Types::Projects::Services::BaseServiceType + end + end + end + + orphan_types Types::Projects::Services::BaseServiceType, Types::Projects::Services::JiraServiceType + end + end +end diff --git a/app/graphql/types/projects/service_type_enum.rb b/app/graphql/types/projects/service_type_enum.rb new file mode 100644 index 00000000000..340fdff6b86 --- /dev/null +++ b/app/graphql/types/projects/service_type_enum.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Types + module Projects + class ServiceTypeEnum < BaseEnum + graphql_name 'ServiceType' + + ::Service.services_types.each do |service_type| + value service_type.underscore.upcase, value: service_type + end + end + end +end diff --git a/app/graphql/types/projects/services/base_service_type.rb b/app/graphql/types/projects/services/base_service_type.rb new file mode 100644 index 00000000000..5341ae2a864 --- /dev/null +++ b/app/graphql/types/projects/services/base_service_type.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Types + module Projects + module Services + class BaseServiceType < BaseObject + graphql_name 'BaseService' + + implements(Types::Projects::ServiceType) + + authorize :admin_project + end + end + end +end diff --git a/app/graphql/types/projects/services/jira_service_type.rb b/app/graphql/types/projects/services/jira_service_type.rb new file mode 100644 index 00000000000..4fd9e61f5a4 --- /dev/null +++ b/app/graphql/types/projects/services/jira_service_type.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Types + module Projects + module Services + class JiraServiceType < BaseObject + graphql_name 'JiraService' + + implements(Types::Projects::ServiceType) + + authorize :admin_project + # This is a placeholder for now for the actuall implementation of the JiraServiceType + # Here we will want to expose a field with jira_projects fetched through Jira Rest API + # MR implementing it https://gitlab.com/gitlab-org/gitlab/-/merge_requests/28190 + end + end + end +end |