Sha256: 3ef6d4b194f5488d55d211e9cab1bd706e9310bec32f0ff27aeedd6fb54210af

Contents?: true

Size: 1.1 KB

Versions: 12

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A command to invite an admin.
    class InviteAdmin < Decidim::Command
      # Public: Initializes the command.
      #
      # form - A form object with the params.
      def initialize(form)
        @form = form
      end

      def call
        return broadcast(:invalid) if form.invalid?

        transaction do
          invite_user
          log_action
        end

        broadcast(:ok)
      end

      private

      attr_reader :user, :form

      def invite_user
        InviteUser.call(form) do
          on(:ok) do |user|
            save_user(user)
          end
        end
      end

      # Ugly fix to get the user from the block inside the
      # `InviteUser#call` method. I'm not proud of this.
      def save_user(user)
        @user = user
      end

      def log_action
        Decidim.traceability.perform_action!(
          "invite",
          user,
          form.current_user,
          extra: {
            invited_user_role: form.role,
            invited_user_id: user.id
          }
        )
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-admin-0.27.9 app/commands/decidim/admin/invite_admin.rb
decidim-admin-0.27.8 app/commands/decidim/admin/invite_admin.rb
decidim-admin-0.27.7 app/commands/decidim/admin/invite_admin.rb
decidim-admin-0.27.6 app/commands/decidim/admin/invite_admin.rb
decidim-admin-0.27.5 app/commands/decidim/admin/invite_admin.rb
decidim-admin-0.27.4 app/commands/decidim/admin/invite_admin.rb
decidim-admin-0.27.3 app/commands/decidim/admin/invite_admin.rb
decidim-admin-0.27.2 app/commands/decidim/admin/invite_admin.rb
decidim-admin-0.27.1 app/commands/decidim/admin/invite_admin.rb
decidim-admin-0.27.0 app/commands/decidim/admin/invite_admin.rb
decidim-admin-0.27.0.rc2 app/commands/decidim/admin/invite_admin.rb
decidim-admin-0.27.0.rc1 app/commands/decidim/admin/invite_admin.rb