Sha256: 0607472581468d7aa404265552edccfec8302d9e1079ece3289cceecc7e185fd

Contents?: true

Size: 1.28 KB

Versions: 31

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

module Decidim
  module Assemblies
    module Admin
      # A command with all the business logic when updated a participatory
      # process admin in the system.
      class UpdateAssemblyAdmin < Rectify::Command
        # Public: Initializes the command.
        #
        # form - A form object with the params.
        # user_role - The AssemblyUSerRole to update
        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!
          log_info = {
            resource: {
              title: user_role.user.name
            }
          }
          Decidim.traceability.update!(
            user_role,
            form.current_user,
            { role: form.role },
            log_info
          )
        end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
decidim-assemblies-0.21.0 app/commands/decidim/assemblies/admin/update_assembly_admin.rb
decidim-assemblies-0.20.1 app/commands/decidim/assemblies/admin/update_assembly_admin.rb
decidim-assemblies-0.20.0 app/commands/decidim/assemblies/admin/update_assembly_admin.rb
decidim-assemblies-0.19.1 app/commands/decidim/assemblies/admin/update_assembly_admin.rb
decidim-assemblies-0.18.1 app/commands/decidim/assemblies/admin/update_assembly_admin.rb
decidim-assemblies-0.19.0 app/commands/decidim/assemblies/admin/update_assembly_admin.rb
decidim-assemblies-0.17.2 app/commands/decidim/assemblies/admin/update_assembly_admin.rb
decidim-assemblies-0.18.0 app/commands/decidim/assemblies/admin/update_assembly_admin.rb
decidim-assemblies-0.17.1 app/commands/decidim/assemblies/admin/update_assembly_admin.rb
decidim-assemblies-0.16.1 app/commands/decidim/assemblies/admin/update_assembly_admin.rb
decidim-assemblies-0.17.0 app/commands/decidim/assemblies/admin/update_assembly_admin.rb
decidim-assemblies-0.16.0 app/commands/decidim/assemblies/admin/update_assembly_admin.rb
decidim-assemblies-0.15.2 app/commands/decidim/assemblies/admin/update_assembly_admin.rb
decidim-assemblies-0.15.1 app/commands/decidim/assemblies/admin/update_assembly_admin.rb
decidim-assemblies-0.15.0 app/commands/decidim/assemblies/admin/update_assembly_admin.rb
decidim-assemblies-0.14.4 app/commands/decidim/assemblies/admin/update_assembly_admin.rb
decidim-assemblies-0.14.3 app/commands/decidim/assemblies/admin/update_assembly_admin.rb
decidim-assemblies-0.14.2 app/commands/decidim/assemblies/admin/update_assembly_admin.rb
decidim-assemblies-0.14.1 app/commands/decidim/assemblies/admin/update_assembly_admin.rb
decidim-assemblies-0.13.1 app/commands/decidim/assemblies/admin/update_assembly_admin.rb