Class: Decidim::Problems::Admin::DestroyProblem

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

Overview

This command deals with destroying a Problem from the admin panel.

Instance Method Summary collapse

Constructor Details

#initialize(problem, current_user) ⇒ DestroyProblem

Public: Initializes the command.

page - The Problem to be destroyed.



11
12
13
14
15
# File 'app/commands/decidim/problems/admin/destroy_problem.rb', line 11

def initialize(problem, current_user)
  super()
  @problem = problem
  @current_user = current_user
end

Instance Method Details

#callObject

Public: Executes the command.

Broadcasts :ok if it got destroyed Broadcasts :has_solutions if not destroyed ‘cause dependent Broadcasts :invalid if it not destroyed



22
23
24
25
26
27
28
29
# File 'app/commands/decidim/problems/admin/destroy_problem.rb', line 22

def call
  destroy_problem
  broadcast(:ok)
rescue ActiveRecord::DeleteRestrictionError
  broadcast(:has_solutions)
rescue ActiveRecord::RecordNotDestroyed
  broadcast(:invalid)
end