Sha256: 9cac999a1068f140f0a5c1dbbd99e1b76a241af6d210ff2d6c25d690e0dd7816
Contents?: true
Size: 1.17 KB
Versions: 5
Compression:
Stored size: 1.17 KB
Contents
# frozen_string_literal: true module Decidim module Comments # A form object used to create comments from the graphql api. # class CommentForm < Form attribute :body, Decidim::Attributes::CleanString attribute :alignment, Integer attribute :user_group_id, Integer attribute :commentable attribute :commentable_gid mimic :comment validates :body, presence: true, length: { maximum: ->(form) { form.max_length } } validates :alignment, inclusion: { in: [0, 1, -1] }, if: ->(form) { form.alignment.present? } validate :max_depth def max_length if current_component&.settings.respond_to?(:comments_max_length) component_length = current_component.try { settings.comments_max_length.positive? } return current_component.settings.comments_max_length if component_length end return current_organization.comments_max_length if current_organization.comments_max_length.positive? 1000 end def max_depth return unless commentable.respond_to?(:depth) errors.add(:base, :invalid) if commentable.depth >= Comment::MAX_DEPTH end end end end
Version data entries
5 entries across 5 versions & 1 rubygems