Sha256: 42f005ed1c6eb20347893315022a5acc5c4c07cabcc64279044c353762dbd39f

Contents?: true

Size: 1.12 KB

Versions: 8

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

module Decidim
  module Votings
    # A command with all the business logic when signing a closure of a polling station
    class CertifyPollingStationClosure < Decidim::Command
      include ::Decidim::GalleryMethods
      # Public: Initializes the command.
      #
      # form - A form object with the params.
      # closure - A closure object.
      def initialize(form, closure)
        @form = form
        @closure = closure
        @attached_to = closure
      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
        return broadcast(:invalid) if form.invalid?

        if process_gallery?
          build_gallery
          return broadcast(:invalid) if gallery_invalid?
        end

        transaction do
          create_gallery if process_gallery?
          closure.update!(phase: :signature)
        end

        broadcast(:ok)
      end

      private

      attr_reader :form, :closure, :attachment
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

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