Class: Decidim::DemoteMembership

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

Overview

A command with all the business logic to demote an admin. This means removing their admin righta dn converting them to a basic member. It's the coutnerpart of `PromoteMembership`.

Instance Method Summary collapse

Constructor Details

#initialize(membership, user_group) ⇒ DemoteMembership

Public: Initializes the command.

membership - the UserGroupMembership to be demoted.


11
12
13
14
# File 'decidim-core/app/commands/decidim/demote_membership.rb', line 11

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.


22
23
24
25
26
27
28
29
30
31
32
33
# File 'decidim-core/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