summaryrefslogtreecommitdiff
path: root/app/graphql/types/work_items/widgets/notifications_type.rb
blob: 85928817d07996062aaf84f6c37d19c6753a6ea6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# frozen_string_literal: true

module Types
  module WorkItems
    module Widgets
      # Disabling widget level authorization as it might be too granular
      # and we already authorize the parent work item
      # rubocop:disable Graphql/AuthorizeTypes
      class NotificationsType < BaseObject
        graphql_name 'WorkItemWidgetNotifications'
        description 'Represents the notifications widget'

        implements Types::WorkItems::WidgetInterface

        field :subscribed, GraphQL::Types::Boolean,
          null: false,
          description: 'Whether the current user is subscribed to notifications on the work item.'

        def subscribed
          object.work_item.subscribed?(current_user, object.work_item.project)
        end
      end
      # rubocop:enable Graphql/AuthorizeTypes
    end
  end
end