Class: HasHelpers::Resolvers::AppNav

Inherits:
Base
  • Object
show all
Defined in:
app/graphql/has_helpers/resolvers/app_nav.rb

Instance Method Summary collapse

Methods included from Middleware::ApplicationAccess

#authorized?

Instance Method Details

#resolveObject

Creates the link sections in the app nav that are tied to a specific user or organization.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/graphql/has_helpers/resolvers/app_nav.rb', line 20

def resolve
  link_sections = []

  # Whether or not an application link section is shown depends on the user.
  link_section_for_applications = application_link_section(current_application_name: current_application.name, user: current_user)
  link_sections << link_section_for_applications if link_section_for_applications[:links].any?

  # Whether or not an external links section is shown depends on the organization.
  external_links = current_organization.organization_links.side_links.select(&:persisted?)
  parent_links = []
  children_links = []
  external_links.each do |el|
    if el.parent_id.nil?
      parent_links << el
    else
      children_links << el
    end
  end
  link_sections << external_link_section(
    organization: current_organization,
    request: request,
    user: current_user,
    organization_links: parent_links,
    sublinks: children_links) if external_links.any?

  { link_sections: link_sections }
end