From 1881f0ee95e0d293285dac5d9c1231e45b841963 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Fri, 24 Nov 2023 21:07:21 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- app/models/user.rb | 12 +++++++++++- app/services/users/build_service.rb | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/models/user.rb b/app/models/user.rb index a7c90765be1..b9dbba27a94 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -151,6 +151,7 @@ class User < MainClusterwide::ApplicationRecord # Namespace for personal projects has_one :namespace, -> { where(type: Namespaces::UserNamespace.sti_name) }, + required: true, dependent: :destroy, # rubocop:disable Cop/ActiveRecordDependent foreign_key: :owner_id, inverse_of: :owner, @@ -1602,7 +1603,7 @@ class User < MainClusterwide::ApplicationRecord if namespace namespace.path = username if username_changed? namespace.name = name if name_changed? - else + elsif Feature.disabled?(:create_user_ns_outside_model) # TODO: we should no longer need the `type` parameter once we can make the # the `has_one :namespace` association use the correct class. # issue https://gitlab.com/gitlab-org/gitlab/-/issues/341070 @@ -1611,6 +1612,15 @@ class User < MainClusterwide::ApplicationRecord end end + def assign_personal_namespace + return namespace if namespace + + build_namespace(path: username, name: name) + namespace.build_namespace_settings + + namespace + end + def set_username_errors namespace_path_errors = self.errors.delete(:"namespace.path") diff --git a/app/services/users/build_service.rb b/app/services/users/build_service.rb index b51684c6899..2a9e4be91d3 100644 --- a/app/services/users/build_service.rb +++ b/app/services/users/build_service.rb @@ -36,6 +36,8 @@ module Users else standard_build_user end + + user.assign_personal_namespace end def admin? -- cgit v1.2.3