From 35e6d945dd5096ea7c3c4d0343b3da00e6b46d11 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 11 Jan 2024 13:39:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E7=BB=84=E7=BB=87?= =?UTF-8?q?=E6=A0=87=E8=AF=86=E6=AD=A3=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/forms/organizations/create_form.rb | 4 ++-- app/models/organization.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/forms/organizations/create_form.rb b/app/forms/organizations/create_form.rb index 2163f477e..1f40350b3 100644 --- a/app/forms/organizations/create_form.rb +++ b/app/forms/organizations/create_form.rb @@ -1,12 +1,12 @@ class Organizations::CreateForm < BaseForm - NAME_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾 + NAME_REGEX = /^[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*$/ #只含有数字、字母、下划线不能以下划线开头和结尾 attr_accessor :name, :description, :website, :location, :repo_admin_change_team_access, :visibility, :max_repo_creation, :nickname, :original_name validates :name, :nickname, :visibility, presence: true validates :name, :nickname, length: { maximum: 100 } validates :location, length: { maximum: 50 } validates :description, length: { maximum: 200 } - validates :name, format: { with: NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" } + validates :name, format: { with: NAME_REGEX, multiline: true, message: "只能以数字或字母开头,仅支持横杠、下划线、点三种符号,不允许符号连续排列,长度4-50个字符" } validate do check_name(name) unless name.blank? || name == original_name diff --git a/app/models/organization.rb b/app/models/organization.rb index d61dda567..f6c14298d 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -63,7 +63,7 @@ class Organization < Owner alias_attribute :name, :login - NAME_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾 + NAME_REGEX = /^[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*$/ #只含有数字、字母、下划线不能以下划线开头和结尾 default_scope { where(type: "Organization") } @@ -74,7 +74,7 @@ class Organization < Owner validates :login, presence: true validates_uniqueness_of :login, :if => Proc.new { |user| user.login_changed? && user.login.present? }, case_sensitive: false - validates :login, format: { with: NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" } + validates :login, format: { with: NAME_REGEX, multiline: true, message: "只能以数字或字母开头,仅支持横杠、下划线、点三种符号,不允许符号连续排列,长度4-50个字符" } delegate :description, :website, :location, :repo_admin_change_team_access, :recommend, :visibility, :max_repo_creation, :num_projects, :num_users, :num_teams, to: :organization_extension, allow_nil: true