poc(batch_operations_controller): implement simple [not yet with procedure_presentation] action to create a batch operation
This commit is contained in:
parent
b11dbafc59
commit
7df86c50fb
8 changed files with 99 additions and 8 deletions
34
app/controllers/instructeurs/batch_operations_controller.rb
Normal file
34
app/controllers/instructeurs/batch_operations_controller.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
module Instructeurs
|
||||
class BatchOperationsController < ApplicationController
|
||||
before_action :set_procedure
|
||||
before_action :ensure_ownership!
|
||||
|
||||
def create
|
||||
ActiveRecord::Base.transaction do
|
||||
batch_operation = BatchOperation.create!(batch_operation_params.merge(instructeur: current_instructeur))
|
||||
BatchOperationEnqueueAllJob.perform_later(batch_operation)
|
||||
end
|
||||
redirect_back(fallback_location: instructeur_procedure_url(@procedure.id))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def batch_operation_params
|
||||
params.require(:batch_operation)
|
||||
.permit(:operation, dossier_ids: []).tap do |params|
|
||||
# TODO: filter dossiers_ids out of instructeurs.dossiers.ids
|
||||
end
|
||||
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
|
Loading…
Add table
Add a link
Reference in a new issue