Sha256: 2b3455d583542d8f31565ff2e3bda79f80e2f77571cd8bf8bdec7f791bb7f970

Contents?: true

Size: 1.08 KB

Versions: 13

Compression:

Stored size: 1.08 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:)

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

        def update
          enforce_permission_to(:close, :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

13 entries across 13 versions & 1 rubygems

Version Path
decidim-debates-0.29.1 app/controllers/decidim/debates/admin/debate_closes_controller.rb
decidim-debates-0.28.4 app/controllers/decidim/debates/admin/debate_closes_controller.rb
decidim-debates-0.29.0 app/controllers/decidim/debates/admin/debate_closes_controller.rb
decidim-debates-0.28.3 app/controllers/decidim/debates/admin/debate_closes_controller.rb
decidim-debates-0.29.0.rc4 app/controllers/decidim/debates/admin/debate_closes_controller.rb
decidim-debates-0.29.0.rc3 app/controllers/decidim/debates/admin/debate_closes_controller.rb
decidim-debates-0.29.0.rc2 app/controllers/decidim/debates/admin/debate_closes_controller.rb
decidim-debates-0.29.0.rc1 app/controllers/decidim/debates/admin/debate_closes_controller.rb
decidim-debates-0.28.2 app/controllers/decidim/debates/admin/debate_closes_controller.rb
decidim-debates-0.28.1 app/controllers/decidim/debates/admin/debate_closes_controller.rb
decidim-debates-0.28.0 app/controllers/decidim/debates/admin/debate_closes_controller.rb
decidim-debates-0.28.0.rc5 app/controllers/decidim/debates/admin/debate_closes_controller.rb
decidim-debates-0.28.0.rc4 app/controllers/decidim/debates/admin/debate_closes_controller.rb