debian-mirror-gitlab/lib/sidebars/projects/menus/packages_registries_menu.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

115 lines
4 KiB
Ruby
Raw Normal View History

2021-06-08 01:23:25 +05:30
# frozen_string_literal: true
module Sidebars
module Projects
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(infrastructure_registry_menu_item)
2022-11-25 23:54:43 +05:30
add_item(harbor_registry_menu_item)
2023-06-20 00:43:36 +05:30
add_item(model_experiments_menu_item)
2021-06-08 01:23:25 +05:30
true
end
override :title
def title
2022-10-11 01:57:18 +05:30
_('Packages and registries')
2021-06-08 01:23:25 +05:30
end
override :sprite_icon
def sprite_icon
'package'
end
2023-05-27 22:25:52 +05:30
override :serialize_as_menu_item_args
def serialize_as_menu_item_args
nil
end
2021-06-08 01:23:25 +05:30
private
def packages_registry_menu_item
2021-10-27 15:23:28 +05:30
if packages_registry_disabled?
2021-06-08 01:23:25 +05:30
return ::Sidebars::NilMenuItem.new(item_id: :packages_registry)
end
::Sidebars::MenuItem.new(
title: _('Package Registry'),
link: project_packages_path(context.project),
2023-05-27 22:25:52 +05:30
super_sidebar_parent: Sidebars::Projects::SuperSidebarMenus::OperationsMenu,
2021-06-08 01:23:25 +05:30
active_routes: { controller: :packages },
item_id: :packages_registry,
container_html_options: { class: 'shortcuts-container-registry' }
)
end
def container_registry_menu_item
if !::Gitlab.config.registry.enabled || !can?(context.current_user, :read_container_image, context.project)
return ::Sidebars::NilMenuItem.new(item_id: :container_registry)
end
::Sidebars::MenuItem.new(
title: _('Container Registry'),
link: project_container_registry_index_path(context.project),
2023-05-27 22:25:52 +05:30
super_sidebar_parent: Sidebars::Projects::SuperSidebarMenus::OperationsMenu,
2022-06-21 17:19:12 +05:30
active_routes: { controller: 'projects/registry/repositories' },
2021-06-08 01:23:25 +05:30
item_id: :container_registry
)
end
def infrastructure_registry_menu_item
2021-10-27 15:23:28 +05:30
if packages_registry_disabled?
2021-06-08 01:23:25 +05:30
return ::Sidebars::NilMenuItem.new(item_id: :infrastructure_registry)
end
::Sidebars::MenuItem.new(
2023-06-20 00:43:36 +05:30
title: _('Terraform modules'),
2021-06-08 01:23:25 +05:30
link: project_infrastructure_registry_index_path(context.project),
2023-05-27 22:25:52 +05:30
super_sidebar_parent: Sidebars::Projects::SuperSidebarMenus::OperationsMenu,
2021-06-08 01:23:25 +05:30
active_routes: { controller: :infrastructure_registry },
item_id: :infrastructure_registry
)
end
2021-10-27 15:23:28 +05:30
2022-11-25 23:54:43 +05:30
def harbor_registry_menu_item
if Feature.disabled?(:harbor_registry_integration, context.project) ||
context.project.harbor_integration.nil? ||
!context.project.harbor_integration.activated?
2022-10-11 01:57:18 +05:30
return ::Sidebars::NilMenuItem.new(item_id: :harbor_registry)
end
2022-05-07 20:08:51 +05:30
::Sidebars::MenuItem.new(
title: _('Harbor Registry'),
2022-08-13 15:12:31 +05:30
link: project_harbor_repositories_path(context.project),
2023-05-27 22:25:52 +05:30
super_sidebar_parent: Sidebars::Projects::SuperSidebarMenus::OperationsMenu,
2023-06-20 00:43:36 +05:30
active_routes: { controller: 'projects/harbor/repositories' },
2022-05-07 20:08:51 +05:30
item_id: :harbor_registry
)
end
2023-06-20 00:43:36 +05:30
def model_experiments_menu_item
if Feature.disabled?(:ml_experiment_tracking, context.project)
return ::Sidebars::NilMenuItem.new(item_id: :model_experiments)
end
::Sidebars::MenuItem.new(
title: _('Model experiments'),
link: project_ml_experiments_path(context.project),
super_sidebar_parent: Sidebars::Projects::SuperSidebarMenus::AnalyzeMenu,
active_routes: { controller: %w[projects/ml/experiments projects/ml/candidates] },
item_id: :model_experiments
)
end
2021-10-27 15:23:28 +05:30
def packages_registry_disabled?
2022-10-11 01:57:18 +05:30
!::Gitlab.config.packages.enabled ||
!can?(context.current_user, :read_package, context.project&.packages_policy_subject)
2021-10-27 15:23:28 +05:30
end
2021-06-08 01:23:25 +05:30
end
end
end
end