Sha256: 8f4fb2d5ac7bfb36af78b391e073cf30be3454d9f1ab5fe37374d76363972842

Contents?: true

Size: 1.28 KB

Versions: 65

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A command with all the business logic when creating a static scope.
    class CreateScope < Rectify::Command
      # Public: Initializes the command.
      #
      # form - A form object with the params.
      # parent_scope - A parent scope for the scope to be created
      def initialize(form, parent_scope = nil)
        @form = form
        @parent_scope = parent_scope
      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?

        create_scope
        broadcast(:ok)
      end

      private

      attr_reader :form

      def create_scope
        Decidim.traceability.create!(
          Scope,
          form.current_user,
          {
            name: form.name,
            organization: form.organization,
            code: form.code,
            scope_type: form.scope_type,
            parent: @parent_scope
          },
          extra: {
            parent_name: @parent_scope.try(:name),
            scope_type_name: form.scope_type.try(:name)
          }
        )
      end
    end
  end
end

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
decidim-admin-0.26.10 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.26.9 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.26.8 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.26.7 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.26.5 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.26.4 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.26.3 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.26.2 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.26.1 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.26.0 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.26.0.rc2 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.26.0.rc1 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.25.2 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.25.1 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.25.0 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.25.0.rc4 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.25.0.rc3 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.25.0.rc2 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.25.0.rc1 app/commands/decidim/admin/create_scope.rb
decidim-admin-0.24.3 app/commands/decidim/admin/create_scope.rb