Class: Decidim::Admin::RemoveAdmin

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

Overview

A command to remove the admin privilege to an user.

Instance Method Summary collapse

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 'app/commands/decidim/admin/remove_admin.rb', line 11

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

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File '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