Class: Decidim::DemoteMembership
- Defined in:
- app/commands/decidim/demote_membership.rb
Overview
A command with all the business logic to demote an admin. This means removing their admin right and converting them to a basic member. It is the counterpart of ‘PromoteMembership`.
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(membership, user_group) ⇒ DemoteMembership
constructor
Public: Initializes the command.
Methods inherited from Command
call, #evaluate, #method_missing, #respond_to_missing?, #transaction, #with_events
Constructor Details
#initialize(membership, user_group) ⇒ DemoteMembership
Public: Initializes the command.
membership - the UserGroupMembership to be demoted.
11 12 13 14 |
# File 'app/commands/decidim/demote_membership.rb', line 11 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
#call ⇒ Object
Executes the command. Broadcasts these events:
-
:ok when everything is valid.
-
:invalid if we could not proceed.
Returns nothing.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/commands/decidim/demote_membership.rb', line 22 def call return broadcast(:invalid) if membership.blank? return broadcast(:invalid) if membership.role != "admin" return broadcast(:invalid) if membership.user_group != user_group transaction do demote_membership send_notification end broadcast(:ok) end |