Commit 19dd5af6 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'ee-mk-validate-username-change-with-container-registry-tags' into 'master'

[EE] Prevent user from changing username with container registry tags

See merge request !2634
parents 29df1bf9 195b746b
......@@ -151,6 +151,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?
......@@ -506,6 +508,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"
......
---
title: Add missing validation error for username change with container registry tags
merge_request: 13356
author:
......@@ -127,6 +127,17 @@ describe User do
expect(user).to validate_uniqueness_of(:username).case_insensitive
end
context 'when username is changed' do
let(:user) { build_stubbed(:user, username: 'old_path', namespace: build_stubbed(:namespace)) }
it 'validates move_dir is allowed for the namespace' do
expect(user.namespace).to receive(:any_project_has_container_registry_tags?).and_return(true)
user.username = 'new_path'
expect(user).to be_invalid
expect(user.errors.messages[:username].first).to match('cannot be changed if a personal project has container registry tags')
end
end
end
it { is_expected.to validate_presence_of(:projects_limit) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment