2019-06-07 17:13:26 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Types
|
|
|
|
module Notes
|
|
|
|
class DiscussionType < BaseObject
|
2021-01-20 15:10:29 +00:00
|
|
|
DiscussionID = ::Types::GlobalIDType[::Discussion]
|
|
|
|
|
2019-06-07 17:13:26 +00:00
|
|
|
graphql_name 'Discussion'
|
|
|
|
|
|
|
|
authorize :read_note
|
|
|
|
|
2020-06-01 00:08:25 +00:00
|
|
|
implements(Types::ResolvableInterface)
|
|
|
|
|
2021-01-20 15:10:29 +00:00
|
|
|
field :id, DiscussionID, null: false,
|
2021-02-05 15:09:28 +00:00
|
|
|
description: "ID of this discussion."
|
2021-01-20 15:10:29 +00:00
|
|
|
field :reply_id, DiscussionID, null: false,
|
2021-02-05 15:09:28 +00:00
|
|
|
description: 'ID used to reply to this discussion.'
|
2019-12-16 00:07:33 +00:00
|
|
|
field :created_at, Types::TimeType, null: false,
|
2021-02-05 15:09:28 +00:00
|
|
|
description: "Timestamp of the discussion's creation."
|
2019-12-16 00:07:33 +00:00
|
|
|
field :notes, Types::Notes::NoteType.connection_type, null: false,
|
2021-02-05 15:09:28 +00:00
|
|
|
description: 'All notes in the discussion.'
|
2021-07-05 15:07:38 +00:00
|
|
|
field :noteable, Types::NoteableType, null: true,
|
|
|
|
description: 'Object which the discussion belongs to.'
|
2019-07-04 03:33:14 +00:00
|
|
|
|
2021-01-20 15:10:29 +00:00
|
|
|
# DiscussionID.coerce_result is suitable here, but will always mark this
|
|
|
|
# as being a 'Discussion'. Using `GlobalId.build` guarantees that we get
|
|
|
|
# the correct class, and that it matches `id`.
|
2019-07-04 03:33:14 +00:00
|
|
|
def reply_id
|
|
|
|
::Gitlab::GlobalId.build(object, id: object.reply_id)
|
|
|
|
end
|
2021-07-05 15:07:38 +00:00
|
|
|
|
|
|
|
def noteable
|
|
|
|
noteable = object.noteable
|
|
|
|
|
|
|
|
return unless Ability.allowed?(context[:current_user], :"read_#{noteable.to_ability_name}", noteable)
|
|
|
|
|
|
|
|
noteable
|
|
|
|
end
|
2019-06-07 17:13:26 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|