diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 73079d82b..e9bef0c9d 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -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 diff --git a/app/models/challenge_answer.rb b/app/models/challenge_answer.rb index 0ce757d71..d3fd69cd0 100644 --- a/app/models/challenge_answer.rb +++ b/app/models/challenge_answer.rb @@ -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 diff --git a/app/models/challenge_choose.rb b/app/models/challenge_choose.rb index 2463d3317..2b8858f21 100644 --- a/app/models/challenge_choose.rb +++ b/app/models/challenge_choose.rb @@ -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 diff --git a/app/models/challenge_question.rb b/app/models/challenge_question.rb index b0927aec0..959b033f9 100644 --- a/app/models/challenge_question.rb +++ b/app/models/challenge_question.rb @@ -1,3 +1,6 @@ class ChallengeQuestion < ApplicationRecord belongs_to :challenge_choose + + validates :option_name, length: { maximum: 500 } + end diff --git a/app/models/competition.rb b/app/models/competition.rb index 96fd14c1c..1d10e2032 100644 --- a/app/models/competition.rb +++ b/app/models/competition.rb @@ -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 diff --git a/app/models/competition_module_md_content.rb b/app/models/competition_module_md_content.rb index 4a8dacf9e..936ded8ef 100644 --- a/app/models/competition_module_md_content.rb +++ b/app/models/competition_module_md_content.rb @@ -5,4 +5,6 @@ class CompetitionModuleMdContent < ApplicationRecord # validates :name, presence: true validates :content, presence: true + validates :content, length: { maximum: 10000 } + end \ No newline at end of file diff --git a/app/models/discuss.rb b/app/models/discuss.rb index a236a2bbc..f35ca4751 100644 --- a/app/models/discuss.rb +++ b/app/models/discuss.rb @@ -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) } diff --git a/app/models/gtask_bank.rb b/app/models/gtask_bank.rb index 55f83ef10..f9d38d33f 100644 --- a/app/models/gtask_bank.rb +++ b/app/models/gtask_bank.rb @@ -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 diff --git a/app/models/gtopic_bank.rb b/app/models/gtopic_bank.rb index 609219711..fe9f184eb 100644 --- a/app/models/gtopic_bank.rb +++ b/app/models/gtopic_bank.rb @@ -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 diff --git a/app/models/homework_bank.rb b/app/models/homework_bank.rb index 7c9de0cda..d6db7bfab 100644 --- a/app/models/homework_bank.rb +++ b/app/models/homework_bank.rb @@ -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 diff --git a/app/models/library.rb b/app/models/library.rb index 743959d30..982db732b 100644 --- a/app/models/library.rb +++ b/app/models/library.rb @@ -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 diff --git a/app/models/shixun_info.rb b/app/models/shixun_info.rb index 7f7aa364e..e3a8d334b 100644 --- a/app/models/shixun_info.rb +++ b/app/models/shixun_info.rb @@ -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 diff --git a/app/models/stage.rb b/app/models/stage.rb index db7b5c0b3..84873b01f 100644 --- a/app/models/stage.rb +++ b/app/models/stage.rb @@ -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 diff --git a/app/models/test_set.rb b/app/models/test_set.rb index 7772a3a00..f774610ee 100644 --- a/app/models/test_set.rb +++ b/app/models/test_set.rb @@ -1,3 +1,7 @@ class TestSet < ApplicationRecord # match_rule: 匹配规则: full: 完全匹配, last: 末尾匹配 + # + validates :input, length: { maximum: 500 } + validates :input, length: { maximum: 500 } + end