2018-09-11 19:08:34 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-23 07:55:14 +00:00
|
|
|
module Types
|
|
|
|
class BaseObject < GraphQL::Schema::Object
|
|
|
|
prepend Gitlab::Graphql::Present
|
2018-06-25 08:59:00 +00:00
|
|
|
prepend Gitlab::Graphql::ExposePermissions
|
2019-06-20 08:02:33 +00:00
|
|
|
prepend Gitlab::Graphql::MarkdownField
|
2018-05-23 07:55:14 +00:00
|
|
|
|
|
|
|
field_class Types::BaseField
|
2019-06-03 17:38:16 +00:00
|
|
|
|
2020-11-07 00:08:58 +00:00
|
|
|
def self.accepts(*types)
|
|
|
|
@accepts ||= []
|
|
|
|
@accepts += types
|
|
|
|
@accepts
|
|
|
|
end
|
|
|
|
|
2019-06-03 17:38:16 +00:00
|
|
|
# All graphql fields exposing an id, should expose a global id.
|
|
|
|
def id
|
|
|
|
GitlabSchema.id_from_object(object)
|
|
|
|
end
|
2020-06-03 00:08:38 +00:00
|
|
|
|
2021-03-18 06:11:52 +00:00
|
|
|
def self.authorization
|
|
|
|
@authorization ||= ::Gitlab::Graphql::Authorize::ObjectAuthorization.new(authorize)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.authorized?(object, context)
|
|
|
|
authorization.ok?(object, context[:current_user])
|
|
|
|
end
|
|
|
|
|
2020-06-03 00:08:38 +00:00
|
|
|
def current_user
|
|
|
|
context[:current_user]
|
|
|
|
end
|
2020-11-07 00:08:58 +00:00
|
|
|
|
|
|
|
def self.assignable?(object)
|
|
|
|
assignable = accepts
|
|
|
|
|
|
|
|
return true if assignable.blank?
|
|
|
|
|
|
|
|
assignable.any? { |cls| object.is_a?(cls) }
|
|
|
|
end
|
2018-05-23 07:55:14 +00:00
|
|
|
end
|
|
|
|
end
|