Class: Decidim::DecidimAwesome::Admin::CreateScopedAdmin
- Includes:
- NeedsConstraintHelpers
- Defined in:
- app/commands/decidim/decidim_awesome/admin/create_scoped_admin.rb
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(organization) ⇒ CreateScopedAdmin
constructor
Public: Initializes the command.
Constructor Details
#initialize(organization) ⇒ CreateScopedAdmin
Public: Initializes the command.
11 12 13 14 |
# File 'app/commands/decidim/decidim_awesome/admin/create_scoped_admin.rb', line 11 def initialize(organization) @organization = organization @ident = rand(36**8).to_s(36) end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:ok when everything is valid.
-
:invalid if we couldn’t proceed.
Returns nothing.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/commands/decidim/decidim_awesome/admin/create_scoped_admin.rb', line 22 def call admins = AwesomeConfig.find_or_initialize_by(var: :scoped_admins, organization: @organization) admins.value = {} unless admins.value.is_a? Hash # TODO: prevent (unlikely) colisions with exisiting values admins.value[@ident] = [] admins.save! create_constraint_never(:scoped_admin) broadcast(:ok, @ident) rescue StandardError => e broadcast(:invalid, e.) end |