2021-09-07 10:37:42 +02:00
|
|
|
module Users
|
|
|
|
class TransfersController < UserController
|
|
|
|
def create
|
|
|
|
transfer = DossierTransfer.new(transfer_params)
|
|
|
|
transfer.save!
|
|
|
|
redirect_to dossiers_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
DossierTransfer.accept(params[:id], current_user)
|
|
|
|
redirect_to dossiers_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2021-10-01 12:10:10 +02:00
|
|
|
transfer = DossierTransfer
|
|
|
|
.joins(:dossiers)
|
|
|
|
.find_by!(id: params[:id], dossiers: { user: current_user })
|
|
|
|
|
2021-10-21 12:19:40 +02:00
|
|
|
transfer.destroy_and_nullify
|
2021-09-07 10:37:42 +02:00
|
|
|
redirect_to dossiers_path
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def transfer_params
|
|
|
|
transfer_params = params.require(:dossier_transfer).permit(:email, :dossiers)
|
|
|
|
if transfer_params[:dossiers].present?
|
|
|
|
transfer_params.merge(dossiers: [current_user.dossiers.find(transfer_params[:dossiers])])
|
|
|
|
else
|
|
|
|
transfer_params.merge(dossiers: current_user.dossiers)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|