Class: Decidim::System::CreateOrganization
- Inherits:
-
Command
- Object
- Command
- Decidim::System::CreateOrganization
- Defined in:
- app/commands/decidim/system/create_organization.rb
Overview
A command with all the business logic when creating a new organization in the system. It creates the organization and invites the admin to the system.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(form) ⇒ CreateOrganization
constructor
Public: Initializes the command.
Constructor Details
#initialize(form) ⇒ CreateOrganization
Public: Initializes the command.
form - A form object with the params.
16 17 18 |
# File 'app/commands/decidim/system/create_organization.rb', line 16 def initialize(form) @form = form end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:ok when everything is valid.
-
:invalid if the form was not valid and we could not proceed.
Returns nothing.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/commands/decidim/system/create_organization.rb', line 26 def call return broadcast(:invalid) if form.invalid? @organization = nil invite_form = nil transaction do @organization = create_organization CreateDefaultPages.call(@organization) CreateDefaultHelpPages.call(@organization) CreateDefaultContentBlocks.call(@organization) invite_form = invite_user_form(@organization) raise InvitationFailedError if invite_form.invalid? end Decidim::InviteUser.call(invite_form) if @organization && invite_form broadcast(:ok) rescue InvitationFailedError broadcast(:invalid_invitation) rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique broadcast(:invalid) end |