Sha256: 0a5aefdd9adc33be434dc16de04486acfb2186c8c6a0c5939710c65be5fafdaf

Contents?: true

Size: 1.36 KB

Versions: 7

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

module Decidim
  module Elections
    module Admin
      # This command is executed when the user updates an Election
      # from the admin panel.
      class UpdateElection < Decidim::Command
        include ::Decidim::GalleryMethods

        def initialize(form, election)
          @form = form
          @election = election
          @attached_to = election
        end

        # Updates the election if valid.
        #
        # Broadcasts :ok if successful, :invalid otherwise.
        def call
          return broadcast(:invalid) if form.invalid?

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

          transaction do
            update_election!
            create_gallery if process_gallery?
            photo_cleanup!
          end

          broadcast(:ok, election)
        end

        private

        attr_reader :form, :election, :gallery

        def update_election!
          attributes = {
            title: form.title,
            description: form.description,
            start_time: form.start_time,
            end_time: form.end_time
          }

          Decidim.traceability.update!(
            election,
            form.current_user,
            attributes,
            visibility: "all"
          )
        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/elections/admin/update_election.rb
decidim-elections-0.28.3 app/commands/decidim/elections/admin/update_election.rb
decidim-elections-0.28.2 app/commands/decidim/elections/admin/update_election.rb
decidim-elections-0.28.1 app/commands/decidim/elections/admin/update_election.rb
decidim-elections-0.28.0 app/commands/decidim/elections/admin/update_election.rb
decidim-elections-0.28.0.rc5 app/commands/decidim/elections/admin/update_election.rb
decidim-elections-0.28.0.rc4 app/commands/decidim/elections/admin/update_election.rb