Sha256: cbe2363931dd9674630d3e426f6a30a61856487794fa568d57a6cb7e4a14546e

Contents?: true

Size: 983 Bytes

Versions: 25

Compression:

Stored size: 983 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Debates
    module Admin
      # This class holds a Form to close debates from Decidim's admin views.
      class CloseDebateForm < Decidim::Form
        include TranslatableAttributes

        mimic :debate

        translatable_attribute :conclusions, Decidim::Attributes::CleanString do |translated_attribute, locale|
          validates translated_attribute, presence: true, if: ->(record) { record.default_locale?(locale) }
          validates translated_attribute, length: { minimum: 10, maximum: 10_000 }, if: ->(record) { record.default_locale?(locale) }
        end

        attribute :debate, Debate

        validates :debate, presence: true
        validate :user_can_close_debate

        def closed_at
          debate&.closed_at || Time.current
        end

        private

        def user_can_close_debate
          errors.add(:debate, :invalid) unless debate.official?
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
decidim-debates-0.24.2 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.24.1 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.24.0 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.24.0.rc2 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.24.0.rc1 app/forms/decidim/debates/admin/close_debate_form.rb