Commit 48652311 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch '224499-add-graphql-authorizetype-cop-to-ee-namespaced-types' into 'master'

Resolve "Add Graphql/AuthorizeType cop to EE namespaced types"

See merge request gitlab-org/gitlab!35531
parents 8e6f1709 0e2f0750
...@@ -328,6 +328,9 @@ Cop/SidekiqOptionsQueue: ...@@ -328,6 +328,9 @@ Cop/SidekiqOptionsQueue:
Graphql/AuthorizeTypes: Graphql/AuthorizeTypes:
Enabled: true Enabled: true
Include:
- 'app/graphql/types/**/*'
- 'ee/app/graphql/types/**/*'
Exclude: Exclude:
- 'spec/**/*.rb' - 'spec/**/*.rb'
- 'ee/spec/**/*.rb' - 'ee/spec/**/*.rb'
......
...@@ -7,8 +7,6 @@ module RuboCop ...@@ -7,8 +7,6 @@ module RuboCop
MSG = 'Add an `authorize :ability` call to the type: '\ MSG = 'Add an `authorize :ability` call to the type: '\
'https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#type-authorization' '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 # We want to exclude our own basetypes and scalars
WHITELISTED_TYPES = %w[BaseEnum BaseScalar BasePermissionType MutationType WHITELISTED_TYPES = %w[BaseEnum BaseScalar BasePermissionType MutationType
QueryType GraphQL::Schema BaseUnion].freeze QueryType GraphQL::Schema BaseUnion].freeze
...@@ -18,7 +16,6 @@ module RuboCop ...@@ -18,7 +16,6 @@ module RuboCop
PATTERN PATTERN
def on_class(node) def on_class(node)
return unless in_type?(node)
return if whitelisted?(class_constant(node)) return if whitelisted?(class_constant(node))
return if whitelisted?(superclass_constant(node)) return if whitelisted?(superclass_constant(node))
...@@ -27,12 +24,6 @@ module RuboCop ...@@ -27,12 +24,6 @@ module RuboCop
private private
def in_type?(node)
path = node.location.expression.source_buffer.name
path.include? TYPES_DIR
end
def whitelisted?(class_node) def whitelisted?(class_node)
class_const = class_node&.const_name class_const = class_node&.const_name
......
...@@ -10,28 +10,6 @@ RSpec.describe RuboCop::Cop::Graphql::AuthorizeTypes, type: :rubocop do ...@@ -10,28 +10,6 @@ RSpec.describe RuboCop::Cop::Graphql::AuthorizeTypes, type: :rubocop do
subject(:cop) { described_class.new } subject(:cop) { described_class.new }
context 'when NOT in a type folder' do
before do
allow(cop).to receive(:in_type?).and_return(false)
end
it 'does not add an offense even though there is no authorize call' do
expect_no_offenses(<<~TYPE.strip)
module Types
class AType < BaseObject
field :a_thing
field :another_thing
end
end
TYPE
end
end
context 'when in a type folder' do
before do
allow(cop).to receive(:in_type?).and_return(true)
end
it 'adds an offense when there is no authorize call' do it 'adds an offense when there is no authorize call' do
inspect_source(<<~TYPE) inspect_source(<<~TYPE)
module Types module Types
...@@ -88,5 +66,4 @@ RSpec.describe RuboCop::Cop::Graphql::AuthorizeTypes, type: :rubocop do ...@@ -88,5 +66,4 @@ RSpec.describe RuboCop::Cop::Graphql::AuthorizeTypes, type: :rubocop do
end end
TYPE TYPE
end end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment