diff --git a/app/forms/projects/migrate_form.rb b/app/forms/projects/migrate_form.rb index f17b75a5a..51116b2b5 100644 --- a/app/forms/projects/migrate_form.rb +++ b/app/forms/projects/migrate_form.rb @@ -2,7 +2,7 @@ class Projects::MigrateForm < BaseForm REPOSITORY_NAME_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾 URL_REGEX = /\A(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?\z/i - attr_accessor :user_id, :name, :description, :repository_name, :project_category_id, :project_language_id, :clone_addr, :private, :is_mirror, :auth_username, :auth_password + attr_accessor :user_id, :name, :description, :repository_name, :project_category_id, :project_language_id, :clone_addr, :private, :is_mirror, :auth_username, :auth_password, :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: "只能含有数字、字母、下划线且不能以下划线开头和结尾" } @@ -12,6 +12,18 @@ class Projects::MigrateForm < BaseForm check_repository_name(user_id, repository_name) unless repository_name.blank? check_project_category(project_category_id) check_project_language(project_language_id) + check_owner + check_max_repo_creation end + def check_owner + @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 diff --git a/app/services/projects/migrate_service.rb b/app/services/projects/migrate_service.rb index ff0c0643d..2f7725db6 100644 --- a/app/services/projects/migrate_service.rb +++ b/app/services/projects/migrate_service.rb @@ -44,7 +44,7 @@ class Projects::MigrateService < ApplicationService hidden: project_secretion[:hidden], identifier: params[:repository_name], mirror_url: params[:clone_addr], - user_id: user.id, + user_id: params[:user_id], login: params[:auth_username], password: params[:auth_password], is_mirror: params[:is_mirror] diff --git a/app/services/repositories/migrate_service.rb b/app/services/repositories/migrate_service.rb index e2f520aeb..156777cc3 100644 --- a/app/services/repositories/migrate_service.rb +++ b/app/services/repositories/migrate_service.rb @@ -28,7 +28,7 @@ class Repositories::MigrateService < ApplicationService { clone_addr: params[:mirror_url], repo_name: params[:identifier], - uid: user.gitea_uid, + uid: project&.owner&.gitea_uid, private: params[:hidden], mirror: wrapper_mirror || false, auth_username: params[:login],