diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 09:08:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 09:08:42 +0000 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /lib/sidebars/groups/menus | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) | |
download | gitlab-ce-b76ae638462ab0f673e5915986070518dd3f9ad3.tar.gz |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'lib/sidebars/groups/menus')
-rw-r--r-- | lib/sidebars/groups/menus/ci_cd_menu.rb | 51 | ||||
-rw-r--r-- | lib/sidebars/groups/menus/group_information_menu.rb | 79 | ||||
-rw-r--r-- | lib/sidebars/groups/menus/issues_menu.rb | 101 | ||||
-rw-r--r-- | lib/sidebars/groups/menus/kubernetes_menu.rb | 41 | ||||
-rw-r--r-- | lib/sidebars/groups/menus/merge_requests_menu.rb | 58 | ||||
-rw-r--r-- | lib/sidebars/groups/menus/packages_registries_menu.rb | 74 | ||||
-rw-r--r-- | lib/sidebars/groups/menus/settings_menu.rb | 117 |
7 files changed, 521 insertions, 0 deletions
diff --git a/lib/sidebars/groups/menus/ci_cd_menu.rb b/lib/sidebars/groups/menus/ci_cd_menu.rb new file mode 100644 index 00000000000..e870bbf5ebc --- /dev/null +++ b/lib/sidebars/groups/menus/ci_cd_menu.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +module Sidebars + module Groups + module Menus + class CiCdMenu < ::Sidebars::Menu + override :configure_menu_items + def configure_menu_items + add_item(runners_menu_item) + + true + end + + override :link + def link + renderable_items.first.link + end + + override :title + def title + _('CI/CD') + end + + override :sprite_icon + def sprite_icon + 'rocket' + end + + private + + def runners_menu_item + return ::Sidebars::NilMenuItem.new(item_id: :runners) unless show_runners? + + ::Sidebars::MenuItem.new( + title: _('Runners'), + link: group_runners_path(context.group), + active_routes: { path: 'groups/runners#index' }, + item_id: :runners + ) + end + + # TODO Proper policies, such as `read_group_runners`, should be implemented per + # See https://gitlab.com/gitlab-org/gitlab/-/issues/334802 + def show_runners? + can?(context.current_user, :admin_group, context.group) && + Feature.enabled?(:runner_list_group_view_vue_ui, context.group, default_enabled: :yaml) + end + end + end + end +end diff --git a/lib/sidebars/groups/menus/group_information_menu.rb b/lib/sidebars/groups/menus/group_information_menu.rb new file mode 100644 index 00000000000..b28cb927ad2 --- /dev/null +++ b/lib/sidebars/groups/menus/group_information_menu.rb @@ -0,0 +1,79 @@ +# frozen_string_literal: true + +module Sidebars + module Groups + module Menus + class GroupInformationMenu < ::Sidebars::Menu + override :configure_menu_items + def configure_menu_items + add_item(activity_menu_item) + add_item(labels_menu_item) + add_item(members_menu_item) + + true + end + + override :link + def link + renderable_items.first.link + end + + override :title + def title + context.group.subgroup? ? _('Subgroup information') : _('Group information') + end + + override :sprite_icon + def sprite_icon + 'group' + end + + override :active_routes + def active_routes + { path: 'groups#subgroups' } + end + + private + + def activity_menu_item + unless can?(context.current_user, :read_group_activity, context.group) + return ::Sidebars::NilMenuItem.new(item_id: :activity) + end + + ::Sidebars::MenuItem.new( + title: _('Activity'), + link: activity_group_path(context.group), + active_routes: { path: 'groups#activity' }, + item_id: :activity + ) + end + + def labels_menu_item + unless can?(context.current_user, :read_group_labels, context.group) + return ::Sidebars::NilMenuItem.new(item_id: :labels) + end + + ::Sidebars::MenuItem.new( + title: _('Labels'), + link: group_labels_path(context.group), + active_routes: { controller: :labels }, + item_id: :labels + ) + end + + def members_menu_item + unless can?(context.current_user, :read_group_member, context.group) + return ::Sidebars::NilMenuItem.new(item_id: :members) + end + + ::Sidebars::MenuItem.new( + title: _('Members'), + link: group_group_members_path(context.group), + active_routes: { path: 'group_members#index' }, + item_id: :members + ) + end + end + end + end +end diff --git a/lib/sidebars/groups/menus/issues_menu.rb b/lib/sidebars/groups/menus/issues_menu.rb new file mode 100644 index 00000000000..95641c09076 --- /dev/null +++ b/lib/sidebars/groups/menus/issues_menu.rb @@ -0,0 +1,101 @@ +# frozen_string_literal: true + +module Sidebars + module Groups + module Menus + class IssuesMenu < ::Sidebars::Menu + include Gitlab::Utils::StrongMemoize + + override :configure_menu_items + def configure_menu_items + return unless can?(context.current_user, :read_group_issues, context.group) + + add_item(list_menu_item) + add_item(boards_menu_item) + add_item(milestones_menu_item) + + true + end + + override :link + def link + issues_group_path(context.group) + end + + override :title + def title + _('Issues') + end + + override :sprite_icon + def sprite_icon + 'issues' + end + + override :has_pill? + def has_pill? + true + end + + override :pill_count + def pill_count + strong_memoize(:pill_count) do + count_service = ::Groups::OpenIssuesCountService + count = count_service.new(context.group, context.current_user).count + + format_cached_count(count_service, count) + end + end + + override :pill_html_options + def pill_html_options + { + class: 'issue_counter' + } + end + + private + + def list_menu_item + ::Sidebars::MenuItem.new( + title: _('List'), + link: issues_group_path(context.group), + active_routes: { path: 'groups#issues' }, + container_html_options: { aria: { label: _('Issues') } }, + item_id: :issue_list + ) + end + + def boards_menu_item + unless can?(context.current_user, :read_group_boards, context.group) + return ::Sidebars::NilMenuItem.new(item_id: :boards) + end + + title = context.group.multiple_issue_boards_available? ? s_('IssueBoards|Boards') : s_('IssueBoards|Board') + + ::Sidebars::MenuItem.new( + title: title, + link: group_boards_path(context.group), + active_routes: { path: %w[boards#index boards#show] }, + item_id: :boards + ) + end + + def milestones_menu_item + unless can?(context.current_user, :read_group_milestones, context.group) + return ::Sidebars::NilMenuItem.new(item_id: :milestones) + end + + ::Sidebars::MenuItem.new( + title: _('Milestones'), + link: group_milestones_path(context.group), + active_routes: { path: 'milestones#index' }, + item_id: :milestones + ) + end + end + end + end +end + +Sidebars::Groups::Menus::IssuesMenu.prepend_mod_with('Sidebars::Groups::Menus::IssuesMenu') diff --git a/lib/sidebars/groups/menus/kubernetes_menu.rb b/lib/sidebars/groups/menus/kubernetes_menu.rb new file mode 100644 index 00000000000..4ea294a4837 --- /dev/null +++ b/lib/sidebars/groups/menus/kubernetes_menu.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +module Sidebars + module Groups + module Menus + class KubernetesMenu < ::Sidebars::Menu + override :link + def link + group_clusters_path(context.group) + end + + override :title + def title + _('Kubernetes') + end + + override :sprite_icon + def sprite_icon + 'cloud-gear' + end + + override :render? + def render? + can?(context.current_user, :read_cluster, context.group) + end + + override :extra_container_html_options + def extra_container_html_options + { + class: 'shortcuts-kubernetes' + } + end + + override :active_routes + def active_routes + { controller: :clusters } + end + end + end + end +end diff --git a/lib/sidebars/groups/menus/merge_requests_menu.rb b/lib/sidebars/groups/menus/merge_requests_menu.rb new file mode 100644 index 00000000000..7faf50305c6 --- /dev/null +++ b/lib/sidebars/groups/menus/merge_requests_menu.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +module Sidebars + module Groups + module Menus + class MergeRequestsMenu < ::Sidebars::Menu + include Gitlab::Utils::StrongMemoize + + override :link + def link + merge_requests_group_path(context.group) + end + + override :title + def title + _('Merge requests') + end + + override :sprite_icon + def sprite_icon + 'git-merge' + end + + override :render? + def render? + can?(context.current_user, :read_group_merge_requests, context.group) + end + + override :has_pill? + def has_pill? + true + end + + override :pill_count + def pill_count + strong_memoize(:pill_count) do + count_service = ::Groups::MergeRequestsCountService + count = count_service.new(context.group, context.current_user).count + + format_cached_count(count_service, count) + end + end + + override :pill_html_options + def pill_html_options + { + class: 'merge_counter js-merge-counter' + } + end + + override :active_routes + def active_routes + { path: 'groups#merge_requests' } + end + end + end + end +end diff --git a/lib/sidebars/groups/menus/packages_registries_menu.rb b/lib/sidebars/groups/menus/packages_registries_menu.rb new file mode 100644 index 00000000000..e46e2820c04 --- /dev/null +++ b/lib/sidebars/groups/menus/packages_registries_menu.rb @@ -0,0 +1,74 @@ +# frozen_string_literal: true + +module Sidebars + module Groups + module Menus + class PackagesRegistriesMenu < ::Sidebars::Menu + override :configure_menu_items + def configure_menu_items + add_item(packages_registry_menu_item) + add_item(container_registry_menu_item) + add_item(dependency_proxy_menu_item) + + true + end + + override :link + def link + renderable_items.first.link + end + + override :title + def title + _('Packages & Registries') + end + + override :sprite_icon + def sprite_icon + 'package' + end + + private + + def packages_registry_menu_item + unless context.group.packages_feature_enabled? + return ::Sidebars::NilMenuItem.new(item_id: :packages_registry) + end + + ::Sidebars::MenuItem.new( + title: _('Package Registry'), + link: group_packages_path(context.group), + active_routes: { controller: 'groups/packages' }, + item_id: :packages_registry + ) + end + + def container_registry_menu_item + if !::Gitlab.config.registry.enabled || !can?(context.current_user, :read_container_image, context.group) + return ::Sidebars::NilMenuItem.new(item_id: :container_registry) + end + + ::Sidebars::MenuItem.new( + title: _('Container Registry'), + link: group_container_registries_path(context.group), + active_routes: { controller: 'groups/registry/repositories' }, + item_id: :container_registry + ) + end + + def dependency_proxy_menu_item + unless context.group.dependency_proxy_feature_available? + return ::Sidebars::NilMenuItem.new(item_id: :dependency_proxy) + end + + ::Sidebars::MenuItem.new( + title: _('Dependency Proxy'), + link: group_dependency_proxy_path(context.group), + active_routes: { controller: 'groups/dependency_proxies' }, + item_id: :dependency_proxy + ) + end + end + end + end +end diff --git a/lib/sidebars/groups/menus/settings_menu.rb b/lib/sidebars/groups/menus/settings_menu.rb new file mode 100644 index 00000000000..8bc6077d302 --- /dev/null +++ b/lib/sidebars/groups/menus/settings_menu.rb @@ -0,0 +1,117 @@ +# frozen_string_literal: true + +module Sidebars + module Groups + module Menus + class SettingsMenu < ::Sidebars::Menu + override :configure_menu_items + def configure_menu_items + return false unless can?(context.current_user, :admin_group, context.group) + + add_item(general_menu_item) + add_item(integrations_menu_item) + add_item(group_projects_menu_item) + add_item(repository_menu_item) + add_item(ci_cd_menu_item) + add_item(applications_menu_item) + add_item(packages_and_registries_menu_item) + + true + end + + override :link + def link + edit_group_path(context.group) + end + + override :title + def title + _('Settings') + end + + override :sprite_icon + def sprite_icon + 'settings' + end + + override :extra_nav_link_html_options + def extra_nav_link_html_options + { + class: 'shortcuts-settings' + } + end + + private + + def general_menu_item + ::Sidebars::MenuItem.new( + title: _('General'), + link: edit_group_path(context.group), + active_routes: { path: 'groups#edit' }, + item_id: :general + ) + end + + def integrations_menu_item + ::Sidebars::MenuItem.new( + title: _('Integrations'), + link: group_settings_integrations_path(context.group), + active_routes: { controller: :integrations }, + item_id: :integrations + ) + end + + def group_projects_menu_item + ::Sidebars::MenuItem.new( + title: _('Projects'), + link: projects_group_path(context.group), + active_routes: { path: 'groups#projects' }, + item_id: :group_projects + ) + end + + def repository_menu_item + ::Sidebars::MenuItem.new( + title: _('Repository'), + link: group_settings_repository_path(context.group), + active_routes: { controller: :repository }, + item_id: :repository + ) + end + + def ci_cd_menu_item + ::Sidebars::MenuItem.new( + title: _('CI/CD'), + link: group_settings_ci_cd_path(context.group), + active_routes: { path: %w[ci_cd#show groups/runners#show groups/runners#edit] }, + item_id: :ci_cd + ) + end + + def applications_menu_item + ::Sidebars::MenuItem.new( + title: _('Applications'), + link: group_settings_applications_path(context.group), + active_routes: { controller: :applications }, + item_id: :applications + ) + end + + def packages_and_registries_menu_item + unless context.group.packages_feature_enabled? + return ::Sidebars::NilMenuItem.new(item_id: :packages_and_registries) + end + + ::Sidebars::MenuItem.new( + title: _('Packages & Registries'), + link: group_settings_packages_and_registries_path(context.group), + active_routes: { controller: :packages_and_registries }, + item_id: :packages_and_registries + ) + end + end + end + end +end + +Sidebars::Groups::Menus::SettingsMenu.prepend_mod_with('Sidebars::Groups::Menus::SettingsMenu') |