2018-04-13 16:56:00 +02:00
|
|
|
module NewAdministrateur
|
|
|
|
class ProceduresController < AdministrateurController
|
2021-02-11 20:19:15 +01:00
|
|
|
before_action :retrieve_procedure, only: [:champs, :annotations, :edit, :monavis, :update_monavis, :jeton, :update_jeton, :publication, :publish, :transfert, :allow_expert_review, :invited_expert_list, :update_allow_decision_access]
|
2019-02-06 18:19:27 +01:00
|
|
|
before_action :procedure_locked?, only: [:champs, :annotations]
|
2019-01-17 15:15:46 +01:00
|
|
|
|
2020-07-28 15:15:56 +02:00
|
|
|
ITEMS_PER_PAGE = 25
|
|
|
|
|
|
|
|
def index
|
|
|
|
@procedures_publiees = paginated_published_procedures
|
|
|
|
@procedures_draft = paginated_draft_procedures
|
|
|
|
@procedures_closed = paginated_closed_procedures
|
|
|
|
@procedures_publiees_count = current_administrateur.procedures.publiees.count
|
|
|
|
@procedures_draft_count = current_administrateur.procedures.brouillons.count
|
|
|
|
@procedures_closed_count = current_administrateur.procedures.closes.count
|
|
|
|
@statut = params[:statut]
|
|
|
|
@statut.blank? ? @statut = 'publiees' : @statut = params[:statut]
|
|
|
|
end
|
|
|
|
|
|
|
|
def paginated_published_procedures
|
|
|
|
current_administrateur
|
|
|
|
.procedures
|
|
|
|
.publiees
|
|
|
|
.page(params[:page])
|
|
|
|
.per(ITEMS_PER_PAGE)
|
|
|
|
.order(published_at: :desc)
|
|
|
|
end
|
|
|
|
|
|
|
|
def paginated_draft_procedures
|
|
|
|
current_administrateur
|
|
|
|
.procedures
|
|
|
|
.brouillons
|
|
|
|
.page(params[:page])
|
|
|
|
.per(ITEMS_PER_PAGE)
|
|
|
|
.order(created_at: :desc)
|
|
|
|
end
|
|
|
|
|
|
|
|
def paginated_closed_procedures
|
|
|
|
current_administrateur
|
|
|
|
.procedures
|
|
|
|
.closes
|
|
|
|
.page(params[:page])
|
|
|
|
.per(ITEMS_PER_PAGE)
|
|
|
|
.order(created_at: :desc)
|
|
|
|
end
|
|
|
|
|
2018-04-13 16:56:00 +02:00
|
|
|
def apercu
|
|
|
|
@dossier = procedure_without_control.new_dossier
|
2018-04-13 17:29:34 +02:00
|
|
|
@tab = apercu_tab
|
2018-04-13 16:56:00 +02:00
|
|
|
end
|
|
|
|
|
2019-09-24 16:38:58 +02:00
|
|
|
def new
|
|
|
|
@procedure ||= Procedure.new(for_individual: true)
|
|
|
|
end
|
|
|
|
|
2020-07-15 10:48:11 +02:00
|
|
|
def show
|
|
|
|
@procedure = current_administrateur.procedures.find(params[:id])
|
2020-09-24 14:36:22 +02:00
|
|
|
@current_administrateur = current_administrateur
|
2020-07-17 11:10:54 +02:00
|
|
|
if @procedure.brouillon?
|
|
|
|
@procedure_lien = commencer_test_url(path: @procedure.path)
|
|
|
|
else
|
|
|
|
@procedure_lien = commencer_url(path: @procedure.path)
|
|
|
|
end
|
2020-07-15 10:48:11 +02:00
|
|
|
end
|
|
|
|
|
2019-09-24 16:38:58 +02:00
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@procedure = Procedure.new(procedure_params.merge(administrateurs: [current_administrateur]))
|
2020-08-27 19:55:10 +02:00
|
|
|
@procedure.draft_revision = @procedure.revisions.build
|
2019-09-24 16:38:58 +02:00
|
|
|
|
|
|
|
if !@procedure.save
|
|
|
|
flash.now.alert = @procedure.errors.full_messages
|
|
|
|
render 'new'
|
|
|
|
else
|
|
|
|
flash.notice = 'Démarche enregistrée.'
|
|
|
|
current_administrateur.instructeur.assign_to_procedure(@procedure)
|
|
|
|
|
2020-07-07 12:03:32 +02:00
|
|
|
redirect_to champs_admin_procedure_path(@procedure)
|
2019-09-24 16:38:58 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@procedure = current_administrateur.procedures.find(params[:id])
|
|
|
|
|
|
|
|
if !@procedure.update(procedure_params)
|
|
|
|
flash.now.alert = @procedure.errors.full_messages
|
|
|
|
render 'edit'
|
|
|
|
elsif @procedure.brouillon?
|
|
|
|
reset_procedure
|
|
|
|
flash.notice = 'Démarche modifiée. Tous les dossiers de cette démarche ont été supprimés.'
|
|
|
|
redirect_to edit_admin_procedure_path(id: @procedure.id)
|
|
|
|
else
|
|
|
|
flash.notice = 'Démarche modifiée.'
|
|
|
|
redirect_to edit_admin_procedure_path(id: @procedure.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-28 15:15:56 +02:00
|
|
|
def destroy
|
|
|
|
procedure = current_administrateur.procedures.find(params[:id])
|
|
|
|
|
|
|
|
if procedure.can_be_deleted_by_administrateur?
|
|
|
|
procedure.discard_and_keep_track!(current_administrateur)
|
|
|
|
|
|
|
|
flash.notice = 'Démarche supprimée'
|
|
|
|
redirect_to admin_procedures_draft_path
|
|
|
|
else
|
|
|
|
render json: {}, status: 403
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-24 16:38:58 +02:00
|
|
|
def monavis
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_monavis
|
|
|
|
if !@procedure.update(procedure_params)
|
|
|
|
flash.now.alert = @procedure.errors.full_messages
|
|
|
|
else
|
|
|
|
flash.notice = 'le champ MonAvis a bien été mis à jour'
|
|
|
|
end
|
|
|
|
render 'monavis'
|
|
|
|
end
|
|
|
|
|
2020-04-27 14:58:12 +02:00
|
|
|
def jeton
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_jeton
|
2020-10-19 11:33:36 +02:00
|
|
|
token = params[:procedure][:api_entreprise_token]
|
|
|
|
@procedure.api_entreprise_token = token
|
|
|
|
|
|
|
|
if @procedure.valid? &&
|
2020-08-05 18:40:47 +02:00
|
|
|
APIEntreprise::PrivilegesAdapter.new(token).valid? &&
|
2020-10-19 11:33:36 +02:00
|
|
|
@procedure.save
|
|
|
|
|
|
|
|
redirect_to jeton_admin_procedure_path(procedure_id: params[:procedure_id]),
|
|
|
|
notice: 'Le jeton a bien été mis à jour'
|
2020-04-27 14:58:12 +02:00
|
|
|
else
|
2020-10-19 11:33:36 +02:00
|
|
|
|
|
|
|
flash.now.alert = "Mise à jour impossible : le jeton n'est pas valide"
|
|
|
|
render 'jeton'
|
2020-04-27 14:58:12 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-08 12:35:44 +02:00
|
|
|
def publication
|
|
|
|
if @procedure.brouillon?
|
|
|
|
@procedure_lien = commencer_test_url(path: @procedure.path)
|
|
|
|
else
|
|
|
|
@procedure_lien = commencer_url(path: @procedure.path)
|
|
|
|
end
|
|
|
|
@procedure.path = @procedure.suggested_path(current_administrateur)
|
|
|
|
@current_administrateur = current_administrateur
|
|
|
|
end
|
|
|
|
|
|
|
|
def publish
|
|
|
|
@procedure.assign_attributes(publish_params)
|
|
|
|
|
|
|
|
if @procedure.publish_or_reopen!(current_administrateur)
|
|
|
|
redirect_to admin_procedure_path(@procedure)
|
|
|
|
flash.notice = "Démarche publiée"
|
|
|
|
else
|
|
|
|
redirect_to admin_procedure_path(@procedure)
|
|
|
|
flash.alert = @procedure.errors.full_messages
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-29 10:52:13 +02:00
|
|
|
def transfert
|
|
|
|
end
|
|
|
|
|
2020-09-30 18:22:06 +02:00
|
|
|
def allow_expert_review
|
|
|
|
@procedure.update!(allow_expert_review: !@procedure.allow_expert_review)
|
|
|
|
flash.notice = @procedure.allow_expert_review? ? "Avis externes activés" : "Avis externes désactivés"
|
|
|
|
redirect_to admin_procedure_path(@procedure)
|
|
|
|
end
|
|
|
|
|
2020-09-08 12:35:44 +02:00
|
|
|
def transfer
|
|
|
|
admin = Administrateur.by_email(params[:email_admin].downcase)
|
|
|
|
if admin.nil?
|
2020-09-29 10:52:13 +02:00
|
|
|
redirect_to admin_procedure_transfert_path(params[:procedure_id])
|
2020-09-08 12:35:44 +02:00
|
|
|
flash.alert = "Envoi vers #{params[:email_admin]} impossible : cet administrateur n'existe pas"
|
|
|
|
else
|
|
|
|
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
|
|
|
procedure.clone(admin, false)
|
|
|
|
redirect_to admin_procedure_path(params[:procedure_id])
|
|
|
|
flash.notice = "La démarche a correctement été clonée vers le nouvel administrateur."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-18 09:16:41 +01:00
|
|
|
def invited_expert_list
|
2021-02-11 19:32:48 +01:00
|
|
|
@experts_procedure = @procedure.experts_procedures.sort_by { |expert_procedure| expert_procedure.expert.email }
|
2020-12-18 09:16:41 +01:00
|
|
|
end
|
|
|
|
|
2021-02-11 20:19:15 +01:00
|
|
|
def update_allow_decision_access
|
|
|
|
@procedure
|
|
|
|
.experts_procedures
|
|
|
|
.find(params[:expert_procedure])
|
|
|
|
.update!(allow_decision_access_params)
|
|
|
|
end
|
|
|
|
|
2018-04-13 16:56:00 +02:00
|
|
|
private
|
|
|
|
|
2018-04-13 17:29:34 +02:00
|
|
|
def apercu_tab
|
|
|
|
params[:tab] || 'dossier'
|
|
|
|
end
|
|
|
|
|
2018-04-13 16:56:00 +02:00
|
|
|
def procedure_without_control
|
|
|
|
Procedure.find(params[:id])
|
|
|
|
end
|
2019-09-24 16:38:58 +02:00
|
|
|
|
|
|
|
def procedure_params
|
2020-04-27 14:58:12 +02:00
|
|
|
editable_params = [:libelle, :description, :organisation, :direction, :lien_site_web, :cadre_juridique, :deliberation, :notice, :web_hook_url, :declarative_with_state, :euro_flag, :logo, :auto_archive_on, :monavis_embed, :api_entreprise_token]
|
2019-09-24 16:38:58 +02:00
|
|
|
permited_params = if @procedure&.locked?
|
|
|
|
params.require(:procedure).permit(*editable_params)
|
|
|
|
else
|
|
|
|
params.require(:procedure).permit(*editable_params, :duree_conservation_dossiers_dans_ds, :duree_conservation_dossiers_hors_ds, :for_individual, :path)
|
|
|
|
end
|
2020-02-29 03:49:31 +01:00
|
|
|
if permited_params[:auto_archive_on].present?
|
|
|
|
permited_params[:auto_archive_on] = Date.parse(permited_params[:auto_archive_on]) + 1.day
|
|
|
|
end
|
2019-09-24 16:38:58 +02:00
|
|
|
permited_params
|
|
|
|
end
|
2020-09-08 12:35:44 +02:00
|
|
|
|
|
|
|
def publish_params
|
|
|
|
params.permit(:path, :lien_site_web)
|
|
|
|
end
|
2021-02-11 20:19:15 +01:00
|
|
|
|
|
|
|
def allow_decision_access_params
|
|
|
|
params.require(:experts_procedure).permit(:allow_decision_access)
|
|
|
|
end
|
2018-04-13 16:56:00 +02:00
|
|
|
end
|
|
|
|
end
|