diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-26 03:08:57 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-26 03:08:57 +0300 |
commit | b8fcf7c3d6c3b48e59e6aae5b1a6b536bba8ac40 (patch) | |
tree | 947b357adb3c1b51f2fb7ec761a7d9a35c260e28 /app | |
parent | 5edc7a04de12237658e7149385661aede45d681c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/super_sidebar/components/flyout_menu.vue | 6 | ||||
-rw-r--r-- | app/finders/projects/ml/model_finder.rb | 9 | ||||
-rw-r--r-- | app/models/ml/model.rb | 4 | ||||
-rw-r--r-- | app/models/ml/model_version.rb | 3 | ||||
-rw-r--r-- | app/models/packages/package.rb | 2 | ||||
-rw-r--r-- | app/presenters/ml/models_index_presenter.rb | 12 | ||||
-rw-r--r-- | app/services/groups/transfer_service.rb | 32 | ||||
-rw-r--r-- | app/services/projects/transfer_service.rb | 34 |
8 files changed, 89 insertions, 13 deletions
diff --git a/app/assets/javascripts/super_sidebar/components/flyout_menu.vue b/app/assets/javascripts/super_sidebar/components/flyout_menu.vue index 4f95b140a23..285fa8ee90b 100644 --- a/app/assets/javascripts/super_sidebar/components/flyout_menu.vue +++ b/app/assets/javascripts/super_sidebar/components/flyout_menu.vue @@ -1,5 +1,5 @@ <script> -import { computePosition, autoUpdate, flip } from '@floating-ui/dom'; +import { computePosition, autoUpdate, flip, shift } from '@floating-ui/dom'; import NavItem from './nav_item.vue'; export default { @@ -22,7 +22,7 @@ export default { function updatePosition() { return computePosition(target, flyout, { - middleware: [flip()], + middleware: [flip(), shift()], placement: 'right-start', strategy: 'fixed', }).then(({ x, y }) => { @@ -44,7 +44,7 @@ export default { <template> <div :id="`${targetId}-flyout`" - class="gl-fixed gl-pl-3 gl-z-index-9999" + class="gl-fixed gl-pl-3 gl-z-index-9999 gl-max-h-full gl-overflow-y-auto" @mouseover="$emit('mouseover')" @mouseleave="$emit('mouseleave')" > diff --git a/app/finders/projects/ml/model_finder.rb b/app/finders/projects/ml/model_finder.rb index 9ef5dacb551..99c66f53de7 100644 --- a/app/finders/projects/ml/model_finder.rb +++ b/app/finders/projects/ml/model_finder.rb @@ -8,12 +8,9 @@ module Projects end def execute - @project - .packages - .installable - .ml_model - .order_name_desc_version_desc - .select_only_first_by_name + ::Ml::Model + .by_project(@project) + .including_latest_version .limit(100) # This is a temporary limit before we add pagination end end diff --git a/app/models/ml/model.rb b/app/models/ml/model.rb index f901eb69be4..cc71b15af52 100644 --- a/app/models/ml/model.rb +++ b/app/models/ml/model.rb @@ -14,6 +14,10 @@ module Ml has_one :default_experiment, class_name: 'Ml::Experiment' belongs_to :project has_many :versions, class_name: 'Ml::ModelVersion' + has_one :latest_version, -> { latest_by_model }, class_name: 'Ml::ModelVersion', inverse_of: :model + + scope :including_latest_version, -> { includes(:latest_version) } + scope :by_project, ->(project) { where(project_id: project.id) } def valid_default_experiment? return unless default_experiment diff --git a/app/models/ml/model_version.rb b/app/models/ml/model_version.rb index 934b924e4af..4bf37e228ab 100644 --- a/app/models/ml/model_version.rb +++ b/app/models/ml/model_version.rb @@ -18,6 +18,9 @@ module Ml delegate :name, to: :model + scope :order_by_model_id_id_desc, -> { order('model_id, id DESC') } + scope :latest_by_model, -> { order_by_model_id_id_desc.select('DISTINCT ON (model_id) *') } + class << self def find_or_create!(model, version, package) create_with(package: package).find_or_create_by!(project: model.project, model: model, version: version) diff --git a/app/models/packages/package.rb b/app/models/packages/package.rb index 9d0ca1acc74..ee8a26e8f19 100644 --- a/app/models/packages/package.rb +++ b/app/models/packages/package.rb @@ -171,14 +171,12 @@ class Packages::Package < ApplicationRecord scope :preload_pipelines, -> { preload(pipelines: :user) } scope :limit_recent, ->(limit) { order_created_desc.limit(limit) } scope :select_distinct_name, -> { select(:name).distinct } - scope :select_only_first_by_name, -> { select('DISTINCT ON (name) *') } # Sorting scope :order_created, -> { reorder(created_at: :asc) } scope :order_created_desc, -> { reorder(created_at: :desc) } scope :order_name, -> { reorder(name: :asc) } scope :order_name_desc, -> { reorder(name: :desc) } - scope :order_name_desc_version_desc, -> { reorder(name: :desc, version: :desc) } scope :order_version, -> { reorder(version: :asc) } scope :order_version_desc, -> { reorder(version: :desc) } scope :order_type, -> { reorder(package_type: :asc) } diff --git a/app/presenters/ml/models_index_presenter.rb b/app/presenters/ml/models_index_presenter.rb index e2cb8e2d6c1..c61f87fc4af 100644 --- a/app/presenters/ml/models_index_presenter.rb +++ b/app/presenters/ml/models_index_presenter.rb @@ -10,12 +10,20 @@ module Ml data = @models.map do |m| { name: m.name, - version: m.version, - path: Gitlab::Routing.url_helpers.project_package_path(m.project, m) + version: m.latest_version&.version, + path: package_path(m) } end Gitlab::Json.generate({ models: data }) end + + private + + def package_path(model) + return unless model.latest_version&.package.present? + + Gitlab::Routing.url_helpers.project_package_path(model.project, model.latest_version.package_id) + end end end diff --git a/app/services/groups/transfer_service.rb b/app/services/groups/transfer_service.rb index 81d4dfddaab..64256e43ce3 100644 --- a/app/services/groups/transfer_service.rb +++ b/app/services/groups/transfer_service.rb @@ -11,19 +11,51 @@ module Groups @error = nil end + def log_group_transfer_success(group, new_parent_group) + log_transfer(group, new_parent_group, nil) + end + + def log_group_transfer_error(group, new_parent_group, error_message) + log_transfer(group, new_parent_group, error_message) + end + def execute(new_parent_group) @new_parent_group = new_parent_group ensure_allowed_transfer proceed_to_transfer + log_group_transfer_success(@group, @new_parent_group) + rescue TransferError, ActiveRecord::RecordInvalid, Gitlab::UpdatePathError => e @group.errors.clear @error = s_("TransferGroup|Transfer failed: %{error_message}") % { error_message: e.message } + + log_group_transfer_error(@group, @new_parent_group, e.message) + false end private + def log_transfer(group, new_namespace, error_message = nil) + action = error_message.nil? ? "was" : "was not" + + log_payload = { + message: "Group #{action} transferred to a new namespace", + group_path: group.full_path, + group_id: group.id, + new_parent_group_path: new_parent_group&.full_path, + new_parent_group_id: new_parent_group&.id, + error_message: error_message + } + + if error_message.nil? + ::Gitlab::AppLogger.info(log_payload) + else + ::Gitlab::AppLogger.error(log_payload) + end + end + def proceed_to_transfer old_root_ancestor_id = @group.root_ancestor.id was_root_group = @group.root? diff --git a/app/services/projects/transfer_service.rb b/app/services/projects/transfer_service.rb index 1bae7bde168..642ec37619f 100644 --- a/app/services/projects/transfer_service.rb +++ b/app/services/projects/transfer_service.rb @@ -13,6 +13,14 @@ module Projects include Gitlab::ShellAdapter TransferError = Class.new(StandardError) + def log_project_transfer_success(project, new_namespace) + log_transfer(project, new_namespace, nil) + end + + def log_project_transfer_error(project, new_namespace, error_message) + log_transfer(project, new_namespace, error_message) + end + def execute(new_namespace) @new_namespace = new_namespace @@ -36,10 +44,15 @@ module Projects transfer(project) + log_project_transfer_success(project, @new_namespace) + true rescue Projects::TransferService::TransferError => ex project.reset project.errors.add(:new_namespace, ex.message) + + log_project_transfer_error(project, @new_namespace, ex.message) + false end @@ -47,6 +60,27 @@ module Projects attr_reader :old_path, :new_path, :new_namespace, :old_namespace + def log_transfer(project, new_namespace, error_message = nil) + action = error_message.nil? ? "was" : "was not" + + log_payload = { + message: "Project #{action} transferred to a new namespace", + project_id: project.id, + project_path: project.full_path, + project_namespace: project.namespace.full_path, + namespace_id: project.namespace_id, + new_namespace_id: new_namespace&.id, + new_project_namespace: new_namespace&.full_path, + error_message: error_message + } + + if error_message.nil? + ::Gitlab::AppLogger.info(log_payload) + else + ::Gitlab::AppLogger.error(log_payload) + end + end + # rubocop: disable CodeReuse/ActiveRecord def transfer(project) @old_path = project.full_path |