2015-11-16 16:16:08 +01:00
|
|
|
class Admin::ProceduresController < AdminController
|
2016-01-07 15:29:29 +01:00
|
|
|
include SmartListing::Helper::ControllerExtensions
|
|
|
|
helper SmartListing::Helper
|
2015-10-26 15:54:20 +01:00
|
|
|
|
2019-07-16 17:24:31 +02:00
|
|
|
before_action :retrieve_procedure, only: [:show, :edit, :delete_logo, :delete_deliberation, :delete_notice, :monavis, :update_monavis]
|
2015-12-21 12:02:53 +01:00
|
|
|
|
2015-10-26 15:54:20 +01:00
|
|
|
def index
|
2018-12-28 18:24:39 +01:00
|
|
|
if current_administrateur.procedures.count != 0
|
|
|
|
@procedures = smart_listing_create :procedures,
|
|
|
|
current_administrateur.procedures.publiees.order(published_at: :desc),
|
|
|
|
partial: "admin/procedures/list",
|
|
|
|
array: true
|
2016-01-07 15:29:29 +01:00
|
|
|
|
2018-12-28 18:24:39 +01:00
|
|
|
active_class
|
|
|
|
else
|
|
|
|
redirect_to new_from_existing_admin_procedures_path
|
|
|
|
end
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
|
2015-11-27 16:23:02 +01:00
|
|
|
def archived
|
2016-01-07 15:29:29 +01:00
|
|
|
@procedures = smart_listing_create :procedures,
|
2017-07-17 16:36:32 +02:00
|
|
|
current_administrateur.procedures.archivees.order(published_at: :desc),
|
2017-06-12 13:49:51 +02:00
|
|
|
partial: "admin/procedures/list",
|
|
|
|
array: true
|
2016-01-07 15:29:29 +01:00
|
|
|
|
2015-12-24 15:22:07 +01:00
|
|
|
archived_class
|
2016-01-07 15:29:29 +01:00
|
|
|
|
|
|
|
render 'index'
|
2015-11-27 16:23:02 +01:00
|
|
|
end
|
|
|
|
|
2016-06-09 17:49:38 +02:00
|
|
|
def draft
|
|
|
|
@procedures = smart_listing_create :procedures,
|
2017-07-11 15:16:06 +02:00
|
|
|
current_administrateur.procedures.brouillons.order(created_at: :desc),
|
2017-06-12 13:49:51 +02:00
|
|
|
partial: "admin/procedures/list",
|
|
|
|
array: true
|
2016-06-09 17:49:38 +02:00
|
|
|
|
|
|
|
draft_class
|
|
|
|
|
|
|
|
render 'index'
|
|
|
|
end
|
|
|
|
|
2015-10-26 15:54:20 +01:00
|
|
|
def show
|
2015-12-04 16:17:35 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2018-09-19 17:12:12 +02:00
|
|
|
@path = @procedure.path || @procedure.default_path
|
2019-03-06 18:09:55 +01:00
|
|
|
@availability = @procedure.path_availability(current_administrateur, @path)
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
|
2017-12-21 17:59:56 +01:00
|
|
|
def destroy
|
|
|
|
procedure = current_administrateur.procedures.find(params[:id])
|
|
|
|
|
2018-10-01 13:24:37 +02:00
|
|
|
if procedure.publiee_ou_archivee?
|
|
|
|
return render json: {}, status: 401
|
|
|
|
end
|
2017-12-21 17:59:56 +01:00
|
|
|
|
2019-01-23 16:13:14 +01:00
|
|
|
procedure.reset!
|
2017-12-21 17:59:56 +01:00
|
|
|
procedure.destroy
|
|
|
|
|
2018-09-05 14:48:42 +02:00
|
|
|
flash.notice = 'Démarche supprimée'
|
2017-12-21 17:59:56 +01:00
|
|
|
redirect_to admin_procedures_draft_path
|
|
|
|
end
|
|
|
|
|
2015-10-26 15:54:20 +01:00
|
|
|
def new
|
2019-07-10 18:47:19 +02:00
|
|
|
@procedure ||= Procedure.new(for_individual: true)
|
2018-10-30 15:59:27 +01:00
|
|
|
@availability = Procedure::PATH_AVAILABLE
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2019-02-26 16:38:58 +01:00
|
|
|
@procedure = Procedure.new(procedure_params.merge(administrateurs: [current_administrateur]))
|
2018-10-25 17:42:09 +02:00
|
|
|
@path = @procedure.path
|
2019-03-06 18:09:55 +01:00
|
|
|
@availability = Procedure.path_availability(current_administrateur, @procedure.path)
|
2015-10-26 15:54:20 +01:00
|
|
|
|
2018-10-25 17:42:09 +02:00
|
|
|
if !@procedure.save
|
2017-07-13 09:46:13 +02:00
|
|
|
flash.now.alert = @procedure.errors.full_messages
|
2018-10-30 15:58:28 +01:00
|
|
|
render 'new'
|
2018-09-19 17:12:12 +02:00
|
|
|
else
|
|
|
|
flash.notice = 'Démarche enregistrée.'
|
2018-12-24 23:55:30 +01:00
|
|
|
gestionnaire = Gestionnaire.find_by(email: current_administrateur.email)
|
|
|
|
if gestionnaire
|
|
|
|
gestionnaire.assign_to_procedure(@procedure)
|
|
|
|
end
|
2018-11-14 16:28:02 +01:00
|
|
|
|
2019-01-17 12:04:05 +01:00
|
|
|
redirect_to champs_procedure_path(@procedure)
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2015-11-27 10:39:05 +01:00
|
|
|
@procedure = current_administrateur.procedures.find(params[:id])
|
2015-10-26 15:54:20 +01:00
|
|
|
|
2018-03-02 16:27:03 +01:00
|
|
|
if !@procedure.update(procedure_params)
|
2018-10-30 15:58:28 +01:00
|
|
|
flash.now.alert = @procedure.errors.full_messages
|
2018-10-30 15:59:27 +01:00
|
|
|
@path = procedure_params[:path]
|
|
|
|
if @path.present?
|
2019-03-06 18:09:55 +01:00
|
|
|
@availability = @procedure.path_availability(current_administrateur, @path)
|
2018-10-30 15:59:27 +01:00
|
|
|
end
|
2018-10-30 15:58:28 +01:00
|
|
|
render 'edit'
|
2019-03-06 14:42:27 +01:00
|
|
|
elsif @procedure.brouillon?
|
2018-08-13 17:49:15 +02:00
|
|
|
reset_procedure
|
2018-10-25 17:42:09 +02:00
|
|
|
flash.notice = 'Démarche modifiée. Tous les dossiers de cette démarche ont été supprimés.'
|
2018-10-30 15:58:28 +01:00
|
|
|
redirect_to edit_admin_procedure_path(id: @procedure.id)
|
2018-10-25 17:42:09 +02:00
|
|
|
else
|
2018-10-13 11:06:31 +02:00
|
|
|
flash.notice = 'Démarche modifiée.'
|
2018-10-30 15:58:28 +01:00
|
|
|
redirect_to edit_admin_procedure_path(id: @procedure.id)
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-09 17:49:38 +02:00
|
|
|
def publish
|
2018-10-30 12:00:58 +01:00
|
|
|
path = params[:path]
|
2016-06-30 10:24:01 +02:00
|
|
|
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
|
|
|
|
2018-10-25 17:42:09 +02:00
|
|
|
procedure.path = path
|
2019-07-11 11:49:01 +02:00
|
|
|
procedure.lien_site_web = params[:lien_site_web]
|
|
|
|
|
2018-10-25 17:42:09 +02:00
|
|
|
if !procedure.validate
|
2018-09-05 14:48:42 +02:00
|
|
|
flash.alert = 'Lien de la démarche invalide'
|
2016-06-24 16:41:44 +02:00
|
|
|
return redirect_to admin_procedures_path
|
2018-10-25 17:42:09 +02:00
|
|
|
else
|
|
|
|
procedure.path = nil
|
2016-06-24 16:41:44 +02:00
|
|
|
end
|
|
|
|
|
2019-03-06 18:09:55 +01:00
|
|
|
if procedure.publish_or_reopen!(current_administrateur, path)
|
2018-09-05 14:48:42 +02:00
|
|
|
flash.notice = "Démarche publiée"
|
2018-05-17 15:42:07 +02:00
|
|
|
redirect_to admin_procedures_path
|
|
|
|
else
|
|
|
|
@mine = false
|
|
|
|
render '/admin/procedures/publish', formats: 'js'
|
|
|
|
end
|
2016-06-24 16:41:44 +02:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
2018-09-05 14:48:42 +02:00
|
|
|
flash.alert = 'Démarche inexistante'
|
2016-06-24 16:41:44 +02:00
|
|
|
redirect_to admin_procedures_path
|
2016-06-09 17:49:38 +02:00
|
|
|
end
|
2015-11-26 18:41:41 +01:00
|
|
|
|
2016-07-22 11:34:34 +02:00
|
|
|
def transfer
|
2018-03-06 13:44:29 +01:00
|
|
|
admin = Administrateur.find_by(email: params[:email_admin].downcase)
|
2016-07-22 12:25:23 +02:00
|
|
|
|
2017-06-22 16:45:52 +02:00
|
|
|
if admin.nil?
|
|
|
|
render '/admin/procedures/transfer', formats: 'js', status: 404
|
|
|
|
else
|
|
|
|
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
2018-04-12 18:35:13 +02:00
|
|
|
clone_procedure = procedure.clone(admin, false)
|
2016-07-22 12:25:23 +02:00
|
|
|
|
2017-06-22 16:45:52 +02:00
|
|
|
clone_procedure.save
|
2016-07-22 11:34:34 +02:00
|
|
|
|
2018-09-05 14:48:42 +02:00
|
|
|
flash.now.notice = "La démarche a correctement été clonée vers le nouvel administrateur."
|
2016-07-22 11:34:34 +02:00
|
|
|
|
2017-06-22 16:45:52 +02:00
|
|
|
render '/admin/procedures/transfer', formats: 'js', status: 200
|
|
|
|
end
|
2016-07-22 11:34:34 +02:00
|
|
|
end
|
|
|
|
|
2016-06-09 17:49:38 +02:00
|
|
|
def archive
|
2016-06-30 10:24:01 +02:00
|
|
|
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
2018-05-17 15:42:07 +02:00
|
|
|
procedure.archive!
|
2016-06-24 16:41:44 +02:00
|
|
|
|
2018-09-05 14:48:42 +02:00
|
|
|
flash.notice = "Démarche archivée"
|
2016-06-24 16:41:44 +02:00
|
|
|
redirect_to admin_procedures_path
|
|
|
|
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
2018-09-05 14:48:42 +02:00
|
|
|
flash.alert = 'Démarche inexistante'
|
2016-06-24 16:41:44 +02:00
|
|
|
redirect_to admin_procedures_path
|
2015-11-26 18:41:41 +01:00
|
|
|
end
|
|
|
|
|
2016-06-15 11:34:05 +02:00
|
|
|
def clone
|
2018-01-08 14:44:28 +01:00
|
|
|
procedure = Procedure.find(params[:procedure_id])
|
2018-04-12 18:35:13 +02:00
|
|
|
new_procedure = procedure.clone(current_administrateur, cloned_from_library?)
|
2018-01-08 15:42:38 +01:00
|
|
|
|
|
|
|
if new_procedure.save
|
2018-09-05 14:48:42 +02:00
|
|
|
flash.notice = 'Démarche clonée'
|
2016-06-15 11:34:05 +02:00
|
|
|
redirect_to edit_admin_procedure_path(id: new_procedure.id)
|
|
|
|
else
|
2018-04-12 18:35:13 +02:00
|
|
|
if cloned_from_library?
|
2018-01-08 15:43:41 +01:00
|
|
|
flash.alert = new_procedure.errors.full_messages
|
|
|
|
redirect_to new_from_existing_admin_procedures_path
|
|
|
|
else
|
2018-05-31 18:32:13 +02:00
|
|
|
flash.alert = new_procedure.errors.full_messages
|
|
|
|
redirect_to admin_procedures_path
|
2018-01-08 15:43:41 +01:00
|
|
|
end
|
2016-06-15 11:34:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
2018-09-05 14:48:42 +02:00
|
|
|
flash.alert = 'Démarche inexistante'
|
2016-06-15 11:34:05 +02:00
|
|
|
redirect_to admin_procedures_path
|
|
|
|
end
|
|
|
|
|
2018-07-03 20:18:06 +02:00
|
|
|
SIGNIFICANT_DOSSIERS_THRESHOLD = 30
|
|
|
|
|
2018-01-04 18:36:45 +01:00
|
|
|
def new_from_existing
|
2018-07-03 20:18:06 +02:00
|
|
|
significant_procedure_ids = Procedure
|
2018-01-04 18:36:45 +01:00
|
|
|
.publiees_ou_archivees
|
|
|
|
.joins(:dossiers)
|
|
|
|
.group("procedures.id")
|
2018-07-03 20:18:06 +02:00
|
|
|
.having("count(dossiers.id) >= ?", SIGNIFICANT_DOSSIERS_THRESHOLD)
|
2018-01-04 18:36:45 +01:00
|
|
|
.pluck('procedures.id')
|
|
|
|
|
|
|
|
@grouped_procedures = Procedure
|
2019-02-26 16:18:04 +01:00
|
|
|
.includes(:administrateurs, :service)
|
2018-07-03 20:18:06 +02:00
|
|
|
.where(id: significant_procedure_ids)
|
2018-07-03 20:18:49 +02:00
|
|
|
.group_by(&:organisation_name)
|
|
|
|
.sort_by { |_, procedures| procedures.first.created_at }
|
2019-03-27 18:31:28 +01:00
|
|
|
render layout: 'application'
|
2018-01-04 18:36:45 +01:00
|
|
|
end
|
|
|
|
|
2019-07-16 17:24:31 +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
|
|
|
|
|
2015-12-24 15:22:07 +01:00
|
|
|
def active_class
|
2016-01-19 17:19:38 +01:00
|
|
|
@active_class = 'active'
|
2015-12-24 15:22:07 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def archived_class
|
2016-01-19 17:19:38 +01:00
|
|
|
@archived_class = 'active'
|
2015-12-24 15:22:07 +01:00
|
|
|
end
|
|
|
|
|
2016-06-09 17:49:38 +02:00
|
|
|
def draft_class
|
|
|
|
@draft_class = 'active'
|
|
|
|
end
|
|
|
|
|
2016-06-24 16:41:44 +02:00
|
|
|
def path_list
|
2018-10-25 17:42:09 +02:00
|
|
|
json_path_list = Procedure
|
2018-09-07 18:28:27 +02:00
|
|
|
.find_with_path(params[:request])
|
2018-10-25 17:42:09 +02:00
|
|
|
.order(:id)
|
2019-02-26 16:18:04 +01:00
|
|
|
.map do |procedure|
|
2018-01-15 19:22:02 +01:00
|
|
|
{
|
2019-02-26 16:18:04 +01:00
|
|
|
label: procedure.path,
|
|
|
|
mine: current_administrateur.owns?(procedure)
|
2018-01-15 19:22:02 +01:00
|
|
|
}
|
|
|
|
end.to_json
|
|
|
|
|
|
|
|
render json: json_path_list
|
2016-06-24 16:41:44 +02:00
|
|
|
end
|
|
|
|
|
2018-09-04 14:53:18 +02:00
|
|
|
def check_availability
|
|
|
|
path = params[:procedure][:path]
|
|
|
|
procedure_id = params[:procedure][:id]
|
|
|
|
|
|
|
|
if procedure_id.present?
|
|
|
|
procedure = current_administrateur.procedures.find(procedure_id)
|
2019-03-06 18:09:55 +01:00
|
|
|
@availability = procedure.path_availability(current_administrateur, path)
|
2018-09-04 14:53:18 +02:00
|
|
|
else
|
2019-03-06 18:09:55 +01:00
|
|
|
@availability = Procedure.path_availability(current_administrateur, path)
|
2018-09-04 14:53:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-24 13:29:35 +02:00
|
|
|
def delete_logo
|
2018-10-02 10:14:38 +02:00
|
|
|
@procedure.remove_logo!
|
|
|
|
@procedure.save
|
2018-09-24 13:29:35 +02:00
|
|
|
|
|
|
|
flash.notice = 'le logo a bien été supprimé'
|
2018-10-02 10:14:38 +02:00
|
|
|
redirect_to edit_admin_procedure_path(@procedure)
|
2018-09-24 13:29:35 +02:00
|
|
|
end
|
|
|
|
|
2018-05-31 11:15:44 +02:00
|
|
|
def delete_deliberation
|
2018-10-02 10:14:38 +02:00
|
|
|
@procedure.deliberation.purge_later
|
2018-05-31 11:15:44 +02:00
|
|
|
|
|
|
|
flash.notice = 'la délibération a bien été supprimée'
|
2018-10-02 10:14:38 +02:00
|
|
|
redirect_to edit_admin_procedure_path(@procedure)
|
2018-05-31 11:15:44 +02:00
|
|
|
end
|
|
|
|
|
2018-09-24 09:49:51 +02:00
|
|
|
def delete_notice
|
2018-10-02 10:14:38 +02:00
|
|
|
@procedure.notice.purge_later
|
2018-09-24 09:49:51 +02:00
|
|
|
|
|
|
|
flash.notice = 'la notice a bien été supprimée'
|
2018-10-02 10:14:38 +02:00
|
|
|
redirect_to edit_admin_procedure_path(@procedure)
|
2018-09-24 09:49:51 +02:00
|
|
|
end
|
|
|
|
|
2015-10-26 15:54:20 +01:00
|
|
|
private
|
|
|
|
|
2018-04-12 18:35:13 +02:00
|
|
|
def cloned_from_library?
|
|
|
|
params[:from_new_from_existing].present?
|
|
|
|
end
|
|
|
|
|
2017-02-14 18:13:19 +01:00
|
|
|
def procedure_params
|
2019-07-17 15:34:10 +02:00
|
|
|
editable_params = [:libelle, :description, :organisation, :direction, :lien_site_web, :cadre_juridique, :deliberation, :notice, :web_hook_url, :euro_flag, :logo, :auto_archive_on, :monavis_embed]
|
2018-05-30 18:45:46 +02:00
|
|
|
if @procedure&.locked?
|
2017-03-14 10:45:59 +01:00
|
|
|
params.require(:procedure).permit(*editable_params)
|
2017-02-15 14:13:02 +01:00
|
|
|
else
|
2019-07-10 18:27:26 +02:00
|
|
|
params.require(:procedure).permit(*editable_params, :duree_conservation_dossiers_dans_ds, :duree_conservation_dossiers_hors_ds, :for_individual, :ask_birthday, :path)
|
2017-02-15 14:13:02 +01:00
|
|
|
end
|
2015-12-08 10:11:58 +01:00
|
|
|
end
|
2015-10-26 15:54:20 +01:00
|
|
|
end
|