Sha256: 41474a8d3567e3ba72a21cc3e2beb591eb5b726d66e8e08e4bbc4385e87e5c75

Contents?: true

Size: 1010 Bytes

Versions: 20

Compression:

Stored size: 1010 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Elections
    module TrusteeZone
      # This command allows the user to update their trustee information
      class UpdateTrustee < Decidim::Command
        # Public: Initializes the command.
        #
        # form - A form with the new trustee information
        def initialize(form)
          @form = form
        end

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

          update_trustee!

          broadcast(:ok, trustee)
        rescue ActiveRecord::RecordNotUnique
          form.errors.add(:name, :taken)
          broadcast(:invalid)
        end

        private

        attr_reader :form

        delegate :trustee, to: :form

        def update_trustee!
          trustee.update!(
            name: form.name,
            public_key: form.public_key
          )
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
decidim-elections-0.28.5 app/commands/decidim/elections/trustee_zone/update_trustee.rb
decidim-elections-0.28.4 app/commands/decidim/elections/trustee_zone/update_trustee.rb
decidim-elections-0.27.9 app/commands/decidim/elections/trustee_zone/update_trustee.rb
decidim-elections-0.28.3 app/commands/decidim/elections/trustee_zone/update_trustee.rb
decidim-elections-0.27.8 app/commands/decidim/elections/trustee_zone/update_trustee.rb
decidim-elections-0.28.2 app/commands/decidim/elections/trustee_zone/update_trustee.rb
decidim-elections-0.27.7 app/commands/decidim/elections/trustee_zone/update_trustee.rb
decidim-elections-0.28.1 app/commands/decidim/elections/trustee_zone/update_trustee.rb
decidim-elections-0.27.6 app/commands/decidim/elections/trustee_zone/update_trustee.rb
decidim-elections-0.28.0 app/commands/decidim/elections/trustee_zone/update_trustee.rb
decidim-elections-0.27.5 app/commands/decidim/elections/trustee_zone/update_trustee.rb
decidim-elections-0.28.0.rc5 app/commands/decidim/elections/trustee_zone/update_trustee.rb
decidim-elections-0.28.0.rc4 app/commands/decidim/elections/trustee_zone/update_trustee.rb
decidim-elections-0.27.4 app/commands/decidim/elections/trustee_zone/update_trustee.rb
decidim-elections-0.27.3 app/commands/decidim/elections/trustee_zone/update_trustee.rb
decidim-elections-0.27.2 app/commands/decidim/elections/trustee_zone/update_trustee.rb
decidim-elections-0.27.1 app/commands/decidim/elections/trustee_zone/update_trustee.rb
decidim-elections-0.27.0 app/commands/decidim/elections/trustee_zone/update_trustee.rb
decidim-elections-0.27.0.rc2 app/commands/decidim/elections/trustee_zone/update_trustee.rb
decidim-elections-0.27.0.rc1 app/commands/decidim/elections/trustee_zone/update_trustee.rb