Sha256: 77cde1e20a0885ed466e23dcdb94da589398ace15b667fad1fb75460227ee7c0

Contents?: true

Size: 1.15 KB

Versions: 14

Compression:

Stored size: 1.15 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,
          organization: form.organization
        )
      end

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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
decidim-admin-0.15.2 app/commands/decidim/admin/create_static_page.rb
decidim-admin-0.15.1 app/commands/decidim/admin/create_static_page.rb
decidim-admin-0.15.0 app/commands/decidim/admin/create_static_page.rb
decidim-admin-0.14.4 app/commands/decidim/admin/create_static_page.rb
decidim-admin-0.14.3 app/commands/decidim/admin/create_static_page.rb
decidim-admin-0.14.2 app/commands/decidim/admin/create_static_page.rb
decidim-admin-0.14.1 app/commands/decidim/admin/create_static_page.rb
decidim-admin-0.13.1 app/commands/decidim/admin/create_static_page.rb
decidim-admin-0.12.2 app/commands/decidim/admin/create_static_page.rb
decidim-admin-0.13.0 app/commands/decidim/admin/create_static_page.rb
decidim-admin-0.12.1 app/commands/decidim/admin/create_static_page.rb
decidim-admin-0.13.0.pre1 app/commands/decidim/admin/create_static_page.rb
decidim-admin-0.12.0 app/commands/decidim/admin/create_static_page.rb
decidim-admin-0.12.0.pre app/commands/decidim/admin/create_static_page.rb