Sha256: 1b07f0b1b10c0996139015eb4fc4d164ff39b4d14f53cfff2782a0594b936cec

Contents?: true

Size: 1 KB

Versions: 12

Compression:

Stored size: 1 KB

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

        validates :debate, presence: true
        validate :user_can_close_debate

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

        def debate
          @debate ||= Debate.find_by(id: id)
        end

        private

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

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-debates-0.27.9 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.27.8 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.27.7 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.27.6 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.27.5 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.27.4 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.27.3 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.27.2 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.27.1 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.27.0 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.27.0.rc2 app/forms/decidim/debates/admin/close_debate_form.rb
decidim-debates-0.27.0.rc1 app/forms/decidim/debates/admin/close_debate_form.rb