Class: Decidim::PromoteMembership

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

Overview

A command with all the business logic to promote a user to group admin.

Instance Method Summary collapse

Constructor Details

#initialize(membership, user_group) ⇒ PromoteMembership

Public: Initializes the command.

membership - the UserGroupMembership to be promoted.



9
10
11
12
# File 'app/commands/decidim/promote_membership.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
31
# File 'app/commands/decidim/promote_membership.rb', line 20

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

  transaction do
    promote_membership
    send_notification
  end

  broadcast(:ok)
end