From cf8e6a9c6755f1821aae5747250ab925c6bea1f7 Mon Sep 17 00:00:00 2001 From: Kara Diaby Date: Thu, 20 Oct 2022 11:51:31 +0200 Subject: [PATCH] controller --- .../administrateurs/procedures_controller.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/controllers/administrateurs/procedures_controller.rb b/app/controllers/administrateurs/procedures_controller.rb index fc6692944..16743c768 100644 --- a/app/controllers/administrateurs/procedures_controller.rb +++ b/app/controllers/administrateurs/procedures_controller.rb @@ -63,6 +63,7 @@ module Administrateurs def new @procedure ||= Procedure.new(for_individual: true) + @existing_tags = get_existing_tags end SIGNIFICANT_DOSSIERS_THRESHOLD = 30 @@ -361,7 +362,8 @@ module Administrateurs { zone_ids: [] }, :lien_dpo, :opendata, - :procedure_expires_when_termine_enabled + :procedure_expires_when_termine_enabled, + :tags ] permited_params = if @procedure&.locked? params.require(:procedure).permit(*editable_params) @@ -371,6 +373,9 @@ module Administrateurs if permited_params[:auto_archive_on].present? permited_params[:auto_archive_on] = Date.parse(permited_params[:auto_archive_on]) + 1.day end + if permited_params[:tags].present? + permited_params[:tags] = JSON.parse(permited_params[:tags]) + end permited_params end @@ -385,5 +390,11 @@ module Administrateurs def cloned_from_library? params[:from_new_from_existing].present? end + + def get_existing_tags + unnest = Arel::Nodes::NamedFunction.new('UNNEST', [Procedure.arel_table[:tags]]) + query = Procedure.select(unnest.as('tags')).distinct.order('tags') + Procedure.connection.query(query.to_sql).flatten + end end end