Class: Decidim::Debates::Admin::DebatesController

Inherits:
ApplicationController show all
Defined in:
decidim-debates/app/controllers/decidim/debates/admin/debates_controller.rb

Overview

This controller allows an admin to manage debates from a Participatory Space

Instance Method Summary collapse

Methods inherited from Admin::Components::BaseController

#current_component, #current_participatory_space, #parent_path, #permission_class_chain, #permission_scope, #permissions_context, #skip_manage_component_permission

Methods included from RegistersPermissions

register_permissions

Methods inherited from Admin::ApplicationController

#permission_class_chain, #permission_scope, #user_has_no_permission_path, #user_not_authorized_path

Methods included from HttpCachingDisabler

#disable_http_caching

Methods included from NeedsSnippets

#snippets

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#createObject


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'decidim-debates/app/controllers/decidim/debates/admin/debates_controller.rb', line 22

def create
  enforce_permission_to :create, :debate

  @form = form(Decidim::Debates::Admin::DebateForm).from_params(params, current_component: current_component)

  CreateDebate.call(@form) do
    on(:ok) do
      flash[:notice] = I18n.t("debates.create.success", scope: "decidim.debates.admin")
      redirect_to debates_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("debates.create.invalid", scope: "decidim.debates.admin")
      render action: "new"
    end
  end
end

#destroyObject


64
65
66
67
68
69
70
71
72
# File 'decidim-debates/app/controllers/decidim/debates/admin/debates_controller.rb', line 64

def destroy
  enforce_permission_to :delete, :debate, debate: debate

  debate.destroy!

  flash[:notice] = I18n.t("debates.destroy.success", scope: "decidim.debates.admin")

  redirect_to debates_path
end

#editObject


40
41
42
43
44
# File 'decidim-debates/app/controllers/decidim/debates/admin/debates_controller.rb', line 40

def edit
  enforce_permission_to :update, :debate, debate: debate

  @form = form(Decidim::Debates::Admin::DebateForm).from_model(debate)
end

#indexObject


12
13
14
# File 'decidim-debates/app/controllers/decidim/debates/admin/debates_controller.rb', line 12

def index
  enforce_permission_to :read, :debate
end

#newObject


16
17
18
19
20
# File 'decidim-debates/app/controllers/decidim/debates/admin/debates_controller.rb', line 16

def new
  enforce_permission_to :create, :debate

  @form = form(Decidim::Debates::Admin::DebateForm).instance
end

#updateObject


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'decidim-debates/app/controllers/decidim/debates/admin/debates_controller.rb', line 46

def update
  enforce_permission_to :update, :debate, debate: debate

  @form = form(Decidim::Debates::Admin::DebateForm).from_params(params, current_component: current_component)

  UpdateDebate.call(@form, debate) do
    on(:ok) do
      flash[:notice] = I18n.t("debates.update.success", scope: "decidim.debates.admin")
      redirect_to debates_path
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("debates.update.invalid", scope: "decidim.debates.admin")
      render action: "edit"
    end
  end
end