diff options
Diffstat (limited to 'app/models/user.rb')
| -rw-r--r-- | app/models/user.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 341b96a0d91..55d75892fc4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -67,6 +67,8 @@ class User < ActiveRecord::Base message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" } + validate :namespace_uniq, if: ->(user) { user.username_changed? } + before_validation :generate_password, on: :create before_save :ensure_authentication_token alias_attribute :private_token, :authentication_token @@ -135,6 +137,12 @@ class User < ActiveRecord::Base end end + def namespace_uniq + namespace_name = self.username + if Namespace.find_by_path(namespace_name) + self.errors.add :username, "already exist" + end + end # Namespaces user has access to def namespaces |
