Class: Decidim::PromoteMembership

Inherits:
Command
  • Object
show all
Defined in:
decidim-core/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

Methods inherited from Command

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

Constructor Details

#initialize(membership, user_group) ⇒ PromoteMembership

Public: Initializes the command.

membership - the UserGroupMembership to be promoted.



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

def initialize(membership, user_group)
  @membership = membership
  @user_group = user_group
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
31
# File 'decidim-core/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