Sha256: cb4467cb56a4366577095fbb83a9e02754390d15c31ec9b1fa31076f2d99579a

Contents?: true

Size: 1023 Bytes

Versions: 7

Compression:

Stored size: 1023 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A command with all the business logic to destroy an area.
    class DestroyArea < Decidim::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 was not valid and we could not 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

7 entries across 7 versions & 1 rubygems

Version Path
decidim-admin-0.28.4 app/commands/decidim/admin/destroy_area.rb
decidim-admin-0.28.3 app/commands/decidim/admin/destroy_area.rb
decidim-admin-0.28.2 app/commands/decidim/admin/destroy_area.rb
decidim-admin-0.28.1 app/commands/decidim/admin/destroy_area.rb
decidim-admin-0.28.0 app/commands/decidim/admin/destroy_area.rb
decidim-admin-0.28.0.rc5 app/commands/decidim/admin/destroy_area.rb
decidim-admin-0.28.0.rc4 app/commands/decidim/admin/destroy_area.rb