Sha256: cd28a0e3b3908e1910f94e034f564c59669a664daa992a556c403873b3323417

Contents?: true

Size: 1.18 KB

Versions: 8

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A command with all the business logic when updating a scope.
    class UpdateScope < Decidim::Command
      # Public: Initializes the command.
      #
      # scope - The Scope to update
      # form - A form object with the params.
      def initialize(scope, form)
        @scope = scope
        @form = form
      end

      # 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.
      def call
        return broadcast(:invalid) if form.invalid?

        update_scope
        broadcast(:ok)
      end

      private

      attr_reader :form

      def update_scope
        Decidim.traceability.update!(
          @scope,
          form.current_user,
          attributes,
          extra: {
            parent_name: @scope.parent.try(:name),
            scope_type_name: form.scope_type.try(:name)
          }
        )
      end

      def attributes
        {
          name: form.name,
          code: form.code,
          scope_type: form.scope_type
        }
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
decidim-admin-0.28.5 app/commands/decidim/admin/update_scope.rb
decidim-admin-0.28.4 app/commands/decidim/admin/update_scope.rb
decidim-admin-0.28.3 app/commands/decidim/admin/update_scope.rb
decidim-admin-0.28.2 app/commands/decidim/admin/update_scope.rb
decidim-admin-0.28.1 app/commands/decidim/admin/update_scope.rb
decidim-admin-0.28.0 app/commands/decidim/admin/update_scope.rb
decidim-admin-0.28.0.rc5 app/commands/decidim/admin/update_scope.rb
decidim-admin-0.28.0.rc4 app/commands/decidim/admin/update_scope.rb