Sha256: a815574cf143740ae92ed36363f34cf50f491a0bc686834567ca3c735630ebb1

Contents?: true

Size: 1.43 KB

Versions: 3

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

module Decidim
  module Assemblies
    module Admin
      # A command with all the business logic when destroying an assembly
      # admin in the system.
      class DestroyAssemblyAdmin < Rectify::Command
        # Public: Initializes the command.
        #
        # role - the AssemblyUserRole to destroy
        # current_user - the user performing this action
        def initialize(role, current_user)
          @role = role
          @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_role!
          dispatch_system_event
          broadcast(:ok)
        end

        private

        attr_reader :role, :current_user

        def dispatch_system_event
          ActiveSupport::Notifications.publish("decidim.system.participatory_space.admin.destroyed", role.class.name, role.id)
        end

        def destroy_role!
          extra_info = {
            resource: {
              title: role.user.name
            }
          }

          Decidim.traceability.perform_action!(
            "delete",
            role,
            current_user,
            extra_info
          ) do
            role.destroy!
            role
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-assemblies-0.26.10 app/commands/decidim/assemblies/admin/destroy_assembly_admin.rb
decidim-assemblies-0.26.9 app/commands/decidim/assemblies/admin/destroy_assembly_admin.rb
decidim-assemblies-0.26.8 app/commands/decidim/assemblies/admin/destroy_assembly_admin.rb