Sha256: e57da4edd921471b6c182c4cf2dfa7036a8d6b37a993cae5d7eae551477b7b93

Contents?: true

Size: 1.31 KB

Versions: 7

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

module Decidim
  module Votings
    module Admin
      # A command with the business logic to destroy a poling officer
      class DestroyPollingOfficer < Decidim::Command
        # Public: Initializes the command.
        #
        # polling_officer - the PollingOfficer to destroy
        # current_user - the user performing this action
        def initialize(polling_officer, current_user)
          @polling_officer = polling_officer
          @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_polling_officer!
          broadcast(:ok)
        end

        private

        attr_reader :polling_officer, :current_user

        def destroy_polling_officer!
          extra_info = {
            resource: {
              title: polling_officer.user.name
            }
          }

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

Version data entries

7 entries across 7 versions & 1 rubygems

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