2018-05-31 15:18:06 +02:00
|
|
|
module Manager
|
|
|
|
class DossiersController < Manager::ApplicationController
|
2018-07-23 13:02:25 +02:00
|
|
|
#
|
|
|
|
# Administrate overrides
|
|
|
|
#
|
|
|
|
|
|
|
|
# Override this if you have certain roles that require a subset
|
|
|
|
# this will be used to set the records shown on the `index` action.
|
|
|
|
def scoped_resource
|
|
|
|
if unfiltered_list?
|
|
|
|
# Don't display deleted dossiers in the unfiltered list…
|
|
|
|
Dossier
|
|
|
|
else
|
|
|
|
# … but allow them to be searched and displayed.
|
|
|
|
Dossier.unscope(:where)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Custom actions
|
|
|
|
#
|
|
|
|
|
2018-07-02 11:46:04 +02:00
|
|
|
def change_state_to_instruction
|
|
|
|
dossier = Dossier.find(params[:id])
|
2018-08-28 14:10:55 +02:00
|
|
|
dossier.update(state: Dossier.states.fetch(:en_instruction), processed_at: nil, motivation: nil)
|
2018-07-02 11:46:04 +02:00
|
|
|
dossier.attestation&.destroy
|
|
|
|
logger.info("Le dossier #{dossier.id} est repassé en instruction par #{current_administration.email}")
|
|
|
|
flash[:notice] = "Le dossier #{dossier.id} est repassé en instruction"
|
2019-03-25 16:04:33 +01:00
|
|
|
DossierMailer.notify_revert_to_instruction(dossier).deliver_later
|
2018-07-02 11:46:04 +02:00
|
|
|
redirect_to manager_dossier_path(dossier)
|
|
|
|
end
|
2018-07-23 13:02:25 +02:00
|
|
|
|
2019-02-13 16:13:37 +01:00
|
|
|
def hide
|
|
|
|
dossier = Dossier.find(params[:id])
|
|
|
|
deleted_dossier = dossier.hide!(current_administration)
|
|
|
|
|
|
|
|
DossierMailer.notify_deletion_to_user(deleted_dossier, dossier.user.email).deliver_later
|
|
|
|
logger.info("Le dossier #{dossier.id} est supprimé par #{current_administration.email}")
|
|
|
|
flash[:notice] = "Le dossier #{dossier.id} est supprimé"
|
|
|
|
|
|
|
|
redirect_to manager_dossier_path(dossier)
|
|
|
|
end
|
|
|
|
|
2018-07-23 13:02:25 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
def unfiltered_list?
|
|
|
|
action_name == "index" && !params[:search]
|
|
|
|
end
|
2018-05-31 15:18:06 +02:00
|
|
|
end
|
|
|
|
end
|