File: packages_registries_menu.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (135 lines) | stat: -rw-r--r-- 4,864 bytes parent folder | download
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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# 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)
          add_item(harbor_registry_menu_item)
          add_item(model_experiments_menu_item)
          add_item(model_registry_menu_item)
          true
        end

        override :title
        def title
          _('Packages and registries')
        end

        override :sprite_icon
        def sprite_icon
          'package'
        end

        override :serialize_as_menu_item_args
        def serialize_as_menu_item_args
          nil
        end

        private

        def packages_registry_menu_item
          if packages_registry_disabled?
            return ::Sidebars::NilMenuItem.new(item_id: :packages_registry)
          end

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

        def container_registry_menu_item
          if container_registry_unavailable?
            return ::Sidebars::NilMenuItem.new(item_id: :container_registry)
          end

          ::Sidebars::MenuItem.new(
            title: _('Container Registry'),
            link: project_container_registry_index_path(context.project),
            super_sidebar_parent: Sidebars::Projects::SuperSidebarMenus::DeployMenu,
            active_routes: { controller: 'projects/registry/repositories' },
            item_id: :container_registry
          )
        end

        def infrastructure_registry_menu_item
          if packages_registry_disabled?
            return ::Sidebars::NilMenuItem.new(item_id: :infrastructure_registry)
          end

          ::Sidebars::MenuItem.new(
            title: _('Terraform modules'),
            link: project_infrastructure_registry_index_path(context.project),
            super_sidebar_parent: Sidebars::Projects::SuperSidebarMenus::OperationsMenu,
            active_routes: { controller: :infrastructure_registry },
            item_id: :infrastructure_registry
          )
        end

        def harbor_registry_menu_item
          if context.project.harbor_integration.nil? ||
              !context.project.harbor_integration.activated?
            return ::Sidebars::NilMenuItem.new(item_id: :harbor_registry)
          end

          ::Sidebars::MenuItem.new(
            title: _('Harbor Registry'),
            link: project_harbor_repositories_path(context.project),
            super_sidebar_parent: Sidebars::Projects::SuperSidebarMenus::DeployMenu,
            active_routes: { controller: 'projects/harbor/repositories' },
            item_id: :harbor_registry
          )
        end

        def model_experiments_menu_item
          unless can?(context.current_user, :read_model_experiments, 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

        def model_registry_menu_item
          unless can?(context.current_user, :read_model_registry, context.project)
            return ::Sidebars::NilMenuItem.new(item_id: :model_registry)
          end

          ::Sidebars::MenuItem.new(
            title: _('Model registry'),
            link: project_ml_models_path(context.project),
            super_sidebar_parent: Sidebars::Projects::SuperSidebarMenus::DeployMenu,
            active_routes: { controller: %w[projects/ml/models] },
            item_id: :model_registry
          )
        end

        def packages_registry_disabled?
          !::Gitlab.config.packages.enabled ||
            !can?(context.current_user, :read_package, context.project&.packages_policy_subject)
        end

        def container_registry_unavailable?
          !::Gitlab.config.registry.enabled ||
            !can?(context.current_user, :read_container_image, context.project)
        end
      end
    end
  end
end

Sidebars::Projects::Menus::PackagesRegistriesMenu.prepend_mod_with('Sidebars::Projects::Menus::PackagesRegistriesMenu')