2022-11-19 06:03:59 +01:00
|
|
|
|
module Instructeurs
|
|
|
|
|
class BatchOperationsController < ApplicationController
|
|
|
|
|
before_action :set_procedure
|
|
|
|
|
before_action :ensure_ownership!
|
|
|
|
|
|
|
|
|
|
def create
|
2022-12-12 10:02:33 +01:00
|
|
|
|
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?
|
2022-11-19 06:03:59 +01:00
|
|
|
|
redirect_back(fallback_location: instructeur_procedure_url(@procedure.id))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def batch_operation_params
|
|
|
|
|
params.require(:batch_operation)
|
2022-12-19 15:03:39 +01:00
|
|
|
|
.permit(:operation, :motivation, :justificatif_motivation, dossier_ids: [])
|
2022-12-01 10:51:10 +01:00
|
|
|
|
.merge(instructeur: current_instructeur)
|
2022-11-19 06:03:59 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def set_procedure
|
|
|
|
|
@procedure = Procedure.find(params[:procedure_id])
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def ensure_ownership!
|
|
|
|
|
if !current_instructeur.procedures.exists?(@procedure.id)
|
|
|
|
|
flash[:alert] = "Vous n’avez pas accès à cette démarche"
|
|
|
|
|
redirect_to root_path
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|