Sha256: 5031b7b17723b3af343075fc9aced5361e7e7b1a05e08aeb23296e1707c2a4f6
Contents?: true
Size: 1.15 KB
Versions: 12
Compression:
Stored size: 1.15 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 < Decidim::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) 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
12 entries across 12 versions & 1 rubygems