Class: Decidim::AcceptUserGroupJoinRequest

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

Overview

A command with all the business logic to accept a join request to a user group.

Instance Method Summary collapse

Constructor Details

#initialize(membership) ⇒ AcceptUserGroupJoinRequest

Public: Initializes the command.

membership - the UserGroupMembership to be accepted.


10
11
12
# File 'decidim-core/app/commands/decidim/accept_user_group_join_request.rb', line 10

def initialize(membership)
  @membership = membership
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
# File 'decidim-core/app/commands/decidim/accept_user_group_join_request.rb', line 20

def call
  return broadcast(:invalid) if membership.role.to_s != "requested"

  transaction do
    accept_membership
    send_notification
  end

  broadcast(:ok, @user_group)
end