Sha256: f1a909804c46a019dc994b59e0ddf8dc74137251962156527eca955ea2ef40e2

Contents?: true

Size: 1.31 KB

Versions: 13

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A command with all the business logic when creating a static page.
    class CreateStaticPage < Rectify::Command
      # Public: Initializes the command.
      #
      # form - A form object with the params.
      def initialize(form)
        @form = form
        @page = nil
      end

      # Executes the command. Broadcasts these events:
      #
      # - :ok when everything is valid.
      # - :invalid if the form wasn't valid and we couldn't proceed.
      #
      # Returns nothing.
      def call
        return broadcast(:invalid) if form.invalid?

        create_page
        update_organization_tos_version
        broadcast(:ok)
      end

      private

      attr_reader :form

      def create_page
        @page = Decidim.traceability.create!(
          StaticPage,
          form.current_user,
          title: form.title,
          slug: form.slug,
          content: form.content,
          show_in_footer: form.show_in_footer,
          weight: form.weight,
          topic: form.topic,
          organization: form.organization,
          allow_public_access: form.allow_public_access
        )
      end

      def update_organization_tos_version
        UpdateOrganizationTosVersion.call(@form.organization, @page, @form)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-admin-0.25.2 app/commands/decidim/admin/create_static_page.rb
decidim-admin-0.25.1 app/commands/decidim/admin/create_static_page.rb
decidim-admin-0.25.0 app/commands/decidim/admin/create_static_page.rb
decidim-admin-0.25.0.rc4 app/commands/decidim/admin/create_static_page.rb
decidim-admin-0.25.0.rc3 app/commands/decidim/admin/create_static_page.rb
decidim-admin-0.25.0.rc2 app/commands/decidim/admin/create_static_page.rb
decidim-admin-0.25.0.rc1 app/commands/decidim/admin/create_static_page.rb
decidim-admin-0.24.3 app/commands/decidim/admin/create_static_page.rb
decidim-admin-0.24.2 app/commands/decidim/admin/create_static_page.rb
decidim-admin-0.24.1 app/commands/decidim/admin/create_static_page.rb
decidim-admin-0.24.0 app/commands/decidim/admin/create_static_page.rb
decidim-admin-0.24.0.rc2 app/commands/decidim/admin/create_static_page.rb
decidim-admin-0.24.0.rc1 app/commands/decidim/admin/create_static_page.rb