app/controllers/decidim/debates/admin/debates_controller.rb in decidim-debates-0.11.2 vs app/controllers/decidim/debates/admin/debates_controller.rb in decidim-debates-0.12.0.pre
- old
+ new
@@ -2,18 +2,26 @@
module Decidim
module Debates
module Admin
# This controller allows an admin to manage debates from a Participatory Space
- class DebatesController < Admin::ApplicationController
+ class DebatesController < Decidim::Debates::Admin::ApplicationController
helper_method :debates
+ def index
+ enforce_permission_to :read, :debate
+ end
+
def new
+ enforce_permission_to :create, :debate
+
@form = form(Decidim::Debates::Admin::DebateForm).instance
end
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")
@@ -26,16 +34,18 @@
end
end
end
def edit
- authorize! :edit, debate
+ enforce_permission_to :update, :debate, debate: debate
+
@form = form(DebateForm).from_model(debate)
end
def update
- authorize! :edit, debate
+ enforce_permission_to :update, :debate, debate: debate
+
@form = form(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")
@@ -48,10 +58,11 @@
end
end
end
def destroy
- authorize! :destroy, debate
+ enforce_permission_to :delete, :debate, debate: debate
+
debate.destroy!
flash[:notice] = I18n.t("debates.destroy.success", scope: "decidim.debates.admin")
redirect_to debates_path