Sha256: 8c9da802e915feaef9e08d508861e8bd2521e5fcf50db2aa8f3bc40b2b8db9f3

Contents?: true

Size: 1.25 KB

Versions: 63

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 < Rectify::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

63 entries across 63 versions & 1 rubygems

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