Sha256: ec4ca78a534bdefa58e47a950d9119bf8dff0d2b96beda208bce0f07b482b797

Contents?: true

Size: 1.07 KB

Versions: 7

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A command with all the business logic to destroy a scope.
    class DestroyScope < Decidim::Command
      # Public: Initializes the command.
      #
      # scope - The Scope to destroy
      # current_user - the user performing the action
      def initialize(scope, current_user)
        @scope = scope
        @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
        update_scope
        broadcast(:ok)
      end

      private

      attr_reader :current_user

      def update_scope
        Decidim.traceability.perform_action!(
          "delete",
          @scope,
          current_user,
          extra: {
            parent_name: @scope.parent.try(:name),
            scope_type_name: @scope.scope_type.try(:name)
          }
        ) do
          @scope.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_scope.rb
decidim-admin-0.28.3 app/commands/decidim/admin/destroy_scope.rb
decidim-admin-0.28.2 app/commands/decidim/admin/destroy_scope.rb
decidim-admin-0.28.1 app/commands/decidim/admin/destroy_scope.rb
decidim-admin-0.28.0 app/commands/decidim/admin/destroy_scope.rb
decidim-admin-0.28.0.rc5 app/commands/decidim/admin/destroy_scope.rb
decidim-admin-0.28.0.rc4 app/commands/decidim/admin/destroy_scope.rb