2021-04-29 21:17:54 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module SidebarsHelper
|
2023-04-23 21:23:45 +05:30
|
|
|
include MergeRequestsHelper
|
|
|
|
include Nav::NewDropdownHelper
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
def sidebar_tracking_attributes_by_object(object)
|
2021-09-30 23:02:18 +05:30
|
|
|
sidebar_attributes_for_object(object).fetch(:tracking_attrs, {})
|
|
|
|
end
|
|
|
|
|
|
|
|
def sidebar_qa_selector(object)
|
|
|
|
sidebar_attributes_for_object(object).fetch(:sidebar_qa_selector, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
def scope_qa_menu_item(object)
|
|
|
|
sidebar_attributes_for_object(object).fetch(:scope_qa_menu_item, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
def scope_avatar_classes(object)
|
|
|
|
%w[avatar-container rect-avatar s32].tap do |klasses|
|
|
|
|
klass = sidebar_attributes_for_object(object).fetch(:scope_avatar_class, nil)
|
|
|
|
klasses << klass if klass
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
def project_sidebar_context(project, user, current_ref, ref_type: nil, **args)
|
2023-03-04 22:38:38 +05:30
|
|
|
context_data = project_sidebar_context_data(project, user, current_ref, ref_type: ref_type)
|
2023-05-27 22:25:52 +05:30
|
|
|
Sidebars::Projects::Context.new(**context_data, **args)
|
2021-09-30 23:02:18 +05:30
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
def group_sidebar_context(group, user, **args)
|
2021-09-30 23:02:18 +05:30
|
|
|
context_data = group_sidebar_context_data(group, user)
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
Sidebars::Groups::Context.new(**context_data, **args)
|
2021-09-30 23:02:18 +05:30
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
def your_work_sidebar_context(user, **args)
|
|
|
|
context_data = your_work_context_data(user)
|
|
|
|
|
|
|
|
Sidebars::Context.new(**context_data, **args)
|
|
|
|
end
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
def super_sidebar_context(user, group:, project:, panel:, panel_type:) # rubocop:disable Metrics/AbcSize
|
2023-03-17 16:20:25 +05:30
|
|
|
{
|
2023-05-27 22:25:52 +05:30
|
|
|
current_menu_items: panel.super_sidebar_menu_items,
|
|
|
|
current_context_header: panel.super_sidebar_context_header,
|
2023-03-17 16:20:25 +05:30
|
|
|
name: user.name,
|
|
|
|
username: user.username,
|
|
|
|
avatar_url: user.avatar_url,
|
2023-05-27 22:25:52 +05:30
|
|
|
has_link_to_profile: current_user_menu?(:profile),
|
|
|
|
link_to_profile: user_url(user),
|
|
|
|
logo_url: current_appearance&.header_logo_path,
|
2023-06-20 00:43:36 +05:30
|
|
|
status: user_status_menu_data(user),
|
2023-05-27 22:25:52 +05:30
|
|
|
settings: {
|
|
|
|
has_settings: current_user_menu?(:settings),
|
|
|
|
profile_path: profile_path,
|
|
|
|
profile_preferences_path: profile_preferences_path
|
|
|
|
},
|
2023-07-09 08:55:56 +05:30
|
|
|
user_counts: {
|
|
|
|
assigned_issues: user.assigned_open_issues_count,
|
|
|
|
assigned_merge_requests: user.assigned_open_merge_requests_count,
|
|
|
|
review_requested_merge_requests: user.review_requested_open_merge_requests_count,
|
|
|
|
todos: user.todos_pending_count,
|
|
|
|
last_update: time_in_milliseconds
|
|
|
|
},
|
2023-05-27 22:25:52 +05:30
|
|
|
can_sign_out: current_user_menu?(:sign_out),
|
|
|
|
sign_out_link: destroy_user_session_path,
|
2023-04-23 21:23:45 +05:30
|
|
|
issues_dashboard_path: issues_dashboard_path(assignee_username: user.username),
|
2023-07-09 08:55:56 +05:30
|
|
|
todos_dashboard_path: dashboard_todos_path,
|
2023-04-23 21:23:45 +05:30
|
|
|
create_new_menu_groups: create_new_menu_groups(group: group, project: project),
|
|
|
|
merge_request_menu: create_merge_request_menu(user),
|
2023-06-20 00:43:36 +05:30
|
|
|
projects_path: dashboard_projects_path,
|
|
|
|
groups_path: dashboard_groups_path,
|
2023-04-23 21:23:45 +05:30
|
|
|
support_path: support_url,
|
|
|
|
display_whats_new: 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,
|
|
|
|
show_version_check: show_version_check?,
|
|
|
|
gitlab_version: Gitlab.version_info,
|
2023-05-27 22:25:52 +05:30
|
|
|
gitlab_version_check: gitlab_version_check,
|
|
|
|
gitlab_com_but_not_canary: Gitlab.com_but_not_canary?,
|
|
|
|
gitlab_com_and_canary: Gitlab.com_and_canary?,
|
|
|
|
canary_toggle_com_url: Gitlab::Saas.canary_toggle_com_url,
|
2023-06-20 00:43:36 +05:30
|
|
|
current_context: super_sidebar_current_context(project: project, group: group),
|
|
|
|
context_switcher_links: context_switcher_links,
|
|
|
|
search: search_data,
|
2023-07-09 08:55:56 +05:30
|
|
|
pinned_items: user.pinned_nav_items[panel_type] || super_sidebar_default_pins(panel_type),
|
2023-06-20 00:43:36 +05:30
|
|
|
panel_type: panel_type,
|
|
|
|
update_pins_url: pins_url,
|
|
|
|
is_impersonating: impersonating?,
|
|
|
|
stop_impersonation_path: admin_impersonation_path,
|
2023-07-09 08:55:56 +05:30
|
|
|
shortcut_links: shortcut_links(user, project: project)
|
2023-03-17 16:20:25 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
def super_sidebar_nav_panel(
|
|
|
|
nav: nil, project: nil, user: nil, group: nil, current_ref: nil, ref_type: nil,
|
|
|
|
viewed_user: nil)
|
|
|
|
context_adds = { route_is_active: method(:active_nav_link?), is_super_sidebar: true }
|
|
|
|
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, **context_adds))
|
2023-06-20 00:43:36 +05:30
|
|
|
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))
|
2023-05-27 22:25:52 +05:30
|
|
|
else
|
|
|
|
context = your_work_sidebar_context(user, **context_adds)
|
|
|
|
Sidebars::YourWork::Panel.new(context)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
private
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
def search_data
|
|
|
|
{
|
|
|
|
search_path: search_path,
|
|
|
|
issues_path: issues_dashboard_path,
|
|
|
|
mr_path: merge_requests_dashboard_path,
|
|
|
|
autocomplete_path: search_autocomplete_path,
|
|
|
|
search_context: header_search_context
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_status_menu_data(user)
|
|
|
|
{
|
|
|
|
can_update: can?(user, :update_user_status, user),
|
|
|
|
busy: user.status&.busy?,
|
|
|
|
customized: user.status&.customized?,
|
|
|
|
availability: user.status&.availability.to_s,
|
|
|
|
emoji: user.status&.emoji,
|
|
|
|
message: user.status&.message_html&.html_safe,
|
|
|
|
clear_after: user_clear_status_at(user)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
def create_new_menu_groups(group:, project:)
|
|
|
|
new_dropdown_sections = new_dropdown_view_model(group: group, project: project)[:menu_sections]
|
|
|
|
show_headers = new_dropdown_sections.length > 1
|
|
|
|
new_dropdown_sections.map do |section|
|
|
|
|
{
|
|
|
|
name: show_headers ? section[:title] : '',
|
|
|
|
items: section[:menu_items].map do |item|
|
2023-07-09 08:55:56 +05:30
|
|
|
{
|
|
|
|
text: item[:title],
|
|
|
|
href: item[:href].presence,
|
|
|
|
component: item[:component].presence,
|
|
|
|
extraAttrs: {
|
|
|
|
'data-track-label': item[:id],
|
|
|
|
'data-track-action': 'click_link',
|
|
|
|
'data-track-property': 'nav_create_menu',
|
|
|
|
'data-qa-selector': 'create_menu_item',
|
|
|
|
'data-qa-create-menu-item': item[:id]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
2023-04-23 21:23:45 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_merge_request_menu(user)
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name: _('Merge requests'),
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
text: _('Assigned'),
|
|
|
|
href: merge_requests_dashboard_path(assignee_username: user.username),
|
2023-07-09 08:55:56 +05:30
|
|
|
count: user.assigned_open_merge_requests_count,
|
|
|
|
userCount: 'assigned_merge_requests',
|
2023-06-20 00:43:36 +05:30
|
|
|
extraAttrs: {
|
|
|
|
'data-track-action': 'click_link',
|
|
|
|
'data-track-label': 'merge_requests_assigned',
|
|
|
|
'data-track-property': 'nav_core_menu',
|
|
|
|
class: 'dashboard-shortcuts-merge_requests'
|
|
|
|
}
|
2023-04-23 21:23:45 +05:30
|
|
|
},
|
|
|
|
{
|
|
|
|
text: _('Review requests'),
|
|
|
|
href: merge_requests_dashboard_path(reviewer_username: user.username),
|
2023-07-09 08:55:56 +05:30
|
|
|
count: user.review_requested_open_merge_requests_count,
|
|
|
|
userCount: 'review_requested_merge_requests',
|
2023-06-20 00:43:36 +05:30
|
|
|
extraAttrs: {
|
|
|
|
'data-track-action': 'click_link',
|
|
|
|
'data-track-label': 'merge_requests_to_review',
|
|
|
|
'data-track-property': 'nav_core_menu',
|
|
|
|
class: 'dashboard-shortcuts-review_requests'
|
|
|
|
}
|
2023-04-23 21:23:45 +05:30
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
def sidebar_attributes_for_object(object)
|
2021-04-29 21:17:54 +05:30
|
|
|
case object
|
|
|
|
when Project
|
2021-09-30 23:02:18 +05:30
|
|
|
sidebar_project_attributes
|
2021-04-29 21:17:54 +05:30
|
|
|
when Group
|
2021-09-30 23:02:18 +05:30
|
|
|
sidebar_group_attributes
|
2021-04-29 21:17:54 +05:30
|
|
|
when User
|
2021-09-30 23:02:18 +05:30
|
|
|
sidebar_user_attributes
|
2021-04-29 21:17:54 +05:30
|
|
|
else
|
|
|
|
{}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
def sidebar_project_attributes
|
|
|
|
{
|
|
|
|
tracking_attrs: sidebar_project_tracking_attrs,
|
|
|
|
sidebar_qa_selector: 'project_sidebar',
|
|
|
|
scope_qa_menu_item: 'Project scope',
|
|
|
|
scope_avatar_class: 'project_avatar'
|
|
|
|
}
|
2021-04-29 21:17:54 +05:30
|
|
|
end
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
def sidebar_group_attributes
|
|
|
|
{
|
|
|
|
tracking_attrs: sidebar_group_tracking_attrs,
|
|
|
|
sidebar_qa_selector: 'group_sidebar',
|
|
|
|
scope_qa_menu_item: 'Group scope',
|
|
|
|
scope_avatar_class: 'group_avatar'
|
|
|
|
}
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
def sidebar_user_attributes
|
|
|
|
{
|
|
|
|
tracking_attrs: sidebar_user_profile_tracking_attrs
|
|
|
|
}
|
2021-09-04 01:27:46 +05:30
|
|
|
end
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
def sidebar_project_tracking_attrs
|
|
|
|
tracking_attrs('projects_side_navigation', 'render', 'projects_side_navigation')
|
|
|
|
end
|
|
|
|
|
|
|
|
def sidebar_group_tracking_attrs
|
|
|
|
tracking_attrs('groups_side_navigation', 'render', 'groups_side_navigation')
|
|
|
|
end
|
|
|
|
|
|
|
|
def sidebar_user_profile_tracking_attrs
|
|
|
|
tracking_attrs('user_side_navigation', 'render', 'user_side_navigation')
|
|
|
|
end
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
def project_sidebar_context_data(project, user, current_ref, ref_type: nil)
|
2021-04-29 21:17:54 +05:30
|
|
|
{
|
|
|
|
current_user: user,
|
|
|
|
container: project,
|
2021-06-08 01:23:25 +05:30
|
|
|
current_ref: current_ref,
|
2023-03-04 22:38:38 +05:30
|
|
|
ref_type: ref_type,
|
2021-06-08 01:23:25 +05:30
|
|
|
jira_issues_integration: project_jira_issues_integration?,
|
|
|
|
can_view_pipeline_editor: can_view_pipeline_editor?(project),
|
|
|
|
show_cluster_hint: show_gke_cluster_integration_callout?(project)
|
2021-04-29 21:17:54 +05:30
|
|
|
}
|
|
|
|
end
|
2021-09-30 23:02:18 +05:30
|
|
|
|
|
|
|
def group_sidebar_context_data(group, user)
|
|
|
|
{
|
|
|
|
current_user: user,
|
|
|
|
container: group
|
|
|
|
}
|
|
|
|
end
|
2023-05-27 22:25:52 +05:30
|
|
|
|
|
|
|
def your_work_context_data(user)
|
|
|
|
{
|
|
|
|
current_user: user,
|
|
|
|
container: user,
|
|
|
|
show_security_dashboard: false
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def super_sidebar_current_context(project: nil, group: nil)
|
|
|
|
if project&.persisted?
|
|
|
|
return {
|
|
|
|
namespace: 'projects',
|
|
|
|
item: {
|
|
|
|
id: project.id,
|
|
|
|
name: project.name,
|
|
|
|
namespace: project.full_name,
|
|
|
|
webUrl: project_path(project),
|
|
|
|
avatarUrl: project.avatar_url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
if group&.persisted?
|
|
|
|
return {
|
|
|
|
namespace: 'groups',
|
|
|
|
item: {
|
|
|
|
id: group.id,
|
|
|
|
name: group.name,
|
|
|
|
namespace: group.full_name,
|
|
|
|
webUrl: group_path(group),
|
|
|
|
avatarUrl: group.avatar_url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
{}
|
|
|
|
end
|
2023-06-20 00:43:36 +05:30
|
|
|
|
|
|
|
def context_switcher_links
|
|
|
|
links = [
|
|
|
|
# We should probably not return "You work" when used is not logged-in
|
|
|
|
{ title: s_('Navigation|Your work'), link: root_path, icon: 'work' },
|
|
|
|
{ title: s_('Navigation|Explore'), link: explore_root_path, icon: 'compass' }
|
|
|
|
]
|
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
# Usually, using current_user.admin? is discouraged because it does not
|
|
|
|
# check for admin mode, but since here we want to check admin? and admin mode
|
|
|
|
# separately, we'll have to ignore the cop rule.
|
|
|
|
# rubocop: disable Cop/UserAdmin
|
2023-06-20 00:43:36 +05:30
|
|
|
if current_user&.can_admin_all_resources?
|
|
|
|
links.append(
|
2023-07-09 08:55:56 +05:30
|
|
|
{ title: s_('Navigation|Admin Area'), link: admin_root_path, icon: 'admin' }
|
2023-06-20 00:43:36 +05:30
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
if Gitlab::CurrentSettings.admin_mode
|
|
|
|
if header_link?(:admin_mode)
|
|
|
|
links.append(
|
|
|
|
{
|
|
|
|
title: s_('Navigation|Leave admin mode'),
|
|
|
|
link: destroy_admin_session_path,
|
|
|
|
icon: 'lock-open',
|
|
|
|
data_method: 'post'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
elsif current_user&.admin?
|
|
|
|
links.append(
|
|
|
|
{
|
|
|
|
title: s_('Navigation|Enter admin mode'),
|
|
|
|
link: new_admin_session_path,
|
|
|
|
icon: 'lock'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
2023-06-20 00:43:36 +05:30
|
|
|
end
|
2023-07-09 08:55:56 +05:30
|
|
|
# rubocop: enable Cop/UserAdmin
|
|
|
|
|
|
|
|
links
|
2023-06-20 00:43:36 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def impersonating?
|
|
|
|
!!session[:impersonator_id]
|
|
|
|
end
|
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
def shortcut_links(user, project: nil)
|
|
|
|
shortcut_links = [
|
2023-06-20 00:43:36 +05:30
|
|
|
{
|
|
|
|
title: _('Milestones'),
|
|
|
|
href: dashboard_milestones_path,
|
|
|
|
css_class: 'dashboard-shortcuts-milestones'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: _('Snippets'),
|
|
|
|
href: dashboard_snippets_path,
|
|
|
|
css_class: 'dashboard-shortcuts-snippets'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: _('Activity'),
|
|
|
|
href: activity_dashboard_path,
|
|
|
|
css_class: 'dashboard-shortcuts-activity'
|
|
|
|
}
|
|
|
|
]
|
2023-07-09 08:55:56 +05:30
|
|
|
|
|
|
|
if project&.persisted? && can?(user, :create_issue, project)
|
|
|
|
shortcut_links << {
|
|
|
|
title: _('Create a new issue'),
|
|
|
|
href: new_project_issue_path(project),
|
|
|
|
css_class: 'shortcuts-new-issue'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
shortcut_links
|
|
|
|
end
|
|
|
|
|
|
|
|
def super_sidebar_default_pins(panel_type)
|
|
|
|
case panel_type
|
|
|
|
when 'project'
|
|
|
|
[:project_issue_list, :project_merge_request_list]
|
|
|
|
when 'group'
|
|
|
|
[:group_issue_list, :group_merge_request_list]
|
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
2023-06-20 00:43:36 +05:30
|
|
|
end
|
2021-04-29 21:17:54 +05:30
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
|
|
|
|
SidebarsHelper.prepend_mod_with('SidebarsHelper')
|