From 492c7f377f5e19058b2a1751fdac448f99b63dc0 Mon Sep 17 00:00:00 2001 From: Kara Diaby Date: Thu, 6 Oct 2022 13:21:14 +0400 Subject: [PATCH 1/4] migration --- app/models/procedure.rb | 1 + db/migrate/20221006074425_add_tags_to_procedures.rb | 7 +++++++ db/schema.rb | 2 ++ 3 files changed, 10 insertions(+) create mode 100644 db/migrate/20221006074425_add_tags_to_procedures.rb diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 4576522c4..7499cc75a 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -41,6 +41,7 @@ # published_at :datetime # routing_criteria_name :text default("Votre ville") # routing_enabled :boolean +# tags :text default([]), is an Array # test_started_at :datetime # unpublished_at :datetime # web_hook_url :string diff --git a/db/migrate/20221006074425_add_tags_to_procedures.rb b/db/migrate/20221006074425_add_tags_to_procedures.rb new file mode 100644 index 000000000..895a77a1a --- /dev/null +++ b/db/migrate/20221006074425_add_tags_to_procedures.rb @@ -0,0 +1,7 @@ +class AddTagsToProcedures < ActiveRecord::Migration[6.1] + disable_ddl_transaction! + def change + add_column :procedures, :tags, :text, array: true, default: [] + add_index :procedures, :tags, using: 'gin', algorithm: :concurrently + end +end diff --git a/db/schema.rb b/db/schema.rb index 2bda24d01..81c7e1606 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -667,6 +667,7 @@ ActiveRecord::Schema.define(version: 2022_10_20_094031) do t.text "routing_criteria_name", default: "Votre ville" t.boolean "routing_enabled" t.bigint "service_id" + t.text "tags", default: [], array: true t.datetime "test_started_at" t.datetime "unpublished_at" t.datetime "updated_at", null: false @@ -683,6 +684,7 @@ ActiveRecord::Schema.define(version: 2022_10_20_094031) do t.index ["procedure_expires_when_termine_enabled"], name: "index_procedures_on_procedure_expires_when_termine_enabled" t.index ["published_revision_id"], name: "index_procedures_on_published_revision_id" t.index ["service_id"], name: "index_procedures_on_service_id" + t.index ["tags"], name: "index_procedures_on_tags", using: :gin t.index ["zone_id"], name: "index_procedures_on_zone_id" end From cf8e6a9c6755f1821aae5747250ab925c6bea1f7 Mon Sep 17 00:00:00 2001 From: Kara Diaby Date: Thu, 20 Oct 2022 11:51:31 +0200 Subject: [PATCH 2/4] 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 From 476dd7e6991526a26162375dfc46f3d8fc9d67b2 Mon Sep 17 00:00:00 2001 From: Kara Diaby Date: Thu, 20 Oct 2022 11:51:37 +0200 Subject: [PATCH 3/4] layout --- .../procedures/_informations.html.haml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/views/administrateurs/procedures/_informations.html.haml b/app/views/administrateurs/procedures/_informations.html.haml index 072f3befc..384234b90 100644 --- a/app/views/administrateurs/procedures/_informations.html.haml +++ b/app/views/administrateurs/procedures/_informations.html.haml @@ -100,6 +100,18 @@ %p.explication Si votre démarche s’adresse indifféremment à une personne morale ou un particulier, choisissez l'option « Particuliers ». Vous pourrez ajouter un champ SIRET directement dans le formulaire. + %h3.header-subsection Ajouter des tags + %p.explication Les tags sont des mots ou des expressions que vous attribuez aux démarches pour décrire leur contenu et pour les retrouver. Les tags sont partagés avec la communauté, ce qui vous permet de voir les tags attribués aux démarches créées par les autres administrateurs. + = hidden_field_tag 'procedure[tags]', nil + = react_component("ComboMultiple", + options: @existing_tags, + selected: [], disabled: [], + label: 'Tags', + group: '.procedure-form__column--form', + name: 'tags', + describedby: 'procedure-tags', + acceptNewValues: true) + %details.procedure-form__options-details %summary.procedure-form__options-summary %h3.header-subsection Options avancées From 9529c6ba9cc355dc9f5b026f72dd83c6bcad103b Mon Sep 17 00:00:00 2001 From: Kara Diaby Date: Thu, 20 Oct 2022 13:07:47 +0200 Subject: [PATCH 4/4] tests --- .../administrateurs/procedures_controller_spec.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/controllers/administrateurs/procedures_controller_spec.rb b/spec/controllers/administrateurs/procedures_controller_spec.rb index f5a03b132..1fad0fcea 100644 --- a/spec/controllers/administrateurs/procedures_controller_spec.rb +++ b/spec/controllers/administrateurs/procedures_controller_spec.rb @@ -13,6 +13,7 @@ describe Administrateurs::ProceduresController, type: :controller do let(:lien_site_web) { 'http://mon-site.gouv.fr' } let(:zone) { create(:zone) } let(:zone_ids) { [zone.id] } + let(:tags) { "[\"planete\",\"environnement\"]" } describe '#apercu' do render_views @@ -56,7 +57,8 @@ describe Administrateurs::ProceduresController, type: :controller do duree_conservation_dossiers_dans_ds: duree_conservation_dossiers_dans_ds, monavis_embed: monavis_embed, zone_ids: zone_ids, - lien_site_web: lien_site_web + lien_site_web: lien_site_web, + tags: tags } } @@ -206,6 +208,7 @@ describe Administrateurs::ProceduresController, type: :controller do it { expect(subject.organisation).to eq(organisation) } it { expect(subject.administrateurs).to eq([admin]) } it { expect(subject.duree_conservation_dossiers_dans_ds).to eq(duree_conservation_dossiers_dans_ds) } + it { expect(subject.tags).to eq(["planete", "environnement"]) } end it { is_expected.to redirect_to(champs_admin_procedure_path(Procedure.last)) }