Commit f23d2727 authored by Sean McGivern's avatar Sean McGivern

Merge branch '33451-graphql-whilelist-enum-types-for-rubocop-in-authorize_types-rb' into 'master'

GraphQL: Whilelist Enum types for rubocop in authorize_types.rb

See merge request gitlab-org/gitlab!20580
parents 655e07d1 c5729733
# frozen_string_literal: true
module Types
# rubocop: disable Graphql/AuthorizeTypes
class IssuableSortEnum < SortEnum
graphql_name 'IssuableSort'
description 'Values for sorting issuables'
end
# rubocop: enable Graphql/AuthorizeTypes
end
# frozen_string_literal: true
module Types
# rubocop: disable Graphql/AuthorizeTypes
class IssueSortEnum < IssuableSortEnum
graphql_name 'IssueSort'
description 'Values for sorting issues'
......@@ -10,7 +9,6 @@ module Types
value 'DUE_DATE_DESC', 'Due date by descending order', value: 'due_date_desc'
value 'RELATIVE_POSITION_ASC', 'Relative position by ascending order', value: 'relative_position_asc'
end
# rubocop: enable Graphql/AuthorizeTypes
end
Types::IssueSortEnum.prepend_if_ee('::EE::Types::IssueSortEnum')
# frozen_string_literal: true
module Types
# rubocop: disable Graphql/AuthorizeTypes
# This is a BaseEnum through IssuableEnum, so it does not need authorization
class IssueStateEnum < IssuableStateEnum
graphql_name 'IssueState'
description 'State of a GitLab issue'
end
# rubocop: enable Graphql/AuthorizeTypes
end
# frozen_string_literal: true
module Types
# rubocop: disable Graphql/AuthorizeTypes
# This is a BaseEnum through IssuableEnum, so it does not need authorization
class MergeRequestStateEnum < IssuableStateEnum
graphql_name 'MergeRequestState'
description 'State of a GitLab merge request'
value 'merged'
end
# rubocop: enable Graphql/AuthorizeTypes
end
......@@ -34,7 +34,10 @@ module RuboCop
end
def whitelisted?(class_node)
return false unless class_node&.const_name
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) }
end
......
......@@ -79,5 +79,15 @@ describe RuboCop::Cop::Graphql::AuthorizeTypes do
end
TYPE
end
it 'does not add an offense for Enums' do
expect_no_offenses(<<~TYPE)
module Types
class ATypeEnum < AnotherEnum
field :a_thing
end
end
TYPE
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