Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-09-20 16:18:24 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-09-20 16:18:24 +0300
commit0653e08efd039a5905f3fa4f6e9cef9f5d2f799c (patch)
tree4dcc884cf6d81db44adae4aa99f8ec1233a41f55 /lib/gitlab/graphql
parent744144d28e3e7fddc117924fef88de5d9674fe4c (diff)
Add latest changes from gitlab-org/gitlab@14-3-stable-eev14.3.0-rc42
Diffstat (limited to 'lib/gitlab/graphql')
-rw-r--r--lib/gitlab/graphql/authorize/connection_filter_extension.rb15
-rw-r--r--lib/gitlab/graphql/loaders/full_path_model_loader.rb5
-rw-r--r--lib/gitlab/graphql/todos_project_permission_preloader/field_extension.rb26
3 files changed, 15 insertions, 31 deletions
diff --git a/lib/gitlab/graphql/authorize/connection_filter_extension.rb b/lib/gitlab/graphql/authorize/connection_filter_extension.rb
index c75510df3e3..889c024ab5e 100644
--- a/lib/gitlab/graphql/authorize/connection_filter_extension.rb
+++ b/lib/gitlab/graphql/authorize/connection_filter_extension.rb
@@ -7,12 +7,14 @@ module Gitlab
class Redactor
include ::Gitlab::Graphql::Laziness
- def initialize(type, context)
+ def initialize(type, context, resolver)
@type = type
@context = context
+ @resolver = resolver
end
def redact(nodes)
+ perform_before_authorize_action(nodes)
remove_unauthorized(nodes)
nodes
@@ -29,6 +31,13 @@ module Gitlab
private
+ def perform_before_authorize_action(nodes)
+ before_connection_authorization_block = @resolver&.before_connection_authorization_block
+ return unless before_connection_authorization_block.respond_to?(:call)
+
+ before_connection_authorization_block.call(nodes, @context[:current_user])
+ end
+
def remove_unauthorized(nodes)
nodes
.map! { |lazy| force(lazy) }
@@ -49,14 +58,14 @@ module Gitlab
end
def redact_connection(conn, context)
- redactor = Redactor.new(@field.type.unwrap.node_type, context)
+ redactor = Redactor.new(@field.type.unwrap.node_type, context, @field.resolver)
return unless redactor.active?
conn.redactor = redactor if conn.respond_to?(:redactor=)
end
def redact_list(list, context)
- redactor = Redactor.new(@field.type.unwrap, context)
+ redactor = Redactor.new(@field.type.unwrap, context, @field.resolver)
redactor.redact(list) if redactor.active?
end
end
diff --git a/lib/gitlab/graphql/loaders/full_path_model_loader.rb b/lib/gitlab/graphql/loaders/full_path_model_loader.rb
index 26c1ce64a83..7f9013c6e4c 100644
--- a/lib/gitlab/graphql/loaders/full_path_model_loader.rb
+++ b/lib/gitlab/graphql/loaders/full_path_model_loader.rb
@@ -5,19 +5,20 @@ module Gitlab
module Loaders
# Suitable for use to find resources that expose `where_full_path_in`,
# such as Project, Group, Namespace
+ # full path is always converted to lowercase for case-insensitive results
class FullPathModelLoader
attr_reader :model_class, :full_path
def initialize(model_class, full_path)
@model_class = model_class
- @full_path = full_path
+ @full_path = full_path.downcase
end
def find
BatchLoader::GraphQL.for(full_path).batch(key: model_class) do |full_paths, loader, args|
# `with_route` avoids an N+1 calculating full_path
args[:key].where_full_path_in(full_paths).with_route.each do |model_instance|
- loader.call(model_instance.full_path, model_instance)
+ loader.call(model_instance.full_path.downcase, model_instance)
end
end
end
diff --git a/lib/gitlab/graphql/todos_project_permission_preloader/field_extension.rb b/lib/gitlab/graphql/todos_project_permission_preloader/field_extension.rb
deleted file mode 100644
index 77f3b1ac71a..00000000000
--- a/lib/gitlab/graphql/todos_project_permission_preloader/field_extension.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-# frozen_string_literal: true
-
-module Gitlab
- module Graphql
- module TodosProjectPermissionPreloader
- class FieldExtension < ::GraphQL::Schema::FieldExtension
- def after_resolve(value:, memo:, **rest)
- todos = value.to_a
-
- Preloaders::UserMaxAccessLevelInProjectsPreloader.new(
- todos.map(&:project).compact,
- current_user(rest)
- ).execute
-
- value
- end
-
- private
-
- def current_user(options)
- options.dig(:context, :current_user)
- end
- end
- end
- end
-end