Sha256: 0b9b500a516ed14b6712f0161da2867a9cde4b884e5d9fa6b4f1b7b31d1796f4
Contents?: true
Size: 1.54 KB
Versions: 19
Compression:
Stored size: 1.54 KB
Contents
# frozen_string_literal: true module Decidim module Admin # A command with all the business logic when officializing a user. class OfficializeUser < Decidim::Command # Public: Initializes the command. # # form - The officialization form. def initialize(form) @form = form end # Executes the command. Broadcasts these events: # # - :ok when the officialization suceeds. # - :invalid when the form is invalid. # # Returns nothing. def call return broadcast(:invalid) unless form.valid? officialize_user Decidim::EventsManager.publish( event: "decidim.events.users.user_officialized", event_class: Decidim::ProfileUpdatedEvent, resource: form.user, followers: form.user.followers ) broadcast(:ok, form.user) end private attr_reader :form def officialize_user timestamp = Time.current Decidim.traceability.perform_action!( "officialize", form.user, form.current_user, extra: { officialized_user_badge: form.officialized_as, officialized_user_badge_previous: form.user.officialized_as, officialized_user_at: timestamp, officialized_user_at_previous: form.user.officialized_at } ) do form.user.update!( officialized_at: timestamp, officialized_as: form.officialized_as ) end end end end end
Version data entries
19 entries across 19 versions & 1 rubygems