Sha256: 07c8bf5b3f6da432ebff5d766bcfc73983f244f9fecae130eff9067984b5a188

Contents?: true

Size: 1010 Bytes

Versions: 19

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 < Rectify::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

19 entries across 19 versions & 1 rubygems

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