Class: Decidim::RemoveUserRole

Inherits:
Rectify::Command
  • Object
show all
Defined in:
app/commands/decidim/remove_user_role.rb

Overview

A command to remove a role from a given User.

Instance Method Summary collapse

Constructor Details

#initialize(user, role) ⇒ RemoveUserRole

Public: Initializes the command.

form - A form object with the params.



9
10
11
12
# File 'app/commands/decidim/remove_user_role.rb', line 9

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

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
# File 'app/commands/decidim/remove_user_role.rb', line 14

def call
  return broadcast(:invalid) unless user

  user.roles.delete(role.to_s)
  user.save!

  broadcast(:ok)
end