Sha256: 50bf8a6aba072088ad01666ece1a77c780c15661994f72f2429ed5690f392f9f

Contents?: true

Size: 1.35 KB

Versions: 31

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module Decidim
  module ParticipatoryProcesses
    module Admin
      # A command with all the business logic when updated a participatory
      # process admin in the system.
      class UpdateParticipatoryProcessAdmin < Rectify::Command
        # Public: Initializes the command.
        #
        # form - A form object with the params.
        # participatory_process - The ParticipatoryProcess that will hold the
        #   user role
        def initialize(form, user_role)
          @form = form
          @user_role = user_role
        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?
          return broadcast(:invalid) unless user_role

          update_role!
          broadcast(:ok)
        end

        private

        attr_reader :form, :user_role

        def update_role!
          extra_info = {
            resource: {
              title: user_role.user.name
            }
          }

          Decidim.traceability.update!(
            user_role,
            form.current_user,
            { role: form.role },
            extra_info
          )
        end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
decidim-participatory_processes-0.12.2 app/commands/decidim/participatory_processes/admin/update_participatory_process_admin.rb
decidim-participatory_processes-0.13.0 app/commands/decidim/participatory_processes/admin/update_participatory_process_admin.rb
decidim-participatory_processes-0.12.1 app/commands/decidim/participatory_processes/admin/update_participatory_process_admin.rb
decidim-participatory_processes-0.13.0.pre1 app/commands/decidim/participatory_processes/admin/update_participatory_process_admin.rb
decidim-participatory_processes-0.12.0 app/commands/decidim/participatory_processes/admin/update_participatory_process_admin.rb
decidim-participatory_processes-0.11.2 app/commands/decidim/participatory_processes/admin/update_participatory_process_admin.rb
decidim-participatory_processes-0.12.0.pre app/commands/decidim/participatory_processes/admin/update_participatory_process_admin.rb
decidim-participatory_processes-0.11.1 app/commands/decidim/participatory_processes/admin/update_participatory_process_admin.rb
decidim-participatory_processes-0.11.0.pre1 app/commands/decidim/participatory_processes/admin/update_participatory_process_admin.rb
decidim-participatory_processes-0.10.1 app/commands/decidim/participatory_processes/admin/update_participatory_process_admin.rb
decidim-participatory_processes-0.10.0 app/commands/decidim/participatory_processes/admin/update_participatory_process_admin.rb