From 0ea69cfc3ed143b138ef38383c444bc4a9ee7e32 Mon Sep 17 00:00:00 2001 From: Julien Portalier Date: Tue, 25 Oct 2016 18:45:05 +0200 Subject: [PATCH 01/15] PostgreSQL full text search [WIP] --- Gemfile | 2 + Gemfile.lock | 7 ++ .../backoffice/dossiers_controller.rb | 10 ++- app/models/search.rb | 39 +++++++++++ db/migrate/20161025150900_create_searches.rb | 68 +++++++++++++++++++ db/schema.rb | 44 +++++++++++- db/views/searches_v01.sql | 57 ++++++++++++++++ spec/models/search_spec.rb | 5 ++ 8 files changed, 230 insertions(+), 2 deletions(-) create mode 100644 app/models/search.rb create mode 100644 db/migrate/20161025150900_create_searches.rb create mode 100644 db/views/searches_v01.sql create mode 100644 spec/models/search_spec.rb diff --git a/Gemfile b/Gemfile index 026ba7955..ba68e79a7 100644 --- a/Gemfile +++ b/Gemfile @@ -62,6 +62,8 @@ gem 'fog' gem 'fog-openstack' gem 'pg' +gem 'scenic' +gem 'textacular' gem 'rgeo-geojson' gem 'leaflet-rails' diff --git a/Gemfile.lock b/Gemfile.lock index a7599faa6..f85d05b05 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -516,6 +516,9 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) + scenic (1.3.0) + activerecord (>= 4.0.0) + railties (>= 4.0.0) sdoc (0.4.1) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) @@ -563,6 +566,8 @@ GEM json (>= 1.4.3) temple (0.7.6) terminal-table (1.5.2) + textacular (4.0.1) + activerecord (>= 3.0, < 5.1) therubyracer (0.12.2) libv8 (~> 3.16.14.0) ref @@ -673,6 +678,7 @@ DEPENDENCIES rubocop-checkstyle_formatter rubocop-rspec sass-rails (~> 5.0) + scenic sdoc (~> 0.4.0) selenium-webdriver sentry-raven @@ -681,6 +687,7 @@ DEPENDENCIES smart_listing spring spring-commands-rspec + textacular therubyracer timecop turbolinks diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index 9c4895798..d4b1d4089 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -27,7 +27,15 @@ class Backoffice::DossiersController < Backoffice::DossiersListController def search @search_terms = params[:q] - @dossier = Dossier.search(current_gestionnaire, @search_terms) + + @dossier = Search.new( + gestionnaire: current_gestionnaire, + query: @search_terms, + ).results + + unless @dossier.empty? + @dossiers = @dossiers.paginate(page: params[:page]) + end smartlisting_dossier @dossier, 'search' diff --git a/app/models/search.rb b/app/models/search.rb new file mode 100644 index 000000000..2380a33b6 --- /dev/null +++ b/app/models/search.rb @@ -0,0 +1,39 @@ +# See: +# - https://robots.thoughtbot.com/implementing-multi-table-full-text-search-with-postgres +# - http://calebthompson.io/talks/search.html +class Search < ActiveRecord::Base + extend Textacular + + attr_accessor :gestionnaire + attr_accessor :query + + belongs_to :dossier + + def results + if @query.present? + self.class + .select("DISTINCT(dossiers.*)") + .search(@query) + .joins(:dossier) + .where(dossier_id: @gestionnaire.dossier_ids) + .where("dossiers.archived = ? AND dossiers.state != ?", false, "draft") + .map(&:dossier) + else + Search.none + end + end + + def self.searchable_language + "french" + end + + def self.searchable_columns + %i(term) + end + + # NOTE: could be executed concurrently + # See https://github.com/thoughtbot/scenic#what-about-materialized-views + def self.refresh + Scenic.database.refresh_materialized_view(table_name, concurrently: false) + end +end diff --git a/db/migrate/20161025150900_create_searches.rb b/db/migrate/20161025150900_create_searches.rb new file mode 100644 index 000000000..017892474 --- /dev/null +++ b/db/migrate/20161025150900_create_searches.rb @@ -0,0 +1,68 @@ +class CreateSearches < ActiveRecord::Migration + def up + create_view :searches, materialized: true + + matrix.each do |table, fields| + fields.each do |field| + execute "CREATE INDEX tsv_index_#{table}_on_#{field} ON #{table} USING GIN(to_tsvector('french', #{field}))" + end + end + end + + def down + drop_view :searches + + matrix.each do |table, fields| + fields.each do |field| + execute "DROP INDEX IF EXISTS tsv_index_#{table}_on_#{field}" + end + end + end + + def matrix + { + cerfas: %i( + content + ), + champs: %i( + value + ), + entreprises: %i( + siren + numero_tva_intracommunautaire + forme_juridique + forme_juridique_code + nom_commercial + raison_sociale + siret_siege_social + nom + prenom + ), + rna_informations: %i( + association_id + titre + objet + ), + etablissements: %i( + siret + naf + libelle_naf + adresse + code_postal + localite + code_insee_localite + ), + individuals: %i( + nom + prenom + ), + pieces_justificatives: %i( + content + ), + france_connect_informations: %i( + given_name + family_name + ), + } + end +end diff --git a/db/schema.rb b/db/schema.rb index 17762a2b4..126477bd2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161011125345) do +ActiveRecord::Schema.define(version: 20161025150900) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -369,4 +369,46 @@ ActiveRecord::Schema.define(version: 20161011125345) do add_foreign_key "dossiers", "users" add_foreign_key "procedure_paths", "administrateurs" add_foreign_key "procedure_paths", "procedures" + + create_view :searches, sql_definition: <<-SQL + SELECT dossiers.id AS dossier_id, + (dossiers.id)::text AS term + FROM dossiers + UNION + SELECT cerfas.dossier_id, + cerfas.content AS term + FROM cerfas + UNION + SELECT champs.dossier_id, + champs.value AS term + FROM champs + UNION + SELECT champs.dossier_id, + drop_down_lists.value AS term + FROM (drop_down_lists + JOIN champs ON ((champs.type_de_champ_id = champs.type_de_champ_id))) + UNION + SELECT entreprises.dossier_id, + (((((((((((((((((((((((entreprises.siren)::text || ' '::text) || (entreprises.numero_tva_intracommunautaire)::text) || ' '::text) || (entreprises.forme_juridique)::text) || ' '::text) || (entreprises.forme_juridique_code)::text) || ' '::text) || (entreprises.nom_commercial)::text) || ' '::text) || (entreprises.raison_sociale)::text) || ' '::text) || (entreprises.siret_siege_social)::text) || ' '::text) || (entreprises.nom)::text) || ' '::text) || (entreprises.prenom)::text) || ' '::text) || (rna_informations.association_id)::text) || ' '::text) || (rna_informations.titre)::text) || ' '::text) || rna_informations.objet) AS term + FROM (entreprises + JOIN rna_informations ON ((rna_informations.entreprise_id = entreprises.id))) + UNION + SELECT etablissements.dossier_id, + (((((((((((((etablissements.siret)::text || ' '::text) || (etablissements.naf)::text) || ' '::text) || (etablissements.libelle_naf)::text) || ' '::text) || (etablissements.adresse)::text) || ' '::text) || (etablissements.code_postal)::text) || ' '::text) || (etablissements.localite)::text) || ' '::text) || (etablissements.code_insee_localite)::text) AS term + FROM etablissements + UNION + SELECT individuals.dossier_id, + (((individuals.nom)::text || ' '::text) || (individuals.prenom)::text) AS term + FROM individuals + UNION + SELECT pieces_justificatives.dossier_id, + pieces_justificatives.content AS term + FROM pieces_justificatives + UNION + SELECT dossiers.id AS dossier_id, + (((france_connect_informations.given_name)::text || ' '::text) || (france_connect_informations.family_name)::text) AS term + FROM (france_connect_informations + JOIN dossiers ON ((dossiers.user_id = france_connect_informations.user_id))); + SQL + end diff --git a/db/views/searches_v01.sql b/db/views/searches_v01.sql new file mode 100644 index 000000000..cd37c0d71 --- /dev/null +++ b/db/views/searches_v01.sql @@ -0,0 +1,57 @@ +SELECT dossiers.id AS dossier_id, + dossiers.id::text AS term + FROM dossiers + +UNION SELECT cerfas.dossier_id, + cerfas.content AS term + FROM cerfas + +UNION SELECT champs.dossier_id, + champs.value AS term + FROM champs + +UNION SELECT champs.dossier_id, + drop_down_lists.value AS term + FROM drop_down_lists + INNER JOIN champs ON champs.type_de_champ_id = champs.type_de_champ_id + +UNION SELECT entreprises.dossier_id, + entreprises.siren || ' ' || + entreprises.numero_tva_intracommunautaire || ' ' || + entreprises.forme_juridique || ' ' || + entreprises.forme_juridique_code || ' ' || + entreprises.nom_commercial || ' ' || + entreprises.raison_sociale || ' ' || + entreprises.siret_siege_social || ' ' || + entreprises.nom || ' ' || + entreprises.prenom || ' ' || + rna_informations.association_id || ' ' || + rna_informations.titre || ' ' || + rna_informations.objet AS term + FROM entreprises + INNER JOIN rna_informations ON rna_informations.entreprise_id = entreprises.id + +UNION SELECT etablissements.dossier_id, + etablissements.siret || ' ' || + etablissements.naf || ' ' || + etablissements.libelle_naf || ' ' || + etablissements.adresse || ' ' || + etablissements.code_postal || ' ' || + etablissements.localite || ' ' || + etablissements.code_insee_localite AS term + FROM etablissements + +UNION SELECT individuals.dossier_id, + individuals.nom || ' ' || + individuals.prenom AS term + FROM individuals + +UNION SELECT pieces_justificatives.dossier_id, + pieces_justificatives.content AS term + FROM pieces_justificatives + +UNION SELECT dossiers.id, + france_connect_informations.given_name || ' ' || + france_connect_informations.family_name AS term + FROM france_connect_informations + INNER JOIN dossiers ON dossiers.user_id = france_connect_informations.user_id diff --git a/spec/models/search_spec.rb b/spec/models/search_spec.rb new file mode 100644 index 000000000..89ac26d2d --- /dev/null +++ b/spec/models/search_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Search, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 6bb1ad892fa1be4f587191990ec9e067c5c34aec Mon Sep 17 00:00:00 2001 From: Julien Portalier Date: Fri, 28 Oct 2016 19:34:29 +0200 Subject: [PATCH 02/15] Fixes for PostgreSQL full text search - Drop individual GIN indices that aren't used by the search query. - Add missing indices to speed up view query (missing dossier_id) - Fix view query for drop_down_lists (and merge it with champs) --- app/models/search.rb | 8 +- db/migrate/20161025150900_create_searches.rb | 77 +- db/schema.rb | 414 ---- db/structure.sql | 2077 ++++++++++++++++++ db/views/searches_v01.sql | 11 +- 5 files changed, 2104 insertions(+), 483 deletions(-) delete mode 100644 db/schema.rb create mode 100644 db/structure.sql diff --git a/app/models/search.rb b/app/models/search.rb index 2380a33b6..89f5d3622 100644 --- a/app/models/search.rb +++ b/app/models/search.rb @@ -12,11 +12,12 @@ class Search < ActiveRecord::Base def results if @query.present? self.class - .select("DISTINCT(dossiers.*)") + .select("DISTINCT(searches.dossier_id)") .search(@query) .joins(:dossier) .where(dossier_id: @gestionnaire.dossier_ids) .where("dossiers.archived = ? AND dossiers.state != ?", false, "draft") + .preload(:dossier) .map(&:dossier) else Search.none @@ -31,9 +32,10 @@ class Search < ActiveRecord::Base %i(term) end - # NOTE: could be executed concurrently - # See https://github.com/thoughtbot/scenic#what-about-materialized-views + # Refreshes the materialized searches view. def self.refresh + # NOTE: could be executed concurrently + # See https://github.com/thoughtbot/scenic#what-about-materialized-views Scenic.database.refresh_materialized_view(table_name, concurrently: false) end end diff --git a/db/migrate/20161025150900_create_searches.rb b/db/migrate/20161025150900_create_searches.rb index 017892474..28f074d6a 100644 --- a/db/migrate/20161025150900_create_searches.rb +++ b/db/migrate/20161025150900_create_searches.rb @@ -1,68 +1,27 @@ class CreateSearches < ActiveRecord::Migration def up + add_index :champs, :dossier_id + add_index :champs, :type_de_champ_id + add_index :drop_down_lists, :type_de_champ_id + add_index :etablissements, :dossier_id + add_index :entreprises, :dossier_id + add_index :france_connect_informations, :user_id + add_index :individuals, :dossier_id + add_index :pieces_justificatives, :dossier_id + add_index :rna_informations, :entreprise_id create_view :searches, materialized: true - - matrix.each do |table, fields| - fields.each do |field| - execute "CREATE INDEX tsv_index_#{table}_on_#{field} ON #{table} USING GIN(to_tsvector('french', #{field}))" - end - end end def down + remove_index :champs, :dossier_id + remove_index :champs, :type_de_champ_id + remove_index :drop_down_lists, :type_de_champ_id + remove_index :etablissements, :dossier_id + remove_index :entreprises, :dossier_id + remove_index :france_connect_informations, :user_id + remove_index :individuals, :dossier_id + remove_index :pieces_justificatives, :dossier_id + remove_index :rna_informations, :entreprise_id drop_view :searches - - matrix.each do |table, fields| - fields.each do |field| - execute "DROP INDEX IF EXISTS tsv_index_#{table}_on_#{field}" - end - end - end - - def matrix - { - cerfas: %i( - content - ), - champs: %i( - value - ), - entreprises: %i( - siren - numero_tva_intracommunautaire - forme_juridique - forme_juridique_code - nom_commercial - raison_sociale - siret_siege_social - nom - prenom - ), - rna_informations: %i( - association_id - titre - objet - ), - etablissements: %i( - siret - naf - libelle_naf - adresse - code_postal - localite - code_insee_localite - ), - individuals: %i( - nom - prenom - ), - pieces_justificatives: %i( - content - ), - france_connect_informations: %i( - given_name - family_name - ), - } end end diff --git a/db/schema.rb b/db/schema.rb deleted file mode 100644 index 126477bd2..000000000 --- a/db/schema.rb +++ /dev/null @@ -1,414 +0,0 @@ -# encoding: UTF-8 -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 20161025150900) do - - # These are extensions that must be enabled in order to support this database - enable_extension "plpgsql" - - create_table "administrateurs", force: :cascade do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" - t.datetime "reset_password_sent_at" - t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false - t.datetime "current_sign_in_at" - t.datetime "last_sign_in_at" - t.inet "current_sign_in_ip" - t.inet "last_sign_in_ip" - t.datetime "created_at" - t.datetime "updated_at" - t.string "api_token" - end - - add_index "administrateurs", ["email"], name: "index_administrateurs_on_email", unique: true, using: :btree - add_index "administrateurs", ["reset_password_token"], name: "index_administrateurs_on_reset_password_token", unique: true, using: :btree - - create_table "administrateurs_gestionnaires", id: false, force: :cascade do |t| - t.integer "administrateur_id" - t.integer "gestionnaire_id" - end - - add_index "administrateurs_gestionnaires", ["administrateur_id"], name: "index_administrateurs_gestionnaires_on_administrateur_id", using: :btree - add_index "administrateurs_gestionnaires", ["gestionnaire_id", "administrateur_id"], name: "unique_couple_administrateur_gestionnaire", unique: true, using: :btree - add_index "administrateurs_gestionnaires", ["gestionnaire_id"], name: "index_administrateurs_gestionnaires_on_gestionnaire_id", using: :btree - - create_table "administrations", force: :cascade do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" - t.datetime "reset_password_sent_at" - t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false - t.datetime "current_sign_in_at" - t.datetime "last_sign_in_at" - t.inet "current_sign_in_ip" - t.inet "last_sign_in_ip" - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "administrations", ["email"], name: "index_administrations_on_email", unique: true, using: :btree - add_index "administrations", ["reset_password_token"], name: "index_administrations_on_reset_password_token", unique: true, using: :btree - - create_table "assign_tos", id: false, force: :cascade do |t| - t.integer "gestionnaire_id" - t.integer "procedure_id" - end - - add_index "assign_tos", ["gestionnaire_id"], name: "index_assign_tos_on_gestionnaire_id", using: :btree - add_index "assign_tos", ["procedure_id"], name: "index_assign_tos_on_procedure_id", using: :btree - - create_table "cadastres", force: :cascade do |t| - t.string "surface_intersection" - t.float "surface_parcelle" - t.string "numero" - t.integer "feuille" - t.string "section" - t.string "code_dep" - t.string "nom_com" - t.string "code_com" - t.string "code_arr" - t.text "geometry" - t.integer "dossier_id" - end - - create_table "cerfas", force: :cascade do |t| - t.string "content" - t.integer "dossier_id" - t.datetime "created_at" - t.integer "user_id" - t.string "original_filename" - t.string "content_secure_token" - end - - add_index "cerfas", ["dossier_id"], name: "index_cerfas_on_dossier_id", using: :btree - - create_table "champs", force: :cascade do |t| - t.string "value" - t.integer "type_de_champ_id" - t.integer "dossier_id" - t.string "type" - end - - create_table "commentaires", force: :cascade do |t| - t.string "email" - t.datetime "created_at", null: false - t.string "body" - t.integer "dossier_id" - t.datetime "updated_at", null: false - t.integer "piece_justificative_id" - end - - add_index "commentaires", ["dossier_id"], name: "index_commentaires_on_dossier_id", using: :btree - - create_table "dossiers", force: :cascade do |t| - t.boolean "autorisation_donnees" - t.string "nom_projet" - t.integer "procedure_id" - t.datetime "created_at" - t.datetime "updated_at" - t.string "state" - t.integer "user_id" - t.text "json_latlngs" - t.boolean "archived", default: false - t.boolean "mandataire_social", default: false - t.datetime "deposit_datetime" - end - - add_index "dossiers", ["procedure_id"], name: "index_dossiers_on_procedure_id", using: :btree - add_index "dossiers", ["user_id"], name: "index_dossiers_on_user_id", using: :btree - - create_table "drop_down_lists", force: :cascade do |t| - t.string "value" - t.integer "type_de_champ_id" - end - - create_table "entreprises", force: :cascade do |t| - t.string "siren" - t.integer "capital_social" - t.string "numero_tva_intracommunautaire" - t.string "forme_juridique" - t.string "forme_juridique_code" - t.string "nom_commercial" - t.string "raison_sociale" - t.string "siret_siege_social" - t.string "code_effectif_entreprise" - t.datetime "date_creation" - t.string "nom" - t.string "prenom" - t.integer "dossier_id" - end - - create_table "etablissements", force: :cascade do |t| - t.string "siret" - t.boolean "siege_social" - t.string "naf" - t.string "libelle_naf" - t.string "adresse" - t.string "numero_voie" - t.string "type_voie" - t.string "nom_voie" - t.string "complement_adresse" - t.string "code_postal" - t.string "localite" - t.string "code_insee_localite" - t.integer "dossier_id" - t.integer "entreprise_id" - end - - create_table "exercices", force: :cascade do |t| - t.string "ca" - t.datetime "dateFinExercice" - t.integer "date_fin_exercice_timestamp" - t.integer "etablissement_id" - end - - create_table "follows", force: :cascade do |t| - t.integer "gestionnaire_id" - t.integer "dossier_id" - end - - add_index "follows", ["dossier_id"], name: "index_follows_on_dossier_id", using: :btree - add_index "follows", ["gestionnaire_id"], name: "index_follows_on_gestionnaire_id", using: :btree - - create_table "france_connect_informations", force: :cascade do |t| - t.string "gender" - t.string "given_name" - t.string "family_name" - t.date "birthdate" - t.string "birthplace" - t.string "france_connect_particulier_id" - t.integer "user_id" - t.string "email_france_connect" - end - - create_table "gestionnaires", force: :cascade do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" - t.datetime "reset_password_sent_at" - t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false - t.datetime "current_sign_in_at" - t.datetime "last_sign_in_at" - t.inet "current_sign_in_ip" - t.inet "last_sign_in_ip" - t.datetime "created_at" - t.datetime "updated_at" - t.integer "procedure_filter" - end - - add_index "gestionnaires", ["email"], name: "index_gestionnaires_on_email", unique: true, using: :btree - add_index "gestionnaires", ["reset_password_token"], name: "index_gestionnaires_on_reset_password_token", unique: true, using: :btree - - create_table "individuals", force: :cascade do |t| - t.string "nom" - t.string "prenom" - t.string "birthdate" - t.integer "dossier_id" - t.string "gender" - end - - create_table "invites", force: :cascade do |t| - t.string "email" - t.string "email_sender" - t.integer "dossier_id" - t.integer "user_id" - t.string "type", default: "InviteGestionnaire" - end - - create_table "mail_templates", force: :cascade do |t| - t.string "object" - t.text "body" - t.string "type" - t.integer "procedure_id" - end - - create_table "module_api_cartos", force: :cascade do |t| - t.integer "procedure_id" - t.boolean "use_api_carto", default: false - t.boolean "quartiers_prioritaires", default: false - t.boolean "cadastre", default: false - end - - add_index "module_api_cartos", ["procedure_id"], name: "index_module_api_cartos_on_procedure_id", unique: true, using: :btree - - create_table "pieces_justificatives", force: :cascade do |t| - t.string "content" - t.integer "dossier_id" - t.integer "type_de_piece_justificative_id" - t.datetime "created_at" - t.integer "user_id" - t.string "original_filename" - t.string "content_secure_token" - end - - add_index "pieces_justificatives", ["type_de_piece_justificative_id"], name: "index_pieces_justificatives_on_type_de_piece_justificative_id", using: :btree - - create_table "preference_list_dossiers", force: :cascade do |t| - t.string "libelle" - t.string "table" - t.string "attr" - t.string "attr_decorate" - t.string "bootstrap_lg" - t.string "order" - t.string "filter" - t.integer "gestionnaire_id" - t.integer "procedure_id" - end - - create_table "preference_smart_listing_pages", force: :cascade do |t| - t.string "liste" - t.integer "page" - t.integer "procedure_id" - t.integer "gestionnaire_id" - end - - create_table "procedure_paths", force: :cascade do |t| - t.string "path", limit: 30 - t.integer "procedure_id" - t.integer "administrateur_id" - end - - add_index "procedure_paths", ["path"], name: "index_procedure_paths_on_path", using: :btree - - create_table "procedures", force: :cascade do |t| - t.string "libelle" - t.string "description" - t.string "organisation" - t.string "direction" - t.string "lien_demarche" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.boolean "test" - t.integer "administrateur_id" - t.boolean "archived", default: false - t.boolean "euro_flag", default: false - t.string "logo" - t.boolean "cerfa_flag", default: false - t.string "logo_secure_token" - t.boolean "published", default: false, null: false - t.string "lien_site_web" - t.string "lien_notice" - t.boolean "for_individual", default: false - t.boolean "individual_with_siret", default: false - end - - create_table "quartier_prioritaires", force: :cascade do |t| - t.string "code" - t.string "nom" - t.string "commune" - t.text "geometry" - t.integer "dossier_id" - end - - create_table "rna_informations", force: :cascade do |t| - t.string "association_id" - t.string "titre" - t.text "objet" - t.date "date_creation" - t.date "date_declaration" - t.date "date_publication" - t.integer "entreprise_id" - end - - create_table "types_de_champ", force: :cascade do |t| - t.string "libelle" - t.string "type_champ" - t.integer "order_place" - t.integer "procedure_id" - t.text "description" - t.boolean "mandatory", default: false - t.string "type" - end - - create_table "types_de_piece_justificative", force: :cascade do |t| - t.string "libelle" - t.string "description" - t.boolean "api_entreprise", default: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "procedure_id" - t.integer "order_place" - end - - create_table "users", force: :cascade do |t| - t.string "email", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" - t.datetime "reset_password_sent_at" - t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false - t.datetime "current_sign_in_at" - t.datetime "last_sign_in_at" - t.inet "current_sign_in_ip" - t.inet "last_sign_in_ip" - t.datetime "created_at" - t.datetime "updated_at" - t.string "siret" - t.string "loged_in_with_france_connect", default: "false" - end - - add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree - add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree - - add_foreign_key "cerfas", "dossiers" - add_foreign_key "commentaires", "dossiers" - add_foreign_key "dossiers", "users" - add_foreign_key "procedure_paths", "administrateurs" - add_foreign_key "procedure_paths", "procedures" - - create_view :searches, sql_definition: <<-SQL - SELECT dossiers.id AS dossier_id, - (dossiers.id)::text AS term - FROM dossiers - UNION - SELECT cerfas.dossier_id, - cerfas.content AS term - FROM cerfas - UNION - SELECT champs.dossier_id, - champs.value AS term - FROM champs - UNION - SELECT champs.dossier_id, - drop_down_lists.value AS term - FROM (drop_down_lists - JOIN champs ON ((champs.type_de_champ_id = champs.type_de_champ_id))) - UNION - SELECT entreprises.dossier_id, - (((((((((((((((((((((((entreprises.siren)::text || ' '::text) || (entreprises.numero_tva_intracommunautaire)::text) || ' '::text) || (entreprises.forme_juridique)::text) || ' '::text) || (entreprises.forme_juridique_code)::text) || ' '::text) || (entreprises.nom_commercial)::text) || ' '::text) || (entreprises.raison_sociale)::text) || ' '::text) || (entreprises.siret_siege_social)::text) || ' '::text) || (entreprises.nom)::text) || ' '::text) || (entreprises.prenom)::text) || ' '::text) || (rna_informations.association_id)::text) || ' '::text) || (rna_informations.titre)::text) || ' '::text) || rna_informations.objet) AS term - FROM (entreprises - JOIN rna_informations ON ((rna_informations.entreprise_id = entreprises.id))) - UNION - SELECT etablissements.dossier_id, - (((((((((((((etablissements.siret)::text || ' '::text) || (etablissements.naf)::text) || ' '::text) || (etablissements.libelle_naf)::text) || ' '::text) || (etablissements.adresse)::text) || ' '::text) || (etablissements.code_postal)::text) || ' '::text) || (etablissements.localite)::text) || ' '::text) || (etablissements.code_insee_localite)::text) AS term - FROM etablissements - UNION - SELECT individuals.dossier_id, - (((individuals.nom)::text || ' '::text) || (individuals.prenom)::text) AS term - FROM individuals - UNION - SELECT pieces_justificatives.dossier_id, - pieces_justificatives.content AS term - FROM pieces_justificatives - UNION - SELECT dossiers.id AS dossier_id, - (((france_connect_informations.given_name)::text || ' '::text) || (france_connect_informations.family_name)::text) AS term - FROM (france_connect_informations - JOIN dossiers ON ((dossiers.user_id = france_connect_informations.user_id))); - SQL - -end diff --git a/db/structure.sql b/db/structure.sql new file mode 100644 index 000000000..cd6223a91 --- /dev/null +++ b/db/structure.sql @@ -0,0 +1,2077 @@ +-- +-- PostgreSQL database dump +-- + +-- Dumped from database version 9.5.4 +-- Dumped by pg_dump version 9.5.4 + +SET statement_timeout = 0; +SET lock_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SET check_function_bodies = false; +SET client_min_messages = warning; +SET row_security = off; + +-- +-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: - +-- + +CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; + + +-- +-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: - +-- + +COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; + + +SET search_path = public, pg_catalog; + +SET default_tablespace = ''; + +SET default_with_oids = false; + +-- +-- Name: administrateurs; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE administrateurs ( + id integer NOT NULL, + email character varying DEFAULT ''::character varying NOT NULL, + encrypted_password character varying DEFAULT ''::character varying NOT NULL, + reset_password_token character varying, + reset_password_sent_at timestamp without time zone, + remember_created_at timestamp without time zone, + sign_in_count integer DEFAULT 0 NOT NULL, + current_sign_in_at timestamp without time zone, + last_sign_in_at timestamp without time zone, + current_sign_in_ip inet, + last_sign_in_ip inet, + created_at timestamp without time zone, + updated_at timestamp without time zone, + api_token character varying +); + + +-- +-- Name: administrateurs_gestionnaires; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE administrateurs_gestionnaires ( + administrateur_id integer, + gestionnaire_id integer +); + + +-- +-- Name: administrateurs_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE administrateurs_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: administrateurs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE administrateurs_id_seq OWNED BY administrateurs.id; + + +-- +-- Name: administrations; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE administrations ( + id integer NOT NULL, + email character varying DEFAULT ''::character varying NOT NULL, + encrypted_password character varying DEFAULT ''::character varying NOT NULL, + reset_password_token character varying, + reset_password_sent_at timestamp without time zone, + remember_created_at timestamp without time zone, + sign_in_count integer DEFAULT 0 NOT NULL, + current_sign_in_at timestamp without time zone, + last_sign_in_at timestamp without time zone, + current_sign_in_ip inet, + last_sign_in_ip inet, + created_at timestamp without time zone, + updated_at timestamp without time zone +); + + +-- +-- Name: administrations_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE administrations_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: administrations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE administrations_id_seq OWNED BY administrations.id; + + +-- +-- Name: assign_tos; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE assign_tos ( + gestionnaire_id integer, + procedure_id integer +); + + +-- +-- Name: cadastres; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE cadastres ( + id integer NOT NULL, + surface_intersection character varying, + surface_parcelle double precision, + numero character varying, + feuille integer, + section character varying, + code_dep character varying, + nom_com character varying, + code_com character varying, + code_arr character varying, + geometry text, + dossier_id integer +); + + +-- +-- Name: cadastres_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE cadastres_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: cadastres_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE cadastres_id_seq OWNED BY cadastres.id; + + +-- +-- Name: cerfas; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE cerfas ( + id integer NOT NULL, + content character varying, + dossier_id integer, + created_at timestamp without time zone, + user_id integer, + original_filename character varying, + content_secure_token character varying +); + + +-- +-- Name: cerfas_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE cerfas_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: cerfas_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE cerfas_id_seq OWNED BY cerfas.id; + + +-- +-- Name: champs; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE champs ( + id integer NOT NULL, + value character varying, + type_de_champ_id integer, + dossier_id integer, + type character varying +); + + +-- +-- Name: champs_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE champs_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: champs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE champs_id_seq OWNED BY champs.id; + + +-- +-- Name: commentaires; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE commentaires ( + id integer NOT NULL, + email character varying, + created_at timestamp without time zone NOT NULL, + body character varying, + dossier_id integer, + updated_at timestamp without time zone NOT NULL, + piece_justificative_id integer +); + + +-- +-- Name: commentaires_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE commentaires_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: commentaires_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE commentaires_id_seq OWNED BY commentaires.id; + + +-- +-- Name: dossiers; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE dossiers ( + id integer NOT NULL, + autorisation_donnees boolean, + nom_projet character varying, + procedure_id integer, + created_at timestamp without time zone, + updated_at timestamp without time zone, + state character varying, + user_id integer, + json_latlngs text, + archived boolean DEFAULT false, + mandataire_social boolean DEFAULT false, + deposit_datetime timestamp without time zone +); + + +-- +-- Name: dossiers_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE dossiers_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: dossiers_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE dossiers_id_seq OWNED BY dossiers.id; + + +-- +-- Name: drop_down_lists; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE drop_down_lists ( + id integer NOT NULL, + value character varying, + type_de_champ_id integer +); + + +-- +-- Name: drop_down_lists_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE drop_down_lists_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: drop_down_lists_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE drop_down_lists_id_seq OWNED BY drop_down_lists.id; + + +-- +-- Name: entreprises; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE entreprises ( + id integer NOT NULL, + siren character varying, + capital_social integer, + numero_tva_intracommunautaire character varying, + forme_juridique character varying, + forme_juridique_code character varying, + nom_commercial character varying, + raison_sociale character varying, + siret_siege_social character varying, + code_effectif_entreprise character varying, + date_creation timestamp without time zone, + nom character varying, + prenom character varying, + dossier_id integer +); + + +-- +-- Name: entreprises_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE entreprises_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: entreprises_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE entreprises_id_seq OWNED BY entreprises.id; + + +-- +-- Name: etablissements; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE etablissements ( + id integer NOT NULL, + siret character varying, + siege_social boolean, + naf character varying, + libelle_naf character varying, + adresse character varying, + numero_voie character varying, + type_voie character varying, + nom_voie character varying, + complement_adresse character varying, + code_postal character varying, + localite character varying, + code_insee_localite character varying, + dossier_id integer, + entreprise_id integer +); + + +-- +-- Name: etablissements_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE etablissements_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: etablissements_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE etablissements_id_seq OWNED BY etablissements.id; + + +-- +-- Name: exercices; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE exercices ( + id integer NOT NULL, + ca character varying, + "dateFinExercice" timestamp without time zone, + date_fin_exercice_timestamp integer, + etablissement_id integer +); + + +-- +-- Name: exercices_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE exercices_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: exercices_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE exercices_id_seq OWNED BY exercices.id; + + +-- +-- Name: follows; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE follows ( + id integer NOT NULL, + gestionnaire_id integer, + dossier_id integer +); + + +-- +-- Name: follows_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE follows_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: follows_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE follows_id_seq OWNED BY follows.id; + + +-- +-- Name: france_connect_informations; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE france_connect_informations ( + id integer NOT NULL, + gender character varying, + given_name character varying, + family_name character varying, + birthdate date, + birthplace character varying, + france_connect_particulier_id character varying, + user_id integer, + email_france_connect character varying +); + + +-- +-- Name: france_connect_informations_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE france_connect_informations_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: france_connect_informations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE france_connect_informations_id_seq OWNED BY france_connect_informations.id; + + +-- +-- Name: gestionnaires; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE gestionnaires ( + id integer NOT NULL, + email character varying DEFAULT ''::character varying NOT NULL, + encrypted_password character varying DEFAULT ''::character varying NOT NULL, + reset_password_token character varying, + reset_password_sent_at timestamp without time zone, + remember_created_at timestamp without time zone, + sign_in_count integer DEFAULT 0 NOT NULL, + current_sign_in_at timestamp without time zone, + last_sign_in_at timestamp without time zone, + current_sign_in_ip inet, + last_sign_in_ip inet, + created_at timestamp without time zone, + updated_at timestamp without time zone, + procedure_filter integer +); + + +-- +-- Name: gestionnaires_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE gestionnaires_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: gestionnaires_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE gestionnaires_id_seq OWNED BY gestionnaires.id; + + +-- +-- Name: individuals; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE individuals ( + id integer NOT NULL, + nom character varying, + prenom character varying, + birthdate character varying, + dossier_id integer, + gender character varying +); + + +-- +-- Name: individuals_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE individuals_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: individuals_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE individuals_id_seq OWNED BY individuals.id; + + +-- +-- Name: invites; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE invites ( + id integer NOT NULL, + email character varying, + email_sender character varying, + dossier_id integer, + user_id integer, + type character varying DEFAULT 'InviteGestionnaire'::character varying +); + + +-- +-- Name: invites_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE invites_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: invites_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE invites_id_seq OWNED BY invites.id; + + +-- +-- Name: mail_templates; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE mail_templates ( + id integer NOT NULL, + object character varying, + body text, + type character varying, + procedure_id integer +); + + +-- +-- Name: mail_templates_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE mail_templates_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: mail_templates_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE mail_templates_id_seq OWNED BY mail_templates.id; + + +-- +-- Name: module_api_cartos; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE module_api_cartos ( + id integer NOT NULL, + procedure_id integer, + use_api_carto boolean DEFAULT false, + quartiers_prioritaires boolean DEFAULT false, + cadastre boolean DEFAULT false +); + + +-- +-- Name: module_api_cartos_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE module_api_cartos_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: module_api_cartos_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE module_api_cartos_id_seq OWNED BY module_api_cartos.id; + + +-- +-- Name: pieces_justificatives; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE pieces_justificatives ( + id integer NOT NULL, + content character varying, + dossier_id integer, + type_de_piece_justificative_id integer, + created_at timestamp without time zone, + user_id integer, + original_filename character varying, + content_secure_token character varying +); + + +-- +-- Name: pieces_justificatives_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE pieces_justificatives_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: pieces_justificatives_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE pieces_justificatives_id_seq OWNED BY pieces_justificatives.id; + + +-- +-- Name: preference_list_dossiers; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE preference_list_dossiers ( + id integer NOT NULL, + libelle character varying, + "table" character varying, + attr character varying, + attr_decorate character varying, + bootstrap_lg character varying, + "order" character varying, + filter character varying, + gestionnaire_id integer, + procedure_id integer +); + + +-- +-- Name: preference_list_dossiers_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE preference_list_dossiers_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: preference_list_dossiers_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE preference_list_dossiers_id_seq OWNED BY preference_list_dossiers.id; + + +-- +-- Name: preference_smart_listing_pages; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE preference_smart_listing_pages ( + id integer NOT NULL, + liste character varying, + page integer, + procedure_id integer, + gestionnaire_id integer +); + + +-- +-- Name: preference_smart_listing_pages_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE preference_smart_listing_pages_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: preference_smart_listing_pages_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE preference_smart_listing_pages_id_seq OWNED BY preference_smart_listing_pages.id; + + +-- +-- Name: procedure_paths; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE procedure_paths ( + id integer NOT NULL, + path character varying(30), + procedure_id integer, + administrateur_id integer +); + + +-- +-- Name: procedure_paths_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE procedure_paths_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: procedure_paths_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE procedure_paths_id_seq OWNED BY procedure_paths.id; + + +-- +-- Name: procedures; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE procedures ( + id integer NOT NULL, + libelle character varying, + description character varying, + organisation character varying, + direction character varying, + lien_demarche character varying, + created_at timestamp without time zone NOT NULL, + updated_at timestamp without time zone NOT NULL, + test boolean, + administrateur_id integer, + archived boolean DEFAULT false, + euro_flag boolean DEFAULT false, + logo character varying, + cerfa_flag boolean DEFAULT false, + logo_secure_token character varying, + published boolean DEFAULT false NOT NULL, + lien_site_web character varying, + lien_notice character varying, + for_individual boolean DEFAULT false, + individual_with_siret boolean DEFAULT false +); + + +-- +-- Name: procedures_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE procedures_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: procedures_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE procedures_id_seq OWNED BY procedures.id; + + +-- +-- Name: quartier_prioritaires; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE quartier_prioritaires ( + id integer NOT NULL, + code character varying, + nom character varying, + commune character varying, + geometry text, + dossier_id integer +); + + +-- +-- Name: quartier_prioritaires_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE quartier_prioritaires_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: quartier_prioritaires_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE quartier_prioritaires_id_seq OWNED BY quartier_prioritaires.id; + + +-- +-- Name: rna_informations; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE rna_informations ( + id integer NOT NULL, + association_id character varying, + titre character varying, + objet text, + date_creation date, + date_declaration date, + date_publication date, + entreprise_id integer +); + + +-- +-- Name: rna_informations_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE rna_informations_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: rna_informations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE rna_informations_id_seq OWNED BY rna_informations.id; + + +-- +-- Name: schema_migrations; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE schema_migrations ( + version character varying NOT NULL +); + + +-- +-- Name: searches; Type: MATERIALIZED VIEW; Schema: public; Owner: - +-- + +CREATE MATERIALIZED VIEW searches AS + SELECT dossiers.id AS dossier_id, + (dossiers.id)::text AS term + FROM dossiers +UNION + SELECT cerfas.dossier_id, + cerfas.content AS term + FROM cerfas +UNION + SELECT champs.dossier_id, + (((champs.value)::text || ' '::text) || (drop_down_lists.value)::text) AS term + FROM (champs + JOIN drop_down_lists ON ((drop_down_lists.type_de_champ_id = champs.type_de_champ_id))) +UNION + SELECT entreprises.dossier_id, + (((((((((((((((((((((((entreprises.siren)::text || ' '::text) || (entreprises.numero_tva_intracommunautaire)::text) || ' '::text) || (entreprises.forme_juridique)::text) || ' '::text) || (entreprises.forme_juridique_code)::text) || ' '::text) || (entreprises.nom_commercial)::text) || ' '::text) || (entreprises.raison_sociale)::text) || ' '::text) || (entreprises.siret_siege_social)::text) || ' '::text) || (entreprises.nom)::text) || ' '::text) || (entreprises.prenom)::text) || ' '::text) || (rna_informations.association_id)::text) || ' '::text) || (rna_informations.titre)::text) || ' '::text) || rna_informations.objet) AS term + FROM (entreprises + JOIN rna_informations ON ((rna_informations.entreprise_id = entreprises.id))) +UNION + SELECT etablissements.dossier_id, + (((((((((((((etablissements.siret)::text || ' '::text) || (etablissements.naf)::text) || ' '::text) || (etablissements.libelle_naf)::text) || ' '::text) || (etablissements.adresse)::text) || ' '::text) || (etablissements.code_postal)::text) || ' '::text) || (etablissements.localite)::text) || ' '::text) || (etablissements.code_insee_localite)::text) AS term + FROM etablissements +UNION + SELECT individuals.dossier_id, + (((individuals.nom)::text || ' '::text) || (individuals.prenom)::text) AS term + FROM individuals +UNION + SELECT pieces_justificatives.dossier_id, + pieces_justificatives.content AS term + FROM pieces_justificatives +UNION + SELECT dossiers.id AS dossier_id, + (((france_connect_informations.given_name)::text || ' '::text) || (france_connect_informations.family_name)::text) AS term + FROM (france_connect_informations + JOIN dossiers ON ((dossiers.user_id = france_connect_informations.user_id))) + WITH NO DATA; + + +-- +-- Name: types_de_champ; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE types_de_champ ( + id integer NOT NULL, + libelle character varying, + type_champ character varying, + order_place integer, + procedure_id integer, + description text, + mandatory boolean DEFAULT false, + type character varying +); + + +-- +-- Name: types_de_champ_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE types_de_champ_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: types_de_champ_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE types_de_champ_id_seq OWNED BY types_de_champ.id; + + +-- +-- Name: types_de_piece_justificative; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE types_de_piece_justificative ( + id integer NOT NULL, + libelle character varying, + description character varying, + api_entreprise boolean DEFAULT false, + created_at timestamp without time zone NOT NULL, + updated_at timestamp without time zone NOT NULL, + procedure_id integer, + order_place integer +); + + +-- +-- Name: types_de_piece_justificative_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE types_de_piece_justificative_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: types_de_piece_justificative_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE types_de_piece_justificative_id_seq OWNED BY types_de_piece_justificative.id; + + +-- +-- Name: users; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE users ( + id integer NOT NULL, + email character varying DEFAULT ''::character varying NOT NULL, + encrypted_password character varying DEFAULT ''::character varying NOT NULL, + reset_password_token character varying, + reset_password_sent_at timestamp without time zone, + remember_created_at timestamp without time zone, + sign_in_count integer DEFAULT 0 NOT NULL, + current_sign_in_at timestamp without time zone, + last_sign_in_at timestamp without time zone, + current_sign_in_ip inet, + last_sign_in_ip inet, + created_at timestamp without time zone, + updated_at timestamp without time zone, + siret character varying, + loged_in_with_france_connect character varying DEFAULT false +); + + +-- +-- Name: users_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE users_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: users_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE users_id_seq OWNED BY users.id; + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY administrateurs ALTER COLUMN id SET DEFAULT nextval('administrateurs_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY administrations ALTER COLUMN id SET DEFAULT nextval('administrations_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY cadastres ALTER COLUMN id SET DEFAULT nextval('cadastres_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY cerfas ALTER COLUMN id SET DEFAULT nextval('cerfas_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY champs ALTER COLUMN id SET DEFAULT nextval('champs_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY commentaires ALTER COLUMN id SET DEFAULT nextval('commentaires_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY dossiers ALTER COLUMN id SET DEFAULT nextval('dossiers_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY drop_down_lists ALTER COLUMN id SET DEFAULT nextval('drop_down_lists_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY entreprises ALTER COLUMN id SET DEFAULT nextval('entreprises_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY etablissements ALTER COLUMN id SET DEFAULT nextval('etablissements_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY exercices ALTER COLUMN id SET DEFAULT nextval('exercices_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY follows ALTER COLUMN id SET DEFAULT nextval('follows_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY france_connect_informations ALTER COLUMN id SET DEFAULT nextval('france_connect_informations_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY gestionnaires ALTER COLUMN id SET DEFAULT nextval('gestionnaires_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY individuals ALTER COLUMN id SET DEFAULT nextval('individuals_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY invites ALTER COLUMN id SET DEFAULT nextval('invites_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY mail_templates ALTER COLUMN id SET DEFAULT nextval('mail_templates_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY module_api_cartos ALTER COLUMN id SET DEFAULT nextval('module_api_cartos_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY pieces_justificatives ALTER COLUMN id SET DEFAULT nextval('pieces_justificatives_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY preference_list_dossiers ALTER COLUMN id SET DEFAULT nextval('preference_list_dossiers_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY preference_smart_listing_pages ALTER COLUMN id SET DEFAULT nextval('preference_smart_listing_pages_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY procedure_paths ALTER COLUMN id SET DEFAULT nextval('procedure_paths_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY procedures ALTER COLUMN id SET DEFAULT nextval('procedures_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY quartier_prioritaires ALTER COLUMN id SET DEFAULT nextval('quartier_prioritaires_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY rna_informations ALTER COLUMN id SET DEFAULT nextval('rna_informations_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY types_de_champ ALTER COLUMN id SET DEFAULT nextval('types_de_champ_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY types_de_piece_justificative ALTER COLUMN id SET DEFAULT nextval('types_de_piece_justificative_id_seq'::regclass); + + +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY users ALTER COLUMN id SET DEFAULT nextval('users_id_seq'::regclass); + + +-- +-- Name: administrateurs_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY administrateurs + ADD CONSTRAINT administrateurs_pkey PRIMARY KEY (id); + + +-- +-- Name: administrations_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY administrations + ADD CONSTRAINT administrations_pkey PRIMARY KEY (id); + + +-- +-- Name: cadastres_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY cadastres + ADD CONSTRAINT cadastres_pkey PRIMARY KEY (id); + + +-- +-- Name: cerfas_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY cerfas + ADD CONSTRAINT cerfas_pkey PRIMARY KEY (id); + + +-- +-- Name: champs_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY champs + ADD CONSTRAINT champs_pkey PRIMARY KEY (id); + + +-- +-- Name: commentaires_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY commentaires + ADD CONSTRAINT commentaires_pkey PRIMARY KEY (id); + + +-- +-- Name: dossiers_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY dossiers + ADD CONSTRAINT dossiers_pkey PRIMARY KEY (id); + + +-- +-- Name: drop_down_lists_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY drop_down_lists + ADD CONSTRAINT drop_down_lists_pkey PRIMARY KEY (id); + + +-- +-- Name: entreprises_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY entreprises + ADD CONSTRAINT entreprises_pkey PRIMARY KEY (id); + + +-- +-- Name: etablissements_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY etablissements + ADD CONSTRAINT etablissements_pkey PRIMARY KEY (id); + + +-- +-- Name: exercices_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY exercices + ADD CONSTRAINT exercices_pkey PRIMARY KEY (id); + + +-- +-- Name: follows_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY follows + ADD CONSTRAINT follows_pkey PRIMARY KEY (id); + + +-- +-- Name: france_connect_informations_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY france_connect_informations + ADD CONSTRAINT france_connect_informations_pkey PRIMARY KEY (id); + + +-- +-- Name: gestionnaires_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY gestionnaires + ADD CONSTRAINT gestionnaires_pkey PRIMARY KEY (id); + + +-- +-- Name: individuals_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY individuals + ADD CONSTRAINT individuals_pkey PRIMARY KEY (id); + + +-- +-- Name: invites_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY invites + ADD CONSTRAINT invites_pkey PRIMARY KEY (id); + + +-- +-- Name: mail_templates_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY mail_templates + ADD CONSTRAINT mail_templates_pkey PRIMARY KEY (id); + + +-- +-- Name: module_api_cartos_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY module_api_cartos + ADD CONSTRAINT module_api_cartos_pkey PRIMARY KEY (id); + + +-- +-- Name: pieces_justificatives_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY pieces_justificatives + ADD CONSTRAINT pieces_justificatives_pkey PRIMARY KEY (id); + + +-- +-- Name: preference_list_dossiers_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY preference_list_dossiers + ADD CONSTRAINT preference_list_dossiers_pkey PRIMARY KEY (id); + + +-- +-- Name: preference_smart_listing_pages_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY preference_smart_listing_pages + ADD CONSTRAINT preference_smart_listing_pages_pkey PRIMARY KEY (id); + + +-- +-- Name: procedure_paths_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY procedure_paths + ADD CONSTRAINT procedure_paths_pkey PRIMARY KEY (id); + + +-- +-- Name: procedures_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY procedures + ADD CONSTRAINT procedures_pkey PRIMARY KEY (id); + + +-- +-- Name: quartier_prioritaires_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY quartier_prioritaires + ADD CONSTRAINT quartier_prioritaires_pkey PRIMARY KEY (id); + + +-- +-- Name: rna_informations_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY rna_informations + ADD CONSTRAINT rna_informations_pkey PRIMARY KEY (id); + + +-- +-- Name: types_de_champ_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY types_de_champ + ADD CONSTRAINT types_de_champ_pkey PRIMARY KEY (id); + + +-- +-- Name: types_de_piece_justificative_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY types_de_piece_justificative + ADD CONSTRAINT types_de_piece_justificative_pkey PRIMARY KEY (id); + + +-- +-- Name: users_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY users + ADD CONSTRAINT users_pkey PRIMARY KEY (id); + + +-- +-- Name: index_administrateurs_gestionnaires_on_administrateur_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_administrateurs_gestionnaires_on_administrateur_id ON administrateurs_gestionnaires USING btree (administrateur_id); + + +-- +-- Name: index_administrateurs_gestionnaires_on_gestionnaire_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_administrateurs_gestionnaires_on_gestionnaire_id ON administrateurs_gestionnaires USING btree (gestionnaire_id); + + +-- +-- Name: index_administrateurs_on_email; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_administrateurs_on_email ON administrateurs USING btree (email); + + +-- +-- Name: index_administrateurs_on_reset_password_token; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_administrateurs_on_reset_password_token ON administrateurs USING btree (reset_password_token); + + +-- +-- Name: index_administrations_on_email; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_administrations_on_email ON administrations USING btree (email); + + +-- +-- Name: index_administrations_on_reset_password_token; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_administrations_on_reset_password_token ON administrations USING btree (reset_password_token); + + +-- +-- Name: index_assign_tos_on_gestionnaire_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_assign_tos_on_gestionnaire_id ON assign_tos USING btree (gestionnaire_id); + + +-- +-- Name: index_assign_tos_on_procedure_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_assign_tos_on_procedure_id ON assign_tos USING btree (procedure_id); + + +-- +-- Name: index_cerfas_on_dossier_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_cerfas_on_dossier_id ON cerfas USING btree (dossier_id); + + +-- +-- Name: index_champs_on_dossier_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_champs_on_dossier_id ON champs USING btree (dossier_id); + + +-- +-- Name: index_champs_on_type_de_champ_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_champs_on_type_de_champ_id ON champs USING btree (type_de_champ_id); + + +-- +-- Name: index_commentaires_on_dossier_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_commentaires_on_dossier_id ON commentaires USING btree (dossier_id); + + +-- +-- Name: index_dossiers_on_procedure_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_dossiers_on_procedure_id ON dossiers USING btree (procedure_id); + + +-- +-- Name: index_dossiers_on_user_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_dossiers_on_user_id ON dossiers USING btree (user_id); + + +-- +-- Name: index_drop_down_lists_on_type_de_champ_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_drop_down_lists_on_type_de_champ_id ON drop_down_lists USING btree (type_de_champ_id); + + +-- +-- Name: index_entreprises_on_dossier_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_entreprises_on_dossier_id ON entreprises USING btree (dossier_id); + + +-- +-- Name: index_etablissements_on_dossier_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_etablissements_on_dossier_id ON etablissements USING btree (dossier_id); + + +-- +-- Name: index_follows_on_dossier_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_follows_on_dossier_id ON follows USING btree (dossier_id); + + +-- +-- Name: index_follows_on_gestionnaire_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_follows_on_gestionnaire_id ON follows USING btree (gestionnaire_id); + + +-- +-- Name: index_france_connect_informations_on_user_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_france_connect_informations_on_user_id ON france_connect_informations USING btree (user_id); + + +-- +-- Name: index_gestionnaires_on_email; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_gestionnaires_on_email ON gestionnaires USING btree (email); + + +-- +-- Name: index_gestionnaires_on_reset_password_token; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_gestionnaires_on_reset_password_token ON gestionnaires USING btree (reset_password_token); + + +-- +-- Name: index_individuals_on_dossier_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_individuals_on_dossier_id ON individuals USING btree (dossier_id); + + +-- +-- Name: index_module_api_cartos_on_procedure_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_module_api_cartos_on_procedure_id ON module_api_cartos USING btree (procedure_id); + + +-- +-- Name: index_pieces_justificatives_on_dossier_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_pieces_justificatives_on_dossier_id ON pieces_justificatives USING btree (dossier_id); + + +-- +-- Name: index_pieces_justificatives_on_type_de_piece_justificative_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_pieces_justificatives_on_type_de_piece_justificative_id ON pieces_justificatives USING btree (type_de_piece_justificative_id); + + +-- +-- Name: index_procedure_paths_on_path; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_procedure_paths_on_path ON procedure_paths USING btree (path); + + +-- +-- Name: index_rna_informations_on_entreprise_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_rna_informations_on_entreprise_id ON rna_informations USING btree (entreprise_id); + + +-- +-- Name: index_users_on_email; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_users_on_email ON users USING btree (email); + + +-- +-- Name: index_users_on_reset_password_token; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_users_on_reset_password_token ON users USING btree (reset_password_token); + + +-- +-- Name: unique_couple_administrateur_gestionnaire; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX unique_couple_administrateur_gestionnaire ON administrateurs_gestionnaires USING btree (gestionnaire_id, administrateur_id); + + +-- +-- Name: unique_schema_migrations; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX unique_schema_migrations ON schema_migrations USING btree (version); + + +-- +-- Name: fk_rails_2692c11f42; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY cerfas + ADD CONSTRAINT fk_rails_2692c11f42 FOREIGN KEY (dossier_id) REFERENCES dossiers(id); + + +-- +-- Name: fk_rails_3ba5f624df; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY procedure_paths + ADD CONSTRAINT fk_rails_3ba5f624df FOREIGN KEY (administrateur_id) REFERENCES administrateurs(id); + + +-- +-- Name: fk_rails_7238f4c1f2; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY procedure_paths + ADD CONSTRAINT fk_rails_7238f4c1f2 FOREIGN KEY (procedure_id) REFERENCES procedures(id); + + +-- +-- Name: fk_rails_7a18851d0c; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY dossiers + ADD CONSTRAINT fk_rails_7a18851d0c FOREIGN KEY (user_id) REFERENCES users(id); + + +-- +-- Name: fk_rails_e74708c22b; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY commentaires + ADD CONSTRAINT fk_rails_e74708c22b FOREIGN KEY (dossier_id) REFERENCES dossiers(id); + + +-- +-- PostgreSQL database dump complete +-- + +SET search_path TO "$user", public; + +INSERT INTO schema_migrations (version) VALUES ('20150623121437'); + +INSERT INTO schema_migrations (version) VALUES ('20150623122513'); + +INSERT INTO schema_migrations (version) VALUES ('20150623123033'); + +INSERT INTO schema_migrations (version) VALUES ('20150624134202'); + +INSERT INTO schema_migrations (version) VALUES ('20150624145400'); + +INSERT INTO schema_migrations (version) VALUES ('20150625130851'); + +INSERT INTO schema_migrations (version) VALUES ('20150626081655'); + +INSERT INTO schema_migrations (version) VALUES ('20150630123827'); + +INSERT INTO schema_migrations (version) VALUES ('20150728140340'); + +INSERT INTO schema_migrations (version) VALUES ('20150731121101'); + +INSERT INTO schema_migrations (version) VALUES ('20150804131511'); + +INSERT INTO schema_migrations (version) VALUES ('20150805081131'); + +INSERT INTO schema_migrations (version) VALUES ('20150806071130'); + +INSERT INTO schema_migrations (version) VALUES ('20150806072031'); + +INSERT INTO schema_migrations (version) VALUES ('20150806075144'); + +INSERT INTO schema_migrations (version) VALUES ('20150806132417'); + +INSERT INTO schema_migrations (version) VALUES ('20150806155734'); + +INSERT INTO schema_migrations (version) VALUES ('20150806162353'); + +INSERT INTO schema_migrations (version) VALUES ('20150810130957'); + +INSERT INTO schema_migrations (version) VALUES ('20150812091703'); + +INSERT INTO schema_migrations (version) VALUES ('20150813095218'); + +INSERT INTO schema_migrations (version) VALUES ('20150813095939'); + +INSERT INTO schema_migrations (version) VALUES ('20150814090717'); + +INSERT INTO schema_migrations (version) VALUES ('20150814101012'); + +INSERT INTO schema_migrations (version) VALUES ('20150814120635'); + +INSERT INTO schema_migrations (version) VALUES ('20150814121848'); + +INSERT INTO schema_migrations (version) VALUES ('20150814122208'); + +INSERT INTO schema_migrations (version) VALUES ('20150814124735'); + +INSERT INTO schema_migrations (version) VALUES ('20150818113123'); + +INSERT INTO schema_migrations (version) VALUES ('20150824134012'); + +INSERT INTO schema_migrations (version) VALUES ('20150825083550'); + +INSERT INTO schema_migrations (version) VALUES ('20150918163159'); + +INSERT INTO schema_migrations (version) VALUES ('20150921085540'); + +INSERT INTO schema_migrations (version) VALUES ('20150921085754'); + +INSERT INTO schema_migrations (version) VALUES ('20150921092320'); + +INSERT INTO schema_migrations (version) VALUES ('20150921092536'); + +INSERT INTO schema_migrations (version) VALUES ('20150921101240'); + +INSERT INTO schema_migrations (version) VALUES ('20150922082053'); + +INSERT INTO schema_migrations (version) VALUES ('20150922082416'); + +INSERT INTO schema_migrations (version) VALUES ('20150922085811'); + +INSERT INTO schema_migrations (version) VALUES ('20150922110719'); + +INSERT INTO schema_migrations (version) VALUES ('20150922113504'); + +INSERT INTO schema_migrations (version) VALUES ('20150922141000'); + +INSERT INTO schema_migrations (version) VALUES ('20150922141232'); + +INSERT INTO schema_migrations (version) VALUES ('20150923101000'); + +INSERT INTO schema_migrations (version) VALUES ('20150928141512'); + +INSERT INTO schema_migrations (version) VALUES ('20151006155256'); + +INSERT INTO schema_migrations (version) VALUES ('20151007085022'); + +INSERT INTO schema_migrations (version) VALUES ('20151008090835'); + +INSERT INTO schema_migrations (version) VALUES ('20151023132121'); + +INSERT INTO schema_migrations (version) VALUES ('20151026155158'); + +INSERT INTO schema_migrations (version) VALUES ('20151027150850'); + +INSERT INTO schema_migrations (version) VALUES ('20151102101616'); + +INSERT INTO schema_migrations (version) VALUES ('20151102102747'); + +INSERT INTO schema_migrations (version) VALUES ('20151102104309'); + +INSERT INTO schema_migrations (version) VALUES ('20151102105011'); + +INSERT INTO schema_migrations (version) VALUES ('20151102135824'); + +INSERT INTO schema_migrations (version) VALUES ('20151102142940'); + +INSERT INTO schema_migrations (version) VALUES ('20151102143908'); + +INSERT INTO schema_migrations (version) VALUES ('20151102163051'); + +INSERT INTO schema_migrations (version) VALUES ('20151103091603'); + +INSERT INTO schema_migrations (version) VALUES ('20151105093644'); + +INSERT INTO schema_migrations (version) VALUES ('20151105095431'); + +INSERT INTO schema_migrations (version) VALUES ('20151110091159'); + +INSERT INTO schema_migrations (version) VALUES ('20151110091451'); + +INSERT INTO schema_migrations (version) VALUES ('20151112151918'); + +INSERT INTO schema_migrations (version) VALUES ('20151113171605'); + +INSERT INTO schema_migrations (version) VALUES ('20151116175817'); + +INSERT INTO schema_migrations (version) VALUES ('20151124085333'); + +INSERT INTO schema_migrations (version) VALUES ('20151126153425'); + +INSERT INTO schema_migrations (version) VALUES ('20151127103412'); + +INSERT INTO schema_migrations (version) VALUES ('20151207095904'); + +INSERT INTO schema_migrations (version) VALUES ('20151207140202'); + +INSERT INTO schema_migrations (version) VALUES ('20151210134135'); + +INSERT INTO schema_migrations (version) VALUES ('20151210150958'); + +INSERT INTO schema_migrations (version) VALUES ('20151211093833'); + +INSERT INTO schema_migrations (version) VALUES ('20151214133426'); + +INSERT INTO schema_migrations (version) VALUES ('20151221164041'); + +INSERT INTO schema_migrations (version) VALUES ('20151222105558'); + +INSERT INTO schema_migrations (version) VALUES ('20151223101322'); + +INSERT INTO schema_migrations (version) VALUES ('20160106100227'); + +INSERT INTO schema_migrations (version) VALUES ('20160115135025'); + +INSERT INTO schema_migrations (version) VALUES ('20160120094750'); + +INSERT INTO schema_migrations (version) VALUES ('20160120141602'); + +INSERT INTO schema_migrations (version) VALUES ('20160121110603'); + +INSERT INTO schema_migrations (version) VALUES ('20160127162841'); + +INSERT INTO schema_migrations (version) VALUES ('20160127170437'); + +INSERT INTO schema_migrations (version) VALUES ('20160204155519'); + +INSERT INTO schema_migrations (version) VALUES ('20160223134354'); + +INSERT INTO schema_migrations (version) VALUES ('20160314102523'); + +INSERT INTO schema_migrations (version) VALUES ('20160314160801'); + +INSERT INTO schema_migrations (version) VALUES ('20160314161959'); + +INSERT INTO schema_migrations (version) VALUES ('20160315101245'); + +INSERT INTO schema_migrations (version) VALUES ('20160317135217'); + +INSERT INTO schema_migrations (version) VALUES ('20160317144949'); + +INSERT INTO schema_migrations (version) VALUES ('20160317153115'); + +INSERT INTO schema_migrations (version) VALUES ('20160419142017'); + +INSERT INTO schema_migrations (version) VALUES ('20160512160602'); + +INSERT INTO schema_migrations (version) VALUES ('20160512160658'); + +INSERT INTO schema_migrations (version) VALUES ('20160512160824'); + +INSERT INTO schema_migrations (version) VALUES ('20160512160836'); + +INSERT INTO schema_migrations (version) VALUES ('20160513093425'); + +INSERT INTO schema_migrations (version) VALUES ('20160519100904'); + +INSERT INTO schema_migrations (version) VALUES ('20160519101018'); + +INSERT INTO schema_migrations (version) VALUES ('20160523163054'); + +INSERT INTO schema_migrations (version) VALUES ('20160524093540'); + +INSERT INTO schema_migrations (version) VALUES ('20160607150440'); + +INSERT INTO schema_migrations (version) VALUES ('20160609125949'); + +INSERT INTO schema_migrations (version) VALUES ('20160609145737'); + +INSERT INTO schema_migrations (version) VALUES ('20160622081321'); + +INSERT INTO schema_migrations (version) VALUES ('20160622081322'); + +INSERT INTO schema_migrations (version) VALUES ('20160718124741'); + +INSERT INTO schema_migrations (version) VALUES ('20160722135927'); + +INSERT INTO schema_migrations (version) VALUES ('20160802113112'); + +INSERT INTO schema_migrations (version) VALUES ('20160802131031'); + +INSERT INTO schema_migrations (version) VALUES ('20160802161734'); + +INSERT INTO schema_migrations (version) VALUES ('20160803081304'); + +INSERT INTO schema_migrations (version) VALUES ('20160804130638'); + +INSERT INTO schema_migrations (version) VALUES ('20160808115924'); + +INSERT INTO schema_migrations (version) VALUES ('20160809083606'); + +INSERT INTO schema_migrations (version) VALUES ('20160822142045'); + +INSERT INTO schema_migrations (version) VALUES ('20160824094151'); + +INSERT INTO schema_migrations (version) VALUES ('20160824094451'); + +INSERT INTO schema_migrations (version) VALUES ('20160829094658'); + +INSERT INTO schema_migrations (version) VALUES ('20160829114646'); + +INSERT INTO schema_migrations (version) VALUES ('20160830142653'); + +INSERT INTO schema_migrations (version) VALUES ('20160901082824'); + +INSERT INTO schema_migrations (version) VALUES ('20160906123255'); + +INSERT INTO schema_migrations (version) VALUES ('20160906134155'); + +INSERT INTO schema_migrations (version) VALUES ('20160913093948'); + +INSERT INTO schema_migrations (version) VALUES ('20160926160051'); + +INSERT INTO schema_migrations (version) VALUES ('20160927154248'); + +INSERT INTO schema_migrations (version) VALUES ('20161004175442'); + +INSERT INTO schema_migrations (version) VALUES ('20161005082113'); + +INSERT INTO schema_migrations (version) VALUES ('20161005144657'); + +INSERT INTO schema_migrations (version) VALUES ('20161006085422'); + +INSERT INTO schema_migrations (version) VALUES ('20161007095443'); + +INSERT INTO schema_migrations (version) VALUES ('20161011125345'); + +INSERT INTO schema_migrations (version) VALUES ('20161025150900'); + diff --git a/db/views/searches_v01.sql b/db/views/searches_v01.sql index cd37c0d71..7499ed37f 100644 --- a/db/views/searches_v01.sql +++ b/db/views/searches_v01.sql @@ -7,13 +7,10 @@ UNION SELECT cerfas.dossier_id, FROM cerfas UNION SELECT champs.dossier_id, - champs.value AS term - FROM champs - -UNION SELECT champs.dossier_id, + champs.value || ' ' || drop_down_lists.value AS term - FROM drop_down_lists - INNER JOIN champs ON champs.type_de_champ_id = champs.type_de_champ_id + FROM champs + INNER JOIN drop_down_lists ON drop_down_lists.type_de_champ_id = champs.type_de_champ_id UNION SELECT entreprises.dossier_id, entreprises.siren || ' ' || @@ -43,7 +40,7 @@ UNION SELECT etablissements.dossier_id, UNION SELECT individuals.dossier_id, individuals.nom || ' ' || - individuals.prenom AS term + individuals.prenom AS term FROM individuals UNION SELECT pieces_justificatives.dossier_id, From f9a5e5c5ff25c17e0e3ae4490883cf6bc552d244 Mon Sep 17 00:00:00 2001 From: Julien Portalier Date: Sat, 29 Oct 2016 00:53:04 +0200 Subject: [PATCH 03/15] Drop textacular (to enable prefix matching) + disable materialized view (for the time being) + specs --- .../backoffice/dossiers_controller.rb | 3 +- app/models/dossier.rb | 31 ------- app/models/search.rb | 86 +++++++++++++----- db/migrate/20161025150900_create_searches.rb | 4 +- db/structure.sql | 74 +++++++-------- db/views/searches_v01.sql | 60 +++++++------ spec/models/dossier_spec.rb | 81 ----------------- spec/models/search_spec.rb | 89 ++++++++++++++++++- 8 files changed, 223 insertions(+), 205 deletions(-) diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index d4b1d4089..b992f6c44 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -31,10 +31,11 @@ class Backoffice::DossiersController < Backoffice::DossiersListController @dossier = Search.new( gestionnaire: current_gestionnaire, query: @search_terms, + page: params[:page] ).results unless @dossier.empty? - @dossiers = @dossiers.paginate(page: params[:page]) + @dossier = @dossier.paginate(page: params[:page]) end smartlisting_dossier @dossier, 'search' diff --git a/app/models/dossier.rb b/app/models/dossier.rb index e7b9599d0..c0cb20197 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -258,37 +258,6 @@ class Dossier < ActiveRecord::Base where(state: TERMINE, archived: false).order("updated_at #{order}") end - def self.search current_gestionnaire, terms - return [] if terms.blank? - - dossiers = Dossier.arel_table - users = User.arel_table - etablissements = Etablissement.arel_table - entreprises = Entreprise.arel_table - - composed_scope = self.joins('LEFT OUTER JOIN users ON users.id = dossiers.user_id') - .joins('LEFT OUTER JOIN entreprises ON entreprises.dossier_id = dossiers.id') - .joins('LEFT OUTER JOIN etablissements ON etablissements.dossier_id = dossiers.id') - - terms.split.each do |word| - query_string = "%#{word}%" - query_string_start_with = "#{word}%" - - composed_scope = composed_scope.where( - users[:email].matches(query_string).or\ - etablissements[:siret].matches(query_string_start_with).or\ - entreprises[:raison_sociale].matches(query_string).or\ - dossiers[:id].eq(word_is_an_integer word)) - end - - composed_scope = composed_scope.where( - dossiers[:id].eq_any(current_gestionnaire.dossiers.ids).and\ - dossiers[:state].does_not_match('draft').and\ - dossiers[:archived].eq(false)) - - composed_scope - end - def cerfa_available? procedure.cerfa_flag? && cerfa.size != 0 end diff --git a/app/models/search.rb b/app/models/search.rb index 89f5d3622..74de5ae1e 100644 --- a/app/models/search.rb +++ b/app/models/search.rb @@ -2,40 +2,82 @@ # - https://robots.thoughtbot.com/implementing-multi-table-full-text-search-with-postgres # - http://calebthompson.io/talks/search.html class Search < ActiveRecord::Base - extend Textacular + # :nodoc: + # + # Englobs a search result (actually a collection of Search objects) so it acts + # like a collection of regular Dossier objects, which can be decorated, + # paginated, ... + class Results + include Enumerable + + def initialize(results) + @results = results + end + + def each + @results.each do |search| + yield search.dossier + end + end + + def method_missing(name, *args, &block) + @results.__send__(name, *args, &block) + end + + def decorate! + @results.each do |search| + search.dossier = search.dossier.decorate + end + end + end + + #extend Textacular attr_accessor :gestionnaire attr_accessor :query + attr_accessor :page belongs_to :dossier def results - if @query.present? - self.class - .select("DISTINCT(searches.dossier_id)") - .search(@query) - .joins(:dossier) - .where(dossier_id: @gestionnaire.dossier_ids) - .where("dossiers.archived = ? AND dossiers.state != ?", false, "draft") - .preload(:dossier) - .map(&:dossier) - else + unless @query.present? + return Search.none + end + + search_term = self.class.connection.quote(to_tsquery) + + q = self.class + .select("DISTINCT(searches.dossier_id)") + .select("COALESCE(ts_rank(to_tsvector('french', searches.term::text), to_tsquery('french', #{search_term})), 0) AS rank") + .joins(:dossier) + .where(dossier_id: @gestionnaire.dossier_ids) + .where("dossiers.archived = ? AND dossiers.state != ?", false, "draft") + .where("to_tsvector('french', searches.term::text) @@ to_tsquery('french', #{search_term})") + .order("rank DESC") + .paginate(page: @page) + .preload(:dossier) + + begin + q.to_a + rescue ActiveRecord::StatementInvalid Search.none + else + Results.new(q) end end - def self.searchable_language - "french" - end + #def self.refresh + # # TODO: could be executed concurrently + # # See https://github.com/thoughtbot/scenic#what-about-materialized-views + # Scenic.database.refresh_materialized_view(table_name, concurrently: false) + #end - def self.searchable_columns - %i(term) - end + private - # Refreshes the materialized searches view. - def self.refresh - # NOTE: could be executed concurrently - # See https://github.com/thoughtbot/scenic#what-about-materialized-views - Scenic.database.refresh_materialized_view(table_name, concurrently: false) + def to_tsquery + @query.gsub(/['?\\:&|!]/, "") # drop disallowed characters + .split(/\s+/) # split words + .map { |x| "#{x}:*" } # enable prefix matching + .join(" & ") end end diff --git a/db/migrate/20161025150900_create_searches.rb b/db/migrate/20161025150900_create_searches.rb index 28f074d6a..911948c7d 100644 --- a/db/migrate/20161025150900_create_searches.rb +++ b/db/migrate/20161025150900_create_searches.rb @@ -9,7 +9,7 @@ class CreateSearches < ActiveRecord::Migration add_index :individuals, :dossier_id add_index :pieces_justificatives, :dossier_id add_index :rna_informations, :entreprise_id - create_view :searches, materialized: true + create_view :searches #, materialized: true end def down @@ -22,6 +22,6 @@ class CreateSearches < ActiveRecord::Migration remove_index :individuals, :dossier_id remove_index :pieces_justificatives, :dossier_id remove_index :rna_informations, :entreprise_id - drop_view :searches + drop_view :searches #, materialized: true end end diff --git a/db/structure.sql b/db/structure.sql index cd6223a91..02c8546cd 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -954,45 +954,68 @@ CREATE TABLE schema_migrations ( -- --- Name: searches; Type: MATERIALIZED VIEW; Schema: public; Owner: - +-- Name: users; Type: TABLE; Schema: public; Owner: - -- -CREATE MATERIALIZED VIEW searches AS +CREATE TABLE users ( + id integer NOT NULL, + email character varying DEFAULT ''::character varying NOT NULL, + encrypted_password character varying DEFAULT ''::character varying NOT NULL, + reset_password_token character varying, + reset_password_sent_at timestamp without time zone, + remember_created_at timestamp without time zone, + sign_in_count integer DEFAULT 0 NOT NULL, + current_sign_in_at timestamp without time zone, + last_sign_in_at timestamp without time zone, + current_sign_in_ip inet, + last_sign_in_ip inet, + created_at timestamp without time zone, + updated_at timestamp without time zone, + siret character varying, + loged_in_with_france_connect character varying DEFAULT false +); + + +-- +-- Name: searches; Type: VIEW; Schema: public; Owner: - +-- + +CREATE VIEW searches AS SELECT dossiers.id AS dossier_id, - (dossiers.id)::text AS term - FROM dossiers + (((dossiers.id)::text || ' '::text) || (COALESCE(users.email, ''::character varying))::text) AS term + FROM (dossiers + JOIN users ON ((users.id = dossiers.user_id))) UNION SELECT cerfas.dossier_id, - cerfas.content AS term + COALESCE(cerfas.content, ''::character varying) AS term FROM cerfas UNION SELECT champs.dossier_id, - (((champs.value)::text || ' '::text) || (drop_down_lists.value)::text) AS term + (((COALESCE(champs.value, ''::character varying))::text || ' '::text) || (COALESCE(drop_down_lists.value, ''::character varying))::text) AS term FROM (champs JOIN drop_down_lists ON ((drop_down_lists.type_de_champ_id = champs.type_de_champ_id))) UNION SELECT entreprises.dossier_id, - (((((((((((((((((((((((entreprises.siren)::text || ' '::text) || (entreprises.numero_tva_intracommunautaire)::text) || ' '::text) || (entreprises.forme_juridique)::text) || ' '::text) || (entreprises.forme_juridique_code)::text) || ' '::text) || (entreprises.nom_commercial)::text) || ' '::text) || (entreprises.raison_sociale)::text) || ' '::text) || (entreprises.siret_siege_social)::text) || ' '::text) || (entreprises.nom)::text) || ' '::text) || (entreprises.prenom)::text) || ' '::text) || (rna_informations.association_id)::text) || ' '::text) || (rna_informations.titre)::text) || ' '::text) || rna_informations.objet) AS term + (((((((((((((((((((((((COALESCE(entreprises.siren, ''::character varying))::text || ' '::text) || (COALESCE(entreprises.numero_tva_intracommunautaire, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.forme_juridique, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.forme_juridique_code, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.nom_commercial, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.raison_sociale, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.siret_siege_social, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.nom, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.prenom, ''::character varying))::text) || ' '::text) || (COALESCE(rna_informations.association_id, ''::character varying))::text) || ' '::text) || (COALESCE(rna_informations.titre, ''::character varying))::text) || ' '::text) || COALESCE(rna_informations.objet, ''::text)) AS term FROM (entreprises - JOIN rna_informations ON ((rna_informations.entreprise_id = entreprises.id))) + LEFT JOIN rna_informations ON ((rna_informations.entreprise_id = entreprises.id))) UNION SELECT etablissements.dossier_id, - (((((((((((((etablissements.siret)::text || ' '::text) || (etablissements.naf)::text) || ' '::text) || (etablissements.libelle_naf)::text) || ' '::text) || (etablissements.adresse)::text) || ' '::text) || (etablissements.code_postal)::text) || ' '::text) || (etablissements.localite)::text) || ' '::text) || (etablissements.code_insee_localite)::text) AS term + (((((((((((((COALESCE(etablissements.siret, ''::character varying))::text || ' '::text) || (COALESCE(etablissements.naf, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.libelle_naf, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.adresse, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.code_postal, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.localite, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.code_insee_localite, ''::character varying))::text) AS term FROM etablissements UNION SELECT individuals.dossier_id, - (((individuals.nom)::text || ' '::text) || (individuals.prenom)::text) AS term + (((COALESCE(individuals.nom, ''::character varying))::text || ' '::text) || (COALESCE(individuals.prenom, ''::character varying))::text) AS term FROM individuals UNION SELECT pieces_justificatives.dossier_id, - pieces_justificatives.content AS term + COALESCE(pieces_justificatives.content, ''::character varying) AS term FROM pieces_justificatives UNION SELECT dossiers.id AS dossier_id, - (((france_connect_informations.given_name)::text || ' '::text) || (france_connect_informations.family_name)::text) AS term + (((COALESCE(france_connect_informations.given_name, ''::character varying))::text || ' '::text) || (COALESCE(france_connect_informations.family_name, ''::character varying))::text) AS term FROM (france_connect_informations - JOIN dossiers ON ((dossiers.user_id = france_connect_informations.user_id))) - WITH NO DATA; + JOIN dossiers ON ((dossiers.user_id = france_connect_informations.user_id))); -- @@ -1065,29 +1088,6 @@ CREATE SEQUENCE types_de_piece_justificative_id_seq ALTER SEQUENCE types_de_piece_justificative_id_seq OWNED BY types_de_piece_justificative.id; --- --- Name: users; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE users ( - id integer NOT NULL, - email character varying DEFAULT ''::character varying NOT NULL, - encrypted_password character varying DEFAULT ''::character varying NOT NULL, - reset_password_token character varying, - reset_password_sent_at timestamp without time zone, - remember_created_at timestamp without time zone, - sign_in_count integer DEFAULT 0 NOT NULL, - current_sign_in_at timestamp without time zone, - last_sign_in_at timestamp without time zone, - current_sign_in_ip inet, - last_sign_in_ip inet, - created_at timestamp without time zone, - updated_at timestamp without time zone, - siret character varying, - loged_in_with_france_connect character varying DEFAULT false -); - - -- -- Name: users_id_seq; Type: SEQUENCE; Schema: public; Owner: - -- diff --git a/db/views/searches_v01.sql b/db/views/searches_v01.sql index 7499ed37f..221f1183a 100644 --- a/db/views/searches_v01.sql +++ b/db/views/searches_v01.sql @@ -1,54 +1,56 @@ SELECT dossiers.id AS dossier_id, - dossiers.id::text AS term + dossiers.id::text || ' ' || + COALESCE(users.email, '') AS term FROM dossiers + INNER JOIN users ON users.id = dossiers.user_id UNION SELECT cerfas.dossier_id, - cerfas.content AS term + COALESCE(cerfas.content, '') AS term FROM cerfas UNION SELECT champs.dossier_id, - champs.value || ' ' || - drop_down_lists.value AS term + COALESCE(champs.value, '') || ' ' || + COALESCE(drop_down_lists.value, '') AS term FROM champs INNER JOIN drop_down_lists ON drop_down_lists.type_de_champ_id = champs.type_de_champ_id UNION SELECT entreprises.dossier_id, - entreprises.siren || ' ' || - entreprises.numero_tva_intracommunautaire || ' ' || - entreprises.forme_juridique || ' ' || - entreprises.forme_juridique_code || ' ' || - entreprises.nom_commercial || ' ' || - entreprises.raison_sociale || ' ' || - entreprises.siret_siege_social || ' ' || - entreprises.nom || ' ' || - entreprises.prenom || ' ' || - rna_informations.association_id || ' ' || - rna_informations.titre || ' ' || - rna_informations.objet AS term + COALESCE(entreprises.siren, '') || ' ' || + COALESCE(entreprises.numero_tva_intracommunautaire, '') || ' ' || + COALESCE(entreprises.forme_juridique, '') || ' ' || + COALESCE(entreprises.forme_juridique_code, '') || ' ' || + COALESCE(entreprises.nom_commercial, '') || ' ' || + COALESCE(entreprises.raison_sociale, '') || ' ' || + COALESCE(entreprises.siret_siege_social, '') || ' ' || + COALESCE(entreprises.nom, '') || ' ' || + COALESCE(entreprises.prenom, '') || ' ' || + COALESCE(rna_informations.association_id, '') || ' ' || + COALESCE(rna_informations.titre, '') || ' ' || + COALESCE(rna_informations.objet, '') AS term FROM entreprises - INNER JOIN rna_informations ON rna_informations.entreprise_id = entreprises.id + LEFT JOIN rna_informations ON rna_informations.entreprise_id = entreprises.id UNION SELECT etablissements.dossier_id, - etablissements.siret || ' ' || - etablissements.naf || ' ' || - etablissements.libelle_naf || ' ' || - etablissements.adresse || ' ' || - etablissements.code_postal || ' ' || - etablissements.localite || ' ' || - etablissements.code_insee_localite AS term + COALESCE(etablissements.siret, '') || ' ' || + COALESCE(etablissements.naf, '') || ' ' || + COALESCE(etablissements.libelle_naf, '') || ' ' || + COALESCE(etablissements.adresse, '') || ' ' || + COALESCE(etablissements.code_postal, '') || ' ' || + COALESCE(etablissements.localite, '') || ' ' || + COALESCE(etablissements.code_insee_localite, '') AS term FROM etablissements UNION SELECT individuals.dossier_id, - individuals.nom || ' ' || - individuals.prenom AS term + COALESCE(individuals.nom, '') || ' ' || + COALESCE(individuals.prenom, '') AS term FROM individuals UNION SELECT pieces_justificatives.dossier_id, - pieces_justificatives.content AS term + COALESCE(pieces_justificatives.content, '') AS term FROM pieces_justificatives UNION SELECT dossiers.id, - france_connect_informations.given_name || ' ' || - france_connect_informations.family_name AS term + COALESCE(france_connect_informations.given_name, '') || ' ' || + COALESCE(france_connect_informations.family_name, '') AS term FROM france_connect_informations INNER JOIN dossiers ON dossiers.user_id = france_connect_informations.user_id diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 5fb127019..b4ee3c005 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -556,87 +556,6 @@ describe Dossier do end end - describe '.search' do - subject { liste_dossiers } - - let(:liste_dossiers) { described_class.search(gestionnaire_1, terms) } - # let(:dossier) { described_class.search(gestionnaire_1, terms)[1] } - - let(:administrateur_1) { create(:administrateur) } - let(:administrateur_2) { create(:administrateur) } - - let(:gestionnaire_1) { create(:gestionnaire, administrateurs: [administrateur_1]) } - let(:gestionnaire_2) { create(:gestionnaire, administrateurs: [administrateur_2]) } - - before do - create :assign_to, gestionnaire: gestionnaire_1, procedure: procedure_1 - create :assign_to, gestionnaire: gestionnaire_2, procedure: procedure_2 - end - - let(:procedure_1) { create(:procedure, administrateur: administrateur_1) } - let(:procedure_2) { create(:procedure, administrateur: administrateur_2) } - - let!(:dossier_0) { create(:dossier, state: 'draft', procedure: procedure_1, user: create(:user, email: 'brouillon@clap.fr')) } - let!(:dossier_1) { create(:dossier, state: 'initiated', procedure: procedure_1, user: create(:user, email: 'contact@test.com')) } - let!(:dossier_2) { create(:dossier, state: 'initiated', procedure: procedure_1, user: create(:user, email: 'plop@gmail.com')) } - let!(:dossier_3) { create(:dossier, state: 'initiated', procedure: procedure_2, user: create(:user, email: 'peace@clap.fr')) } - let!(:dossier_archived) { create(:dossier, state: 'initiated', procedure: procedure_1, archived: true, user: create(:user, email: 'brouillonArchived@clap.fr')) } - - let!(:etablissement_1) { create(:etablissement, entreprise: create(:entreprise, raison_sociale: 'OCTO Academy', dossier: dossier_1), dossier: dossier_1, siret: '41636169600051') } - let!(:etablissement_2) { create(:etablissement, entreprise: create(:entreprise, raison_sociale: 'Plop octo', dossier: dossier_2), dossier: dossier_2, siret: '41816602300012') } - let!(:etablissement_3) { create(:etablissement, entreprise: create(:entreprise, raison_sociale: 'OCTO Technology', dossier: dossier_3), dossier: dossier_3, siret: '41816609600051') } - - describe 'search is empty' do - let(:terms) { '' } - - it { expect(subject.size).to eq(0) } - end - - describe 'search draft file' do - let(:terms) { 'brouillon' } - - it { expect(subject.size).to eq(0) } - it { expect(subject.class).to eq Dossier::ActiveRecord_Relation } - end - - describe 'search on contact email' do - let(:terms) { 'clap' } - - it { expect(subject.size).to eq(0) } - end - - describe 'search on ID dossier' do - let(:terms) { "#{dossier_2.id}" } - - it { expect(subject.size).to eq(1) } - end - - describe 'search on SIRET' do - context 'when is part of SIRET' do - let(:terms) { '4181' } - - it { expect(subject.size).to eq(1) } - end - - context 'when is a complet SIRET' do - let(:terms) { '41816602300012' } - - it { expect(subject.size).to eq(1) } - end - end - - describe 'search on raison social' do - let(:terms) { 'OCTO' } - - it { expect(subject.size).to eq(2) } - end - - describe 'search on multiple fields' do - let(:terms) { 'octo test' } - - it { expect(subject.size).to eq(1) } - end - end end describe '#cerfa_available?' do diff --git a/spec/models/search_spec.rb b/spec/models/search_spec.rb index 89ac26d2d..2e18d5d35 100644 --- a/spec/models/search_spec.rb +++ b/spec/models/search_spec.rb @@ -1,5 +1,90 @@ require 'rails_helper' -RSpec.describe Search, type: :model do - pending "add some examples to (or delete) #{__FILE__}" +describe Search do + describe '.results' do + subject { liste_dossiers } + + let(:liste_dossiers) do + #described_class.refresh + described_class.new(gestionnaire: gestionnaire_1, query: terms).results + end + #let(:dossier) do + # described_class.refresh + # described_class.search(gestionnaire: gestionnaire_1, query: terms)[1] + #end + + let(:administrateur_1) { create(:administrateur) } + let(:administrateur_2) { create(:administrateur) } + + let(:gestionnaire_1) { create(:gestionnaire, administrateurs: [administrateur_1]) } + let(:gestionnaire_2) { create(:gestionnaire, administrateurs: [administrateur_2]) } + + before do + create :assign_to, gestionnaire: gestionnaire_1, procedure: procedure_1 + create :assign_to, gestionnaire: gestionnaire_2, procedure: procedure_2 + end + + let(:procedure_1) { create(:procedure, administrateur: administrateur_1) } + let(:procedure_2) { create(:procedure, administrateur: administrateur_2) } + + let!(:dossier_0) { create(:dossier, state: 'draft', procedure: procedure_1, user: create(:user, email: 'brouillon@clap.fr')) } + let!(:dossier_1) { create(:dossier, state: 'initiated', procedure: procedure_1, user: create(:user, email: 'contact@test.com')) } + let!(:dossier_2) { create(:dossier, state: 'initiated', procedure: procedure_1, user: create(:user, email: 'plop@gmail.com')) } + let!(:dossier_3) { create(:dossier, state: 'initiated', procedure: procedure_2, user: create(:user, email: 'peace@clap.fr')) } + let!(:dossier_archived) { create(:dossier, state: 'initiated', procedure: procedure_1, archived: true, user: create(:user, email: 'brouillonArchived@clap.fr')) } + + let!(:etablissement_1) { create(:etablissement, entreprise: create(:entreprise, raison_sociale: 'OCTO Academy', dossier: dossier_1), dossier: dossier_1, siret: '41636169600051') } + let!(:etablissement_2) { create(:etablissement, entreprise: create(:entreprise, raison_sociale: 'Plop octo', dossier: dossier_2), dossier: dossier_2, siret: '41816602300012') } + let!(:etablissement_3) { create(:etablissement, entreprise: create(:entreprise, raison_sociale: 'OCTO Technology', dossier: dossier_3), dossier: dossier_3, siret: '41816609600051') } + + describe 'search is empty' do + let(:terms) { '' } + + it { expect(subject.size).to eq(0) } + end + + describe 'search draft file' do + let(:terms) { 'brouillon' } + + it { expect(subject.size).to eq(0) } + end + + describe 'search on contact email' do + let(:terms) { 'clap' } + + it { expect(subject.size).to eq(0) } + end + + #describe 'search on ID dossier' do + # let(:terms) { "#{dossier_2.id}" } + + # it { expect(dossier.id).to eq(dossier_2.id) } + #end + + describe 'search on SIRET' do + context 'when is part of SIRET' do + let(:terms) { '4181' } + + it { expect(subject.size).to eq(1) } + end + + context 'when is a complet SIRET' do + let(:terms) { '41816602300012' } + + it { expect(subject.size).to eq(1) } + end + end + + describe 'search on raison social' do + let(:terms) { 'OCTO' } + + it { expect(subject.size).to eq(2) } + end + + describe 'search on multiple fields' do + let(:terms) { 'octo test' } + + pending { expect(subject.size).to eq(1) } + end + end end From ce7e2c8a87e2e7285ed44ff75af5602f14dac22f Mon Sep 17 00:00:00 2001 From: Julien Portalier Date: Wed, 2 Nov 2016 17:34:29 +0100 Subject: [PATCH 04/15] Rework searches to enable cross-table searches It allows to search for multiple terms in multiple tables at once. --- app/models/search.rb | 8 +++- ...1102154835_update_searches_to_version_2.rb | 9 ++++ db/structure.sql | 44 +++++-------------- db/views/searches_v01.sql | 3 ++ db/views/searches_v02.sql | 43 ++++++++++++++++++ spec/models/search_spec.rb | 15 +------ 6 files changed, 75 insertions(+), 47 deletions(-) create mode 100644 db/migrate/20161102154835_update_searches_to_version_2.rb create mode 100644 db/views/searches_v02.sql diff --git a/app/models/search.rb b/app/models/search.rb index 74de5ae1e..34e8d08f1 100644 --- a/app/models/search.rb +++ b/app/models/search.rb @@ -46,12 +46,16 @@ class Search < ActiveRecord::Base search_term = self.class.connection.quote(to_tsquery) + dossier_ids = @gestionnaire.dossiers + .select(:id) + .where(archived: false) + .where.not(state: "draft") + q = self.class .select("DISTINCT(searches.dossier_id)") .select("COALESCE(ts_rank(to_tsvector('french', searches.term::text), to_tsquery('french', #{search_term})), 0) AS rank") .joins(:dossier) - .where(dossier_id: @gestionnaire.dossier_ids) - .where("dossiers.archived = ? AND dossiers.state != ?", false, "draft") + .where(dossier_id: dossier_ids) .where("to_tsvector('french', searches.term::text) @@ to_tsquery('french', #{search_term})") .order("rank DESC") .paginate(page: @page) diff --git a/db/migrate/20161102154835_update_searches_to_version_2.rb b/db/migrate/20161102154835_update_searches_to_version_2.rb new file mode 100644 index 000000000..55223b4cf --- /dev/null +++ b/db/migrate/20161102154835_update_searches_to_version_2.rb @@ -0,0 +1,9 @@ +class UpdateSearchesToVersion2 < ActiveRecord::Migration + def up + replace_view :searches, version: 2 + end + + def down + replace_view :searches, version: 1 + end +end diff --git a/db/structure.sql b/db/structure.sql index 02c8546cd..8b12f3907 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -982,40 +982,18 @@ CREATE TABLE users ( CREATE VIEW searches AS SELECT dossiers.id AS dossier_id, - (((dossiers.id)::text || ' '::text) || (COALESCE(users.email, ''::character varying))::text) AS term - FROM (dossiers + (((((((((((((((((((((((((((((((((((((((((((((((((((((((COALESCE(users.email, ''::character varying))::text || ' '::text) || (COALESCE(france_connect_informations.given_name, ''::character varying))::text) || ' '::text) || (COALESCE(france_connect_informations.family_name, ''::character varying))::text) || ' '::text) || (COALESCE(cerfas.content, ''::character varying))::text) || ' '::text) || (COALESCE(champs.value, ''::character varying))::text) || ' '::text) || (COALESCE(drop_down_lists.value, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.siren, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.numero_tva_intracommunautaire, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.forme_juridique, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.forme_juridique_code, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.nom_commercial, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.raison_sociale, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.siret_siege_social, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.nom, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.prenom, ''::character varying))::text) || ' '::text) || (COALESCE(rna_informations.association_id, ''::character varying))::text) || ' '::text) || (COALESCE(rna_informations.titre, ''::character varying))::text) || ' '::text) || COALESCE(rna_informations.objet, ''::text)) || ' '::text) || (COALESCE(etablissements.siret, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.naf, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.libelle_naf, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.adresse, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.code_postal, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.localite, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.code_insee_localite, ''::character varying))::text) || ' '::text) || (COALESCE(individuals.nom, ''::character varying))::text) || ' '::text) || (COALESCE(individuals.prenom, ''::character varying))::text) || ' '::text) || (COALESCE(pieces_justificatives.content, ''::character varying))::text) AS term + FROM ((((((((((dossiers JOIN users ON ((users.id = dossiers.user_id))) -UNION - SELECT cerfas.dossier_id, - COALESCE(cerfas.content, ''::character varying) AS term - FROM cerfas -UNION - SELECT champs.dossier_id, - (((COALESCE(champs.value, ''::character varying))::text || ' '::text) || (COALESCE(drop_down_lists.value, ''::character varying))::text) AS term - FROM (champs - JOIN drop_down_lists ON ((drop_down_lists.type_de_champ_id = champs.type_de_champ_id))) -UNION - SELECT entreprises.dossier_id, - (((((((((((((((((((((((COALESCE(entreprises.siren, ''::character varying))::text || ' '::text) || (COALESCE(entreprises.numero_tva_intracommunautaire, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.forme_juridique, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.forme_juridique_code, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.nom_commercial, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.raison_sociale, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.siret_siege_social, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.nom, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.prenom, ''::character varying))::text) || ' '::text) || (COALESCE(rna_informations.association_id, ''::character varying))::text) || ' '::text) || (COALESCE(rna_informations.titre, ''::character varying))::text) || ' '::text) || COALESCE(rna_informations.objet, ''::text)) AS term - FROM (entreprises + LEFT JOIN france_connect_informations ON ((france_connect_informations.user_id = dossiers.user_id))) + LEFT JOIN cerfas ON ((cerfas.dossier_id = dossiers.id))) + LEFT JOIN champs ON ((champs.dossier_id = dossiers.id))) + LEFT JOIN drop_down_lists ON ((drop_down_lists.type_de_champ_id = champs.type_de_champ_id))) + LEFT JOIN entreprises ON ((entreprises.dossier_id = dossiers.id))) LEFT JOIN rna_informations ON ((rna_informations.entreprise_id = entreprises.id))) -UNION - SELECT etablissements.dossier_id, - (((((((((((((COALESCE(etablissements.siret, ''::character varying))::text || ' '::text) || (COALESCE(etablissements.naf, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.libelle_naf, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.adresse, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.code_postal, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.localite, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.code_insee_localite, ''::character varying))::text) AS term - FROM etablissements -UNION - SELECT individuals.dossier_id, - (((COALESCE(individuals.nom, ''::character varying))::text || ' '::text) || (COALESCE(individuals.prenom, ''::character varying))::text) AS term - FROM individuals -UNION - SELECT pieces_justificatives.dossier_id, - COALESCE(pieces_justificatives.content, ''::character varying) AS term - FROM pieces_justificatives -UNION - SELECT dossiers.id AS dossier_id, - (((COALESCE(france_connect_informations.given_name, ''::character varying))::text || ' '::text) || (COALESCE(france_connect_informations.family_name, ''::character varying))::text) AS term - FROM (france_connect_informations - JOIN dossiers ON ((dossiers.user_id = france_connect_informations.user_id))); + LEFT JOIN etablissements ON ((etablissements.dossier_id = dossiers.id))) + LEFT JOIN individuals ON ((individuals.dossier_id = dossiers.id))) + LEFT JOIN pieces_justificatives ON ((pieces_justificatives.dossier_id = dossiers.id))); -- @@ -2075,3 +2053,5 @@ INSERT INTO schema_migrations (version) VALUES ('20161011125345'); INSERT INTO schema_migrations (version) VALUES ('20161025150900'); +INSERT INTO schema_migrations (version) VALUES ('20161102154835'); + diff --git a/db/views/searches_v01.sql b/db/views/searches_v01.sql index 221f1183a..e5f2cfd71 100644 --- a/db/views/searches_v01.sql +++ b/db/views/searches_v01.sql @@ -1,3 +1,6 @@ +-- this version allows to search for a single term within many tables, +-- but behaves badly with multiple terms scattered in multiple tables. + SELECT dossiers.id AS dossier_id, dossiers.id::text || ' ' || COALESCE(users.email, '') AS term diff --git a/db/views/searches_v02.sql b/db/views/searches_v02.sql new file mode 100644 index 000000000..8a168f465 --- /dev/null +++ b/db/views/searches_v02.sql @@ -0,0 +1,43 @@ +-- this version merges all possible search terms together, complicating the +-- view, but enables searching for multiple terms from multiple tables at once. + +SELECT dossiers.id AS dossier_id, + COALESCE(users.email, '') || ' ' || + COALESCE(france_connect_informations.given_name, '') || ' ' || + COALESCE(france_connect_informations.family_name, '') || ' ' || + COALESCE(cerfas.content, '') || ' ' || + COALESCE(champs.value, '') || ' ' || + COALESCE(drop_down_lists.value, '') || ' ' || + COALESCE(entreprises.siren, '') || ' ' || + COALESCE(entreprises.numero_tva_intracommunautaire, '') || ' ' || + COALESCE(entreprises.forme_juridique, '') || ' ' || + COALESCE(entreprises.forme_juridique_code, '') || ' ' || + COALESCE(entreprises.nom_commercial, '') || ' ' || + COALESCE(entreprises.raison_sociale, '') || ' ' || + COALESCE(entreprises.siret_siege_social, '') || ' ' || + COALESCE(entreprises.nom, '') || ' ' || + COALESCE(entreprises.prenom, '') || ' ' || + COALESCE(rna_informations.association_id, '') || ' ' || + COALESCE(rna_informations.titre, '') || ' ' || + COALESCE(rna_informations.objet, '') || ' ' || + COALESCE(etablissements.siret, '') || ' ' || + COALESCE(etablissements.naf, '') || ' ' || + COALESCE(etablissements.libelle_naf, '') || ' ' || + COALESCE(etablissements.adresse, '') || ' ' || + COALESCE(etablissements.code_postal, '') || ' ' || + COALESCE(etablissements.localite, '') || ' ' || + COALESCE(etablissements.code_insee_localite, '') || ' ' || + COALESCE(individuals.nom, '') || ' ' || + COALESCE(individuals.prenom, '') || ' ' || + COALESCE(pieces_justificatives.content, '') AS term +FROM dossiers +INNER JOIN users ON users.id = dossiers.user_id +LEFT JOIN france_connect_informations ON france_connect_informations.user_id = dossiers.user_id +LEFT JOIN cerfas ON cerfas.dossier_id = dossiers.id +LEFT JOIN champs ON champs.dossier_id = dossiers.id +LEFT JOIN drop_down_lists ON drop_down_lists.type_de_champ_id = champs.type_de_champ_id +LEFT JOIN entreprises ON entreprises.dossier_id = dossiers.id +LEFT JOIN rna_informations ON rna_informations.entreprise_id = entreprises.id +LEFT JOIN etablissements ON etablissements.dossier_id = dossiers.id +LEFT JOIN individuals ON individuals.dossier_id = dossiers.id +LEFT JOIN pieces_justificatives ON pieces_justificatives.dossier_id = dossiers.id diff --git a/spec/models/search_spec.rb b/spec/models/search_spec.rb index 2e18d5d35..4e7d20ec2 100644 --- a/spec/models/search_spec.rb +++ b/spec/models/search_spec.rb @@ -5,13 +5,8 @@ describe Search do subject { liste_dossiers } let(:liste_dossiers) do - #described_class.refresh described_class.new(gestionnaire: gestionnaire_1, query: terms).results end - #let(:dossier) do - # described_class.refresh - # described_class.search(gestionnaire: gestionnaire_1, query: terms)[1] - #end let(:administrateur_1) { create(:administrateur) } let(:administrateur_2) { create(:administrateur) } @@ -55,12 +50,6 @@ describe Search do it { expect(subject.size).to eq(0) } end - #describe 'search on ID dossier' do - # let(:terms) { "#{dossier_2.id}" } - - # it { expect(dossier.id).to eq(dossier_2.id) } - #end - describe 'search on SIRET' do context 'when is part of SIRET' do let(:terms) { '4181' } @@ -82,9 +71,9 @@ describe Search do end describe 'search on multiple fields' do - let(:terms) { 'octo test' } + let(:terms) { 'octo plop' } - pending { expect(subject.size).to eq(1) } + it { expect(subject.size).to eq(1) } end end end From 31272cf0f544f0930eedfb5fe82ac28a32c25c62 Mon Sep 17 00:00:00 2001 From: Julien Portalier Date: Fri, 4 Nov 2016 17:11:26 +0100 Subject: [PATCH 05/15] Fix: rebased off the develop branch (not master) Remove textacular gem, drop `db/structure.sql` (no special indices) and regenerates `db/schema.rb` --- Gemfile | 1 - Gemfile.lock | 5 +- .../backoffice/dossiers_controller.rb | 4 - app/models/search.rb | 17 +- app/views/backoffice/dossiers/_list.html.haml | 2 +- db/schema.rb | 405 ++++ db/structure.sql | 2057 ----------------- 7 files changed, 413 insertions(+), 2078 deletions(-) create mode 100644 db/schema.rb delete mode 100644 db/structure.sql diff --git a/Gemfile b/Gemfile index ba68e79a7..6833a2cd7 100644 --- a/Gemfile +++ b/Gemfile @@ -63,7 +63,6 @@ gem 'fog-openstack' gem 'pg' gem 'scenic' -gem 'textacular' gem 'rgeo-geojson' gem 'leaflet-rails' diff --git a/Gemfile.lock b/Gemfile.lock index f85d05b05..422928561 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -566,8 +566,6 @@ GEM json (>= 1.4.3) temple (0.7.6) terminal-table (1.5.2) - textacular (4.0.1) - activerecord (>= 3.0, < 5.1) therubyracer (0.12.2) libv8 (~> 3.16.14.0) ref @@ -687,7 +685,6 @@ DEPENDENCIES smart_listing spring spring-commands-rspec - textacular therubyracer timecop turbolinks @@ -699,4 +696,4 @@ DEPENDENCIES will_paginate-bootstrap BUNDLED WITH - 1.12.5 + 1.13.2 diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index b992f6c44..4de0b31a2 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -34,10 +34,6 @@ class Backoffice::DossiersController < Backoffice::DossiersListController page: params[:page] ).results - unless @dossier.empty? - @dossier = @dossier.paginate(page: params[:page]) - end - smartlisting_dossier @dossier, 'search' rescue RuntimeError diff --git a/app/models/search.rb b/app/models/search.rb index 34e8d08f1..6b4557677 100644 --- a/app/models/search.rb +++ b/app/models/search.rb @@ -31,8 +31,6 @@ class Search < ActiveRecord::Base end end - #extend Textacular - attr_accessor :gestionnaire attr_accessor :query attr_accessor :page @@ -44,30 +42,27 @@ class Search < ActiveRecord::Base return Search.none end - search_term = self.class.connection.quote(to_tsquery) + search_term = Search.connection.quote(to_tsquery) dossier_ids = @gestionnaire.dossiers .select(:id) .where(archived: false) .where.not(state: "draft") - q = self.class + q = Search .select("DISTINCT(searches.dossier_id)") .select("COALESCE(ts_rank(to_tsvector('french', searches.term::text), to_tsquery('french', #{search_term})), 0) AS rank") .joins(:dossier) .where(dossier_id: dossier_ids) .where("to_tsvector('french', searches.term::text) @@ to_tsquery('french', #{search_term})") .order("rank DESC") - .paginate(page: @page) .preload(:dossier) - begin - q.to_a - rescue ActiveRecord::StatementInvalid - Search.none - else - Results.new(q) + if @page.present? + q = q.paginate(page: @page) end + + Results.new(q) end #def self.refresh diff --git a/app/views/backoffice/dossiers/_list.html.haml b/app/views/backoffice/dossiers/_list.html.haml index 3b6793ef5..e887a2031 100644 --- a/app/views/backoffice/dossiers/_list.html.haml +++ b/app/views/backoffice/dossiers/_list.html.haml @@ -48,4 +48,4 @@ - if smart_listing.empty? %h4.center - Aucun dossier \ No newline at end of file + Aucun dossier diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 000000000..7ef1e735e --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,405 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20161102154835) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "administrateurs", force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.integer "sign_in_count", default: 0, null: false + t.datetime "current_sign_in_at" + t.datetime "last_sign_in_at" + t.inet "current_sign_in_ip" + t.inet "last_sign_in_ip" + t.datetime "created_at" + t.datetime "updated_at" + t.string "api_token" + end + + add_index "administrateurs", ["email"], name: "index_administrateurs_on_email", unique: true, using: :btree + add_index "administrateurs", ["reset_password_token"], name: "index_administrateurs_on_reset_password_token", unique: true, using: :btree + + create_table "administrateurs_gestionnaires", id: false, force: :cascade do |t| + t.integer "administrateur_id" + t.integer "gestionnaire_id" + end + + add_index "administrateurs_gestionnaires", ["administrateur_id"], name: "index_administrateurs_gestionnaires_on_administrateur_id", using: :btree + add_index "administrateurs_gestionnaires", ["gestionnaire_id", "administrateur_id"], name: "unique_couple_administrateur_gestionnaire", unique: true, using: :btree + add_index "administrateurs_gestionnaires", ["gestionnaire_id"], name: "index_administrateurs_gestionnaires_on_gestionnaire_id", using: :btree + + create_table "administrations", force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.integer "sign_in_count", default: 0, null: false + t.datetime "current_sign_in_at" + t.datetime "last_sign_in_at" + t.inet "current_sign_in_ip" + t.inet "last_sign_in_ip" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "administrations", ["email"], name: "index_administrations_on_email", unique: true, using: :btree + add_index "administrations", ["reset_password_token"], name: "index_administrations_on_reset_password_token", unique: true, using: :btree + + create_table "assign_tos", id: false, force: :cascade do |t| + t.integer "gestionnaire_id" + t.integer "procedure_id" + end + + add_index "assign_tos", ["gestionnaire_id"], name: "index_assign_tos_on_gestionnaire_id", using: :btree + add_index "assign_tos", ["procedure_id"], name: "index_assign_tos_on_procedure_id", using: :btree + + create_table "cadastres", force: :cascade do |t| + t.string "surface_intersection" + t.float "surface_parcelle" + t.string "numero" + t.integer "feuille" + t.string "section" + t.string "code_dep" + t.string "nom_com" + t.string "code_com" + t.string "code_arr" + t.text "geometry" + t.integer "dossier_id" + end + + create_table "cerfas", force: :cascade do |t| + t.string "content" + t.integer "dossier_id" + t.datetime "created_at" + t.integer "user_id" + t.string "original_filename" + t.string "content_secure_token" + end + + add_index "cerfas", ["dossier_id"], name: "index_cerfas_on_dossier_id", using: :btree + + create_table "champs", force: :cascade do |t| + t.string "value" + t.integer "type_de_champ_id" + t.integer "dossier_id" + t.string "type" + end + + add_index "champs", ["dossier_id"], name: "index_champs_on_dossier_id", using: :btree + add_index "champs", ["type_de_champ_id"], name: "index_champs_on_type_de_champ_id", using: :btree + + create_table "commentaires", force: :cascade do |t| + t.string "email" + t.datetime "created_at", null: false + t.string "body" + t.integer "dossier_id" + t.datetime "updated_at", null: false + t.integer "piece_justificative_id" + end + + add_index "commentaires", ["dossier_id"], name: "index_commentaires_on_dossier_id", using: :btree + + create_table "dossiers", force: :cascade do |t| + t.boolean "autorisation_donnees" + t.string "nom_projet" + t.integer "procedure_id" + t.datetime "created_at" + t.datetime "updated_at" + t.string "state" + t.integer "user_id" + t.text "json_latlngs" + t.boolean "archived", default: false + t.boolean "mandataire_social", default: false + t.datetime "deposit_datetime" + end + + add_index "dossiers", ["procedure_id"], name: "index_dossiers_on_procedure_id", using: :btree + add_index "dossiers", ["user_id"], name: "index_dossiers_on_user_id", using: :btree + + create_table "drop_down_lists", force: :cascade do |t| + t.string "value" + t.integer "type_de_champ_id" + end + + add_index "drop_down_lists", ["type_de_champ_id"], name: "index_drop_down_lists_on_type_de_champ_id", using: :btree + + create_table "entreprises", force: :cascade do |t| + t.string "siren" + t.integer "capital_social" + t.string "numero_tva_intracommunautaire" + t.string "forme_juridique" + t.string "forme_juridique_code" + t.string "nom_commercial" + t.string "raison_sociale" + t.string "siret_siege_social" + t.string "code_effectif_entreprise" + t.datetime "date_creation" + t.string "nom" + t.string "prenom" + t.integer "dossier_id" + end + + add_index "entreprises", ["dossier_id"], name: "index_entreprises_on_dossier_id", using: :btree + + create_table "etablissements", force: :cascade do |t| + t.string "siret" + t.boolean "siege_social" + t.string "naf" + t.string "libelle_naf" + t.string "adresse" + t.string "numero_voie" + t.string "type_voie" + t.string "nom_voie" + t.string "complement_adresse" + t.string "code_postal" + t.string "localite" + t.string "code_insee_localite" + t.integer "dossier_id" + t.integer "entreprise_id" + end + + add_index "etablissements", ["dossier_id"], name: "index_etablissements_on_dossier_id", using: :btree + + create_table "exercices", force: :cascade do |t| + t.string "ca" + t.datetime "dateFinExercice" + t.integer "date_fin_exercice_timestamp" + t.integer "etablissement_id" + end + + create_table "follows", force: :cascade do |t| + t.integer "gestionnaire_id" + t.integer "dossier_id" + end + + add_index "follows", ["dossier_id"], name: "index_follows_on_dossier_id", using: :btree + add_index "follows", ["gestionnaire_id"], name: "index_follows_on_gestionnaire_id", using: :btree + + create_table "france_connect_informations", force: :cascade do |t| + t.string "gender" + t.string "given_name" + t.string "family_name" + t.date "birthdate" + t.string "birthplace" + t.string "france_connect_particulier_id" + t.integer "user_id" + t.string "email_france_connect" + end + + add_index "france_connect_informations", ["user_id"], name: "index_france_connect_informations_on_user_id", using: :btree + + create_table "gestionnaires", force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.integer "sign_in_count", default: 0, null: false + t.datetime "current_sign_in_at" + t.datetime "last_sign_in_at" + t.inet "current_sign_in_ip" + t.inet "last_sign_in_ip" + t.datetime "created_at" + t.datetime "updated_at" + t.integer "procedure_filter" + end + + add_index "gestionnaires", ["email"], name: "index_gestionnaires_on_email", unique: true, using: :btree + add_index "gestionnaires", ["reset_password_token"], name: "index_gestionnaires_on_reset_password_token", unique: true, using: :btree + + create_table "individuals", force: :cascade do |t| + t.string "nom" + t.string "prenom" + t.string "birthdate" + t.integer "dossier_id" + t.string "gender" + end + + add_index "individuals", ["dossier_id"], name: "index_individuals_on_dossier_id", using: :btree + + create_table "invites", force: :cascade do |t| + t.string "email" + t.string "email_sender" + t.integer "dossier_id" + t.integer "user_id" + t.string "type", default: "InviteGestionnaire" + end + + create_table "mail_templates", force: :cascade do |t| + t.string "object" + t.text "body" + t.string "type" + t.integer "procedure_id" + end + + create_table "module_api_cartos", force: :cascade do |t| + t.integer "procedure_id" + t.boolean "use_api_carto", default: false + t.boolean "quartiers_prioritaires", default: false + t.boolean "cadastre", default: false + end + + add_index "module_api_cartos", ["procedure_id"], name: "index_module_api_cartos_on_procedure_id", unique: true, using: :btree + + create_table "pieces_justificatives", force: :cascade do |t| + t.string "content" + t.integer "dossier_id" + t.integer "type_de_piece_justificative_id" + t.datetime "created_at" + t.integer "user_id" + t.string "original_filename" + t.string "content_secure_token" + end + + add_index "pieces_justificatives", ["dossier_id"], name: "index_pieces_justificatives_on_dossier_id", using: :btree + add_index "pieces_justificatives", ["type_de_piece_justificative_id"], name: "index_pieces_justificatives_on_type_de_piece_justificative_id", using: :btree + + create_table "preference_list_dossiers", force: :cascade do |t| + t.string "libelle" + t.string "table" + t.string "attr" + t.string "attr_decorate" + t.string "bootstrap_lg" + t.string "order" + t.string "filter" + t.integer "gestionnaire_id" + t.integer "procedure_id" + end + + create_table "preference_smart_listing_pages", force: :cascade do |t| + t.string "liste" + t.integer "page" + t.integer "procedure_id" + t.integer "gestionnaire_id" + end + + create_table "procedure_paths", force: :cascade do |t| + t.string "path", limit: 30 + t.integer "procedure_id" + t.integer "administrateur_id" + end + + add_index "procedure_paths", ["path"], name: "index_procedure_paths_on_path", using: :btree + + create_table "procedures", force: :cascade do |t| + t.string "libelle" + t.string "description" + t.string "organisation" + t.string "direction" + t.string "lien_demarche" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.boolean "test" + t.integer "administrateur_id" + t.boolean "archived", default: false + t.boolean "euro_flag", default: false + t.string "logo" + t.boolean "cerfa_flag", default: false + t.string "logo_secure_token" + t.boolean "published", default: false, null: false + t.string "lien_site_web" + t.string "lien_notice" + t.boolean "for_individual", default: false + t.boolean "individual_with_siret", default: false + end + + create_table "quartier_prioritaires", force: :cascade do |t| + t.string "code" + t.string "nom" + t.string "commune" + t.text "geometry" + t.integer "dossier_id" + end + + create_table "rna_informations", force: :cascade do |t| + t.string "association_id" + t.string "titre" + t.text "objet" + t.date "date_creation" + t.date "date_declaration" + t.date "date_publication" + t.integer "entreprise_id" + end + + add_index "rna_informations", ["entreprise_id"], name: "index_rna_informations_on_entreprise_id", using: :btree + + create_table "types_de_champ", force: :cascade do |t| + t.string "libelle" + t.string "type_champ" + t.integer "order_place" + t.integer "procedure_id" + t.text "description" + t.boolean "mandatory", default: false + t.string "type" + end + + create_table "types_de_piece_justificative", force: :cascade do |t| + t.string "libelle" + t.string "description" + t.boolean "api_entreprise", default: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "procedure_id" + t.integer "order_place" + end + + create_table "users", force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.integer "sign_in_count", default: 0, null: false + t.datetime "current_sign_in_at" + t.datetime "last_sign_in_at" + t.inet "current_sign_in_ip" + t.inet "last_sign_in_ip" + t.datetime "created_at" + t.datetime "updated_at" + t.string "siret" + t.string "loged_in_with_france_connect", default: "false" + end + + add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree + add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree + + add_foreign_key "cerfas", "dossiers" + add_foreign_key "commentaires", "dossiers" + add_foreign_key "dossiers", "users" + add_foreign_key "procedure_paths", "administrateurs" + add_foreign_key "procedure_paths", "procedures" + + create_view :searches, sql_definition: <<-SQL + SELECT dossiers.id AS dossier_id, + (((((((((((((((((((((((((((((((((((((((((((((((((((((((COALESCE(users.email, ''::character varying))::text || ' '::text) || (COALESCE(france_connect_informations.given_name, ''::character varying))::text) || ' '::text) || (COALESCE(france_connect_informations.family_name, ''::character varying))::text) || ' '::text) || (COALESCE(cerfas.content, ''::character varying))::text) || ' '::text) || (COALESCE(champs.value, ''::character varying))::text) || ' '::text) || (COALESCE(drop_down_lists.value, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.siren, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.numero_tva_intracommunautaire, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.forme_juridique, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.forme_juridique_code, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.nom_commercial, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.raison_sociale, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.siret_siege_social, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.nom, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.prenom, ''::character varying))::text) || ' '::text) || (COALESCE(rna_informations.association_id, ''::character varying))::text) || ' '::text) || (COALESCE(rna_informations.titre, ''::character varying))::text) || ' '::text) || COALESCE(rna_informations.objet, ''::text)) || ' '::text) || (COALESCE(etablissements.siret, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.naf, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.libelle_naf, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.adresse, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.code_postal, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.localite, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.code_insee_localite, ''::character varying))::text) || ' '::text) || (COALESCE(individuals.nom, ''::character varying))::text) || ' '::text) || (COALESCE(individuals.prenom, ''::character varying))::text) || ' '::text) || (COALESCE(pieces_justificatives.content, ''::character varying))::text) AS term + FROM ((((((((((dossiers + JOIN users ON ((users.id = dossiers.user_id))) + LEFT JOIN france_connect_informations ON ((france_connect_informations.user_id = dossiers.user_id))) + LEFT JOIN cerfas ON ((cerfas.dossier_id = dossiers.id))) + LEFT JOIN champs ON ((champs.dossier_id = dossiers.id))) + LEFT JOIN drop_down_lists ON ((drop_down_lists.type_de_champ_id = champs.type_de_champ_id))) + LEFT JOIN entreprises ON ((entreprises.dossier_id = dossiers.id))) + LEFT JOIN rna_informations ON ((rna_informations.entreprise_id = entreprises.id))) + LEFT JOIN etablissements ON ((etablissements.dossier_id = dossiers.id))) + LEFT JOIN individuals ON ((individuals.dossier_id = dossiers.id))) + LEFT JOIN pieces_justificatives ON ((pieces_justificatives.dossier_id = dossiers.id))); + SQL + +end diff --git a/db/structure.sql b/db/structure.sql deleted file mode 100644 index 8b12f3907..000000000 --- a/db/structure.sql +++ /dev/null @@ -1,2057 +0,0 @@ --- --- PostgreSQL database dump --- - --- Dumped from database version 9.5.4 --- Dumped by pg_dump version 9.5.4 - -SET statement_timeout = 0; -SET lock_timeout = 0; -SET client_encoding = 'UTF8'; -SET standard_conforming_strings = on; -SET check_function_bodies = false; -SET client_min_messages = warning; -SET row_security = off; - --- --- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: - --- - -CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; - - --- --- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: - --- - -COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; - - -SET search_path = public, pg_catalog; - -SET default_tablespace = ''; - -SET default_with_oids = false; - --- --- Name: administrateurs; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE administrateurs ( - id integer NOT NULL, - email character varying DEFAULT ''::character varying NOT NULL, - encrypted_password character varying DEFAULT ''::character varying NOT NULL, - reset_password_token character varying, - reset_password_sent_at timestamp without time zone, - remember_created_at timestamp without time zone, - sign_in_count integer DEFAULT 0 NOT NULL, - current_sign_in_at timestamp without time zone, - last_sign_in_at timestamp without time zone, - current_sign_in_ip inet, - last_sign_in_ip inet, - created_at timestamp without time zone, - updated_at timestamp without time zone, - api_token character varying -); - - --- --- Name: administrateurs_gestionnaires; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE administrateurs_gestionnaires ( - administrateur_id integer, - gestionnaire_id integer -); - - --- --- Name: administrateurs_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE administrateurs_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: administrateurs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE administrateurs_id_seq OWNED BY administrateurs.id; - - --- --- Name: administrations; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE administrations ( - id integer NOT NULL, - email character varying DEFAULT ''::character varying NOT NULL, - encrypted_password character varying DEFAULT ''::character varying NOT NULL, - reset_password_token character varying, - reset_password_sent_at timestamp without time zone, - remember_created_at timestamp without time zone, - sign_in_count integer DEFAULT 0 NOT NULL, - current_sign_in_at timestamp without time zone, - last_sign_in_at timestamp without time zone, - current_sign_in_ip inet, - last_sign_in_ip inet, - created_at timestamp without time zone, - updated_at timestamp without time zone -); - - --- --- Name: administrations_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE administrations_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: administrations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE administrations_id_seq OWNED BY administrations.id; - - --- --- Name: assign_tos; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE assign_tos ( - gestionnaire_id integer, - procedure_id integer -); - - --- --- Name: cadastres; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE cadastres ( - id integer NOT NULL, - surface_intersection character varying, - surface_parcelle double precision, - numero character varying, - feuille integer, - section character varying, - code_dep character varying, - nom_com character varying, - code_com character varying, - code_arr character varying, - geometry text, - dossier_id integer -); - - --- --- Name: cadastres_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE cadastres_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: cadastres_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE cadastres_id_seq OWNED BY cadastres.id; - - --- --- Name: cerfas; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE cerfas ( - id integer NOT NULL, - content character varying, - dossier_id integer, - created_at timestamp without time zone, - user_id integer, - original_filename character varying, - content_secure_token character varying -); - - --- --- Name: cerfas_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE cerfas_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: cerfas_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE cerfas_id_seq OWNED BY cerfas.id; - - --- --- Name: champs; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE champs ( - id integer NOT NULL, - value character varying, - type_de_champ_id integer, - dossier_id integer, - type character varying -); - - --- --- Name: champs_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE champs_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: champs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE champs_id_seq OWNED BY champs.id; - - --- --- Name: commentaires; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE commentaires ( - id integer NOT NULL, - email character varying, - created_at timestamp without time zone NOT NULL, - body character varying, - dossier_id integer, - updated_at timestamp without time zone NOT NULL, - piece_justificative_id integer -); - - --- --- Name: commentaires_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE commentaires_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: commentaires_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE commentaires_id_seq OWNED BY commentaires.id; - - --- --- Name: dossiers; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE dossiers ( - id integer NOT NULL, - autorisation_donnees boolean, - nom_projet character varying, - procedure_id integer, - created_at timestamp without time zone, - updated_at timestamp without time zone, - state character varying, - user_id integer, - json_latlngs text, - archived boolean DEFAULT false, - mandataire_social boolean DEFAULT false, - deposit_datetime timestamp without time zone -); - - --- --- Name: dossiers_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE dossiers_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: dossiers_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE dossiers_id_seq OWNED BY dossiers.id; - - --- --- Name: drop_down_lists; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE drop_down_lists ( - id integer NOT NULL, - value character varying, - type_de_champ_id integer -); - - --- --- Name: drop_down_lists_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE drop_down_lists_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: drop_down_lists_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE drop_down_lists_id_seq OWNED BY drop_down_lists.id; - - --- --- Name: entreprises; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE entreprises ( - id integer NOT NULL, - siren character varying, - capital_social integer, - numero_tva_intracommunautaire character varying, - forme_juridique character varying, - forme_juridique_code character varying, - nom_commercial character varying, - raison_sociale character varying, - siret_siege_social character varying, - code_effectif_entreprise character varying, - date_creation timestamp without time zone, - nom character varying, - prenom character varying, - dossier_id integer -); - - --- --- Name: entreprises_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE entreprises_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: entreprises_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE entreprises_id_seq OWNED BY entreprises.id; - - --- --- Name: etablissements; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE etablissements ( - id integer NOT NULL, - siret character varying, - siege_social boolean, - naf character varying, - libelle_naf character varying, - adresse character varying, - numero_voie character varying, - type_voie character varying, - nom_voie character varying, - complement_adresse character varying, - code_postal character varying, - localite character varying, - code_insee_localite character varying, - dossier_id integer, - entreprise_id integer -); - - --- --- Name: etablissements_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE etablissements_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: etablissements_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE etablissements_id_seq OWNED BY etablissements.id; - - --- --- Name: exercices; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE exercices ( - id integer NOT NULL, - ca character varying, - "dateFinExercice" timestamp without time zone, - date_fin_exercice_timestamp integer, - etablissement_id integer -); - - --- --- Name: exercices_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE exercices_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: exercices_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE exercices_id_seq OWNED BY exercices.id; - - --- --- Name: follows; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE follows ( - id integer NOT NULL, - gestionnaire_id integer, - dossier_id integer -); - - --- --- Name: follows_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE follows_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: follows_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE follows_id_seq OWNED BY follows.id; - - --- --- Name: france_connect_informations; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE france_connect_informations ( - id integer NOT NULL, - gender character varying, - given_name character varying, - family_name character varying, - birthdate date, - birthplace character varying, - france_connect_particulier_id character varying, - user_id integer, - email_france_connect character varying -); - - --- --- Name: france_connect_informations_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE france_connect_informations_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: france_connect_informations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE france_connect_informations_id_seq OWNED BY france_connect_informations.id; - - --- --- Name: gestionnaires; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE gestionnaires ( - id integer NOT NULL, - email character varying DEFAULT ''::character varying NOT NULL, - encrypted_password character varying DEFAULT ''::character varying NOT NULL, - reset_password_token character varying, - reset_password_sent_at timestamp without time zone, - remember_created_at timestamp without time zone, - sign_in_count integer DEFAULT 0 NOT NULL, - current_sign_in_at timestamp without time zone, - last_sign_in_at timestamp without time zone, - current_sign_in_ip inet, - last_sign_in_ip inet, - created_at timestamp without time zone, - updated_at timestamp without time zone, - procedure_filter integer -); - - --- --- Name: gestionnaires_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE gestionnaires_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: gestionnaires_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE gestionnaires_id_seq OWNED BY gestionnaires.id; - - --- --- Name: individuals; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE individuals ( - id integer NOT NULL, - nom character varying, - prenom character varying, - birthdate character varying, - dossier_id integer, - gender character varying -); - - --- --- Name: individuals_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE individuals_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: individuals_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE individuals_id_seq OWNED BY individuals.id; - - --- --- Name: invites; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE invites ( - id integer NOT NULL, - email character varying, - email_sender character varying, - dossier_id integer, - user_id integer, - type character varying DEFAULT 'InviteGestionnaire'::character varying -); - - --- --- Name: invites_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE invites_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: invites_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE invites_id_seq OWNED BY invites.id; - - --- --- Name: mail_templates; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE mail_templates ( - id integer NOT NULL, - object character varying, - body text, - type character varying, - procedure_id integer -); - - --- --- Name: mail_templates_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE mail_templates_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: mail_templates_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE mail_templates_id_seq OWNED BY mail_templates.id; - - --- --- Name: module_api_cartos; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE module_api_cartos ( - id integer NOT NULL, - procedure_id integer, - use_api_carto boolean DEFAULT false, - quartiers_prioritaires boolean DEFAULT false, - cadastre boolean DEFAULT false -); - - --- --- Name: module_api_cartos_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE module_api_cartos_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: module_api_cartos_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE module_api_cartos_id_seq OWNED BY module_api_cartos.id; - - --- --- Name: pieces_justificatives; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE pieces_justificatives ( - id integer NOT NULL, - content character varying, - dossier_id integer, - type_de_piece_justificative_id integer, - created_at timestamp without time zone, - user_id integer, - original_filename character varying, - content_secure_token character varying -); - - --- --- Name: pieces_justificatives_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE pieces_justificatives_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: pieces_justificatives_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE pieces_justificatives_id_seq OWNED BY pieces_justificatives.id; - - --- --- Name: preference_list_dossiers; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE preference_list_dossiers ( - id integer NOT NULL, - libelle character varying, - "table" character varying, - attr character varying, - attr_decorate character varying, - bootstrap_lg character varying, - "order" character varying, - filter character varying, - gestionnaire_id integer, - procedure_id integer -); - - --- --- Name: preference_list_dossiers_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE preference_list_dossiers_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: preference_list_dossiers_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE preference_list_dossiers_id_seq OWNED BY preference_list_dossiers.id; - - --- --- Name: preference_smart_listing_pages; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE preference_smart_listing_pages ( - id integer NOT NULL, - liste character varying, - page integer, - procedure_id integer, - gestionnaire_id integer -); - - --- --- Name: preference_smart_listing_pages_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE preference_smart_listing_pages_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: preference_smart_listing_pages_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE preference_smart_listing_pages_id_seq OWNED BY preference_smart_listing_pages.id; - - --- --- Name: procedure_paths; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE procedure_paths ( - id integer NOT NULL, - path character varying(30), - procedure_id integer, - administrateur_id integer -); - - --- --- Name: procedure_paths_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE procedure_paths_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: procedure_paths_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE procedure_paths_id_seq OWNED BY procedure_paths.id; - - --- --- Name: procedures; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE procedures ( - id integer NOT NULL, - libelle character varying, - description character varying, - organisation character varying, - direction character varying, - lien_demarche character varying, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL, - test boolean, - administrateur_id integer, - archived boolean DEFAULT false, - euro_flag boolean DEFAULT false, - logo character varying, - cerfa_flag boolean DEFAULT false, - logo_secure_token character varying, - published boolean DEFAULT false NOT NULL, - lien_site_web character varying, - lien_notice character varying, - for_individual boolean DEFAULT false, - individual_with_siret boolean DEFAULT false -); - - --- --- Name: procedures_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE procedures_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: procedures_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE procedures_id_seq OWNED BY procedures.id; - - --- --- Name: quartier_prioritaires; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE quartier_prioritaires ( - id integer NOT NULL, - code character varying, - nom character varying, - commune character varying, - geometry text, - dossier_id integer -); - - --- --- Name: quartier_prioritaires_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE quartier_prioritaires_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: quartier_prioritaires_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE quartier_prioritaires_id_seq OWNED BY quartier_prioritaires.id; - - --- --- Name: rna_informations; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE rna_informations ( - id integer NOT NULL, - association_id character varying, - titre character varying, - objet text, - date_creation date, - date_declaration date, - date_publication date, - entreprise_id integer -); - - --- --- Name: rna_informations_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE rna_informations_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: rna_informations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE rna_informations_id_seq OWNED BY rna_informations.id; - - --- --- Name: schema_migrations; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE schema_migrations ( - version character varying NOT NULL -); - - --- --- Name: users; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE users ( - id integer NOT NULL, - email character varying DEFAULT ''::character varying NOT NULL, - encrypted_password character varying DEFAULT ''::character varying NOT NULL, - reset_password_token character varying, - reset_password_sent_at timestamp without time zone, - remember_created_at timestamp without time zone, - sign_in_count integer DEFAULT 0 NOT NULL, - current_sign_in_at timestamp without time zone, - last_sign_in_at timestamp without time zone, - current_sign_in_ip inet, - last_sign_in_ip inet, - created_at timestamp without time zone, - updated_at timestamp without time zone, - siret character varying, - loged_in_with_france_connect character varying DEFAULT false -); - - --- --- Name: searches; Type: VIEW; Schema: public; Owner: - --- - -CREATE VIEW searches AS - SELECT dossiers.id AS dossier_id, - (((((((((((((((((((((((((((((((((((((((((((((((((((((((COALESCE(users.email, ''::character varying))::text || ' '::text) || (COALESCE(france_connect_informations.given_name, ''::character varying))::text) || ' '::text) || (COALESCE(france_connect_informations.family_name, ''::character varying))::text) || ' '::text) || (COALESCE(cerfas.content, ''::character varying))::text) || ' '::text) || (COALESCE(champs.value, ''::character varying))::text) || ' '::text) || (COALESCE(drop_down_lists.value, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.siren, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.numero_tva_intracommunautaire, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.forme_juridique, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.forme_juridique_code, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.nom_commercial, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.raison_sociale, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.siret_siege_social, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.nom, ''::character varying))::text) || ' '::text) || (COALESCE(entreprises.prenom, ''::character varying))::text) || ' '::text) || (COALESCE(rna_informations.association_id, ''::character varying))::text) || ' '::text) || (COALESCE(rna_informations.titre, ''::character varying))::text) || ' '::text) || COALESCE(rna_informations.objet, ''::text)) || ' '::text) || (COALESCE(etablissements.siret, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.naf, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.libelle_naf, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.adresse, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.code_postal, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.localite, ''::character varying))::text) || ' '::text) || (COALESCE(etablissements.code_insee_localite, ''::character varying))::text) || ' '::text) || (COALESCE(individuals.nom, ''::character varying))::text) || ' '::text) || (COALESCE(individuals.prenom, ''::character varying))::text) || ' '::text) || (COALESCE(pieces_justificatives.content, ''::character varying))::text) AS term - FROM ((((((((((dossiers - JOIN users ON ((users.id = dossiers.user_id))) - LEFT JOIN france_connect_informations ON ((france_connect_informations.user_id = dossiers.user_id))) - LEFT JOIN cerfas ON ((cerfas.dossier_id = dossiers.id))) - LEFT JOIN champs ON ((champs.dossier_id = dossiers.id))) - LEFT JOIN drop_down_lists ON ((drop_down_lists.type_de_champ_id = champs.type_de_champ_id))) - LEFT JOIN entreprises ON ((entreprises.dossier_id = dossiers.id))) - LEFT JOIN rna_informations ON ((rna_informations.entreprise_id = entreprises.id))) - LEFT JOIN etablissements ON ((etablissements.dossier_id = dossiers.id))) - LEFT JOIN individuals ON ((individuals.dossier_id = dossiers.id))) - LEFT JOIN pieces_justificatives ON ((pieces_justificatives.dossier_id = dossiers.id))); - - --- --- Name: types_de_champ; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE types_de_champ ( - id integer NOT NULL, - libelle character varying, - type_champ character varying, - order_place integer, - procedure_id integer, - description text, - mandatory boolean DEFAULT false, - type character varying -); - - --- --- Name: types_de_champ_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE types_de_champ_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: types_de_champ_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE types_de_champ_id_seq OWNED BY types_de_champ.id; - - --- --- Name: types_de_piece_justificative; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE types_de_piece_justificative ( - id integer NOT NULL, - libelle character varying, - description character varying, - api_entreprise boolean DEFAULT false, - created_at timestamp without time zone NOT NULL, - updated_at timestamp without time zone NOT NULL, - procedure_id integer, - order_place integer -); - - --- --- Name: types_de_piece_justificative_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE types_de_piece_justificative_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: types_de_piece_justificative_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE types_de_piece_justificative_id_seq OWNED BY types_de_piece_justificative.id; - - --- --- Name: users_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE users_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: users_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE users_id_seq OWNED BY users.id; - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY administrateurs ALTER COLUMN id SET DEFAULT nextval('administrateurs_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY administrations ALTER COLUMN id SET DEFAULT nextval('administrations_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY cadastres ALTER COLUMN id SET DEFAULT nextval('cadastres_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY cerfas ALTER COLUMN id SET DEFAULT nextval('cerfas_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY champs ALTER COLUMN id SET DEFAULT nextval('champs_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY commentaires ALTER COLUMN id SET DEFAULT nextval('commentaires_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY dossiers ALTER COLUMN id SET DEFAULT nextval('dossiers_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY drop_down_lists ALTER COLUMN id SET DEFAULT nextval('drop_down_lists_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY entreprises ALTER COLUMN id SET DEFAULT nextval('entreprises_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY etablissements ALTER COLUMN id SET DEFAULT nextval('etablissements_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY exercices ALTER COLUMN id SET DEFAULT nextval('exercices_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY follows ALTER COLUMN id SET DEFAULT nextval('follows_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY france_connect_informations ALTER COLUMN id SET DEFAULT nextval('france_connect_informations_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY gestionnaires ALTER COLUMN id SET DEFAULT nextval('gestionnaires_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY individuals ALTER COLUMN id SET DEFAULT nextval('individuals_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY invites ALTER COLUMN id SET DEFAULT nextval('invites_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY mail_templates ALTER COLUMN id SET DEFAULT nextval('mail_templates_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY module_api_cartos ALTER COLUMN id SET DEFAULT nextval('module_api_cartos_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY pieces_justificatives ALTER COLUMN id SET DEFAULT nextval('pieces_justificatives_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY preference_list_dossiers ALTER COLUMN id SET DEFAULT nextval('preference_list_dossiers_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY preference_smart_listing_pages ALTER COLUMN id SET DEFAULT nextval('preference_smart_listing_pages_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY procedure_paths ALTER COLUMN id SET DEFAULT nextval('procedure_paths_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY procedures ALTER COLUMN id SET DEFAULT nextval('procedures_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY quartier_prioritaires ALTER COLUMN id SET DEFAULT nextval('quartier_prioritaires_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY rna_informations ALTER COLUMN id SET DEFAULT nextval('rna_informations_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY types_de_champ ALTER COLUMN id SET DEFAULT nextval('types_de_champ_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY types_de_piece_justificative ALTER COLUMN id SET DEFAULT nextval('types_de_piece_justificative_id_seq'::regclass); - - --- --- Name: id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY users ALTER COLUMN id SET DEFAULT nextval('users_id_seq'::regclass); - - --- --- Name: administrateurs_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY administrateurs - ADD CONSTRAINT administrateurs_pkey PRIMARY KEY (id); - - --- --- Name: administrations_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY administrations - ADD CONSTRAINT administrations_pkey PRIMARY KEY (id); - - --- --- Name: cadastres_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY cadastres - ADD CONSTRAINT cadastres_pkey PRIMARY KEY (id); - - --- --- Name: cerfas_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY cerfas - ADD CONSTRAINT cerfas_pkey PRIMARY KEY (id); - - --- --- Name: champs_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY champs - ADD CONSTRAINT champs_pkey PRIMARY KEY (id); - - --- --- Name: commentaires_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY commentaires - ADD CONSTRAINT commentaires_pkey PRIMARY KEY (id); - - --- --- Name: dossiers_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY dossiers - ADD CONSTRAINT dossiers_pkey PRIMARY KEY (id); - - --- --- Name: drop_down_lists_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY drop_down_lists - ADD CONSTRAINT drop_down_lists_pkey PRIMARY KEY (id); - - --- --- Name: entreprises_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY entreprises - ADD CONSTRAINT entreprises_pkey PRIMARY KEY (id); - - --- --- Name: etablissements_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY etablissements - ADD CONSTRAINT etablissements_pkey PRIMARY KEY (id); - - --- --- Name: exercices_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY exercices - ADD CONSTRAINT exercices_pkey PRIMARY KEY (id); - - --- --- Name: follows_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY follows - ADD CONSTRAINT follows_pkey PRIMARY KEY (id); - - --- --- Name: france_connect_informations_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY france_connect_informations - ADD CONSTRAINT france_connect_informations_pkey PRIMARY KEY (id); - - --- --- Name: gestionnaires_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY gestionnaires - ADD CONSTRAINT gestionnaires_pkey PRIMARY KEY (id); - - --- --- Name: individuals_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY individuals - ADD CONSTRAINT individuals_pkey PRIMARY KEY (id); - - --- --- Name: invites_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY invites - ADD CONSTRAINT invites_pkey PRIMARY KEY (id); - - --- --- Name: mail_templates_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY mail_templates - ADD CONSTRAINT mail_templates_pkey PRIMARY KEY (id); - - --- --- Name: module_api_cartos_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY module_api_cartos - ADD CONSTRAINT module_api_cartos_pkey PRIMARY KEY (id); - - --- --- Name: pieces_justificatives_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY pieces_justificatives - ADD CONSTRAINT pieces_justificatives_pkey PRIMARY KEY (id); - - --- --- Name: preference_list_dossiers_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY preference_list_dossiers - ADD CONSTRAINT preference_list_dossiers_pkey PRIMARY KEY (id); - - --- --- Name: preference_smart_listing_pages_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY preference_smart_listing_pages - ADD CONSTRAINT preference_smart_listing_pages_pkey PRIMARY KEY (id); - - --- --- Name: procedure_paths_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY procedure_paths - ADD CONSTRAINT procedure_paths_pkey PRIMARY KEY (id); - - --- --- Name: procedures_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY procedures - ADD CONSTRAINT procedures_pkey PRIMARY KEY (id); - - --- --- Name: quartier_prioritaires_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY quartier_prioritaires - ADD CONSTRAINT quartier_prioritaires_pkey PRIMARY KEY (id); - - --- --- Name: rna_informations_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY rna_informations - ADD CONSTRAINT rna_informations_pkey PRIMARY KEY (id); - - --- --- Name: types_de_champ_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY types_de_champ - ADD CONSTRAINT types_de_champ_pkey PRIMARY KEY (id); - - --- --- Name: types_de_piece_justificative_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY types_de_piece_justificative - ADD CONSTRAINT types_de_piece_justificative_pkey PRIMARY KEY (id); - - --- --- Name: users_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY users - ADD CONSTRAINT users_pkey PRIMARY KEY (id); - - --- --- Name: index_administrateurs_gestionnaires_on_administrateur_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_administrateurs_gestionnaires_on_administrateur_id ON administrateurs_gestionnaires USING btree (administrateur_id); - - --- --- Name: index_administrateurs_gestionnaires_on_gestionnaire_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_administrateurs_gestionnaires_on_gestionnaire_id ON administrateurs_gestionnaires USING btree (gestionnaire_id); - - --- --- Name: index_administrateurs_on_email; Type: INDEX; Schema: public; Owner: - --- - -CREATE UNIQUE INDEX index_administrateurs_on_email ON administrateurs USING btree (email); - - --- --- Name: index_administrateurs_on_reset_password_token; Type: INDEX; Schema: public; Owner: - --- - -CREATE UNIQUE INDEX index_administrateurs_on_reset_password_token ON administrateurs USING btree (reset_password_token); - - --- --- Name: index_administrations_on_email; Type: INDEX; Schema: public; Owner: - --- - -CREATE UNIQUE INDEX index_administrations_on_email ON administrations USING btree (email); - - --- --- Name: index_administrations_on_reset_password_token; Type: INDEX; Schema: public; Owner: - --- - -CREATE UNIQUE INDEX index_administrations_on_reset_password_token ON administrations USING btree (reset_password_token); - - --- --- Name: index_assign_tos_on_gestionnaire_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_assign_tos_on_gestionnaire_id ON assign_tos USING btree (gestionnaire_id); - - --- --- Name: index_assign_tos_on_procedure_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_assign_tos_on_procedure_id ON assign_tos USING btree (procedure_id); - - --- --- Name: index_cerfas_on_dossier_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_cerfas_on_dossier_id ON cerfas USING btree (dossier_id); - - --- --- Name: index_champs_on_dossier_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_champs_on_dossier_id ON champs USING btree (dossier_id); - - --- --- Name: index_champs_on_type_de_champ_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_champs_on_type_de_champ_id ON champs USING btree (type_de_champ_id); - - --- --- Name: index_commentaires_on_dossier_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_commentaires_on_dossier_id ON commentaires USING btree (dossier_id); - - --- --- Name: index_dossiers_on_procedure_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_dossiers_on_procedure_id ON dossiers USING btree (procedure_id); - - --- --- Name: index_dossiers_on_user_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_dossiers_on_user_id ON dossiers USING btree (user_id); - - --- --- Name: index_drop_down_lists_on_type_de_champ_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_drop_down_lists_on_type_de_champ_id ON drop_down_lists USING btree (type_de_champ_id); - - --- --- Name: index_entreprises_on_dossier_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_entreprises_on_dossier_id ON entreprises USING btree (dossier_id); - - --- --- Name: index_etablissements_on_dossier_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_etablissements_on_dossier_id ON etablissements USING btree (dossier_id); - - --- --- Name: index_follows_on_dossier_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_follows_on_dossier_id ON follows USING btree (dossier_id); - - --- --- Name: index_follows_on_gestionnaire_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_follows_on_gestionnaire_id ON follows USING btree (gestionnaire_id); - - --- --- Name: index_france_connect_informations_on_user_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_france_connect_informations_on_user_id ON france_connect_informations USING btree (user_id); - - --- --- Name: index_gestionnaires_on_email; Type: INDEX; Schema: public; Owner: - --- - -CREATE UNIQUE INDEX index_gestionnaires_on_email ON gestionnaires USING btree (email); - - --- --- Name: index_gestionnaires_on_reset_password_token; Type: INDEX; Schema: public; Owner: - --- - -CREATE UNIQUE INDEX index_gestionnaires_on_reset_password_token ON gestionnaires USING btree (reset_password_token); - - --- --- Name: index_individuals_on_dossier_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_individuals_on_dossier_id ON individuals USING btree (dossier_id); - - --- --- Name: index_module_api_cartos_on_procedure_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE UNIQUE INDEX index_module_api_cartos_on_procedure_id ON module_api_cartos USING btree (procedure_id); - - --- --- Name: index_pieces_justificatives_on_dossier_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_pieces_justificatives_on_dossier_id ON pieces_justificatives USING btree (dossier_id); - - --- --- Name: index_pieces_justificatives_on_type_de_piece_justificative_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_pieces_justificatives_on_type_de_piece_justificative_id ON pieces_justificatives USING btree (type_de_piece_justificative_id); - - --- --- Name: index_procedure_paths_on_path; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_procedure_paths_on_path ON procedure_paths USING btree (path); - - --- --- Name: index_rna_informations_on_entreprise_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_rna_informations_on_entreprise_id ON rna_informations USING btree (entreprise_id); - - --- --- Name: index_users_on_email; Type: INDEX; Schema: public; Owner: - --- - -CREATE UNIQUE INDEX index_users_on_email ON users USING btree (email); - - --- --- Name: index_users_on_reset_password_token; Type: INDEX; Schema: public; Owner: - --- - -CREATE UNIQUE INDEX index_users_on_reset_password_token ON users USING btree (reset_password_token); - - --- --- Name: unique_couple_administrateur_gestionnaire; Type: INDEX; Schema: public; Owner: - --- - -CREATE UNIQUE INDEX unique_couple_administrateur_gestionnaire ON administrateurs_gestionnaires USING btree (gestionnaire_id, administrateur_id); - - --- --- Name: unique_schema_migrations; Type: INDEX; Schema: public; Owner: - --- - -CREATE UNIQUE INDEX unique_schema_migrations ON schema_migrations USING btree (version); - - --- --- Name: fk_rails_2692c11f42; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY cerfas - ADD CONSTRAINT fk_rails_2692c11f42 FOREIGN KEY (dossier_id) REFERENCES dossiers(id); - - --- --- Name: fk_rails_3ba5f624df; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY procedure_paths - ADD CONSTRAINT fk_rails_3ba5f624df FOREIGN KEY (administrateur_id) REFERENCES administrateurs(id); - - --- --- Name: fk_rails_7238f4c1f2; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY procedure_paths - ADD CONSTRAINT fk_rails_7238f4c1f2 FOREIGN KEY (procedure_id) REFERENCES procedures(id); - - --- --- Name: fk_rails_7a18851d0c; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY dossiers - ADD CONSTRAINT fk_rails_7a18851d0c FOREIGN KEY (user_id) REFERENCES users(id); - - --- --- Name: fk_rails_e74708c22b; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY commentaires - ADD CONSTRAINT fk_rails_e74708c22b FOREIGN KEY (dossier_id) REFERENCES dossiers(id); - - --- --- PostgreSQL database dump complete --- - -SET search_path TO "$user", public; - -INSERT INTO schema_migrations (version) VALUES ('20150623121437'); - -INSERT INTO schema_migrations (version) VALUES ('20150623122513'); - -INSERT INTO schema_migrations (version) VALUES ('20150623123033'); - -INSERT INTO schema_migrations (version) VALUES ('20150624134202'); - -INSERT INTO schema_migrations (version) VALUES ('20150624145400'); - -INSERT INTO schema_migrations (version) VALUES ('20150625130851'); - -INSERT INTO schema_migrations (version) VALUES ('20150626081655'); - -INSERT INTO schema_migrations (version) VALUES ('20150630123827'); - -INSERT INTO schema_migrations (version) VALUES ('20150728140340'); - -INSERT INTO schema_migrations (version) VALUES ('20150731121101'); - -INSERT INTO schema_migrations (version) VALUES ('20150804131511'); - -INSERT INTO schema_migrations (version) VALUES ('20150805081131'); - -INSERT INTO schema_migrations (version) VALUES ('20150806071130'); - -INSERT INTO schema_migrations (version) VALUES ('20150806072031'); - -INSERT INTO schema_migrations (version) VALUES ('20150806075144'); - -INSERT INTO schema_migrations (version) VALUES ('20150806132417'); - -INSERT INTO schema_migrations (version) VALUES ('20150806155734'); - -INSERT INTO schema_migrations (version) VALUES ('20150806162353'); - -INSERT INTO schema_migrations (version) VALUES ('20150810130957'); - -INSERT INTO schema_migrations (version) VALUES ('20150812091703'); - -INSERT INTO schema_migrations (version) VALUES ('20150813095218'); - -INSERT INTO schema_migrations (version) VALUES ('20150813095939'); - -INSERT INTO schema_migrations (version) VALUES ('20150814090717'); - -INSERT INTO schema_migrations (version) VALUES ('20150814101012'); - -INSERT INTO schema_migrations (version) VALUES ('20150814120635'); - -INSERT INTO schema_migrations (version) VALUES ('20150814121848'); - -INSERT INTO schema_migrations (version) VALUES ('20150814122208'); - -INSERT INTO schema_migrations (version) VALUES ('20150814124735'); - -INSERT INTO schema_migrations (version) VALUES ('20150818113123'); - -INSERT INTO schema_migrations (version) VALUES ('20150824134012'); - -INSERT INTO schema_migrations (version) VALUES ('20150825083550'); - -INSERT INTO schema_migrations (version) VALUES ('20150918163159'); - -INSERT INTO schema_migrations (version) VALUES ('20150921085540'); - -INSERT INTO schema_migrations (version) VALUES ('20150921085754'); - -INSERT INTO schema_migrations (version) VALUES ('20150921092320'); - -INSERT INTO schema_migrations (version) VALUES ('20150921092536'); - -INSERT INTO schema_migrations (version) VALUES ('20150921101240'); - -INSERT INTO schema_migrations (version) VALUES ('20150922082053'); - -INSERT INTO schema_migrations (version) VALUES ('20150922082416'); - -INSERT INTO schema_migrations (version) VALUES ('20150922085811'); - -INSERT INTO schema_migrations (version) VALUES ('20150922110719'); - -INSERT INTO schema_migrations (version) VALUES ('20150922113504'); - -INSERT INTO schema_migrations (version) VALUES ('20150922141000'); - -INSERT INTO schema_migrations (version) VALUES ('20150922141232'); - -INSERT INTO schema_migrations (version) VALUES ('20150923101000'); - -INSERT INTO schema_migrations (version) VALUES ('20150928141512'); - -INSERT INTO schema_migrations (version) VALUES ('20151006155256'); - -INSERT INTO schema_migrations (version) VALUES ('20151007085022'); - -INSERT INTO schema_migrations (version) VALUES ('20151008090835'); - -INSERT INTO schema_migrations (version) VALUES ('20151023132121'); - -INSERT INTO schema_migrations (version) VALUES ('20151026155158'); - -INSERT INTO schema_migrations (version) VALUES ('20151027150850'); - -INSERT INTO schema_migrations (version) VALUES ('20151102101616'); - -INSERT INTO schema_migrations (version) VALUES ('20151102102747'); - -INSERT INTO schema_migrations (version) VALUES ('20151102104309'); - -INSERT INTO schema_migrations (version) VALUES ('20151102105011'); - -INSERT INTO schema_migrations (version) VALUES ('20151102135824'); - -INSERT INTO schema_migrations (version) VALUES ('20151102142940'); - -INSERT INTO schema_migrations (version) VALUES ('20151102143908'); - -INSERT INTO schema_migrations (version) VALUES ('20151102163051'); - -INSERT INTO schema_migrations (version) VALUES ('20151103091603'); - -INSERT INTO schema_migrations (version) VALUES ('20151105093644'); - -INSERT INTO schema_migrations (version) VALUES ('20151105095431'); - -INSERT INTO schema_migrations (version) VALUES ('20151110091159'); - -INSERT INTO schema_migrations (version) VALUES ('20151110091451'); - -INSERT INTO schema_migrations (version) VALUES ('20151112151918'); - -INSERT INTO schema_migrations (version) VALUES ('20151113171605'); - -INSERT INTO schema_migrations (version) VALUES ('20151116175817'); - -INSERT INTO schema_migrations (version) VALUES ('20151124085333'); - -INSERT INTO schema_migrations (version) VALUES ('20151126153425'); - -INSERT INTO schema_migrations (version) VALUES ('20151127103412'); - -INSERT INTO schema_migrations (version) VALUES ('20151207095904'); - -INSERT INTO schema_migrations (version) VALUES ('20151207140202'); - -INSERT INTO schema_migrations (version) VALUES ('20151210134135'); - -INSERT INTO schema_migrations (version) VALUES ('20151210150958'); - -INSERT INTO schema_migrations (version) VALUES ('20151211093833'); - -INSERT INTO schema_migrations (version) VALUES ('20151214133426'); - -INSERT INTO schema_migrations (version) VALUES ('20151221164041'); - -INSERT INTO schema_migrations (version) VALUES ('20151222105558'); - -INSERT INTO schema_migrations (version) VALUES ('20151223101322'); - -INSERT INTO schema_migrations (version) VALUES ('20160106100227'); - -INSERT INTO schema_migrations (version) VALUES ('20160115135025'); - -INSERT INTO schema_migrations (version) VALUES ('20160120094750'); - -INSERT INTO schema_migrations (version) VALUES ('20160120141602'); - -INSERT INTO schema_migrations (version) VALUES ('20160121110603'); - -INSERT INTO schema_migrations (version) VALUES ('20160127162841'); - -INSERT INTO schema_migrations (version) VALUES ('20160127170437'); - -INSERT INTO schema_migrations (version) VALUES ('20160204155519'); - -INSERT INTO schema_migrations (version) VALUES ('20160223134354'); - -INSERT INTO schema_migrations (version) VALUES ('20160314102523'); - -INSERT INTO schema_migrations (version) VALUES ('20160314160801'); - -INSERT INTO schema_migrations (version) VALUES ('20160314161959'); - -INSERT INTO schema_migrations (version) VALUES ('20160315101245'); - -INSERT INTO schema_migrations (version) VALUES ('20160317135217'); - -INSERT INTO schema_migrations (version) VALUES ('20160317144949'); - -INSERT INTO schema_migrations (version) VALUES ('20160317153115'); - -INSERT INTO schema_migrations (version) VALUES ('20160419142017'); - -INSERT INTO schema_migrations (version) VALUES ('20160512160602'); - -INSERT INTO schema_migrations (version) VALUES ('20160512160658'); - -INSERT INTO schema_migrations (version) VALUES ('20160512160824'); - -INSERT INTO schema_migrations (version) VALUES ('20160512160836'); - -INSERT INTO schema_migrations (version) VALUES ('20160513093425'); - -INSERT INTO schema_migrations (version) VALUES ('20160519100904'); - -INSERT INTO schema_migrations (version) VALUES ('20160519101018'); - -INSERT INTO schema_migrations (version) VALUES ('20160523163054'); - -INSERT INTO schema_migrations (version) VALUES ('20160524093540'); - -INSERT INTO schema_migrations (version) VALUES ('20160607150440'); - -INSERT INTO schema_migrations (version) VALUES ('20160609125949'); - -INSERT INTO schema_migrations (version) VALUES ('20160609145737'); - -INSERT INTO schema_migrations (version) VALUES ('20160622081321'); - -INSERT INTO schema_migrations (version) VALUES ('20160622081322'); - -INSERT INTO schema_migrations (version) VALUES ('20160718124741'); - -INSERT INTO schema_migrations (version) VALUES ('20160722135927'); - -INSERT INTO schema_migrations (version) VALUES ('20160802113112'); - -INSERT INTO schema_migrations (version) VALUES ('20160802131031'); - -INSERT INTO schema_migrations (version) VALUES ('20160802161734'); - -INSERT INTO schema_migrations (version) VALUES ('20160803081304'); - -INSERT INTO schema_migrations (version) VALUES ('20160804130638'); - -INSERT INTO schema_migrations (version) VALUES ('20160808115924'); - -INSERT INTO schema_migrations (version) VALUES ('20160809083606'); - -INSERT INTO schema_migrations (version) VALUES ('20160822142045'); - -INSERT INTO schema_migrations (version) VALUES ('20160824094151'); - -INSERT INTO schema_migrations (version) VALUES ('20160824094451'); - -INSERT INTO schema_migrations (version) VALUES ('20160829094658'); - -INSERT INTO schema_migrations (version) VALUES ('20160829114646'); - -INSERT INTO schema_migrations (version) VALUES ('20160830142653'); - -INSERT INTO schema_migrations (version) VALUES ('20160901082824'); - -INSERT INTO schema_migrations (version) VALUES ('20160906123255'); - -INSERT INTO schema_migrations (version) VALUES ('20160906134155'); - -INSERT INTO schema_migrations (version) VALUES ('20160913093948'); - -INSERT INTO schema_migrations (version) VALUES ('20160926160051'); - -INSERT INTO schema_migrations (version) VALUES ('20160927154248'); - -INSERT INTO schema_migrations (version) VALUES ('20161004175442'); - -INSERT INTO schema_migrations (version) VALUES ('20161005082113'); - -INSERT INTO schema_migrations (version) VALUES ('20161005144657'); - -INSERT INTO schema_migrations (version) VALUES ('20161006085422'); - -INSERT INTO schema_migrations (version) VALUES ('20161007095443'); - -INSERT INTO schema_migrations (version) VALUES ('20161011125345'); - -INSERT INTO schema_migrations (version) VALUES ('20161025150900'); - -INSERT INTO schema_migrations (version) VALUES ('20161102154835'); - From 5284df5ce0afbd14c6531e1a800fbba868e5c5a5 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Mon, 7 Nov 2016 17:08:33 +0100 Subject: [PATCH 06/15] =?UTF-8?q?Add=20page=20=C2=AB=C2=A0Proc=C3=A9dure?= =?UTF-8?q?=20termin=C3=A9e=C2=A0=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/procedures_controller.rb | 7 ++- app/controllers/users/dossiers_controller.rb | 7 +++ app/models/procedure.rb | 1 - app/views/commencer/archived.html.haml | 15 +++++++ .../sessions/_resume_procedure.html.haml | 18 ++++++++ app/views/users/sessions/new.html.haml | 20 +-------- .../admin/procedures_controller_spec.rb | 44 ++++++++++++++----- .../users/dossiers_controller_spec.rb | 10 +++++ spec/models/procedure_spec.rb | 6 +-- 9 files changed, 93 insertions(+), 35 deletions(-) create mode 100644 app/views/commencer/archived.html.haml create mode 100644 app/views/users/sessions/_resume_procedure.html.haml diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index 0e51c2097..4d8e44af3 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -179,7 +179,12 @@ class Admin::ProceduresController < AdminController end def path_list - render json: ProcedurePath.where("path LIKE '%#{params[:request]}%'").pluck(:path, :administrateur_id).inject([]) { + render json: ProcedurePath + .joins(', procedures') + .where("procedures.id = procedure_paths.procedure_id AND procedures.archived != true") + .where("path LIKE '%#{params[:request]}%'") + .pluck(:path, :administrateur_id) + .inject([]) { |acc, value| acc.push({label: value.first, mine: value.second == current_administrateur.id}) }.to_json end diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 8e175d8b2..f5ef2472f 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -30,6 +30,13 @@ class Users::DossiersController < UsersController procedure = ProcedurePath.where(path: params[:procedure_path]).first!.procedure end + if procedure.archived? + + @dossier = Dossier.new(procedure: procedure) + + return render 'commencer/archived' + end + redirect_to new_users_dossier_path(procedure_id: procedure.id) rescue ActiveRecord::RecordNotFound error_procedure diff --git a/app/models/procedure.rb b/app/models/procedure.rb index f8d737532..9a81ed2b6 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -103,7 +103,6 @@ class Procedure < ActiveRecord::Base end def archive - self.procedure_path.destroy! if self.path self.update_attributes!({archived: true}) end diff --git a/app/views/commencer/archived.html.haml b/app/views/commencer/archived.html.haml new file mode 100644 index 000000000..5ad9c0f18 --- /dev/null +++ b/app/views/commencer/archived.html.haml @@ -0,0 +1,15 @@ +%br +%div{style: 'text-align: center; max-width:500px; margin-left:auto; margin-right:auto; padding: 20px;'} + = render partial: 'users/sessions/resume_procedure' + +.center{style:'margin-top: -20px'} + %h3 + La campagne de création de nouveau dossier + %br + pour cette démarche en ligne est maintenant terminée. + + %br + %p + Si vous avez déjà déposé un ou plusieurs dossiers : + %a.btn.btn-lg.btn-info{href: new_user_session_path} + Accéder à mon espace en ligne. \ No newline at end of file diff --git a/app/views/users/sessions/_resume_procedure.html.haml b/app/views/users/sessions/_resume_procedure.html.haml new file mode 100644 index 000000000..f99ce8bd8 --- /dev/null +++ b/app/views/users/sessions/_resume_procedure.html.haml @@ -0,0 +1,18 @@ +- if @dossier + = link_to 'X', users_no_procedure_url, class: 'btn btn-xs', style:'float: right' + + - if @dossier.procedure.euro_flag + #euro_flag.flag + =image_tag('drapeau_europe.png') + + #logo_procedure.flag + =image_tag( @dossier.procedure.decorate.logo_img ) + + %h2#titre_procedure.text-info + = @dossier.procedure.libelle + %p + = h @dossier.procedure.description.html_safe + +- else + = image_tag(image_url(LOGO_NAME), {id: 'logo_tps'}) +%br \ No newline at end of file diff --git a/app/views/users/sessions/new.html.haml b/app/views/users/sessions/new.html.haml index c82745969..718da7056 100644 --- a/app/views/users/sessions/new.html.haml +++ b/app/views/users/sessions/new.html.haml @@ -1,24 +1,6 @@ #form_login %br - - if @dossier - = link_to 'X', users_no_procedure_url, class: 'btn btn-xs', style:'float: right' - - - if @dossier.procedure.euro_flag - #euro_flag.flag - =image_tag('drapeau_europe.png') - - #logo_procedure.flag - =image_tag( @dossier.procedure.decorate.logo_img ) - - %h2#titre_procedure.text-info - = @dossier.procedure.libelle - %p - = h @dossier.procedure.description.html_safe - - - - else - = image_tag(image_url(LOGO_NAME), {id: 'logo_tps'}) - %br + = render partial: 'users/sessions/resume_procedure' %h2#login_user =t('dynamics.users.connexion_title') diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index c6ddc9462..c72a02d35 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -299,7 +299,7 @@ describe Admin::ProceduresController, type: :controller do it 'archive previous procedure' do expect(procedure2.published).to be_truthy expect(procedure2.archived).to be_truthy - expect(procedure2.path).to be_nil + expect(procedure2.path).not_to be_nil end end @@ -427,21 +427,31 @@ describe Admin::ProceduresController, type: :controller do let!(:procedure) { create(:procedure, :published, administrateur: admin) } let(:admin2) { create(:administrateur) } let!(:procedure2) { create(:procedure, :published, administrateur: admin2) } + let!(:procedure3) { create(:procedure, :published, administrateur: admin2) } + subject { get :path_list } + let(:body) { JSON.parse(response.body) } - before do - subject + describe 'when no params' do + before do + subject + end + + it { expect(response.status).to eq(200) } + it { expect(body.size).to eq(3) } + it { expect(body.first['label']).to eq(procedure.path) } + it { expect(body.first['mine']).to be_truthy } + it { expect(body.second['label']).to eq(procedure2.path) } + it { expect(body.second['mine']).to be_falsy } + end - it { expect(response.status).to eq(200) } - it { expect(body.size).to eq(2) } - it { expect(body.first['label']).to eq(procedure.path) } - it { expect(body.first['mine']).to be_truthy } - it { expect(body.second['label']).to eq(procedure2.path) } - it { expect(body.second['mine']).to be_falsy } - context 'filtered' do + before do + subject + end + subject { get :path_list, request: procedure2.path } it { expect(response.status).to eq(200) } @@ -449,6 +459,18 @@ describe Admin::ProceduresController, type: :controller do it { expect(body.first['label']).to eq(procedure2.path) } it { expect(body.first['mine']).to be_falsy } end + + context 'when procedure is archived' do + + before do + procedure3.update_attribute :archived, true + subject + end + + it 'do not return on the json' do + expect(body.size).to eq(2) + end + end end describe 'POST transfer' do @@ -467,7 +489,7 @@ describe Admin::ProceduresController, type: :controller do let(:email_admin) { new_admin.email } it { expect(subject.status).to eq 200 } - it { expect {subject}.to change(Procedure, :count).by(1) } + it { expect { subject }.to change(Procedure, :count).by(1) } context { before do diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index d88ae049a..9bdb158de 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -157,6 +157,16 @@ describe Users::DossiersController, type: :controller do it { expect(subject.status).to eq 302 } it { expect(subject).to redirect_to new_users_dossier_path(procedure_id: procedure.id) } + + context 'when procedure is archived' do + let(:procedure) { create(:procedure, :published, archived: true) } + + before do + procedure.update_column :archived, true + end + + it { expect(subject.status).to eq 200 } + end end describe 'POST #siret_informations' do diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 47356f165..db62fda24 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -243,14 +243,14 @@ describe Procedure do end it 'is not available from a valid path anymore' do - expect(procedure.path).to be_nil + expect(procedure.path).to eq procedure_path.path expect(procedure.published).to be_truthy expect(procedure.archived).to be_truthy end it 'is not in ProcedurePath table anymore' do - expect(ProcedurePath.where(path: procedure.path).count).to eq(0) - expect(ProcedurePath.find_by_procedure_id(procedure.id)).to be_nil + expect(ProcedurePath.where(path: procedure.path).count).to eq(1) + expect(ProcedurePath.find_by_procedure_id(procedure.id)).not_to be_nil end end From eb64e04aba37a5e9d05742097a22cbb4f1de5f2f Mon Sep 17 00:00:00 2001 From: Xavier J Date: Tue, 8 Nov 2016 10:57:15 +0100 Subject: [PATCH 07/15] Dynamic Page title --- app/views/layouts/application.html.haml | 3 ++- config/locales/dynamics/fr.yml | 1 + config/locales/dynamics/fr_opensimplif.yml | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index d1bda0bb0..baf25cfeb 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -2,7 +2,8 @@ %html %head %meta{:content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/ - %title TPS - Téléprocédures simplifiées + %title + =t('dynamics.page_title') %meta{'http-equiv' => "X-UA-Compatible", :content => "IE=edge"} = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true diff --git a/config/locales/dynamics/fr.yml b/config/locales/dynamics/fr.yml index 0d8e42293..c16ec0ab7 100644 --- a/config/locales/dynamics/fr.yml +++ b/config/locales/dynamics/fr.yml @@ -1,5 +1,6 @@ fr: dynamics: + page_title: TPS - Téléprocédures simplifiées contact_email: contact@tps.apientreprise.fr users: connexion_title: Connexion diff --git a/config/locales/dynamics/fr_opensimplif.yml b/config/locales/dynamics/fr_opensimplif.yml index ed8b4c7e0..09b11be21 100644 --- a/config/locales/dynamics/fr_opensimplif.yml +++ b/config/locales/dynamics/fr_opensimplif.yml @@ -1,5 +1,6 @@ fr_opensimplif: dynamics: + page_title: OpenSimplif contact_email: simplification.sgmap@modernisation.gouv.fr users: connexion_title: "Connectez-vous en tant qu'utilisateur" From 40a792bd1374d6aa63f6dfb3b9761fecc105db93 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Tue, 8 Nov 2016 11:54:16 +0100 Subject: [PATCH 08/15] dynamic CGU page --- config/deploy.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/config/deploy.rb b/config/deploy.rb index cf3617318..cfa3be8aa 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -98,7 +98,8 @@ set :shared_paths, [ 'config/france_connect.yml', 'config/initializers/mailjet.rb', 'config/initializers/storage_url.rb', - 'app/views/root/landing.html.haml' + 'app/views/root/landing.html.haml', + 'app/views/cgu/index.html.haml' ] @@ -139,6 +140,9 @@ task :setup => :environment do queue! %[mkdir -p "#{deploy_to}/shared/app"] queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/app"] + queue! %[mkdir -p "#{deploy_to}/shared/views/cgu"] + queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/views/cgu"] + queue! %[mkdir -p "#{deploy_to}/shared/config/locales/dynamics"] queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/config/locales/dynamics"] From f2a5d582b8b0afcfcd6a91187b288523ffb90cff Mon Sep 17 00:00:00 2001 From: Xavier J Date: Tue, 8 Nov 2016 14:08:16 +0100 Subject: [PATCH 09/15] Change UX on dossier list (user and backoffice) to go on recap dossier. --- app/assets/javascripts/dossiers_list_link.js | 9 +++++++++ app/assets/stylesheets/dossiers.scss | 5 +++++ app/views/backoffice/dossiers/_list.html.haml | 9 +++------ app/views/users/dossiers/_list.html.haml | 15 +++++++++------ 4 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 app/assets/javascripts/dossiers_list_link.js diff --git a/app/assets/javascripts/dossiers_list_link.js b/app/assets/javascripts/dossiers_list_link.js new file mode 100644 index 000000000..1764dd571 --- /dev/null +++ b/app/assets/javascripts/dossiers_list_link.js @@ -0,0 +1,9 @@ +$(document).on('page:load', link_init); +$(document).ready(link_init); + + +function link_init() { + $('#dossiers_list tr').on('click', function () { + $(location).attr('href', $(this).data('dossier_url')) + }); +} \ No newline at end of file diff --git a/app/assets/stylesheets/dossiers.scss b/app/assets/stylesheets/dossiers.scss index 98ed7d31f..76ce739db 100644 --- a/app/assets/stylesheets/dossiers.scss +++ b/app/assets/stylesheets/dossiers.scss @@ -27,4 +27,9 @@ h5 span { #validate_button { float: right; } +} + +#dossiers_list tr:hover{ + background-color: #eeeeee; + cursor: pointer; } \ No newline at end of file diff --git a/app/views/backoffice/dossiers/_list.html.haml b/app/views/backoffice/dossiers/_list.html.haml index 3b6793ef5..ddc640150 100644 --- a/app/views/backoffice/dossiers/_list.html.haml +++ b/app/views/backoffice/dossiers/_list.html.haml @@ -1,4 +1,4 @@ -%table.table +%table#dossiers_list.table %thead - @dossiers_list_facade.preference_list_dossiers_filter.each do |preference| %th{class: "col-md-#{preference.bootstrap_lg} col-lg-#{preference.bootstrap_lg}"} @@ -15,7 +15,7 @@ - unless smart_listing.empty? - @dossiers.each do |dossier| - %tr + %tr{'data-dossier_url' => backoffice_dossier_url(id: dossier.id)} - @dossiers_list_facade.preference_list_dossiers_filter.each_with_index do |preference, index| %td - if preference.table.nil? || preference.table.empty? @@ -30,10 +30,7 @@ - rescue NoMethodError - value = '' - - if index == 0 - = link_to value, backoffice_dossier_path(id: dossier.id) - - else - = value + = value %td.center - if current_gestionnaire.follow?(dossier.id) diff --git a/app/views/users/dossiers/_list.html.haml b/app/views/users/dossiers/_list.html.haml index 34139cce4..96eb526ec 100644 --- a/app/views/users/dossiers/_list.html.haml +++ b/app/views/users/dossiers/_list.html.haml @@ -1,5 +1,5 @@ - unless smart_listing.empty? - %table.table + %table#dossiers_list.table %thead %th.col-md-1.col-lg-1= smart_listing.sortable 'Numéro', 'id' %th.col-md-5.col-lg-5= smart_listing.sortable 'Procédure', 'procedure.libelle' @@ -13,14 +13,17 @@ -dossier = invite.dossier.decorate - else - dossier = dossier.decorate - %tr + + - dossier_url = users_dossiers_invite_path(id: invite.id) unless invite.nil? + - if invite.nil? + - dossier_url = users_dossier_recapitulatif_path(dossier) unless dossier.brouillon? + - dossier_url = users_dossier_description_path(dossier) if dossier.brouillon? + + %tr{'data-dossier_url' => dossier_url} %td.center = dossier.id %td - = link_to(dossier.procedure.libelle, users_dossiers_invite_path(id: invite.id)) unless invite.nil? - - if invite.nil? - = link_to(dossier.procedure.libelle, users_dossier_recapitulatif_path(dossier)) unless dossier.brouillon? - = link_to(dossier.procedure.libelle, users_dossier_description_path(dossier)) if dossier.brouillon? + = dossier.procedure.libelle %td{id: "dossier_#{dossier.id}_state"}= dossier.display_state %td= dossier.last_update From b44da7b43db15d2114bb84a9ae7c5740d3ac60ab Mon Sep 17 00:00:00 2001 From: Xavier J Date: Tue, 8 Nov 2016 15:13:40 +0100 Subject: [PATCH 10/15] Fix tests --- app/views/backoffice/dossiers/_list.html.haml | 2 +- app/views/users/dossiers/_list.html.haml | 2 +- spec/features/backoffice/navigate_to_dossier_spec.rb | 8 ++++---- spec/features/users/list_dossiers_spec.rb | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/views/backoffice/dossiers/_list.html.haml b/app/views/backoffice/dossiers/_list.html.haml index ddc640150..509b7a00d 100644 --- a/app/views/backoffice/dossiers/_list.html.haml +++ b/app/views/backoffice/dossiers/_list.html.haml @@ -15,7 +15,7 @@ - unless smart_listing.empty? - @dossiers.each do |dossier| - %tr{'data-dossier_url' => backoffice_dossier_url(id: dossier.id)} + %tr{id: "tr_dossier_#{dossier.id}", 'data-dossier_url' => backoffice_dossier_url(id: dossier.id)} - @dossiers_list_facade.preference_list_dossiers_filter.each_with_index do |preference, index| %td - if preference.table.nil? || preference.table.empty? diff --git a/app/views/users/dossiers/_list.html.haml b/app/views/users/dossiers/_list.html.haml index 96eb526ec..398b31876 100644 --- a/app/views/users/dossiers/_list.html.haml +++ b/app/views/users/dossiers/_list.html.haml @@ -19,7 +19,7 @@ - dossier_url = users_dossier_recapitulatif_path(dossier) unless dossier.brouillon? - dossier_url = users_dossier_description_path(dossier) if dossier.brouillon? - %tr{'data-dossier_url' => dossier_url} + %tr{id: "tr_dossier_#{dossier.id}", 'data-dossier_url' => dossier_url} %td.center = dossier.id %td diff --git a/spec/features/backoffice/navigate_to_dossier_spec.rb b/spec/features/backoffice/navigate_to_dossier_spec.rb index 972c70f58..1c19cb3f9 100644 --- a/spec/features/backoffice/navigate_to_dossier_spec.rb +++ b/spec/features/backoffice/navigate_to_dossier_spec.rb @@ -20,9 +20,9 @@ feature 'on backoffice page' do page.click_on 'Se connecter' end - context 'when he click on first dossier' do + context 'when he click on first dossier', js: true do before do - page.click_on dossier.id + page.find("#tr_dossier_#{dossier.id}").click end scenario 'it redirect to dossier page' do @@ -30,7 +30,7 @@ feature 'on backoffice page' do end end - context 'when gestionnaire have enterprise and individual dossier in his inbox' do + context 'when gestionnaire have enterprise and individual dossier in his inbox', js: true do let!(:procedure_individual) { create :procedure, libelle: 'procedure individual', administrateur: administrateur, for_individual: true } let!(:dossier_individual) { create :dossier, procedure: procedure_individual, state: 'updated' } @@ -38,7 +38,7 @@ feature 'on backoffice page' do create :assign_to, gestionnaire: gestionnaire, procedure: procedure_individual visit backoffice_path - page.click_on dossier_individual.id + page.find("#tr_dossier_#{dossier_individual.id}").click end scenario 'it redirect to dossier page' do diff --git a/spec/features/users/list_dossiers_spec.rb b/spec/features/users/list_dossiers_spec.rb index 85fdc963f..b3a767551 100644 --- a/spec/features/users/list_dossiers_spec.rb +++ b/spec/features/users/list_dossiers_spec.rb @@ -32,9 +32,9 @@ feature 'user access to the list of his dossier' do expect(page).to have_css("#dossier_#{dossier1.id}_state") end - context 'when user clicks on a projet in list' do + context 'when user clicks on a projet in list', js: true do before do - page.click_on dossier1.procedure.libelle + page.find("#tr_dossier_#{dossier1.id}").click end scenario 'user is redirected to dossier page' do expect(page).to have_css('#recap_dossier') From 86125b219ac98fe2e0eb1f68b0b3a8b7117f6478 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Tue, 8 Nov 2016 19:02:57 +0100 Subject: [PATCH 11/15] Import opensimplif rake task --- lib/tasks/opensimplif_import.rake | 118 ++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 lib/tasks/opensimplif_import.rake diff --git a/lib/tasks/opensimplif_import.rake b/lib/tasks/opensimplif_import.rake new file mode 100644 index 000000000..7131153ed --- /dev/null +++ b/lib/tasks/opensimplif_import.rake @@ -0,0 +1,118 @@ +require 'csv' +require 'json' + +namespace :opensimplif_import do + task :import_all => :environment do + puts 'start opensimplif' + + Rake::Task['opensimplif_import:import_proposition'].invoke + Rake::Task['opensimplif_import:import_piste'].invoke + Rake::Task['opensimplif_import:import_mesure'].invoke + + puts 'end import opensimplif' + end + + task :import_proposition do + file_path = "lib/tasks/161102_OS_Inputs_test_propositions.csv" + procedure_id = 35 + + matching = [ + {id: 44, key: 'Intitulé de la proposition'}, + {id: 43, key: 'Champ concerné'}, + {id: 45, key: 'Champ ministériel chef de file'}, + {id: 59, key: 'Date de la proposition'}, + {id: 60, key: 'Moment de vie'}, + {id: 61, key: 'Source'}, + {id: 48, key: 'Description de la proposition'} + ] + + puts 'start propositions' + import file_path, procedure_id, matching + puts 'done propositions' + end + + task :import_piste do + file_path = "lib/tasks/161102_OS_Inputs_test_pistes.csv" + procedure_id = 36 + + matching = [ + {id: 81, key: 'Intitulé de la piste *'}, + {id: 82, key: 'Usager concerné *'}, + {id: 83, key: 'Champ ministériel chef de file *'}, + {id: 84, key: 'Champ ministériel contributeur'}, + {id: 85, key: 'Date de saisine'}, + {id: 66, key: 'Moment de vie'}, + {id: 80, key: 'Source de la piste'}, + {id: 70, key: 'Description de la piste '}, + {id: 68, key: 'Objectifs / bénéfices attendus'}, + {id: 65, key: 'Description détaillée des démarches impactées par la piste'}, + {id: 69, key: 'Levier de mise en oeuvre'}, + {id: 67, key: 'Précision sur le levier de meo'}, + {id: 64, key: 'Calendrier de mise en oeuvre'} + ] + + puts 'start piste' + import file_path, procedure_id, matching + puts 'done pistes' + end + + task :import_mesure do + file_path = "lib/tasks/161102_OS_Inputs_test_mesures.csv" + procedure_id = 37 + + matching = [ + {id: 107, key: 'Intitulé projet / mesure'}, + {id: 104, key: 'Champ concerné'}, + {id: 105, key: 'Champ ministériel chef de file'}, + {id: 112, key: 'Direction chef de file'}, + {id: 106, key: 'Champ ministériel contributeur'}, + {id: 113, key: 'Direction contributrice'}, + {id: 92, key: 'Moment de vie'}, + {id: 109, key: 'Date d\'annonce'}, + {id: 114, key: 'N° de la mesure'}, + {id: 115, key: 'Responsable ministère'}, + {id: 116, key: 'Responsable SGMAP'}, + {id: 89, key: 'Actions réalisées'}, + {id: 95, key: 'Etapes nécessaires à l\'atteinte de la cible et alertes'}, + {id: 102, key: 'Alertes'}, + {id: 101, key: 'Échéance initiale'}, + {id: 96, key: 'Échéance prévisionnelle / réelle'}, + {id: 94, key: 'Appréciation avancement'}, + {id: 91, key: 'Etat d\'avancement LOLF'}, + {id: 111, key: '§ de com'} + ] + + puts 'start mesures' + import file_path, procedure_id, matching + puts 'done mesures' + end + + def self.import file_path, procedure_id, matching + user = User.find_or_create_by(email: 'import@opensimplif.modernisation.fr') + + unless user.valid? + user.password = 'TPSpassword2016' + user.save + end + + file ||= CSV.open(file_path, :col_sep => ";", :headers => true).map { |x| x.to_h }.to_json + file = JSON.parse(file) + + procedure = Procedure.find(procedure_id) + + user.dossiers.where(procedure_id: procedure.id).destroy_all + + file.each do |proposition| + dossier = Dossier.create procedure: procedure, user: user, state: :initiated + + dossier.champs.each do |champ| + matching.each do |match| + if match[:id] == champ.type_de_champ.id + champ.update_column :value, proposition[match[:key]] + break + end + end + end + end + end +end From 9c863c7bff23a43379b6bb1346cd080cdfeb353c Mon Sep 17 00:00:00 2001 From: Xavier J Date: Tue, 8 Nov 2016 19:03:21 +0100 Subject: [PATCH 12/15] Fix bug go to dossier list tableau de bord --- app/views/backoffice/dossiers/index.js.erb | 3 ++- app/views/users/dossiers/index.js.erb | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/backoffice/dossiers/index.js.erb b/app/views/backoffice/dossiers/index.js.erb index 0f7d43419..876f677fd 100644 --- a/app/views/backoffice/dossiers/index.js.erb +++ b/app/views/backoffice/dossiers/index.js.erb @@ -1,3 +1,4 @@ <%= smart_listing_update :dossiers %> -filters_init(); \ No newline at end of file +filters_init(); +link_init(); \ No newline at end of file diff --git a/app/views/users/dossiers/index.js.erb b/app/views/users/dossiers/index.js.erb index 1517a60d3..5a2505268 100644 --- a/app/views/users/dossiers/index.js.erb +++ b/app/views/users/dossiers/index.js.erb @@ -1 +1,2 @@ <%= smart_listing_update :dossiers %> +link_init(); \ No newline at end of file From ec4b634f8a59e7e19db10989d769f9b6d968ec6d Mon Sep 17 00:00:00 2001 From: Xavier J Date: Thu, 10 Nov 2016 15:57:14 +0100 Subject: [PATCH 13/15] Change onglet presentation for gestionnaire. --- app/facades/dossiers_list_facades.rb | 14 +++++++++++- app/models/dossier.rb | 17 ++++++++++++++ .../dossiers_list_gestionnaire_service.rb | 14 ++++++------ .../backoffice/dossiers/_onglets.html.haml | 12 +++++----- .../dossiers/_state_description.html.haml | 16 +++++++++----- .../backoffice/dossiers_controller_spec.rb | 4 ++-- spec/features/backoffice/onglets_link_spec.rb | 6 ++--- .../dossiers/index_html.haml_spec.rb | 22 +++++++++---------- 8 files changed, 69 insertions(+), 36 deletions(-) diff --git a/app/facades/dossiers_list_facades.rb b/app/facades/dossiers_list_facades.rb index 50d2848d7..4f96caa4d 100644 --- a/app/facades/dossiers_list_facades.rb +++ b/app/facades/dossiers_list_facades.rb @@ -58,6 +58,10 @@ class DossiersListFacades (@liste == 'a_traiter' ? 'active' : '') end + def fige_class + (@liste == 'fige' ? 'active' : '') + end + def en_attente_class (@liste == 'en_attente' ? 'active' : '') end @@ -103,13 +107,17 @@ class DossiersListFacades end def a_traiter_total - service.waiting_for_gestionnaire.count + service.ouvert.count end def en_construction_total service.en_construction.count end + def fige_total + service.fige.count + end + def en_attente_total service.waiting_for_user.count end @@ -158,6 +166,10 @@ class DossiersListFacades base_url 'a_traiter' end + def fige_url + base_url 'fige' + end + def en_attente_url base_url 'en_attente' end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index c0cb20197..c6ef99b8c 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -45,6 +45,7 @@ class Dossier < ActiveRecord::Base BROUILLON = %w(draft) NOUVEAUX = %w(initiated) + OUVERT = %w(updated replied) WAITING_FOR_GESTIONNAIRE = %w(updated) WAITING_FOR_USER = %w(replied validated) EN_CONSTRUCTION = %w(initiated updated replied) @@ -194,6 +195,10 @@ class Dossier < ActiveRecord::Base EN_CONSTRUCTION.include?(state) end + def ouvert? + OUVERT.include?(state) + end + def deposes? DEPOSES.include?(state) end @@ -202,6 +207,10 @@ class Dossier < ActiveRecord::Base VALIDES.include?(state) end + def fige? + VALIDES.include?(state) + end + def a_instruire? A_INSTRUIRE.include?(state) end @@ -238,10 +247,18 @@ class Dossier < ActiveRecord::Base where(state: EN_CONSTRUCTION, archived: false).order("updated_at #{order}") end + def self.ouvert order = 'ASC' + where(state: OUVERT, archived: false).order("updated_at #{order}") + end + def self.valides order = 'ASC' where(state: VALIDES, archived: false).order("updated_at #{order}") end + def self.fige order = 'ASC' + where(state: VALIDES, archived: false).order("updated_at #{order}") + end + def self.deposes order = 'ASC' where(state: DEPOSES, archived: false).order("updated_at #{order}") end diff --git a/app/services/dossiers_list_gestionnaire_service.rb b/app/services/dossiers_list_gestionnaire_service.rb index bc7923d08..7cb09366f 100644 --- a/app/services/dossiers_list_gestionnaire_service.rb +++ b/app/services/dossiers_list_gestionnaire_service.rb @@ -7,8 +7,8 @@ class DossiersListGestionnaireService def dossiers_to_display {'nouveaux' => nouveaux, - 'a_traiter' => waiting_for_gestionnaire, - 'en_attente' => waiting_for_user, + 'a_traiter' => ouvert, + 'fige' => fige, 'deposes' => deposes, 'a_instruire' => a_instruire, 'termine' => termine, @@ -16,7 +16,7 @@ class DossiersListGestionnaireService end def self.dossiers_liste_libelle - ['nouveaux', 'a_traiter', 'en_attente', 'deposes', 'a_instruire', 'termine', 'all_state'] + ['nouveaux', 'a_traiter', 'fige' ,'deposes', 'a_instruire', 'termine', 'all_state'] end def all_state @@ -27,12 +27,12 @@ class DossiersListGestionnaireService @nouveaux ||= filter_dossiers.nouveaux end - def waiting_for_gestionnaire - @waiting_for_gestionnaire ||= filter_dossiers.waiting_for_gestionnaire + def ouvert + @ouvert ||= filter_dossiers.ouvert end - def waiting_for_user - @waiting_for_user ||= filter_dossiers.waiting_for_user + def fige + @fige ||= filter_dossiers.fige end def deposes diff --git a/app/views/backoffice/dossiers/_onglets.html.haml b/app/views/backoffice/dossiers/_onglets.html.haml index fa32c51b0..b35281247 100644 --- a/app/views/backoffice/dossiers/_onglets.html.haml +++ b/app/views/backoffice/dossiers/_onglets.html.haml @@ -19,18 +19,18 @@ =@dossiers_list_facade.nouveaux_total %li{ class: (@dossiers_list_facade.a_traiter_class) } - %a{:href => "#{url_for @dossiers_list_facade.a_traiter_url}", 'data-toggle' => :tooltip, title: 'Les dossiers qui requièrent une action de votre part.'} + %a{:href => "#{url_for @dossiers_list_facade.a_traiter_url}", 'data-toggle' => :tooltip, title: 'Les dossiers qui ne sont pas encore déclarés complets.'} %h5.text-danger - = "Action requise" + ="Ouverts" .badge.progress-bar-danger =@dossiers_list_facade.a_traiter_total - %li{ class: (@dossiers_list_facade.en_attente_class) } - %a{:href => "#{url_for @dossiers_list_facade.en_attente_url}", 'data-toggle' => :tooltip, title: 'Les dossiers en attentes d\'une action de la part de l\'usager.'} + %li{ class: (@dossiers_list_facade.fige_class) } + %a{:href => "#{url_for @dossiers_list_facade.fige_url}", 'data-toggle' => :tooltip, title: 'Les dossiers qui sont déclarés complets et donc figés.'} %h5.text-default - ="Attente usager " + ="Figés" .badge.progress-bar-default - =@dossiers_list_facade.en_attente_total + =@dossiers_list_facade.fige_total %li{ class: (@dossiers_list_facade.deposes_class) } %a{:href => "#{url_for @dossiers_list_facade.deposes_url}", 'data-toggle' => :tooltip, title: 'Les dossiers qui ont été validés et déposés par les usager qui attendent une réponse de bonne réception avant examen.'} diff --git a/app/views/backoffice/dossiers/_state_description.html.haml b/app/views/backoffice/dossiers/_state_description.html.haml index 13d1cf58f..b3d1946d1 100644 --- a/app/views/backoffice/dossiers/_state_description.html.haml +++ b/app/views/backoffice/dossiers/_state_description.html.haml @@ -11,12 +11,18 @@ n'ont jamais été ouvert par votre service. Il attende une première lecture et intervention de votre part. -elsif dossiers_list_facade.liste == 'a_traiter' - Tous les dossiers présents dans cette liste sont ceux qui + Tous les dossiers présents dans cette liste sont ceux qui sont %b - attendent une action de votre part. - Cela peut être par exemple une demande client ou une relecture pour validation de complétude. - -elsif dossiers_list_facade.liste == 'en_attente' - Tous les dossiers présents dans cette liste sont ceux qui requière une action de la part de l'usager. À priori, vous n'avez donc pas d'intervention particulière à réaliser. + en cours de construction avec l'usager. + Ils ne sont pas figés et ne sont donc pas complets. + -elsif dossiers_list_facade.liste == 'fige' + Tous les dossiers présents dans cette liste ont été déclarés + %b + complets + et ne sont + %b + plus modifiables par l'usager. + Ils attendent donc leurs dépots officiels qui doit être effectué par l'usager. -elsif dossiers_list_facade.liste == 'deposes' Tous les dossiers présents dans cette liste ont été %b diff --git a/spec/controllers/backoffice/dossiers_controller_spec.rb b/spec/controllers/backoffice/dossiers_controller_spec.rb index 61c5c0428..542b7fc12 100644 --- a/spec/controllers/backoffice/dossiers_controller_spec.rb +++ b/spec/controllers/backoffice/dossiers_controller_spec.rb @@ -63,14 +63,14 @@ describe Backoffice::DossiersController, type: :controller do end end - describe 'GET #en_attente' do + describe 'GET #fige' do context 'when gestionnaire is connected' do before do sign_in gestionnaire end it 'returns http success' do - get :index, liste: :en_attente + get :index, liste: :fige expect(response).to have_http_status(200) end end diff --git a/spec/features/backoffice/onglets_link_spec.rb b/spec/features/backoffice/onglets_link_spec.rb index 3232d02c4..087bb3d95 100644 --- a/spec/features/backoffice/onglets_link_spec.rb +++ b/spec/features/backoffice/onglets_link_spec.rb @@ -37,7 +37,7 @@ feature 'on click on tabs button' do context 'when he click on tabs a traite' do before do visit backoffice_dossiers_url(liste: :a_traiter) - page.click_on 'Action requise 1' + page.click_on 'Ouverts 2' end scenario 'it redirect to backoffice dossier termine' do @@ -47,8 +47,8 @@ feature 'on click on tabs button' do context 'when he click on tabs en attente' do before do - visit backoffice_dossiers_url(liste: :en_attente) - page.click_on 'Attente usager 2' + visit backoffice_dossiers_url(liste: :figes) + page.click_on 'Figés 1' end scenario 'it redirect to backoffice dossier en attente' do diff --git a/spec/views/backoffice/dossiers/index_html.haml_spec.rb b/spec/views/backoffice/dossiers/index_html.haml_spec.rb index ddca9e976..879b76cf2 100644 --- a/spec/views/backoffice/dossiers/index_html.haml_spec.rb +++ b/spec/views/backoffice/dossiers/index_html.haml_spec.rb @@ -95,29 +95,27 @@ describe 'backoffice/dossiers/index.html.haml', type: :view do end describe 'on tab a_traiter' do - let(:total_dossiers) { 1 } + let(:total_dossiers) { 2 } let(:active_class) { '.active .text-danger' } - let(:dossiers_to_display) { gestionnaire.dossiers.waiting_for_gestionnaire } + let(:dossiers_to_display) { gestionnaire.dossiers.ouvert } let(:liste) { 'a_traiter' } it_behaves_like 'check_tab_content' do let(:decorate_dossier_at_check) { decorate_dossier_updated } end + + it_behaves_like 'check_tab_content' do + let(:decorate_dossier_at_check) { decorate_dossier_replied } + end end - describe 'on tab en_attente' do - let(:total_dossiers) { 2 } + describe 'on tab figes' do + let(:total_dossiers) { 1 } let(:active_class) { '.active .text-default' } - let(:dossiers_to_display) { gestionnaire.dossiers.waiting_for_user } - let(:liste) { 'en_attente' } + let(:dossiers_to_display) { gestionnaire.dossiers.fige } + let(:liste) { 'fige' } describe 'for state replied' do - it_behaves_like 'check_tab_content' do - let(:decorate_dossier_at_check) { decorate_dossier_replied } - end - end - - describe 'for state validated' do it_behaves_like 'check_tab_content' do let(:decorate_dossier_at_check) { decorate_dossier_validated } end From a72709b6da6d2039ad7f6fb8d8dcdf5ff1b450c1 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Thu, 10 Nov 2016 17:26:00 +0100 Subject: [PATCH 14/15] =?UTF-8?q?Fix=20bug=20Cerfa=20on=20=C2=AB=C2=A0Modi?= =?UTF-8?q?fier=20document=C2=A0=C2=BB=20recap=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../users/description_controller.rb | 36 +++++++++++++------ config/locales/fr.yml | 4 +-- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/app/controllers/users/description_controller.rb b/app/controllers/users/description_controller.rb index a8a08fc09..b74671a45 100644 --- a/app/controllers/users/description_controller.rb +++ b/app/controllers/users/description_controller.rb @@ -38,6 +38,15 @@ class Users::DescriptionController < UsersController return render 'show' end + unless params[:champs].nil? + champs_service_errors = ChampsService.save_formulaire @dossier.champs, params, mandatory + + unless champs_service_errors.empty? + flash.now.alert = (champs_service_errors.inject('') { |acc, error| acc+= error[:message]+'
' }).html_safe + return render 'show' + end + end + if @procedure.cerfa_flag? unless params[:cerfa_pdf].nil? cerfa = Cerfa.new(content: params[:cerfa_pdf], dossier: @dossier, user: current_user) @@ -48,15 +57,6 @@ class Users::DescriptionController < UsersController end end - unless params[:champs].nil? - champs_service_errors = ChampsService.save_formulaire @dossier.champs, params, mandatory - - unless champs_service_errors.empty? - flash.now.alert = (champs_service_errors.inject('') { |acc, error| acc+= error[:message]+'
' }).html_safe - return render 'show' - end - end - unless (errors_upload = PiecesJustificativesService.upload!(@dossier, current_user, params)).empty? flash.alert = errors_upload.html_safe return render 'show' @@ -82,10 +82,24 @@ class Users::DescriptionController < UsersController @dossier ||= Dossier.find(params[:dossier_id]) if invite @dossier ||= current_user_dossier + if @dossier.procedure.cerfa_flag? + unless params[:cerfa_pdf].nil? + cerfa = Cerfa.new(content: params[:cerfa_pdf], dossier: @dossier, user: current_user) + unless cerfa.save + flash.alert = cerfa.errors.full_messages.join('
').html_safe + end + end + end + if !((errors_upload = PiecesJustificativesService.upload!(@dossier, current_user, params)).empty?) - flash.alert = errors_upload.html_safe + if flash.alert.nil? + flash.alert = errors_upload.html_safe + else + flash.alert = (flash.alert + '
' + errors_upload.html_safe).html_safe + end + else - flash.notice = 'Nouveaux fichiers envoyés' + flash.notice = 'Nouveaux fichiers envoyés' if flash.alert.nil? @dossier.next_step! 'user', 'update' end diff --git a/config/locales/fr.yml b/config/locales/fr.yml index afe725ff8..bb400f609 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -44,11 +44,11 @@ fr: piece_justificative: attributes: content: - size_too_big: "La taille du fichier joint est trop importante. Elle doit être inférieure à 3Mo." + size_too_big: "La taille du fichier joint est trop importante. Elle doit être inférieure à 6Mo." cerfa: attributes: content: - size_too_big: "La taille du fichier joint est trop importante. Elle doit être inférieure à 3Mo." + size_too_big: "La taille du fichier joint est trop importante. Elle doit être inférieure à 6Mo." user: attributes: reset_password_token: From ec53f64a644d92db98ca3084552a38d1c38fd9e5 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Mon, 14 Nov 2016 11:03:17 +0100 Subject: [PATCH 15/15] Fix bug tag received mailer --- app/views/notification_mailer/dossier_received.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/notification_mailer/dossier_received.html.erb b/app/views/notification_mailer/dossier_received.html.erb index 4bcdc394f..2b39f1abe 100644 --- a/app/views/notification_mailer/dossier_received.html.erb +++ b/app/views/notification_mailer/dossier_received.html.erb @@ -1 +1 @@ -<%= escape_once (MailTemplate.replace_tags @dossier.procedure.mail_received.body, @dossier).html_safe %> \ No newline at end of file +<%= MailTemplate.replace_tags(@dossier.procedure.mail_received.body, @dossier).html_safe %> \ No newline at end of file