Sha256: 18f09c579138bd2034e1a50b0f78f201ad67eb84702f1265f6f7f2047410a0bc

Contents?: true

Size: 1.25 KB

Versions: 17

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # This command deals with destroying a Component from the admin panel.
    class DestroyComponent < Decidim::Command
      # Public: Initializes the command.
      #
      # component - The Component to be destroyed.
      # current_user - the user performing the action
      def initialize(component, current_user)
        @component = component
        @current_user = current_user
      end

      # Public: Executes the command.
      #
      # Broadcasts :ok if it got destroyed, raises an exception otherwise.
      def call
        begin
          destroy_component
        rescue StandardError
          return broadcast(:invalid)
        end
        broadcast(:ok)
      end

      private

      def destroy_component
        transaction do
          run_before_hooks

          Decidim.traceability.perform_action!(
            "delete",
            @component,
            @current_user
          ) do
            @component.destroy!
          end

          run_hooks
        end
      end

      def run_before_hooks
        @component.manifest.run_hooks(:before_destroy, @component)
      end

      def run_hooks
        @component.manifest.run_hooks(:destroy, @component)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
decidim-admin-0.27.9 app/commands/decidim/admin/destroy_component.rb
decidim-admin-0.27.8 app/commands/decidim/admin/destroy_component.rb
decidim-admin-0.28.2 app/commands/decidim/admin/destroy_component.rb
decidim-admin-0.27.7 app/commands/decidim/admin/destroy_component.rb
decidim-admin-0.28.1 app/commands/decidim/admin/destroy_component.rb
decidim-admin-0.27.6 app/commands/decidim/admin/destroy_component.rb
decidim-admin-0.28.0 app/commands/decidim/admin/destroy_component.rb
decidim-admin-0.27.5 app/commands/decidim/admin/destroy_component.rb
decidim-admin-0.28.0.rc5 app/commands/decidim/admin/destroy_component.rb
decidim-admin-0.28.0.rc4 app/commands/decidim/admin/destroy_component.rb
decidim-admin-0.27.4 app/commands/decidim/admin/destroy_component.rb
decidim-admin-0.27.3 app/commands/decidim/admin/destroy_component.rb
decidim-admin-0.27.2 app/commands/decidim/admin/destroy_component.rb
decidim-admin-0.27.1 app/commands/decidim/admin/destroy_component.rb
decidim-admin-0.27.0 app/commands/decidim/admin/destroy_component.rb
decidim-admin-0.27.0.rc2 app/commands/decidim/admin/destroy_component.rb
decidim-admin-0.27.0.rc1 app/commands/decidim/admin/destroy_component.rb