mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-03 20:00:49 +08:00
init project
This commit is contained in:
10
app/forms/add_school_apply_form.rb
Normal file
10
app/forms/add_school_apply_form.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
class AddSchoolApplyForm
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :name, :province, :city, :address, :remarks
|
||||
|
||||
validates :name, presence: true
|
||||
# validates :province, presence: true
|
||||
# validates :city, presence: true
|
||||
# validates :address, presence: true
|
||||
end
|
||||
27
app/forms/apply_shixun_mirror_form.rb
Normal file
27
app/forms/apply_shixun_mirror_form.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
class ApplyShixunMirrorForm
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :language, :runtime, :run_method, :attachment_id
|
||||
|
||||
validates :language, presence: true
|
||||
validates :runtime, presence: true
|
||||
validates :run_method, presence: true
|
||||
validates :attachment_id, presence: true, numericality: { only_integer: true }
|
||||
|
||||
validate :ensure_attachment_presence
|
||||
def ensure_attachment_presence
|
||||
return unless attachment_id
|
||||
|
||||
if attachment.blank?
|
||||
errors.add(:attachment_id, :attachment_not_exist)
|
||||
end
|
||||
end
|
||||
|
||||
def attachment
|
||||
@attachment ||= Attachment.find_by_id(attachment_id)
|
||||
end
|
||||
|
||||
def to_json
|
||||
{ language: language, runtime: runtime, run_method: run_method, attachment_id: attachment_id }.to_json
|
||||
end
|
||||
end
|
||||
19
app/forms/base_form.rb
Normal file
19
app/forms/base_form.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
class BaseForm
|
||||
include ActiveModel::Model
|
||||
|
||||
def check_project_category(project_category_id)
|
||||
raise "project_category_id参数值无效." if (ProjectCategory.find_by_id project_category_id).blank?
|
||||
end
|
||||
|
||||
def check_project_language(project_language_id)
|
||||
raise "project_language_id参数值无效." if (ProjectLanguage.find_by_id project_language_id).blank?
|
||||
end
|
||||
|
||||
def check_repository_name(user_id, repository_name)
|
||||
raise "仓库名称已被使用." if Repository.where(user_id: user_id, identifier: repository_name.strip).exists?
|
||||
end
|
||||
|
||||
def check_project_name(user_id, project_name)
|
||||
raise "项目名称已被使用." if Project.where(user_id: user_id, name: project_name.strip).exists?
|
||||
end
|
||||
end
|
||||
13
app/forms/contents/create_form.rb
Normal file
13
app/forms/contents/create_form.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class Contents::CreateForm < BaseForm
|
||||
attr_accessor :login, :repo_identifier, :filepath, :branch, :new_branch
|
||||
|
||||
validates :login, :repo_identifier, :filepath, presence: true
|
||||
|
||||
validate :check_branch
|
||||
|
||||
def check_branch
|
||||
raise "branch和new_branch必须存在一个 " if branch.blank? && new_branch.blank?
|
||||
raise "branch和new_branch只能存在一个" if !branch.blank? && !new_branch.blank?
|
||||
end
|
||||
|
||||
end
|
||||
6
app/forms/contents/delete_form.rb
Normal file
6
app/forms/contents/delete_form.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
class Contents::DeleteForm < BaseForm
|
||||
attr_accessor :login, :repo_identifier, :filepath, :branch, :new_branch, :sha
|
||||
|
||||
validates :login, :repo_identifier, :filepath, :sha, presence: true
|
||||
|
||||
end
|
||||
13
app/forms/contents/update_form.rb
Normal file
13
app/forms/contents/update_form.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class Contents::UpdateForm < BaseForm
|
||||
attr_accessor :login, :repo_identifier, :filepath, :branch, :new_branch, :sha
|
||||
|
||||
validates :login, :repo_identifier, :filepath, :sha, presence: true
|
||||
|
||||
validate :check_branch
|
||||
|
||||
def check_branch
|
||||
raise "branch和new_branch必须存在一个 " if branch.blank? && new_branch.blank?
|
||||
raise "branch和new_branch只能存在一个" if !branch.blank? && !new_branch.blank?
|
||||
end
|
||||
|
||||
end
|
||||
15
app/forms/examination_banks/save_exam_form.rb
Normal file
15
app/forms/examination_banks/save_exam_form.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
class ExaminationBanks::SaveExamForm
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :discipline_id, :sub_discipline_id, :difficulty, :name, :duration, :tag_discipline_id
|
||||
|
||||
validates :discipline_id, presence: true
|
||||
validates :sub_discipline_id, presence: true
|
||||
validates :difficulty, presence: true, inclusion: {in: 1..3}, numericality: { only_integer: true }
|
||||
validates :name, presence: true, length: { maximum: 60, too_long: "不能超过60个字符" }
|
||||
validate :validate_duration
|
||||
|
||||
def validate_duration
|
||||
raise '时长应为大于0的整数' if duration.present? && duration.to_i < 1
|
||||
end
|
||||
end
|
||||
12
app/forms/examination_intelligent_settings/save_exam_form.rb
Normal file
12
app/forms/examination_intelligent_settings/save_exam_form.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
class ExaminationIntelligentSettings::SaveExamForm
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :name, :duration
|
||||
|
||||
validates :name, presence: true, length: { maximum: 60 }
|
||||
validate :validate_duration
|
||||
|
||||
def validate_duration
|
||||
raise '时长应为大于0的整数' if duration.present? && duration.to_i < 1
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
class ExaminationIntelligentSettings::SaveExamSettingForm
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :discipline_id, :sub_discipline_id, :source, :difficulty, :tag_discipline_id, :question_settings
|
||||
|
||||
validates :discipline_id, presence: true
|
||||
validates :sub_discipline_id, presence: true
|
||||
validates :source, presence: true
|
||||
validates :difficulty, presence: true, inclusion: {in: 1..3}, numericality: { only_integer: true }
|
||||
validates :question_settings, presence: true
|
||||
end
|
||||
9
app/forms/gitea/repository_form.rb
Normal file
9
app/forms/gitea/repository_form.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class Gitea::RepositoryForm
|
||||
include ActiveModel::Model
|
||||
attr_accessor :name, :description, :auto_init, :gitignores,
|
||||
:issue_labels, :license, :private, :readme
|
||||
|
||||
validates :name, presence: true
|
||||
# validates :name, uniqueness: true
|
||||
|
||||
end
|
||||
37
app/forms/gitea/user_form.rb
Normal file
37
app/forms/gitea/user_form.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
class Gitea::UserForm
|
||||
include ActiveModel::Model
|
||||
EMAIL_REGEX = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/
|
||||
|
||||
include ActiveModel::Model
|
||||
attr_accessor :username, :email, :password
|
||||
|
||||
validates :username, presence: true
|
||||
validates :email, presence: true, format: { with: EMAIL_REGEX, multiline: true }
|
||||
validates :password, presence: true
|
||||
|
||||
validate :check_username, :check_email
|
||||
|
||||
attr_reader :record
|
||||
|
||||
def persist
|
||||
@record = id ? User.find(id) : User.new
|
||||
|
||||
if valid?
|
||||
@record.attributes = attributes.except(:password_confirmation, :id)
|
||||
@record.save!
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def check_username
|
||||
# errors.add(:login, :exist)
|
||||
raise "#{username} 已使用." if User.exists?(login: username.strip)
|
||||
end
|
||||
|
||||
def check_email
|
||||
raise "#{email} 已使用." if User.exists?(mail: email.strip)
|
||||
end
|
||||
end
|
||||
12
app/forms/libraries/save_form.rb
Normal file
12
app/forms/libraries/save_form.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
class Libraries::SaveForm
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :title, :content, :author_name, :author_school_name, :cover_id,
|
||||
:publish, :attachment_ids, :tag_ids
|
||||
|
||||
validates :title, presence: true, length: { maximum: 255 }
|
||||
validates :content, presence: true
|
||||
validates :author_name, presence: true, length: { maximum: 10 }
|
||||
validates :author_school_name, presence: true, length: { maximum: 50 }
|
||||
validates :attachment_ids, presence: true
|
||||
end
|
||||
15
app/forms/project_packages/save_form.rb
Normal file
15
app/forms/project_packages/save_form.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
class ProjectPackages::SaveForm
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :category_id, :title, :content, :attachment_ids, :deadline_at,
|
||||
:min_price, :max_price, :contact_name, :contact_phone, :code, :publish
|
||||
|
||||
validates :category_id, presence: true
|
||||
validates :title, presence: true, length: { maximum: 60 }
|
||||
validates :content, presence: true
|
||||
validates :deadline_at, presence: true
|
||||
validates :min_price, numericality: { greater_than: 0 }, allow_blank: true
|
||||
validates :max_price, numericality: { greater_than: ->(obj){ obj.min_price.to_i } }, allow_blank: true
|
||||
validates :contact_name, presence: true, length: { maximum: 20 }
|
||||
validates :contact_phone, presence: true, format: { with: /1\d{10}/ }
|
||||
end
|
||||
10
app/forms/projects/change_member_role_form.rb
Normal file
10
app/forms/projects/change_member_role_form.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
class Projects::ChangeMemberRoleForm < BaseForm
|
||||
attr_accessor :user_id, :role
|
||||
|
||||
validates :user_id, :role, presence: true
|
||||
validate :check_roles
|
||||
|
||||
def check_roles
|
||||
raise '无效的role值.' unless ["Manager","Developer", "Reporter"].include? role
|
||||
end
|
||||
end
|
||||
23
app/forms/projects/create_form.rb
Normal file
23
app/forms/projects/create_form.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
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
|
||||
|
||||
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
|
||||
validate do
|
||||
check_project_category(project_category_id)
|
||||
check_project_language(project_language_id)
|
||||
end
|
||||
|
||||
def check_license
|
||||
raise "license_id值无效. " if license_id && License.find_by(id: license_id).blank?
|
||||
end
|
||||
|
||||
def check_ignore
|
||||
raise "ignore_id值无效." if ignore_id && Ignore.find_by(id: ignore_id).blank?
|
||||
end
|
||||
end
|
||||
17
app/forms/projects/migrate_form.rb
Normal file
17
app/forms/projects/migrate_form.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
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
|
||||
|
||||
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: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
|
||||
validates :clone_addr, format: { with: URL_REGEX, multiline: true, message: "地址格式不正确" }
|
||||
validate do
|
||||
check_project_name(user_id, name) unless name.blank?
|
||||
check_repository_name(user_id, repository_name) unless repository_name.blank?
|
||||
check_project_category(project_category_id)
|
||||
check_project_language(project_language_id)
|
||||
end
|
||||
|
||||
end
|
||||
4
app/forms/projects/update_form.rb
Normal file
4
app/forms/projects/update_form.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
class Projects::UpdateForm < BaseForm
|
||||
attr_reader :name, :description, :repository_name, :project_category_id
|
||||
|
||||
end
|
||||
5
app/forms/repositories/search_sub_entries_form.rb
Normal file
5
app/forms/repositories/search_sub_entries_form.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class Repositories::SearchSubEntriesForm < BaseForm
|
||||
attr_accessor :filepath, :login, :repo_identifier
|
||||
|
||||
validates :filepath, :login, :repo_identifier, presence: true
|
||||
end
|
||||
22
app/forms/users/apply_authentication_form.rb
Normal file
22
app/forms/users/apply_authentication_form.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
class Users::ApplyAuthenticationForm
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :name, :show_realname, :id_number, :gender, :upload_image, :attachment_ids
|
||||
|
||||
validates :name, presence: true, length: { minimum: 2, maximum: 10 }, format: { with: CustomRegexp::LASTNAME, message: "2-10位中英文、数字" }
|
||||
validate :validate_ID_number
|
||||
validate :validate_attachment_ids
|
||||
|
||||
|
||||
def validate_ID_number
|
||||
unless id_number =~ User::VALID_NUMBER_REGEX
|
||||
raise("身份证格式不对")
|
||||
end
|
||||
end
|
||||
|
||||
def validate_attachment_ids
|
||||
unless attachment_ids.is_a?(Array) || attachment_ids.length != 1
|
||||
raise("图片参数不对")
|
||||
end
|
||||
end
|
||||
end
|
||||
17
app/forms/users/apply_professional_auth_form.rb
Normal file
17
app/forms/users/apply_professional_auth_form.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
class Users::ApplyProfessionalAuthForm
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :school_id, :department_id, :identity, :extra, :upload_image, :attachment_ids
|
||||
|
||||
validates :school_id, presence: true, numericality: { only_integer: true, greater_than: 0 }
|
||||
validates :department_id, numericality: { only_integer: true, greater_than: 0 }, allow_blank: true
|
||||
validates :identity, presence: true, inclusion: { in: %w(student teacher professional) }
|
||||
validates :extra, presence: true
|
||||
validate :validate_attachment_ids
|
||||
|
||||
def validate_attachment_ids
|
||||
unless attachment_ids.is_a?(Array) || attachment_ids.length != 1
|
||||
raise("图片参数不对")
|
||||
end
|
||||
end
|
||||
end
|
||||
16
app/forms/users/apply_trail_form.rb
Normal file
16
app/forms/users/apply_trail_form.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
class Users::ApplyTrailForm
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :user, :phone, :code, :reason
|
||||
|
||||
validates :reason, presence: true
|
||||
validates :phone, presence: true, format: { with: CustomRegexp::PHONE }, unless: -> { user.phone_binded? }
|
||||
validates :code, presence: true, unless: -> { user.phone_binded? }
|
||||
|
||||
validate :check_user_certification
|
||||
def check_user_certification
|
||||
return if user.certification != 1
|
||||
|
||||
errors.add(:user, :already_trial)
|
||||
end
|
||||
end
|
||||
8
app/forms/users/bind_email_form.rb
Normal file
8
app/forms/users/bind_email_form.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class Users::BindEmailForm
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :email, :code
|
||||
|
||||
validates :email, presence: true#, format: { with: CustomRegexp::EMAIL }
|
||||
validates :code, presence: true
|
||||
end
|
||||
8
app/forms/users/bind_phone_form.rb
Normal file
8
app/forms/users/bind_phone_form.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class Users::BindPhoneForm
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :phone, :code
|
||||
|
||||
validates :phone, presence: true, format: { with: CustomRegexp::PHONE }
|
||||
validates :code, presence: true
|
||||
end
|
||||
33
app/forms/users/update_account_form.rb
Normal file
33
app/forms/users/update_account_form.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
class Users::UpdateAccountForm
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :user
|
||||
attr_accessor :nickname, :name, :show_realname, :gender, :location, :location_city,
|
||||
:identity, :student_id, :technical_title, :school_id, :department_id
|
||||
|
||||
validates :nickname, presence: true, length: { minimum: 2, maximum: 20 }, format: { with: CustomRegexp::NICKNAME, message: "2-20位中英文、数字及下划线" }
|
||||
validates :name, presence: true, length: { minimum: 2, maximum: 10 }, format: { with: CustomRegexp::LASTNAME, message: "2-10位中英文、数字" }
|
||||
validates :gender, presence: true, numericality: { only_integer: true }, inclusion: { in: [0, 1] }
|
||||
validates :location, presence: true
|
||||
validates :location_city, presence: true
|
||||
validates :identity, presence: true, inclusion: { in: %w[teacher student professional ] }
|
||||
validates :technical_title, presence: true, unless: -> { identity.to_s == 'student' }
|
||||
validates :student_id, presence: true, if: -> { identity.to_s == 'student' }
|
||||
validates :school_id, presence: true
|
||||
|
||||
validate :check_school_exist
|
||||
def check_school_exist
|
||||
return if school_id.blank?
|
||||
unless School.exists?(id: school_id)
|
||||
errors.add(:school_id, :not_exist)
|
||||
end
|
||||
end
|
||||
|
||||
validate :check_department_exist
|
||||
def check_department_exist
|
||||
return if department_id.blank?
|
||||
unless Department.exists?(id: department_id)
|
||||
errors.add(:department_id, :not_exist)
|
||||
end
|
||||
end
|
||||
end
|
||||
7
app/forms/users/update_password_form.rb
Normal file
7
app/forms/users/update_password_form.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
class Users::UpdatePasswordForm
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :password, :old_password
|
||||
|
||||
validates :password, presence: true, length: { minimum: 8, maximum: 16 }, format: { with: CustomRegexp::PASSWORD, message: "8~16位密码,支持字母数字和符号" }
|
||||
end
|
||||
10
app/forms/validate/user.rb
Normal file
10
app/forms/validate/user.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
module Validate
|
||||
class User
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :nickname, :lastname
|
||||
|
||||
validates :nickname, presence: true, length: { maximum: 10, too_long: "不能超过10个字符" }
|
||||
validates :lastname, presence: true
|
||||
end
|
||||
end
|
||||
9
app/forms/validate/user_extension.rb
Normal file
9
app/forms/validate/user_extension.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
module Validate
|
||||
class UserExtension
|
||||
include ActiveModel::Model
|
||||
attr_accessor :location
|
||||
|
||||
validates :location, presence: true
|
||||
|
||||
end
|
||||
end
|
||||
20
app/forms/weapps/create_course_form.rb
Normal file
20
app/forms/weapps/create_course_form.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
class Weapps::CreateCourseForm
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :course
|
||||
attr_accessor :name, :course_list_name, :credit, :course_module_types, :end_date
|
||||
|
||||
validates :name, presence: true
|
||||
validates :course_list_name, presence: true
|
||||
|
||||
validate :course_name_prefix
|
||||
validate :check_course_modules
|
||||
|
||||
def course_name_prefix
|
||||
raise '课堂名称应以课程名称开头' unless name.index(course_list_name) && name.index(course_list_name) == 0
|
||||
end
|
||||
|
||||
def check_course_modules
|
||||
raise '请至少添加一个课堂模块' if course_module_types.blank?
|
||||
end
|
||||
end
|
||||
15
app/forms/weapps/update_course_form.rb
Normal file
15
app/forms/weapps/update_course_form.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
class Weapps::UpdateCourseForm
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :course
|
||||
attr_accessor :name, :course_list_name, :credit, :end_date
|
||||
|
||||
validates :name, presence: true
|
||||
validates :course_list_name, presence: true
|
||||
|
||||
validate :course_name_prefix
|
||||
|
||||
def course_name_prefix
|
||||
raise '课堂名称应以课程名称开头' unless name.index(course_list_name) && name.index(course_list_name) == 0
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user