diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/models/user.rb | 12 | ||||
-rw-r--r-- | app/services/users/build_service.rb | 2 |
2 files changed, 13 insertions, 1 deletions
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? |