From 03a1d9f27782c6948b4f54b5e4d24aa9518aa568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Wed, 1 Nov 2023 22:26:53 +0100 Subject: [PATCH] Allow existing user records with reserved usernames to be saved --- app/models/user.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index acda860..9c933a3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -38,7 +38,8 @@ class User < ApplicationRecord message: "is invalid. Usernames need to start with a letter." # FIXME This needs a server restart to apply values validates_format_of :cn, without: /\A(#{Setting.reserved_usernames.join('|')})\z/i, - message: "has already been taken" + message: "has already been taken", + unless: Proc.new{ |u| u.persisted? } validates_uniqueness_of :email validates :email, email: true