Sha256: 4929430ddf991976bab74c9e9ef254443c1f93be5064227d82bce2df25757297

Contents?: true

Size: 1.09 KB

Versions: 12

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module Decidim
  module Debates
    module Admin
      # This controller allows an admin to close debates
      class DebateClosesController < Admin::ApplicationController
        helper_method :debate

        def edit
          enforce_permission_to :close, :debate, debate: debate

          @form = form(Admin::CloseDebateForm).from_model(debate)
        end

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

          @form = form(Admin::CloseDebateForm).from_params(params)

          CloseDebate.call(@form) do
            on(:ok) do |_debate|
              flash[:notice] = I18n.t("debates.close.success", scope: "decidim.debates")
              redirect_to debates_path
            end

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

        private

        def debate
          @debate ||= Debate.where(component: current_component).find(params[:id])
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-debates-0.27.9 app/controllers/decidim/debates/admin/debate_closes_controller.rb
decidim-debates-0.27.8 app/controllers/decidim/debates/admin/debate_closes_controller.rb
decidim-debates-0.27.7 app/controllers/decidim/debates/admin/debate_closes_controller.rb
decidim-debates-0.27.6 app/controllers/decidim/debates/admin/debate_closes_controller.rb
decidim-debates-0.27.5 app/controllers/decidim/debates/admin/debate_closes_controller.rb
decidim-debates-0.27.4 app/controllers/decidim/debates/admin/debate_closes_controller.rb
decidim-debates-0.27.3 app/controllers/decidim/debates/admin/debate_closes_controller.rb
decidim-debates-0.27.2 app/controllers/decidim/debates/admin/debate_closes_controller.rb
decidim-debates-0.27.1 app/controllers/decidim/debates/admin/debate_closes_controller.rb
decidim-debates-0.27.0 app/controllers/decidim/debates/admin/debate_closes_controller.rb
decidim-debates-0.27.0.rc2 app/controllers/decidim/debates/admin/debate_closes_controller.rb
decidim-debates-0.27.0.rc1 app/controllers/decidim/debates/admin/debate_closes_controller.rb