实训和竞赛等模块的字符长度限制

dev_tj
cxt 5 years ago
parent 908d2cb273
commit 8b1e290ec5

@ -28,6 +28,9 @@ class Challenge < ApplicationRecord
scope :fields_for_list, -> { select([:id, :subject, :st, :score, :position, :shixun_id]) }
validates :task_pass, length: { maximum: 10000 }
after_commit :create_diff_record
def next_challenge

@ -3,6 +3,8 @@ class ChallengeAnswer < ApplicationRecord
belongs_to :challenge
has_many :game_answers, :dependent => :destroy
validates :contents, length: { maximum: 5000 }
def view_answer_time(user_id)
game_answers.where(user_id: user_id).last&.view_time
end

@ -3,4 +3,7 @@ class ChallengeChoose < ApplicationRecord
belongs_to :challenge, optional: true
has_many :challenge_tags, :dependent => :destroy
has_many :challenge_questions, dependent: :destroy
validates :subject, length: { maximum: 1000 }
end

@ -1,3 +1,6 @@
class ChallengeQuestion < ApplicationRecord
belongs_to :challenge_choose
validates :option_name, length: { maximum: 500 }
end

@ -33,6 +33,8 @@ class Competition < ApplicationRecord
has_many :competition_prizes, dependent: :destroy
has_many :competition_prize_users, dependent: :destroy
validates :introduction, length: { maximum: 500 }
before_save :set_laboratory
after_create :create_competition_modules

@ -5,4 +5,6 @@ class CompetitionModuleMdContent < ApplicationRecord
# validates :name, presence: true
validates :content, presence: true
validates :content, length: { maximum: 10000 }
end

@ -13,6 +13,8 @@ class Discuss < ApplicationRecord
belongs_to :challenge, optional: true
validate :validate_sensitive_string
validates :content, length: { maximum: 1000 }
after_create :send_tiding
scope :children, -> (discuss_id){ where(parent_id: discuss_id).includes(:user).reorder(created_at: :asc) }

@ -9,4 +9,6 @@ class GtaskBank < ApplicationRecord
scope :myself, ->(user_id) { where(user_id: user_id)}
scope :is_public, -> { where(:is_public => true) }
validates :name, length: { maximum: 60 }
validates :description, length: { maximum: 5000 }
end

@ -7,4 +7,11 @@ class GtopicBank < ApplicationRecord
has_many :graduation_topics, dependent: :nullify
scope :myself, ->(user_id) { where(user_id: user_id)}
# 课题名称和描述字段长度限制
validates :name, length: { maximum: 60,
too_long: "60 characters is the maximum allowed" }
validates :description, length: { maximum: 5000,
too_long: "5000 characters is the maximum allowed" }
end

@ -10,4 +10,7 @@ class HomeworkBank < ApplicationRecord
scope :is_public, -> { where(is_public: true)}
scope :myself, ->(user_id) { where(user_id: user_id)}
validates :name, length: { maximum: 60 }
validates :description, length: { maximum: 15000 }
validates :reference_answer, length: { maximum: 15000 }
end

@ -13,6 +13,7 @@ class Library < ApplicationRecord
has_one :praise_tread_cache, foreign_key: :object_id
has_many :praise_treads, as: :praise_tread_object, dependent: :destroy
validates :content, length: { maximum: 5000 }
validates :uuid, presence: true, uniqueness: true

@ -4,6 +4,8 @@ class ShixunInfo < ApplicationRecord
validates_length_of :fork_reason, maximum: 60
after_commit :create_diff_record
validates :description, length: { maximum: 5000 }
private
def create_diff_record

@ -7,5 +7,5 @@ class Stage < ApplicationRecord
has_many :shixuns, :through => :stage_shixuns
validates :name, length: { maximum: 60 }
validates :description, length: { maximum: 300 }
validates :description, length: { maximum: 1000 }
end

@ -1,3 +1,7 @@
class TestSet < ApplicationRecord
# match_rule: 匹配规则: full 完全匹配, last 末尾匹配
#
validates :input, length: { maximum: 500 }
validates :input, length: { maximum: 500 }
end

Loading…
Cancel
Save