diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 11:43:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 11:43:02 +0300 |
commit | d9ab72d6080f594d0b3cae15f14b3ef2c6c638cb (patch) | |
tree | 2341ef426af70ad1e289c38036737e04b0aa5007 /app/graphql/resolvers | |
parent | d6e514dd13db8947884cd58fe2a9c2a063400a9b (diff) |
Add latest changes from gitlab-org/gitlab@14-4-stable-eev14.4.0-rc42
Diffstat (limited to 'app/graphql/resolvers')
11 files changed, 208 insertions, 14 deletions
diff --git a/app/graphql/resolvers/board_list_issues_resolver.rb b/app/graphql/resolvers/board_list_issues_resolver.rb index 7c85dd8fb9b..d70acdf7ca0 100644 --- a/app/graphql/resolvers/board_list_issues_resolver.rb +++ b/app/graphql/resolvers/board_list_issues_resolver.rb @@ -18,11 +18,8 @@ module Resolvers filter_params = filters.merge(board_id: list.board.id, id: list.id) service = ::Boards::Issues::ListService.new(list.board.resource_parent, context[:current_user], filter_params) - pagination_connections = Gitlab::Graphql::Pagination::Keyset::Connection.new(service.execute) - ::Boards::Issues::ListService.initialize_relative_positions(list.board, current_user, pagination_connections.items) - - pagination_connections + service.execute end # https://gitlab.com/gitlab-org/gitlab/-/issues/235681 diff --git a/app/graphql/resolvers/board_list_resolver.rb b/app/graphql/resolvers/board_list_resolver.rb new file mode 100644 index 00000000000..d853846b674 --- /dev/null +++ b/app/graphql/resolvers/board_list_resolver.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module Resolvers + class BoardListResolver < BaseResolver.single + include Gitlab::Graphql::Authorize::AuthorizeResource + include BoardItemFilterable + + type Types::BoardListType, null: true + description 'Find an issue board list.' + + authorize :read_issue_board_list + + argument :id, Types::GlobalIDType[List], + required: true, + description: 'Global ID of the list.' + + argument :issue_filters, Types::Boards::BoardIssueInputType, + required: false, + description: 'Filters applied when getting issue metadata in the board list.' + + def resolve(id: nil, issue_filters: {}) + context.scoped_set!(:issue_filters, item_filters(issue_filters)) + + Gitlab::Graphql::Lazy.with_value(find_list(id: id)) do |list| + list if authorized_resource?(list) + end + end + + private + + def find_list(id:) + GitlabSchema.object_from_id(id, expected_type: ::List) + end + end +end diff --git a/app/graphql/resolvers/clusters/agent_tokens_resolver.rb b/app/graphql/resolvers/clusters/agent_tokens_resolver.rb new file mode 100644 index 00000000000..5ae19700fd5 --- /dev/null +++ b/app/graphql/resolvers/clusters/agent_tokens_resolver.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +module Resolvers + module Clusters + class AgentTokensResolver < BaseResolver + type Types::Clusters::AgentTokenType, null: true + + alias_method :agent, :object + + delegate :project, to: :agent + + def resolve(**args) + return ::Clusters::AgentToken.none unless can_read_agent_tokens? + + agent.last_used_agent_tokens + end + + private + + def can_read_agent_tokens? + current_user.can?(:admin_cluster, project) + end + end + end +end diff --git a/app/graphql/resolvers/clusters/agents_resolver.rb b/app/graphql/resolvers/clusters/agents_resolver.rb new file mode 100644 index 00000000000..9b8cea52e3b --- /dev/null +++ b/app/graphql/resolvers/clusters/agents_resolver.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module Resolvers + module Clusters + class AgentsResolver < BaseResolver + include LooksAhead + + type Types::Clusters::AgentType.connection_type, null: true + + extras [:lookahead] + + when_single do + argument :name, GraphQL::Types::String, + required: true, + description: 'Name of the cluster agent.' + end + + alias_method :project, :object + + def resolve_with_lookahead(**args) + apply_lookahead( + ::Clusters::AgentsFinder + .new(project, current_user, params: args) + .execute + ) + end + + private + + def preloads + { tokens: :last_used_agent_tokens } + end + end + end +end diff --git a/app/graphql/resolvers/concerns/issue_resolver_arguments.rb b/app/graphql/resolvers/concerns/issue_resolver_arguments.rb index 9de36b5b7d1..855877110e5 100644 --- a/app/graphql/resolvers/concerns/issue_resolver_arguments.rb +++ b/app/graphql/resolvers/concerns/issue_resolver_arguments.rb @@ -4,6 +4,7 @@ module IssueResolverArguments extend ActiveSupport::Concern prepended do + include SearchArguments include LooksAhead argument :iid, GraphQL::Types::String, @@ -49,9 +50,6 @@ module IssueResolverArguments argument :closed_after, Types::TimeType, required: false, description: 'Issues closed after this date.' - argument :search, GraphQL::Types::String, - required: false, - description: 'Search query for issue title or description.' argument :types, [Types::IssueTypeEnum], as: :issue_types, description: 'Filter issues by the given issue types.', @@ -62,6 +60,10 @@ module IssueResolverArguments argument :my_reaction_emoji, GraphQL::Types::String, required: false, description: 'Filter by reaction emoji applied by the current user. Wildcard values "NONE" and "ANY" are supported.' + argument :confidential, + GraphQL::Types::Boolean, + required: false, + description: 'Filter for confidential issues. If "false", excludes confidential issues. If "true", returns only confidential issues.' argument :not, Types::Issues::NegatedIssueFilterInputType, description: 'Negated arguments.', prepare: ->(negated_args, ctx) { negated_args.to_h }, @@ -91,6 +93,7 @@ module IssueResolverArguments params_not_mutually_exclusive(args, mutually_exclusive_assignee_username_args) params_not_mutually_exclusive(args, mutually_exclusive_milestone_args) params_not_mutually_exclusive(args.fetch(:not, {}), mutually_exclusive_milestone_args) + validate_anonymous_search_access! if args[:search].present? super end diff --git a/app/graphql/resolvers/concerns/search_arguments.rb b/app/graphql/resolvers/concerns/search_arguments.rb new file mode 100644 index 00000000000..7f480f9d0b6 --- /dev/null +++ b/app/graphql/resolvers/concerns/search_arguments.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module SearchArguments + extend ActiveSupport::Concern + + included do + argument :search, GraphQL::Types::String, + required: false, + description: 'Search query for title or description.' + end + + def validate_anonymous_search_access! + return if current_user.present? || Feature.disabled?(:disable_anonymous_search, type: :ops) + + raise ::Gitlab::Graphql::Errors::ArgumentError, + "User must be authenticated to include the `search` argument." + end +end diff --git a/app/graphql/resolvers/issues_resolver.rb b/app/graphql/resolvers/issues_resolver.rb index 47e4e3c0b32..b556964ae0c 100644 --- a/app/graphql/resolvers/issues_resolver.rb +++ b/app/graphql/resolvers/issues_resolver.rb @@ -47,7 +47,8 @@ module Resolvers alert_management_alert: [:alert_management_alert], labels: [:labels], assignees: [:assignees], - timelogs: [:timelogs] + timelogs: [:timelogs], + customer_relations_contacts: { customer_relations_contacts: [:group] } } end diff --git a/app/graphql/resolvers/kas/agent_configurations_resolver.rb b/app/graphql/resolvers/kas/agent_configurations_resolver.rb new file mode 100644 index 00000000000..238dae0bf12 --- /dev/null +++ b/app/graphql/resolvers/kas/agent_configurations_resolver.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +module Resolvers + module Kas + class AgentConfigurationsResolver < BaseResolver + type Types::Kas::AgentConfigurationType, null: true + + # Calls Gitaly via KAS + calls_gitaly! + + alias_method :project, :object + + def resolve + return [] unless can_read_agent_configuration? + + kas_client.list_agent_config_files(project: project) + rescue GRPC::BadStatus => e + raise Gitlab::Graphql::Errors::ResourceNotAvailable, e.class.name + end + + private + + def can_read_agent_configuration? + current_user.can?(:admin_cluster, project) + end + + def kas_client + @kas_client ||= Gitlab::Kas::Client.new + end + end + end +end diff --git a/app/graphql/resolvers/kas/agent_connections_resolver.rb b/app/graphql/resolvers/kas/agent_connections_resolver.rb new file mode 100644 index 00000000000..8b7c4003598 --- /dev/null +++ b/app/graphql/resolvers/kas/agent_connections_resolver.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +module Resolvers + module Kas + class AgentConnectionsResolver < BaseResolver + type Types::Kas::AgentConnectionType, null: true + + alias_method :agent, :object + + delegate :project, to: :agent + + def resolve + return [] unless can_read_connected_agents? + + BatchLoader::GraphQL.for(agent.id).batch(key: project, default_value: []) do |agent_ids, loader| + agents = get_connected_agents.group_by(&:agent_id).slice(*agent_ids) + + agents.each do |agent_id, connections| + loader.call(agent_id, connections) + end + end + end + + private + + def can_read_connected_agents? + current_user.can?(:admin_cluster, project) + end + + def get_connected_agents + kas_client.get_connected_agents(project: project) + rescue GRPC::BadStatus => e + raise Gitlab::Graphql::Errors::ResourceNotAvailable, e.class.name + end + + def kas_client + @kas_client ||= Gitlab::Kas::Client.new + end + end + end +end diff --git a/app/graphql/resolvers/project_pipeline_resolver.rb b/app/graphql/resolvers/project_pipeline_resolver.rb index ce4b6ac6b0c..5acd7f95606 100644 --- a/app/graphql/resolvers/project_pipeline_resolver.rb +++ b/app/graphql/resolvers/project_pipeline_resolver.rb @@ -2,6 +2,8 @@ module Resolvers class ProjectPipelineResolver < BaseResolver + include LooksAhead + type ::Types::Ci::PipelineType, null: true alias_method :project, :object @@ -14,7 +16,7 @@ module Resolvers required: false, description: 'SHA of the Pipeline. For example, "dyd0f15ay83993f5ab66k927w28673882x99100b".' - def ready?(iid: nil, sha: nil) + def ready?(iid: nil, sha: nil, **args) unless iid.present? ^ sha.present? raise Gitlab::Graphql::Errors::ArgumentError, 'Provide one of an IID or SHA' end @@ -22,18 +24,21 @@ module Resolvers super end - def resolve(iid: nil, sha: nil) + # the preloads are defined on ee/app/graphql/ee/resolvers/project_pipeline_resolver.rb + def resolve(iid: nil, sha: nil, **args) + self.lookahead = args.delete(:lookahead) + if iid - BatchLoader::GraphQL.for(iid).batch(key: project) do |iids, loader, args| + BatchLoader::GraphQL.for(iid).batch(key: project) do |iids, loader| finder = ::Ci::PipelinesFinder.new(project, current_user, iids: iids) - finder.execute.each { |pipeline| loader.call(pipeline.iid.to_s, pipeline) } + apply_lookahead(finder.execute).each { |pipeline| loader.call(pipeline.iid.to_s, pipeline) } end else - BatchLoader::GraphQL.for(sha).batch(key: project) do |shas, loader, args| + BatchLoader::GraphQL.for(sha).batch(key: project) do |shas, loader| finder = ::Ci::PipelinesFinder.new(project, current_user, sha: shas) - finder.execute.each { |pipeline| loader.call(pipeline.sha.to_s, pipeline) } + apply_lookahead(finder.execute).each { |pipeline| loader.call(pipeline.sha.to_s, pipeline) } end end end diff --git a/app/graphql/resolvers/project_pipelines_resolver.rb b/app/graphql/resolvers/project_pipelines_resolver.rb index 0171473a77f..5a1e92efc96 100644 --- a/app/graphql/resolvers/project_pipelines_resolver.rb +++ b/app/graphql/resolvers/project_pipelines_resolver.rb @@ -26,3 +26,5 @@ module Resolvers end end # rubocop: enable Graphql/ResolverType + +Resolvers::ProjectPipelinesResolver.prepend_mod |