Class: Decidim::RemoveUserFromGroup

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

Overview

A command with all the business logic to remove a user from a group.

Instance Method Summary collapse

Constructor Details

#initialize(membership, user_group) ⇒ RemoveUserFromGroup

Public: Initializes the command.

membership - the UserGroupMembership to be accepted.



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

def initialize(membership, user_group)
  @membership = membership
  @user_group = user_group
end

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if we couldn’t proceed.

Returns nothing.



20
21
22
23
24
25
26
27
28
29
30
# File 'app/commands/decidim/remove_user_from_group.rb', line 20

def call
  return broadcast(:invalid) if membership.blank?
  return broadcast(:invalid) if membership.user_group != user_group

  transaction do
    remove_membership
    send_notification
  end

  broadcast(:ok)
end