diff options
Diffstat (limited to 'app/graphql/types/work_items')
4 files changed, 72 insertions, 2 deletions
diff --git a/app/graphql/types/work_items/notes_filter_type_enum.rb b/app/graphql/types/work_items/notes_filter_type_enum.rb new file mode 100644 index 00000000000..93fb4689f0b --- /dev/null +++ b/app/graphql/types/work_items/notes_filter_type_enum.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Types + module WorkItems + class NotesFilterTypeEnum < BaseEnum + graphql_name 'NotesFilterType' + description 'Work item notes collection type.' + + ::UserPreference::NOTES_FILTERS.each_pair do |key, value| + value key.upcase, + value: value, + description: UserPreference.notes_filters.invert[::UserPreference::NOTES_FILTERS[key]] + end + + def self.default_value + ::UserPreference::NOTES_FILTERS[:all_notes] + end + end + end +end diff --git a/app/graphql/types/work_items/widget_interface.rb b/app/graphql/types/work_items/widget_interface.rb index b85d0a23535..672a78f12e1 100644 --- a/app/graphql/types/work_items/widget_interface.rb +++ b/app/graphql/types/work_items/widget_interface.rb @@ -17,7 +17,8 @@ module Types ::Types::WorkItems::Widgets::LabelsType, ::Types::WorkItems::Widgets::AssigneesType, ::Types::WorkItems::Widgets::StartAndDueDateType, - ::Types::WorkItems::Widgets::MilestoneType + ::Types::WorkItems::Widgets::MilestoneType, + ::Types::WorkItems::Widgets::NotesType ].freeze def self.ce_orphan_types @@ -41,6 +42,8 @@ module Types ::Types::WorkItems::Widgets::StartAndDueDateType when ::WorkItems::Widgets::Milestone ::Types::WorkItems::Widgets::MilestoneType + when ::WorkItems::Widgets::Notes + ::Types::WorkItems::Widgets::NotesType else raise "Unknown GraphQL type for widget #{object}" end diff --git a/app/graphql/types/work_items/widgets/hierarchy_type.rb b/app/graphql/types/work_items/widgets/hierarchy_type.rb index 0ccd8af7dc8..4ec8ec84779 100644 --- a/app/graphql/types/work_items/widgets/hierarchy_type.rb +++ b/app/graphql/types/work_items/widgets/hierarchy_type.rb @@ -20,8 +20,29 @@ module Types null: true, complexity: 5, description: 'Child work items.' + field :has_children, GraphQL::Types::Boolean, + null: false, description: 'Indicates if the work item has children.' + + # rubocop: disable CodeReuse/ActiveRecord + def has_children? + BatchLoader::GraphQL.for(object.work_item.id).batch(default_value: false) do |ids, loader| + links_for_parents = ::WorkItems::ParentLink.for_parents(ids) + .select(:work_item_parent_id) + .group(:work_item_parent_id) + .reorder(nil) + + links_for_parents.each { |link| loader.call(link.work_item_parent_id, true) } + end + end + # rubocop: enable CodeReuse/ActiveRecord + + alias_method :has_children, :has_children? + def children - object.children.inc_relations_for_permission_check + relation = object.children + relation = relation.inc_relations_for_permission_check unless object.children.loaded? + + relation end end # rubocop:enable Graphql/AuthorizeTypes diff --git a/app/graphql/types/work_items/widgets/notes_type.rb b/app/graphql/types/work_items/widgets/notes_type.rb new file mode 100644 index 00000000000..7da2777beee --- /dev/null +++ b/app/graphql/types/work_items/widgets/notes_type.rb @@ -0,0 +1,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 NotesType < BaseObject + graphql_name 'WorkItemWidgetNotes' + description 'Represents a notes widget' + + implements Types::WorkItems::WidgetInterface + + # This field loads user comments, system notes and resource events as a discussion for an work item, + # raising the complexity considerably. In order to discourage fetching this field as part of fetching + # a list of issues we raise the complexity + field :discussions, Types::Notes::DiscussionType.connection_type, + null: true, + description: "Notes on this work item.", + resolver: Resolvers::WorkItems::WorkItemDiscussionsResolver + end + # rubocop:enable Graphql/AuthorizeTypes + end + end +end |