Sha256: 52fda2e096cee7b21c780426bf1d6b1ce17f16f070823695f020dd91b10174ad
Contents?: true
Size: 1.34 KB
Versions: 23
Compression:
Stored size: 1.34 KB
Contents
# frozen_string_literal: true module Decidim module Admin # A command with all the business logic to create a new managed user in the # admin panel. class CreateManagedUser < Rectify::Command # Public: Initializes the command. # # form - A form object with the params. def initialize(form) @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? transaction do create_managed_user raise ActiveRecord::Rollback unless authorized_user? end broadcast(:ok) end private attr_reader :form, :user def create_managed_user @user = Decidim::User.create!( name: form.name, organization: form.current_organization, admin: false, managed: true, tos_agreement: true ) end def authorized_user? form.authorization.user = @user AuthorizeUser.call(form.authorization) do on(:ok) do return true end on(:invalid) do return false end end end end end end
Version data entries
23 entries across 23 versions & 2 rubygems