Class: Decidim::Admin::RemoveAdmin

Inherits:
Command
  • Object
show all
Defined in:
decidim-admin/app/commands/decidim/admin/remove_admin.rb

Overview

A command to remove the admin privilege to an user.

Instance Method Summary collapse

Methods inherited from Command

call, #evaluate, #method_missing, #respond_to_missing?, #transaction, #with_events

Constructor Details

#initialize(user, current_user) ⇒ RemoveAdmin

Public: Initializes the command.

user - the user that will no longer be an admin current_user - the user that performs the action



11
12
13
14
# File 'decidim-admin/app/commands/decidim/admin/remove_admin.rb', line 11

def initialize(user, current_user)
  @user = user
  @current_user = current_user
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Decidim::Command

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'decidim-admin/app/commands/decidim/admin/remove_admin.rb', line 16

def call
  return broadcast(:invalid) unless user

  Decidim.traceability.perform_action!(
    "remove_from_admin",
    user,
    current_user,
    extra: {
      invited_user_role: user_role
    }
  ) do
    user.update!(admin: false, roles: [])
  end

  broadcast(:ok)
end