Sha256: 661b050ebf1e066012ee7a17d26f42c29b850613e5832e0af41fa93e67a9d679

Contents?: true

Size: 1.4 KB

Versions: 25

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A command with all the business logic when updating a static page.
    class UpdateStaticPage < Rectify::Command
      # Public: Initializes the command.
      #
      # page - The StaticPage to update
      # form - A form object with the params.
      def initialize(page, form)
        @page = page
        @form = form
      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?

        update_page
        update_organization_tos_version if form.changed_notably
        broadcast(:ok)
      end

      private

      attr_reader :form

      def update_page
        Decidim.traceability.update!(
          @page,
          form.current_user,
          attributes
        )
      end

      def attributes
        {
          title: form.title,
          slug: form.slug,
          show_in_footer: form.show_in_footer,
          weight: form.weight,
          topic: form.topic,
          content: form.content,
          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

25 entries across 25 versions & 1 rubygems

Version Path
decidim-admin-0.26.10 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.26.9 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.26.8 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.26.7 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.26.5 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.26.4 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.26.3 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.26.2 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.26.1 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.26.0 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.26.0.rc2 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.26.0.rc1 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.25.2 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.25.1 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.25.0 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.25.0.rc4 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.25.0.rc3 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.25.0.rc2 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.25.0.rc1 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.24.3 app/commands/decidim/admin/update_static_page.rb