Skip to content

Commit

Permalink
Merge pull request #185 from PnX-SI/develop
Browse files Browse the repository at this point in the history
Develop >> Master / Preparation 1.6.0
  • Loading branch information
camillemonchicourt authored Jan 15, 2019
2 parents a88582f + 411ce43 commit ed4a7b8
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 310 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.2.dev0
1.6.0
30 changes: 23 additions & 7 deletions apptax/taxonomie/routestaxref.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask import jsonify, Blueprint, request
from sqlalchemy import distinct, desc
from sqlalchemy import distinct, desc, func

from ..utils.utilssqlalchemy import (
json_resp, serializeQuery, serializeQueryOneResult
Expand Down Expand Up @@ -263,6 +263,8 @@ def get_regneGroup2Inpn_taxref():
def get_AllTaxrefNameByListe(id_liste):
"""
Route utilisée pour les autocompletes
Si le paramètre search_name est passé, la requête SQL utilise l'algorithme
des trigrames pour améliorer la pertinence des résultats
params URL:
- id_liste : identifiant de la liste
params GET:
Expand All @@ -272,14 +274,25 @@ def get_AllTaxrefNameByListe(id_liste):
- group2_inpn : filtre sur le groupe 2 de l'INPN
"""

q = db.session.query(VMTaxrefListForautocomplete)\
.filter(VMTaxrefListForautocomplete.id_liste == id_liste)
q = db.session.query(
VMTaxrefListForautocomplete
).filter(
VMTaxrefListForautocomplete.id_liste == id_liste
)
search_name = request.args.get('search_name')
if search_name:
q = db.session.query(
VMTaxrefListForautocomplete,
func.similarity(
VMTaxrefListForautocomplete.search_name, search_name
).label('idx_trgm')
).filter(
VMTaxrefListForautocomplete.id_liste == id_liste
)
search_name = search_name.replace(' ', '%')
q = q.filter(
VMTaxrefListForautocomplete.search_name.ilike(search_name+"%")
)
VMTaxrefListForautocomplete.search_name.ilike('%'+search_name+"%")
).order_by(desc('idx_trgm'))

regne = request.args.get('regne')
if regne:
Expand All @@ -293,11 +306,14 @@ def get_AllTaxrefNameByListe(id_liste):
VMTaxrefListForautocomplete.cd_nom ==
VMTaxrefListForautocomplete.cd_ref
))

data = q.limit(20).all()
limit = request.args.get('limit', 20)
data = q.limit(limit).all()
if search_name:
return [d[0].as_dict() for d in data]
return [d.as_dict() for d in data]



@adresses.route('/bib_lr', methods=['GET'])
@json_resp
def get_bib_lr():
Expand Down
20 changes: 20 additions & 0 deletions data/adds_for_usershub.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

SET search_path = utilisateurs, pg_catalog;

-- Insérer les applications de base liées à TaxHub
INSERT INTO t_applications (code_application, nom_application, desc_application, id_parent) VALUES
('TH', 'TaxHub', 'Application permettant d''administrer les taxons.', NULL)
;
SELECT pg_catalog.setval('t_applications_id_application_seq', (SELECT max(id_application)+1 FROM t_applications), false);

--Définir les profils utilisables pour TaxHub
INSERT INTO cor_profil_for_app (id_profil, id_application) VALUES
(2, (SELECT id_application FROM utilisateurs.t_applications WHERE code_application = 'TH'))
,(3, (SELECT id_application FROM utilisateurs.t_applications WHERE code_application = 'TH'))
,(4, (SELECT id_application FROM utilisateurs.t_applications WHERE code_application = 'TH'))
,(6, (SELECT id_application FROM utilisateurs.t_applications WHERE code_application = 'TH'))
;

INSERT INTO cor_role_app_profil (id_role, id_application, id_profil) VALUES
(9, (SELECT id_application FROM utilisateurs.t_applications WHERE code_application = 'TH'), 6) --admin Taxhub
;
38 changes: 38 additions & 0 deletions data/adds_for_usershub_views.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
-- Vues permettant de gérer la compatibilité avec UsersHub V1. Quelle utilité ?

SET search_path = utilisateurs, pg_catalog;

-- Vue permettant de simuler le contenu de la table "t_menus" de la V1
CREATE OR REPLACE VIEW t_menus AS
SELECT
id_liste AS id_menu,
nom_liste AS nom_menu,
desc_liste AS desc_menu,
null::integer AS id_application
FROM utilisateurs.t_listes
;

-- Vue permettant de simuler le contenu de la table "cor_role_menu" de la V1
CREATE OR REPLACE VIEW cor_role_menu AS
SELECT
DISTINCT
crl.id_role,
crl.id_liste AS id_menu
FROM utilisateurs.cor_role_liste crl;

-- Vue permettant de simuler le contenu de la table "bib_droits" de la V1
CREATE OR REPLACE VIEW bib_droits AS
SELECT
id_profil AS id_droit,
nom_profil AS nom_droit,
desc_profil AS desc_droit
FROM utilisateurs.t_profils
WHERE id_profil <= 6;

-- Vue permettant de simuler le contenu de la table "cor_role_droit_application" de la V1
CREATE OR REPLACE VIEW cor_role_droit_application AS
SELECT
id_role,
id_profil as id_droit,
id_application
FROM utilisateurs.cor_role_app_profil;
40 changes: 22 additions & 18 deletions data/create_fdw_utilisateurs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ CREATE FOREIGN TABLE utilisateurs.v_userslist_forall_applications (
prenom_role varchar(50),
desc_role text,
pass varchar(100),
pass_plus text,
email varchar(250),
id_organisme int,
organisme varchar(32),
organisme varchar(100)
id_unite int,
remarques text,
pn boolean,
Expand All @@ -30,30 +31,33 @@ CREATE FOREIGN TABLE utilisateurs.v_userslist_forall_applications (
SERVER server_usershubdb;

CREATE FOREIGN TABLE utilisateurs.t_roles (
groupe boolean NOT NULL DEFAULT false,
id_role integer,
identifiant character varying(100),
nom_role character varying(50),
prenom_role character varying(50),
desc_role text,
pass character varying(100),
email character varying(250),
id_organisme integer,
organisme character(32),
id_unite integer,
remarques text,
pn boolean,
session_appli character varying(50),
date_insert timestamp without time zone,
date_update timestamp without time zone
groupe boolean DEFAULT false NOT NULL,
id_role serial NOT NULL,
uuid_role uuid NOT NULL DEFAULT public.uuid_generate_v4(),
identifiant character varying(100),
nom_role character varying(50),
prenom_role character varying(50),
desc_role text,
pass character varying(100),
pass_plus text,
email character varying(250),
id_organisme integer,
remarques text,
pn boolean,
active boolean DEFAULT true,
session_appli character varying(50),
date_insert timestamp without time zone,
date_update timestamp without time zone
)
SERVER server_usershubdb;


CREATE FOREIGN TABLE utilisateurs.t_applications (
id_application int,
code_application character varying(20) NOT NULL,
nom_application character varying(50) NOT NULL,
desc_application text
desc_application text,
id_parent integer
)
SERVER server_usershubdb;

Expand Down
Loading

0 comments on commit ed4a7b8

Please sign in to comment.