summaryrefslogtreecommitdiff
path: root/lib/sidebars/projects/menus/packages_registries_menu.rb
blob: 51a1df7f1d3a1c4c740af0fe0c1b7b4b2381db77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 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)

          true
        end

        override :link
        def link
          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
          return unless ::Gitlab.config.packages.enabled
          return unless can?(context.current_user, :read_package, context.project)

          ::Sidebars::MenuItem.new(
            title: _('Package Registry'),
            link: project_packages_path(context.project),
            active_routes: { controller: :packages },
            item_id: :packages_registry,
            container_html_options: { class: 'shortcuts-container-registry' }
          )
        end

        def container_registry_menu_item
          return unless ::Gitlab.config.registry.enabled
          return unless can?(context.current_user, :read_container_image, context.project)

          ::Sidebars::MenuItem.new(
            title: _('Container Registry'),
            link: project_container_registry_index_path(context.project),
            active_routes: { controller: :repositories },
            item_id: :container_registry
          )
        end

        def infrastructure_registry_menu_item
          return if Feature.disabled?(:infrastructure_registry_page, context.current_user)

          ::Sidebars::MenuItem.new(
            title: _('Infrastructure Registry'),
            link: project_infrastructure_registry_index_path(context.project),
            active_routes: { controller: :infrastructure_registry },
            item_id: :infrastructure_registry
          )
        end
      end
    end
  end
end