Class: Decidim::RejectUserGroupJoinRequest

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

Overview

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

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

#initialize(membership) ⇒ RejectUserGroupJoinRequest

Public: Initializes the command.

membership - the UserGroupMembership to be accepted.



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

def initialize(membership)
  @membership = membership
end

Dynamic Method Handling

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

Instance Method Details

#callObject

Executes the command. Broadcasts these events:

  • :ok when everything is valid.

  • :invalid if we could not proceed.

Returns nothing.



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

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

  transaction do
    send_notification
    reject_membership
  end

  broadcast(:ok, @user_group)
end