Module: SidebarsHelper

Includes:
MergeRequestsHelper, Nav::NewDropdownHelper
Included in:
Users::PinsController
Defined in:
app/helpers/sidebars_helper.rb

Constant Summary

Constants included from MergeRequestsHelper

MergeRequestsHelper::DIFF_BATCH_ENDPOINT_PER_PAGE

Instance Method Summary collapse

Methods included from Nav::NewDropdownHelper

#new_dropdown_view_model

Methods included from MergeRequestsHelper

#allow_collaboration_unavailable_reason, #award_emoji_merge_request_api_path, #can_use_description_composer, #common_merge_request_list_data, #create_mr_button_from_event?, #create_mr_path_from_push_event, #default_merge_request_sort, #diffs_tab_pane_data, #format_mr_branch_names, #group_merge_requests_list_data, #how_merge_modal_data, #identity_verification_alert_data, #merge_params, #merge_path_description, #merge_request_button_hidden?, #merge_request_dashboard_show_drafts?, #merge_request_source_project_for_project, #merge_request_squash_option?, #merge_request_version_path, #mr_change_branches_path, #mr_compare_form_data, #mr_css_classes, #notifications_todos_buttons_enabled?, #project_merge_requests_list_data, #reviewers_label, #show_mr_dashboard_banner?, #sticky_header_data, #summarize_new_merge_request_disabled_reason, #tab_link_for, #target_projects

Methods included from CompareHelper

#create_mr_button?, #create_mr_path, #project_compare_selector_data, #target_projects

Instance Method Details

#command_palette_data(project: nil, current_ref: nil) ⇒ Object



213
214
215
216
217
218
219
220
221
# File 'app/helpers/sidebars_helper.rb', line 213

def command_palette_data(project: nil, current_ref: nil)
  return {} unless project&.repo_exists?
  return {} if project.empty_repo?

  {
    project_files_url: project_files_path(project, current_ref || project.default_branch, format: :json),
    project_blob_url: project_blob_path(project, current_ref || project.default_branch)
  }
end

#compare_plans_urlObject



223
224
225
# File 'app/helpers/sidebars_helper.rb', line 223

def compare_plans_url(*)
  "#{promo_url}/pricing"
end

#group_sidebar_context(group, user, **args) ⇒ Object



16
17
18
19
20
# File 'app/helpers/sidebars_helper.rb', line 16

def group_sidebar_context(group, user, **args)
  context_data = group_sidebar_context_data(group, user)

  Sidebars::Groups::Context.new(**context_data, **args)
end

#organization_sidebar_context(organization, user, **args) ⇒ Object



7
8
9
# File 'app/helpers/sidebars_helper.rb', line 7

def organization_sidebar_context(organization, user, **args)
  Sidebars::Context.new(container: organization, current_user: user, **args)
end

#project_sidebar_context(project, user, current_ref, ref_type: nil, **args) ⇒ Object



11
12
13
14
# File 'app/helpers/sidebars_helper.rb', line 11

def project_sidebar_context(project, user, current_ref, ref_type: nil, **args)
  context_data = project_sidebar_context_data(project, user, current_ref, ref_type: ref_type)
  Sidebars::Projects::Context.new(**context_data, **args)
end

#super_sidebar_context(user, group:, project:, panel:, panel_type:) ⇒ Object



28
29
30
31
32
# File 'app/helpers/sidebars_helper.rb', line 28

def super_sidebar_context(user, group:, project:, panel:, panel_type:)
  return super_sidebar_logged_out_context(panel: panel, panel_type: panel_type) unless user

  super_sidebar_logged_in_context(user, group: group, project: project, panel: panel, panel_type: panel_type)
end

#super_sidebar_instance_version_dataObject



121
122
123
124
125
126
127
128
# File 'app/helpers/sidebars_helper.rb', line 121

def super_sidebar_instance_version_data
  return {} unless show_version_check?

  {
    gitlab_version: Gitlab.version_info,
    gitlab_version_check: gitlab_version_check
  }
end

#super_sidebar_logged_in_context(user, group:, project:, panel:, panel_type:) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'app/helpers/sidebars_helper.rb', line 66

def super_sidebar_logged_in_context(user, group:, project:, panel:, panel_type:)
  super_sidebar_shared_context(panel: panel, panel_type: panel_type).merge({
    is_logged_in: true,
    is_admin: user.can_admin_all_resources?,
    name: user.name,
    username: user.username,
    admin_url: admin_root_path,
    admin_mode: {
      admin_mode_feature_enabled: Gitlab::CurrentSettings.admin_mode,
      admin_mode_active: current_user_mode.admin_mode?,
      enter_admin_mode_url: new_admin_session_path,
      leave_admin_mode_url: destroy_admin_session_path,
      user_is_admin: user.can_access_admin_area?
    },
    avatar_url: user.avatar_url,
    has_link_to_profile: current_user_menu?(:profile),
    link_to_profile: user_path(user),
    logo_url: current_appearance&.header_logo_path,
    status: user_status_menu_data(user),
    settings: {
      has_settings: current_user_menu?(:settings),
      profile_path: ,
      profile_preferences_path: profile_preferences_path
    },
    user_counts: {
      assigned_issues: user.assigned_open_issues_count,
      assigned_merge_requests: user.all_assigned_merge_requests_count(cached_only: true),
      review_requested_merge_requests: user.review_requested_open_merge_requests_count(cached_only: true),
      todos: user.todos_pending_count,
      last_update: time_in_milliseconds
    },
    can_sign_out: current_user_menu?(:sign_out),
    sign_out_link: destroy_user_session_path,
    issues_dashboard_path: issues_dashboard_path(assignee_username: user.username),
    merge_request_dashboard_path: merge_requests_dashboard_path,
    todos_dashboard_path: dashboard_todos_path,
    compare_plans_url: compare_plans_url(user: user, project: project, group: group),
    create_new_menu_groups: create_new_menu_groups(group: group, project: project),
    projects_path: dashboard_projects_path,
    groups_path: dashboard_groups_path,
    gitlab_com_but_not_canary: Gitlab.com_but_not_canary?,
    gitlab_com_and_canary: Gitlab.com_and_canary?,
    canary_toggle_com_url: Gitlab.canary_toggle_com_url,
    current_context: super_sidebar_current_context(project: project, group: group),
    pinned_items: pinned_items(user, panel_type, group: group),
    update_pins_url: pins_path,
    is_impersonating: impersonating?,
    stop_impersonation_path: admin_impersonation_path,
    shortcut_links: shortcut_links(user: user, project: project),
    track_visits_path: track_namespace_visits_path,
    work_items: work_items_modal_data(group, project),
    has_multiple_organizations: user.has_multiple_organizations?
  })
end

#super_sidebar_logged_out_context(panel:, panel_type:) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/helpers/sidebars_helper.rb', line 53

def super_sidebar_logged_out_context(panel:, panel_type:)
  sidebar_context = super_sidebar_shared_context(panel: panel, panel_type: panel_type)

  return sidebar_context unless project_studio_enabled?

  sidebar_context.merge({
    sign_in_visible: header_link?(:sign_in).to_s,
    allow_signup: allow_signup?.to_s,
    new_user_registration_path: new_user_registration_path,
    sign_in_path: new_session_path(:user, redirect_to_referer: 'yes')
  })
end

#super_sidebar_nav_panel(nav: nil, project: nil, user: nil, group: nil, current_ref: nil, ref_type: nil, viewed_user: nil, organization: nil) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'app/helpers/sidebars_helper.rb', line 168

def super_sidebar_nav_panel(
  nav: nil, project: nil, user: nil, group: nil, current_ref: nil, ref_type: nil,
  viewed_user: nil, organization: nil)
  context_adds = { route_is_active: method(:active_nav_link?), is_super_sidebar: true }
  panel = case nav
          when 'project'
            context = project_sidebar_context(project, user, current_ref, ref_type: ref_type, **context_adds)
            Sidebars::Projects::SuperSidebarPanel.new(context)
          when 'group'
            context = group_sidebar_context(group, user, **context_adds)
            Sidebars::Groups::SuperSidebarPanel.new(context)
          when 'profile'
            context = Sidebars::Context.new(current_user: user, container: user, **context_adds)
            Sidebars::UserSettings::Panel.new(context)
          when 'user_profile'
            context = Sidebars::Context.new(current_user: user, container: viewed_user, **context_adds)
            Sidebars::UserProfile::Panel.new(context)
          when 'explore'
            Sidebars::Explore::Panel.new(
              Sidebars::Context.new(
                current_user: user,
                container: nil,
                current_organization: Current.organization,
                **context_adds
              )
            )
          when 'search'
            context = Sidebars::Context.new(current_user: user, container: nil, **context_adds)
            Sidebars::Search::Panel.new(context)
          when 'admin'
            Sidebars::Admin::Panel.new(Sidebars::Context.new(current_user: user, container: nil, **context_adds))
          when 'organization'
            context = organization_sidebar_context(organization, user, **context_adds)
            Sidebars::Organizations::SuperSidebarPanel.new(context)
          when 'your_work'
            context = your_work_sidebar_context(user, **context_adds)
            Sidebars::YourWork::Panel.new(context)
          end

  # We only return the panel if any menu item is rendered, otherwise fallback
  return panel if panel&.render?

  fallback_sidebar_panel(nav, context_adds, user)
end

#super_sidebar_shared_context(panel:, panel_type:) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/helpers/sidebars_helper.rb', line 34

def super_sidebar_shared_context(panel:, panel_type:)
  super_sidebar_instance_version_data.merge(super_sidebar_whats_new_data).merge({
    is_logged_in: false,
    compare_plans_url: compare_plans_url,
    context_switcher_links: context_switcher_links,
    current_menu_items: panel.super_sidebar_menu_items,
    current_context_header: panel.super_sidebar_context_header,
    university_path: university_url,
    support_path: support_url,
    docs_path: help_docs_path,
    display_whats_new: display_whats_new?,
    show_version_check: show_version_check?,
    search: search_data,
    panel_type: panel_type,
    shortcut_links: shortcut_links,
    terms: terms_link
  })
end

#super_sidebar_whats_new_dataObject



130
131
132
133
134
135
136
137
138
139
# File 'app/helpers/sidebars_helper.rb', line 130

def super_sidebar_whats_new_data
  return {} unless display_whats_new?

  {
    whats_new_most_recent_release_items_count: whats_new_most_recent_release_items_count,
    whats_new_version_digest: whats_new_version_digest,
    whats_new_read_articles: whats_new_read_articles,
    whats_new_mark_as_read_path: whats_new_mark_as_read_path
  }
end

#work_items_modal_data(group, project) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'app/helpers/sidebars_helper.rb', line 141

def work_items_modal_data(group, project)
  if project&.persisted?
    return {
      full_path: project.full_path,
      has_issuable_health_status_feature: project.licensed_feature_available?(:issuable_health_status).to_s,
      issues_list_path: project_issues_path(project),
      labels_manage_path: project_labels_path(project),
      can_admin_label: can?(current_user, :admin_label, project).to_s,
      has_issue_weights_feature: project.licensed_feature_available?(:issue_weights).to_s,
      has_iterations_feature: project.licensed_feature_available?(:iterations).to_s,
      work_item_planning_view_enabled: project.work_items_consolidated_list_enabled?(current_user).to_s
    }
  end

  return unless group && group.id

  {
    full_path: group.full_path,
    has_issuable_health_status_feature: group.licensed_feature_available?(:issuable_health_status).to_s,
    issues_list_path: issues_group_path(group),
    labels_manage_path: group_labels_path(group),
    can_admin_label: can?(current_user, :admin_label, group).to_s,
    has_issue_weights_feature: group.licensed_feature_available?(:issue_weights).to_s,
    work_item_planning_view_enabled: group.work_items_consolidated_list_enabled?(current_user).to_s
  }
end

#your_work_sidebar_context(user, **args) ⇒ Object



22
23
24
25
26
# File 'app/helpers/sidebars_helper.rb', line 22

def your_work_sidebar_context(user, **args)
  context_data = your_work_context_data(user)

  Sidebars::Context.new(**context_data, **args)
end