Sha256: ab81c71ad7c5ee96caff0b7c7e195553573b6448fa743e8eea39790b08097442

Contents?: true

Size: 1.16 KB

Versions: 17

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true
module Decidim
  module System
    # A command with all the business logic when updating an admin in
    # the system.
    class UpdateAdmin < Rectify::Command
      # Public: Initializes the command.
      #
      # form - A form object with the params.
      def initialize(admin, form)
        @admin = admin
        @form = form
      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?

        update_admin
        broadcast(:ok)
      end

      private

      attr_reader :form

      def update_admin
        @admin.update_attributes!(attributes)
      end

      def attributes
        {
          email: form.email
        }.merge(password_attributes)
      end

      def password_attributes
        return {} if form.password == form.password_confirmation && form.password.blank?

        {
          password: form.password,
          password_confirmation: form.password_confirmation
        }
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
decidim-system-0.1.0 app/commands/decidim/system/update_admin.rb
decidim-0.1.0 decidim-system/app/commands/decidim/system/update_admin.rb
decidim-system-0.0.8.1 app/commands/decidim/system/update_admin.rb
decidim-0.0.8.1 decidim-system/app/commands/decidim/system/update_admin.rb
decidim-system-0.0.7 app/commands/decidim/system/update_admin.rb
decidim-0.0.7 decidim-system/app/commands/decidim/system/update_admin.rb
decidim-system-0.0.6 app/commands/decidim/system/update_admin.rb
decidim-0.0.6 decidim-system/app/commands/decidim/system/update_admin.rb
decidim-system-0.0.5 app/commands/decidim/system/update_admin.rb
decidim-0.0.5 decidim-system/app/commands/decidim/system/update_admin.rb
decidim-0.0.4 decidim-system/app/commands/decidim/system/update_admin.rb
decidim-system-0.0.3 app/commands/decidim/system/update_admin.rb
decidim-0.0.3 decidim-system/app/commands/decidim/system/update_admin.rb
decidim-system-0.0.2 app/commands/decidim/system/update_admin.rb
decidim-0.0.2 decidim-system/app/commands/decidim/system/update_admin.rb
decidim-system-0.0.1 app/commands/decidim/system/update_admin.rb
decidim-0.0.1 decidim-system/app/commands/decidim/system/update_admin.rb