Sha256: 49da716feb073e2013e76a7f740cb36589cf3cf79df175a5cb581f87d42bd927

Contents?: true

Size: 1.24 KB

Versions: 14

Compression:

Stored size: 1.24 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,
          content: form.content
        }
      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/update_static_page.rb
decidim-admin-0.15.1 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.15.0 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.14.4 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.14.3 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.14.2 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.14.1 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.13.1 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.12.2 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.13.0 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.12.1 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.13.0.pre1 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.12.0 app/commands/decidim/admin/update_static_page.rb
decidim-admin-0.12.0.pre app/commands/decidim/admin/update_static_page.rb