Sha256: da541939d8aa1375d7f94281b295a9d441c7312383855263c62baa10651a2994

Contents?: true

Size: 1021 Bytes

Versions: 41

Compression:

Stored size: 1021 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A command with all the business logic to destroy an area.
    class DestroyArea < Rectify::Command
      # Public: Initializes the command.
      #
      # area - The area to destroy
      # current_user - the user performing the action
      def initialize(area, current_user)
        @area = area
        @current_user = current_user
      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
        destroy_area
        broadcast(:ok)
      rescue ActiveRecord::RecordNotDestroyed
        broadcast(:has_spaces)
      end

      private

      attr_reader :current_user

      def destroy_area
        Decidim.traceability.perform_action!(
          "delete",
          @area,
          current_user
        ) do
          @area.destroy!
        end
      end
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

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