Sha256: f5d61e8fb4b30de90ebf04c39238b1c636d7c2ea6e36f8cc23b890c46211d4bf

Contents?: true

Size: 1.03 KB

Versions: 22

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Decidim
  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!
        user_role.update_attributes!(role: form.role)
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
decidim-admin-0.5.1 app/commands/decidim/admin/update_participatory_process_admin.rb
decidim-0.5.1 decidim-admin/app/commands/decidim/admin/update_participatory_process_admin.rb
decidim-admin-0.5.0 app/commands/decidim/admin/update_participatory_process_admin.rb
decidim-0.5.0 decidim-admin/app/commands/decidim/admin/update_participatory_process_admin.rb
decidim-admin-0.4.4 app/commands/decidim/admin/update_participatory_process_admin.rb
decidim-0.4.4 decidim-admin/app/commands/decidim/admin/update_participatory_process_admin.rb
decidim-admin-0.4.3 app/commands/decidim/admin/update_participatory_process_admin.rb
decidim-admin-0.4.2 app/commands/decidim/admin/update_participatory_process_admin.rb
decidim-admin-0.4.1 app/commands/decidim/admin/update_participatory_process_admin.rb
decidim-0.4.3 decidim-admin/app/commands/decidim/admin/update_participatory_process_admin.rb
decidim-0.4.2 decidim-admin/app/commands/decidim/admin/update_participatory_process_admin.rb
decidim-0.4.1 decidim-admin/app/commands/decidim/admin/update_participatory_process_admin.rb
decidim-admin-0.4.0 app/commands/decidim/admin/update_participatory_process_admin.rb
decidim-0.4.0 decidim-admin/app/commands/decidim/admin/update_participatory_process_admin.rb
decidim-admin-0.3.2 app/commands/decidim/admin/update_participatory_process_admin.rb
decidim-0.3.2 decidim-admin/app/commands/decidim/admin/update_participatory_process_admin.rb
decidim-admin-0.3.1 app/commands/decidim/admin/update_participatory_process_admin.rb
decidim-0.3.1 decidim-admin/app/commands/decidim/admin/update_participatory_process_admin.rb
decidim-admin-0.3.0 app/commands/decidim/admin/update_participatory_process_admin.rb
decidim-0.3.0 decidim-admin/app/commands/decidim/admin/update_participatory_process_admin.rb