Sha256: 87a20a79907a2bf108403320951e96cd3e9b5ebcb91e7de3bdb64fad740546e0

Contents?: true

Size: 1.13 KB

Versions: 13

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Decidim
  module Templates
    module Admin
      class CopyTemplate < Decidim::Command
        def initialize(template, user)
          @template = template
          @user = user
        end

        # Executes the command. Broadcasts these events:
        #
        # - :ok when everything is valid.
        # - :invalid if the form was not valid and we could not proceed.
        #
        # Returns nothing.
        def call
          return broadcast(:invalid) unless @template.valid?

          Decidim.traceability.perform_action!("duplicate", @template, @user) do
            Template.transaction do
              copy_template
            end
          end

          broadcast(:ok, @copied_template)
        end

        def copy_template
          @copied_template = Template.create!(
            organization: @template.organization,
            name: @template.name,
            description: @template.description,
            target: @template.target,
            field_values: @template.field_values,
            templatable: @template.templatable
          )
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-templates-0.29.1 app/commands/decidim/templates/admin/copy_template.rb
decidim-templates-0.28.4 app/commands/decidim/templates/admin/copy_template.rb
decidim-templates-0.29.0 app/commands/decidim/templates/admin/copy_template.rb
decidim-templates-0.28.3 app/commands/decidim/templates/admin/copy_template.rb
decidim-templates-0.29.0.rc4 app/commands/decidim/templates/admin/copy_template.rb
decidim-templates-0.29.0.rc3 app/commands/decidim/templates/admin/copy_template.rb
decidim-templates-0.29.0.rc2 app/commands/decidim/templates/admin/copy_template.rb
decidim-templates-0.29.0.rc1 app/commands/decidim/templates/admin/copy_template.rb
decidim-templates-0.28.2 app/commands/decidim/templates/admin/copy_template.rb
decidim-templates-0.28.1 app/commands/decidim/templates/admin/copy_template.rb
decidim-templates-0.28.0 app/commands/decidim/templates/admin/copy_template.rb
decidim-templates-0.28.0.rc5 app/commands/decidim/templates/admin/copy_template.rb
decidim-templates-0.28.0.rc4 app/commands/decidim/templates/admin/copy_template.rb