2021-09-07 10:37:42 +02:00
|
|
|
module Users
|
|
|
|
class TransfersController < UserController
|
|
|
|
def create
|
|
|
|
transfer = DossierTransfer.new(transfer_params)
|
2022-08-02 15:20:33 +02:00
|
|
|
|
|
|
|
if transfer.valid?
|
|
|
|
transfer.save!
|
2022-11-24 19:17:04 +01:00
|
|
|
flash.notice = t("users.dossiers.transferer.notice_sent")
|
2022-08-02 15:20:33 +02:00
|
|
|
redirect_to dossiers_path
|
|
|
|
else
|
|
|
|
flash.alert = transfer.errors.full_messages
|
|
|
|
redirect_to transferer_dossier_path(transfer_params[:dossiers].first)
|
|
|
|
end
|
2021-09-07 10:37:42 +02:00
|
|
|
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
|
2022-08-02 15:20:33 +02:00
|
|
|
transfer_params = params.require(:dossier_transfer).permit(:email, :dossier)
|
|
|
|
|
|
|
|
dossier_id = transfer_params.delete(:dossier)
|
|
|
|
dossiers = if dossier_id.present?
|
|
|
|
[current_user.dossiers.find(dossier_id)]
|
2021-09-07 10:37:42 +02:00
|
|
|
else
|
2022-08-02 15:20:33 +02:00
|
|
|
current_user.dossiers
|
2021-09-07 10:37:42 +02:00
|
|
|
end
|
2022-08-02 15:20:33 +02:00
|
|
|
|
|
|
|
transfer_params.merge(dossiers: dossiers)
|
2021-09-07 10:37:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|