Sha256: 1acd19358d1524d76b0c001bb375d59f0fb87c357a2a9c250e6d7de7523031d1

Contents?: true

Size: 1.16 KB

Versions: 19

Compression:

Stored size: 1.16 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 < Rectify::Command
      include ::Decidim::AttachmentMethods
      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 wasn't valid and we couldn't 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

19 entries across 19 versions & 1 rubygems

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