Add max question content limit of 32,768 characters

This commit is contained in:
Andreas Nedbal 2024-03-10 20:30:21 +01:00 committed by Andreas Nedbal
parent bb24124d6a
commit b7e8187cd4
3 changed files with 8 additions and 0 deletions

View File

@ -11,6 +11,7 @@ class Question < ApplicationRecord
validates :content, length: { minimum: 1 }
SHORT_QUESTION_MAX_LENGTH = 512
LONG_QUESTION_MAX_LENGTH = 32768
before_destroy do
rep = Report.where(target_id: self.id, type: "Reports::Question")

View File

@ -65,6 +65,7 @@ module UseCase
def check_user
raise Errors::NotAuthorized if target_user.privacy_require_user && !source_user_id
raise Errors::QuestionTooLong if content.length > ::Question::SHORT_QUESTION_MAX_LENGTH && !target_user.profile.allow_long_questions
raise Errors::QuestionTooLong if content.length > ::Question::LONG_QUESTION_MAX_LENGTH && target_user.profile.allow_long_questions
end
def create_question

View File

@ -9,6 +9,8 @@ module UseCase
option :send_to_own_inbox, type: Types::Params::Bool, default: proc { false }
def call
check_question
question = ::Question.create!(
content:,
author_is_anonymous: false,
@ -32,6 +34,10 @@ module UseCase
private
def check_question
raise Errors::QuestionTooLong if content.length > ::Question::LONG_QUESTION_MAX_LENGTH
end
def increment_asked_count
source_user.increment(:asked_count)
source_user.save