Sha256: 280c4bcb1516a00ff3da71594e4fa454b9416ef2c2aff01d9668b74c6c2da80c

Contents?: true

Size: 1.25 KB

Versions: 25

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module Decidim
  module Elections
    module Admin
      # This command updates the status of the action and the election if it got changed
      class UpdateActionStatus < Rectify::Command
        # Public: Initializes the command.
        #
        # action - The pending action to be updated
        def initialize(action)
          @action = action
        end

        # Update the statuses of the action and the election if pending message status got changed.
        #
        # Broadcasts :ok if successful, :invalid otherwise.
        def call
          return broadcast(:ok) unless action.pending?

          transaction do
            update_pending_message_status
            update_election_status if action.accepted?
          end

          broadcast(:ok)
        end

        private

        attr_reader :action

        delegate :election, to: :action

        def update_pending_message_status
          action.status = Decidim::Elections.bulletin_board.get_pending_message_status(action.message_id)
          action.save!
        end

        def update_election_status
          election.bb_status = Decidim::Elections.bulletin_board.get_election_status(election.id)
          election.save!
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
decidim-elections-0.26.10 app/commands/decidim/elections/admin/update_action_status.rb
decidim-elections-0.26.9 app/commands/decidim/elections/admin/update_action_status.rb
decidim-elections-0.26.8 app/commands/decidim/elections/admin/update_action_status.rb
decidim-elections-0.26.7 app/commands/decidim/elections/admin/update_action_status.rb
decidim-elections-0.26.5 app/commands/decidim/elections/admin/update_action_status.rb
decidim-elections-0.26.4 app/commands/decidim/elections/admin/update_action_status.rb
decidim-elections-0.26.3 app/commands/decidim/elections/admin/update_action_status.rb
decidim-elections-0.26.2 app/commands/decidim/elections/admin/update_action_status.rb
decidim-elections-0.26.1 app/commands/decidim/elections/admin/update_action_status.rb
decidim-elections-0.26.0 app/commands/decidim/elections/admin/update_action_status.rb
decidim-elections-0.26.0.rc2 app/commands/decidim/elections/admin/update_action_status.rb
decidim-elections-0.26.0.rc1 app/commands/decidim/elections/admin/update_action_status.rb
decidim-elections-0.25.2 app/commands/decidim/elections/admin/update_action_status.rb
decidim-elections-0.25.1 app/commands/decidim/elections/admin/update_action_status.rb
decidim-elections-0.25.0 app/commands/decidim/elections/admin/update_action_status.rb
decidim-elections-0.25.0.rc4 app/commands/decidim/elections/admin/update_action_status.rb
decidim-elections-0.25.0.rc3 app/commands/decidim/elections/admin/update_action_status.rb
decidim-elections-0.25.0.rc2 app/commands/decidim/elections/admin/update_action_status.rb
decidim-elections-0.25.0.rc1 app/commands/decidim/elections/admin/update_action_status.rb
decidim-elections-0.24.3 app/commands/decidim/elections/admin/update_action_status.rb