Sha256: d10198f6fb3cfbdc57156d5a27c958d9d36a8847a3f1768975bc12f27e43fa7b
Contents?: true
Size: 1.08 KB
Versions: 25
Compression:
Stored size: 1.08 KB
Contents
# frozen_string_literal: true module Decidim module Debates # This class holds a Form to close debates from Decidim's public views. class CloseDebateForm < Decidim::Form mimic :debate attribute :conclusions, Decidim::Attributes::CleanString attribute :debate, Debate validates :debate, presence: true validates :conclusions, presence: true, length: { minimum: 10, maximum: 10_000 } validate :user_can_close_debate def closed_at debate&.closed_at || Time.current end def map_model(debate) super self.debate = debate # Debates can be translated in different languages from the admin but # the public form doesn't allow it. When a user closes a debate the # user locale is taken as the text locale. self.conclusions = debate.conclusions&.values&.first end private def user_can_close_debate return if !debate || !debate.respond_to?(:closeable_by?) errors.add(:debate, :invalid) unless debate.closeable_by?(current_user) end end end end
Version data entries
25 entries across 25 versions & 1 rubygems