From 255be6c5ca805446ad29d8f45b3ef7ca9b11e23f Mon Sep 17 00:00:00 2001 From: Michael Kozono Date: Wed, 9 Aug 2017 16:24:49 +0000 Subject: Prevent user from changing username with container registry tags --- app/models/user.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'app') diff --git a/app/models/user.rb b/app/models/user.rb index 5d8672d60b3..7935b89662b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -148,6 +148,8 @@ class User < ActiveRecord::Base uniqueness: { case_sensitive: false } validate :namespace_uniq, if: :username_changed? + validate :namespace_move_dir_allowed, if: :username_changed? + validate :avatar_type, if: ->(user) { user.avatar.present? && user.avatar_changed? } validate :unique_email, if: :email_changed? validate :owns_notification_email, if: :notification_email_changed? @@ -487,6 +489,12 @@ class User < ActiveRecord::Base end end + def namespace_move_dir_allowed + if namespace&.any_project_has_container_registry_tags? + errors.add(:username, 'cannot be changed if a personal project has container registry tags.') + end + end + def avatar_type unless avatar.image? errors.add :avatar, "only images allowed" -- cgit v1.2.1