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.26.10 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.26.9 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.26.8 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.26.7 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.26.5 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.26.4 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.26.3 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.26.2 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.26.1 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.26.0 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.26.0.rc2 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.26.0.rc1 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.25.2 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.25.1 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.25.0 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.25.0.rc4 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.25.0.rc3 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.25.0.rc2 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.25.0.rc1 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.24.3 app/forms/decidim/debates/admin/close_debate_form.rb