Sha256: fba13e27cc352b8c931ea06b63d18e78086d74f8146f15f0c68235e28ef892e7

Contents?: true

Size: 1.24 KB

Versions: 73

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

require "decidim/translatable_attributes"

module Decidim
  module System
    # A form object used to update organizations from the system dashboard.
    #
    class UpdateOrganizationForm < Form
      include TranslatableAttributes

      mimic :organization

      attribute :name, String
      attribute :host, String
      attribute :secondary_hosts, String
      attribute :available_authorizations, Array[String]

      validates :name, presence: true
      validates :host, presence: true
      validate :validate_organization_uniqueness

      def map_model(model)
        self.secondary_hosts = model.secondary_hosts.join("\n")
      end

      def clean_secondary_hosts
        return unless secondary_hosts
        secondary_hosts.split("\n").map(&:chomp).select(&:present?)
      end

      def clean_available_authorizations
        return unless available_authorizations
        available_authorizations.select(&:present?)
      end

      private

      def validate_organization_uniqueness
        errors.add(:name, :taken) if Decidim::Organization.where(name: name).where.not(id: id).exists?
        errors.add(:host, :taken) if Decidim::Organization.where(host: host).where.not(id: id).exists?
      end
    end
  end
end

Version data entries

73 entries across 73 versions & 2 rubygems

Version Path
decidim-0.6.5 decidim-system/app/forms/decidim/system/update_organization_form.rb
decidim-system-0.6.4 app/forms/decidim/system/update_organization_form.rb
decidim-0.6.4 decidim-system/app/forms/decidim/system/update_organization_form.rb
decidim-system-0.6.3 app/forms/decidim/system/update_organization_form.rb
decidim-0.6.3 decidim-system/app/forms/decidim/system/update_organization_form.rb
decidim-system-0.6.2 app/forms/decidim/system/update_organization_form.rb
decidim-0.6.2 decidim-system/app/forms/decidim/system/update_organization_form.rb
decidim-system-0.6.1 app/forms/decidim/system/update_organization_form.rb
decidim-0.6.1 decidim-system/app/forms/decidim/system/update_organization_form.rb
decidim-system-0.6.0 app/forms/decidim/system/update_organization_form.rb
decidim-0.6.0 decidim-system/app/forms/decidim/system/update_organization_form.rb
decidim-system-0.5.1 app/forms/decidim/system/update_organization_form.rb
decidim-0.5.1 decidim-system/app/forms/decidim/system/update_organization_form.rb
decidim-system-0.5.0 app/forms/decidim/system/update_organization_form.rb
decidim-0.5.0 decidim-system/app/forms/decidim/system/update_organization_form.rb
decidim-system-0.4.4 app/forms/decidim/system/update_organization_form.rb
decidim-0.4.4 decidim-system/app/forms/decidim/system/update_organization_form.rb
decidim-system-0.4.3 app/forms/decidim/system/update_organization_form.rb
decidim-system-0.4.2 app/forms/decidim/system/update_organization_form.rb
decidim-system-0.4.1 app/forms/decidim/system/update_organization_form.rb