2020-05-24 23:13:21 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Resolvers
|
|
|
|
module DesignManagement
|
|
|
|
class DesignAtVersionResolver < BaseResolver
|
|
|
|
include Gitlab::Graphql::Authorize::AuthorizeResource
|
|
|
|
|
|
|
|
type Types::DesignManagement::DesignAtVersionType, null: false
|
|
|
|
|
|
|
|
authorize :read_design
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
argument :id, ::Types::GlobalIDType[::DesignManagement::DesignAtVersion],
|
2020-05-24 23:13:21 +05:30
|
|
|
required: true,
|
|
|
|
description: 'The Global ID of the design at this version'
|
|
|
|
|
|
|
|
def resolve(id:)
|
|
|
|
authorized_find!(id: id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_object(id:)
|
2021-01-29 00:20:46 +05:30
|
|
|
# TODO: remove this line when the compatibility layer is removed
|
|
|
|
# See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883
|
|
|
|
id = ::Types::GlobalIDType[::DesignManagement::DesignAtVersion].coerce_isolated_input(id)
|
|
|
|
dav = GitlabSchema.find_by_gid(id)
|
2020-05-24 23:13:21 +05:30
|
|
|
return unless consistent?(dav)
|
|
|
|
|
|
|
|
dav
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.single
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# If this resolver is mounted on something that has an issue
|
|
|
|
# (such as design collection for instance), then we should check
|
|
|
|
# that the DesignAtVersion as found by its ID does in fact belong
|
|
|
|
# to this issue.
|
|
|
|
def consistent?(dav)
|
2021-01-29 00:20:46 +05:30
|
|
|
issue.nil? || (dav.present? && dav.design&.issue_id == issue.id)
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def issue
|
|
|
|
object&.issue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|