Sha256: 9d1f8922f02f43a87feddbb908636e8408f7e77df188fb407a94a44164172073

Contents?: true

Size: 1.45 KB

Versions: 37

Compression:

Stored size: 1.45 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
      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 :title, :content, translatable_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: 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: slug).where.not(id: id).any?

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

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
decidim-admin-0.26.1 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.26.0 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.26.0.rc2 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.26.0.rc1 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.25.2 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.25.1 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.25.0 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.25.0.rc4 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.25.0.rc3 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.25.0.rc2 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.25.0.rc1 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.24.3 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.24.2 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.24.1 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.24.0 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.24.0.rc2 app/forms/decidim/admin/static_page_form.rb
decidim-admin-0.24.0.rc1 app/forms/decidim/admin/static_page_form.rb