Sha256: b53a314238d1bbf0d3c46454734fd7fb9aaf2de54b78f4ed2117e26290a1187a
Contents?: true
Size: 1.55 KB
Versions: 19
Compression:
Stored size: 1.55 KB
Contents
# frozen_string_literal: true module Decidim module Admin # A command with all the business logic when officializing a user. class OfficializeUser < Rectify::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, recipient_ids: form.user.followers.pluck(:id) ) 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