demarches-normaliennes/app/controllers/instructeurs/batch_operations_controller.rb
2023-02-03 15:13:06 +01:00

32 lines
1.1 KiB
Ruby
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

module Instructeurs
class BatchOperationsController < ApplicationController
before_action :set_procedure
before_action :ensure_ownership!
def create
batch = BatchOperation.safe_create!(batch_operation_params)
flash[:alert] = "Le traitement de masse n'a pas été lancé. Vérifiez que l'action demandée est possible pour les dossiers sélectionnés" if batch.blank?
redirect_back(fallback_location: instructeur_procedure_url(@procedure.id))
end
private
def batch_operation_params
params.require(:batch_operation)
.permit(:operation, :motivation, :justificatif_motivation, dossier_ids: [])
.merge(dossier_ids: params['batch_operation']['dossier_ids'].join(',').split(',').uniq)
.merge(instructeur: current_instructeur)
end
def set_procedure
@procedure = Procedure.find(params[:procedure_id])
end
def ensure_ownership!
if !current_instructeur.procedures.exists?(@procedure.id)
flash[:alert] = "Vous navez pas accès à cette démarche"
redirect_to root_path
end
end
end
end