diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 16:18:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-20 16:18:24 +0300 |
commit | 0653e08efd039a5905f3fa4f6e9cef9f5d2f799c (patch) | |
tree | 4dcc884cf6d81db44adae4aa99f8ec1233a41f55 /lib/gitlab/graphql | |
parent | 744144d28e3e7fddc117924fef88de5d9674fe4c (diff) |
Add latest changes from gitlab-org/gitlab@14-3-stable-eev14.3.0-rc42
Diffstat (limited to 'lib/gitlab/graphql')
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 |