Sha256: 366158488cbfa40e3ff2bf3b37f9057e363689f98b898f5ccefaec87c85b159f

Contents?: true

Size: 780 Bytes

Versions: 4

Compression:

Stored size: 780 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module ActionDelegator
    module Admin
      class SettingForm < Form
        mimic :setting

        attribute :max_grants, Integer
        attribute :decidim_consultation_id, Integer
        attribute :authorization_method, String
        attribute :copy_from_setting_id, Integer

        validates :max_grants, :decidim_consultation_id, presence: true
        validate :consultation_uniqueness

        # TODO: validate consultation vote starting in the future
        def consultation_uniqueness
          errors.add(:decidim_consultation_id, :taken) if record.exists?(decidim_consultation_id: decidim_consultation_id)
        end

        def record
          Setting.where.not(id: id)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
decidim-action_delegator-0.8.1 app/forms/decidim/action_delegator/admin/setting_form.rb
decidim-action_delegator-0.7.2 app/forms/decidim/action_delegator/admin/setting_form.rb
decidim-action_delegator-0.7.1 app/forms/decidim/action_delegator/admin/setting_form.rb
decidim-action_delegator-0.7.0 app/forms/decidim/action_delegator/admin/setting_form.rb