Class: Types::WorkItems::Widgets::HierarchyType

Inherits:
BaseObject
  • Object
show all
Defined in:
app/graphql/types/work_items/widgets/hierarchy_type.rb

Overview

Disabling widget level authorization as it might be too granular and we already authorize the parent work item rubocop:disable Graphql/AuthorizeTypes

Instance Method Summary collapse

Methods inherited from BaseObject

accepts, assignable?, authorization, authorize, authorized?, #current_user, #id

Methods included from Gitlab::Graphql::Present

#present, #unpresented

Instance Method Details

#childrenObject



41
42
43
44
45
46
# File 'app/graphql/types/work_items/widgets/hierarchy_type.rb', line 41

def children
  relation = object.children
  relation = relation.inc_relations_for_permission_check unless object.children.loaded?

  relation
end

#has_children?Boolean Also known as: has_children

rubocop: disable CodeReuse/ActiveRecord

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
# File 'app/graphql/types/work_items/widgets/hierarchy_type.rb', line 27

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