Class: Decidim::Votings::Admin::UnpublishVoting

Inherits:
Command
  • Object
show all
Defined in:
app/commands/decidim/votings/admin/unpublish_voting.rb

Overview

This command gets called when a voting is unpublished from the admin panel.

Instance Method Summary collapse

Constructor Details

#initialize(voting, current_user) ⇒ UnpublishVoting

Public: Initializes the command.

voting - The voting to unpublish. current_user - the user performing the action



12
13
14
15
# File 'app/commands/decidim/votings/admin/unpublish_voting.rb', line 12

def initialize(voting, current_user)
  @voting = voting
  @current_user = current_user
end

Instance Method Details

#callObject

Public: Unpublishes the Voting.

Broadcasts :ok if unpublished, :invalid otherwise.



20
21
22
23
24
25
26
# File 'app/commands/decidim/votings/admin/unpublish_voting.rb', line 20

def call
  return broadcast(:invalid) if voting.nil? || !voting.published?

  unpublish_voting

  broadcast(:ok, voting)
end