Sha256: c56051cf6ad1c303cb1b7618878a798a79d5040a34c8b80a7746ea9aa5aa6719

Contents?: true

Size: 1.42 KB

Versions: 7

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A form object to create or update pages.
    class StaticPageForm < Form
      include TranslatableAttributes

      attribute :slug, String
      validates :title, translatable_presence: true
      translatable_attribute :title, String
      translatable_attribute :content, String
      attribute :changed_notably, Boolean
      attribute :show_in_footer, Boolean
      attribute :allow_public_access, Boolean
      attribute :weight, Integer
      attribute :topic_id, Integer

      mimic :static_page

      validates :slug, presence: true
      validates :slug, format: { with: %r{\A[a-zA-Z]+[a-zA-Z0-9\-_/]+\z} }, allow_blank: true

      validate :slug, :slug_uniqueness

      alias organization current_organization

      def slug
        super.to_s.downcase
      end

      def topic
        @topic ||= StaticPageTopic.find_by(
          organization:,
          id: topic_id
        )
      end

      def topics
        @topics ||= StaticPageTopic.where(
          organization: current_organization
        )
      end

      def control_public_access?
        current_organization.force_users_to_authenticate_before_access_organization?
      end

      private

      def slug_uniqueness
        return unless organization
        return unless organization.static_pages.where(slug:).where.not(id:).any?

        errors.add(:slug, :taken)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-admin-0.28.4 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.28.3 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.28.2 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.28.1 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.28.0 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.28.0.rc5 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.28.0.rc4 app/forms/decidim/admin/static_page_form.rb