Sha256: 48e95beb30497e62e585925e0f5cc9b06ab83181a61965c0d05893d794da3905

Contents?: true

Size: 1.02 KB

Versions: 8

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module Decidim
  module DecidimAwesome
    module Admin
      class CreateScopedAdmin < Command
        include NeedsConstraintHelpers

        # Public: Initializes the command.
        #
        def initialize(organization)
          @organization = organization
          @ident = rand(36**8).to_s(36)
        end

        # Executes the command. Broadcasts these events:
        #
        # - :ok when everything is valid.
        # - :invalid if we couldn't proceed.
        #
        # Returns nothing.
        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.message)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
decidim-decidim_awesome-0.10.3 app/commands/decidim/decidim_awesome/admin/create_scoped_admin.rb
decidim-decidim_awesome-0.11.2 app/commands/decidim/decidim_awesome/admin/create_scoped_admin.rb
decidim-decidim_awesome-0.11.1 app/commands/decidim/decidim_awesome/admin/create_scoped_admin.rb
decidim-decidim_awesome-0.10.2 app/commands/decidim/decidim_awesome/admin/create_scoped_admin.rb
decidim-decidim_awesome-0.10.1 app/commands/decidim/decidim_awesome/admin/create_scoped_admin.rb
decidim-decidim_awesome-0.10.0 app/commands/decidim/decidim_awesome/admin/create_scoped_admin.rb
decidim-decidim_awesome-0.9.3 app/commands/decidim/decidim_awesome/admin/create_scoped_admin.rb
decidim-decidim_awesome-0.9.1 app/commands/decidim/decidim_awesome/admin/create_scoped_admin.rb