diff options
Diffstat (limited to 'rubocop/cop/graphql/authorize_types.rb')
-rw-r--r-- | rubocop/cop/graphql/authorize_types.rb | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/rubocop/cop/graphql/authorize_types.rb b/rubocop/cop/graphql/authorize_types.rb index 7aaa9299362..1dba719cdff 100644 --- a/rubocop/cop/graphql/authorize_types.rb +++ b/rubocop/cop/graphql/authorize_types.rb @@ -7,39 +7,30 @@ module RuboCop MSG = 'Add an `authorize :ability` call to the type: '\ 'https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#type-authorization' - TYPES_DIR = 'app/graphql/types' - # We want to exclude our own basetypes and scalars - WHITELISTED_TYPES = %w[BaseEnum BaseScalar BasePermissionType MutationType - QueryType GraphQL::Schema BaseUnion].freeze + ALLOWED_TYPES = %w[BaseEnum BaseScalar BasePermissionType MutationType + QueryType GraphQL::Schema BaseUnion].freeze def_node_search :authorize?, <<~PATTERN (send nil? :authorize ...) PATTERN def on_class(node) - return unless in_type?(node) - return if whitelisted?(class_constant(node)) - return if whitelisted?(superclass_constant(node)) + return if allowed?(class_constant(node)) + return if allowed?(superclass_constant(node)) add_offense(node, location: :expression) unless authorize?(node) end private - def in_type?(node) - path = node.location.expression.source_buffer.name - - path.include? TYPES_DIR - end - - def whitelisted?(class_node) + def allowed?(class_node) class_const = class_node&.const_name return false unless class_const return true if class_const.end_with?('Enum') - WHITELISTED_TYPES.any? { |whitelisted| class_node.const_name.include?(whitelisted) } + ALLOWED_TYPES.any? { |allowed| class_node.const_name.include?(allowed) } end def class_constant(node) |