Sha256: 195dc7d3e5827f644571b5f66c34040db756e9eff4e532c5120fd9064d44c291

Contents?: true

Size: 1.07 KB

Versions: 65

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 < Rectify::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 wasn't valid and we couldn't 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

65 entries across 65 versions & 1 rubygems

Version Path
decidim-admin-0.12.0.pre app/commands/decidim/admin/destroy_scope.rb
decidim-admin-0.11.1 app/commands/decidim/admin/destroy_scope.rb
decidim-admin-0.11.0.pre1 app/commands/decidim/admin/destroy_scope.rb
decidim-admin-0.10.1 app/commands/decidim/admin/destroy_scope.rb
decidim-admin-0.10.0 app/commands/decidim/admin/destroy_scope.rb