From 0e08747b3d348b6c0effae19fe7050af327c05e2 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 28 Dec 2023 15:20:21 +0000 Subject: [PATCH] Add latest changes from gitlab-org/gitlab@master --- doc/administration/settings/help_page.md | 2 +- lib/gitlab/encoding_helper.rb | 6 ++-- lib/gitlab/git/blob.rb | 4 +-- lib/gitlab/gitaly_client/blobs_stitcher.rb | 2 +- .../menus/packages_registries_menu.rb | 15 ++++++++++ .../super_sidebar_menus/deploy_menu.rb | 3 +- locale/gitlab.pot | 3 ++ spec/features/projects/navbar_spec.rb | 13 +++++++++ .../menus/packages_registries_menu_spec.rb | 29 ++++++++++++++++++- .../super_sidebar_menus/deploy_menu_spec.rb | 3 +- .../helpers/navbar_structure_helper.rb | 8 +++++ 11 files changed, 78 insertions(+), 10 deletions(-) diff --git a/doc/administration/settings/help_page.md b/doc/administration/settings/help_page.md index 1077bbec316..bb7f214a106 100644 --- a/doc/administration/settings/help_page.md +++ b/doc/administration/settings/help_page.md @@ -55,7 +55,7 @@ GitLab marketing-related entries are occasionally shown on the Help page. To hid You can specify a custom URL to which users are directed when they: -- Select **Support** from the Help dropdown list. +- Select **Help > Support**. - Select **See our website for help** on the Help page. 1. On the left sidebar, at the bottom, select **Admin Area**. diff --git a/lib/gitlab/encoding_helper.rb b/lib/gitlab/encoding_helper.rb index b080cb197d4..7ad4cf96dd4 100644 --- a/lib/gitlab/encoding_helper.rb +++ b/lib/gitlab/encoding_helper.rb @@ -40,7 +40,7 @@ module Gitlab "--broken encoding: #{encoding}" end - def detect_encoding(data, limit: CharlockHolmes::EncodingDetector::DEFAULT_BINARY_SCAN_LEN, cache_key: nil) + def detect_encoding(data, limit: CharlockHolmes::EncodingDetector::DEFAULT_BINARY_SCAN_LEN) return if data.nil? CharlockHolmes::EncodingDetector.new(limit).detect(data) @@ -54,8 +54,8 @@ module Gitlab # EncodingDetector checks the first 1024 * 1024 bytes for NUL byte, libgit2 checks # only the first 8000 (https://github.com/libgit2/libgit2/blob/2ed855a9e8f9af211e7274021c2264e600c0f86b/src/filter.h#L15), # which is what we use below to keep a consistent behavior. - def detect_libgit2_binary?(data, cache_key: nil) - detect = detect_encoding(data, limit: 8000, cache_key: cache_key) + def detect_libgit2_binary?(data) + detect = detect_encoding(data, limit: 8000) detect && detect[:type] == :binary end diff --git a/lib/gitlab/git/blob.rb b/lib/gitlab/git/blob.rb index aa59caa4268..6bbb0f4b7a0 100644 --- a/lib/gitlab/git/blob.rb +++ b/lib/gitlab/git/blob.rb @@ -110,8 +110,8 @@ module Gitlab end end - def binary?(data, cache_key: nil) - EncodingHelper.detect_libgit2_binary?(data, cache_key: cache_key) + def binary?(data) + EncodingHelper.detect_libgit2_binary?(data) end def size_could_be_lfs?(size) diff --git a/lib/gitlab/gitaly_client/blobs_stitcher.rb b/lib/gitlab/gitaly_client/blobs_stitcher.rb index 6c51b4cf8c6..95053207d1a 100644 --- a/lib/gitlab/gitaly_client/blobs_stitcher.rb +++ b/lib/gitlab/gitaly_client/blobs_stitcher.rb @@ -41,7 +41,7 @@ module Gitlab size: blob_data[:size], commit_id: blob_data[:revision], data: data, - binary: Gitlab::Git::Blob.binary?(data, cache_key: blob_data[:oid]) + binary: Gitlab::Git::Blob.binary?(data) ) end end diff --git a/lib/sidebars/projects/menus/packages_registries_menu.rb b/lib/sidebars/projects/menus/packages_registries_menu.rb index 5a378d5f9a8..2d12bfbd6bb 100644 --- a/lib/sidebars/projects/menus/packages_registries_menu.rb +++ b/lib/sidebars/projects/menus/packages_registries_menu.rb @@ -11,6 +11,7 @@ module Sidebars 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 @@ -103,6 +104,20 @@ module Sidebars ) 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) diff --git a/lib/sidebars/projects/super_sidebar_menus/deploy_menu.rb b/lib/sidebars/projects/super_sidebar_menus/deploy_menu.rb index 9f667466d1c..f3f73fc4b78 100644 --- a/lib/sidebars/projects/super_sidebar_menus/deploy_menu.rb +++ b/lib/sidebars/projects/super_sidebar_menus/deploy_menu.rb @@ -20,7 +20,8 @@ module Sidebars :releases, :feature_flags, :packages_registry, - :container_registry + :container_registry, + :model_registry ].each { |id| add_item(::Sidebars::NilMenuItem.new(item_id: id)) } end end diff --git a/locale/gitlab.pot b/locale/gitlab.pot index d8ad4824829..fb8a9ffe7f7 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -31196,6 +31196,9 @@ msgstr "" msgid "Model experiments" msgstr "" +msgid "Model registry" +msgstr "" + msgid "ModelRegistry|Model registry" msgstr "" diff --git a/spec/features/projects/navbar_spec.rb b/spec/features/projects/navbar_spec.rb index 348a661855c..9babe3c3b71 100644 --- a/spec/features/projects/navbar_spec.rb +++ b/spec/features/projects/navbar_spec.rb @@ -16,6 +16,7 @@ RSpec.describe 'Project navbar', :with_license, :js, feature_category: :groups_a stub_config(registry: { enabled: false }) stub_feature_flags(ml_experiment_tracking: false) + stub_feature_flags(model_registry: false) insert_package_nav insert_infrastructure_registry_nav insert_infrastructure_google_cloud_nav @@ -93,4 +94,16 @@ RSpec.describe 'Project navbar', :with_license, :js, feature_category: :groups_a it_behaves_like 'verified navigation bar' end + + context 'when model registry is available' do + before do + stub_feature_flags(model_registry: true) + + insert_model_registry_nav(_('Package Registry')) + + visit project_path(project) + end + + it_behaves_like 'verified navigation bar' + end end diff --git a/spec/lib/sidebars/projects/menus/packages_registries_menu_spec.rb b/spec/lib/sidebars/projects/menus/packages_registries_menu_spec.rb index 0cf95391a26..85c109615c8 100644 --- a/spec/lib/sidebars/projects/menus/packages_registries_menu_spec.rb +++ b/spec/lib/sidebars/projects/menus/packages_registries_menu_spec.rb @@ -39,7 +39,7 @@ RSpec.describe Sidebars::Projects::Menus::PackagesRegistriesMenu, feature_catego before do stub_container_registry_config(enabled: registry_enabled) stub_config(packages: { enabled: packages_enabled }) - stub_feature_flags(ml_experiment_tracking: false) + stub_feature_flags(ml_experiment_tracking: false, model_registry: false) end context 'when Packages Registry is visible' do @@ -195,5 +195,32 @@ RSpec.describe Sidebars::Projects::Menus::PackagesRegistriesMenu, feature_catego end end end + + describe 'Model registry' do + let(:item_id) { :model_registry } + + before do + allow(Ability).to receive(:allowed?).and_call_original + allow(Ability).to receive(:allowed?) + .with(user, :read_model_registry, project) + .and_return(model_registry_enabled) + end + + context 'when user can read model registry' do + let(:model_registry_enabled) { true } + + it 'shows the menu item' do + is_expected.not_to be_nil + end + end + + context 'when user can not read model registry' do + let(:model_registry_enabled) { false } + + it 'does not show the menu item' do + is_expected.to be_nil + end + end + end end end diff --git a/spec/lib/sidebars/projects/super_sidebar_menus/deploy_menu_spec.rb b/spec/lib/sidebars/projects/super_sidebar_menus/deploy_menu_spec.rb index 98d62948ac3..f23aaad71f9 100644 --- a/spec/lib/sidebars/projects/super_sidebar_menus/deploy_menu_spec.rb +++ b/spec/lib/sidebars/projects/super_sidebar_menus/deploy_menu_spec.rb @@ -18,7 +18,8 @@ RSpec.describe Sidebars::Projects::SuperSidebarMenus::DeployMenu, feature_catego :releases, :feature_flags, :packages_registry, - :container_registry + :container_registry, + :model_registry ]) end end diff --git a/spec/support/helpers/navbar_structure_helper.rb b/spec/support/helpers/navbar_structure_helper.rb index 5519a6910a2..49a9508b1ff 100644 --- a/spec/support/helpers/navbar_structure_helper.rb +++ b/spec/support/helpers/navbar_structure_helper.rb @@ -124,6 +124,14 @@ module NavbarStructureHelper ) end + def insert_model_registry_nav(within) + insert_after_sub_nav_item( + within, + within: _('Deploy'), + new_sub_nav_item_name: _('Model registry') + ) + end + def project_analytics_sub_nav_item [ _('Value stream analytics'),