mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-21 20:25:45 +08:00
[FIX]一些筛选以及创建最大项目数量验证
[FIX]
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
class Projects::CreateForm < BaseForm
|
||||
REPOSITORY_NAME_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾
|
||||
attr_accessor :user_id, :name, :description, :repository_name, :project_category_id,
|
||||
:project_language_id, :ignore_id, :license_id, :private
|
||||
:project_language_id, :ignore_id, :license_id, :private, :owner
|
||||
|
||||
validates :user_id, :name, :description,:repository_name,
|
||||
:project_category_id, :project_language_id, presence: true
|
||||
validates :repository_name, format: { with: REPOSITORY_NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
|
||||
|
||||
validate :check_ignore, :check_license, :check_owner
|
||||
validate :check_ignore, :check_license, :check_owner, :check_max_repo_creation
|
||||
validate do
|
||||
check_project_category(project_category_id)
|
||||
check_project_language(project_language_id)
|
||||
@@ -22,6 +22,13 @@ class Projects::CreateForm < BaseForm
|
||||
end
|
||||
|
||||
def check_owner
|
||||
raise "user_id值无效." if user_id && Owner.find_by(id: user_id).blank?
|
||||
@owner = Owner.find_by(id: user_id)
|
||||
raise "user_id值无效." if user_id && owner.blank?
|
||||
end
|
||||
|
||||
def check_max_repo_creation
|
||||
return unless owner.is_a?(Organization)
|
||||
return if owner.max_repo_creation <= -1
|
||||
raise "已超过组织设置最大仓库数" if owner.max_repo_creation == owner.num_projects
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user