Add max question content limit of 32,768 characters
This commit is contained in:
parent
bb24124d6a
commit
b7e8187cd4
|
@ -11,6 +11,7 @@ class Question < ApplicationRecord
|
||||||
validates :content, length: { minimum: 1 }
|
validates :content, length: { minimum: 1 }
|
||||||
|
|
||||||
SHORT_QUESTION_MAX_LENGTH = 512
|
SHORT_QUESTION_MAX_LENGTH = 512
|
||||||
|
LONG_QUESTION_MAX_LENGTH = 32768
|
||||||
|
|
||||||
before_destroy do
|
before_destroy do
|
||||||
rep = Report.where(target_id: self.id, type: "Reports::Question")
|
rep = Report.where(target_id: self.id, type: "Reports::Question")
|
||||||
|
|
|
@ -65,6 +65,7 @@ module UseCase
|
||||||
def check_user
|
def check_user
|
||||||
raise Errors::NotAuthorized if target_user.privacy_require_user && !source_user_id
|
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::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
|
end
|
||||||
|
|
||||||
def create_question
|
def create_question
|
||||||
|
|
|
@ -9,6 +9,8 @@ module UseCase
|
||||||
option :send_to_own_inbox, type: Types::Params::Bool, default: proc { false }
|
option :send_to_own_inbox, type: Types::Params::Bool, default: proc { false }
|
||||||
|
|
||||||
def call
|
def call
|
||||||
|
check_question
|
||||||
|
|
||||||
question = ::Question.create!(
|
question = ::Question.create!(
|
||||||
content:,
|
content:,
|
||||||
author_is_anonymous: false,
|
author_is_anonymous: false,
|
||||||
|
@ -32,6 +34,10 @@ module UseCase
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def check_question
|
||||||
|
raise Errors::QuestionTooLong if content.length > ::Question::LONG_QUESTION_MAX_LENGTH
|
||||||
|
end
|
||||||
|
|
||||||
def increment_asked_count
|
def increment_asked_count
|
||||||
source_user.increment(:asked_count)
|
source_user.increment(:asked_count)
|
||||||
source_user.save
|
source_user.save
|
||||||
|
|
Loading…
Reference in New Issue