Skip to content

Commit

Permalink
Fix info_user: display user without organism
Browse files Browse the repository at this point in the history
Fix #125.

Fix t_roles: accept user first or last name null

Fix #107.
  • Loading branch information
jpm-cbna authored and amandine-sahl committed Jun 22, 2023
1 parent 4fa9923 commit 2c845e2
Show file tree
Hide file tree
Showing 5 changed files with 539 additions and 17 deletions.
10 changes: 6 additions & 4 deletions app/genericRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ class GenericRepository(db.Model):

@classmethod
def get_one(cls, id, as_model=False):

"""
Methode qui retourne un dictionnaire d'un élément d'un Model
Avec pour paramètres l'id de l'élément
Si as_model != False alors au lieu de retourner un dictionnaire on retourne l'object du modèle
"""
if not id:
return None

data = db.session.query(cls).get(id)

if as_model == False:
data = db.session.query(cls).get(id)
if not as_model:
return data.as_dict(True)
else:
return db.session.query(cls).get(id)
return data

@classmethod
def get_all(
Expand Down
23 changes: 13 additions & 10 deletions app/t_roles/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ def updatepass(id_role=None):
"""
form = t_rolesforms.UserPass()
myuser = TRoles.get_one(id_role)
# Build title
role_fullname= buildUserFullName(myuser)
title=f"Changer le mot de passe de l'utilisateur '{role_fullname}'"

if request.method == "POST":
if form.validate_on_submit() and form.validate():
Expand All @@ -241,11 +244,7 @@ def updatepass(id_role=None):
return render_template(
"user_pass.html",
form=form,
title="Changer le mot de passe de l'utilisateur '"
+ myuser["nom_role"]
+ " "
+ myuser["prenom_role"]
+ "'",
title=title,
id_role=id_role,
)
form_user["id_role"] = id_role
Expand All @@ -257,11 +256,7 @@ def updatepass(id_role=None):
return render_template(
"user_pass.html",
form=form,
title="Changer le mot de passe de l'utilisateur '"
+ myuser["nom_role"]
+ " "
+ myuser["prenom_role"]
+ "'",
title=title,
id_role=id_role,
)

Expand Down Expand Up @@ -300,6 +295,14 @@ def info(id_role):
pathU=URL_APPLICATION + "/user/update/",
)

def buildUserFullName(user):
fullname = []
if user["nom_role"]:
fullname.append(user["nom_role"].upper())
if user["prenom_role"]:
fullname.append(user["prenom_role"].title())
return ' '.join(fullname)


def pops(form, with_group=True):
"""
Expand Down
6 changes: 3 additions & 3 deletions app/templates/info_user.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

{%set is_identifiant = user['identifiant'] is not none and user['identifiant'] != '' %}
{%set is_uuid = user['uuid_role'] is not none and user['uuid_role'] != '' %}
{%set is_organisme = organisme.nom_organisme is not none and organisme.nom_organisme != '' %}
{%set is_organisme = organisme is not none and organisme['nom_organisme'] != '' %}
{%set is_desc = user['desc_role'] is not none and user['desc_role'] != '' %}
{%set is_remarques = user['remarques'] is not none and user['remarques'] != '' %}
{%set is_mail = user['email'] is not none and user['email'] != '' %}
{%set is_group = groups|length > 0 %}
{%set is_list = lists|length > 0 %}
{%set is_right = rights|length > 0 %}
<div class="container main-zone ng-scope ">
<h3>Utilisateur "{{user['nom_role']}} {{user['prenom_role']}}"</h3>
<h3>Utilisateur "{{user['fullname']}}"</h3>
<div class="ml-5">
<small>
{% if is_desc %}
Expand All @@ -21,7 +21,7 @@ <h3>Utilisateur "{{user['nom_role']}} {{user['prenom_role']}}"</h3>
<br /><strong>UUID :</strong> {{user['uuid_role']}}
{% endif %}
{% if is_identifiant %}
<br /><strong>Identifiant :</strong>{{user['identifiant']}}
<br /><strong>Identifiant :</strong> {{user['identifiant']}}
{% endif %}
{% if is_mail %}
<br /><strong>Email :</strong> <a href="mailto:{{user['email']}}">{{user['email']}}</a>
Expand Down
78 changes: 78 additions & 0 deletions data/update_2.1.3to2.1.4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
-- Update UsersHub DB schema from v2.1.3 to v2.1.4
BEGIN;

ALTER TABLE utilisateurs.bib_organismes
ADD COLUMN IF NOT EXISTS additional_data JSONB;

-- Fix LEFT JOIN on bib_organismes
CREATE OR REPLACE VIEW utilisateurs.v_roleslist_forall_applications AS
SELECT a.groupe,
a.active,
a.id_role,
a.identifiant,
a.nom_role,
a.prenom_role,
a.desc_role,
a.pass,
a.pass_plus,
a.email,
a.id_organisme,
a.organisme,
a.id_unite,
a.remarques,
a.date_insert,
a.date_update,
max(a.id_droit) AS id_droit_max,
a.id_application
FROM ( SELECT u.groupe,
u.id_role,
u.identifiant,
u.nom_role,
u.prenom_role,
u.desc_role,
u.pass,
u.pass_plus,
u.email,
u.id_organisme,
u.active,
o.nom_organisme AS organisme,
0 AS id_unite,
u.remarques,
u.date_insert,
u.date_update,
c.id_profil AS id_droit,
c.id_application
FROM utilisateurs.t_roles u
JOIN utilisateurs.cor_role_app_profil c ON c.id_role = u.id_role
LEFT JOIN utilisateurs.bib_organismes o ON o.id_organisme = u.id_organisme
UNION
SELECT u.groupe,
u.id_role,
u.identifiant,
u.nom_role,
u.prenom_role,
u.desc_role,
u.pass,
u.pass_plus,
u.email,
u.id_organisme,
u.active,
o.nom_organisme AS organisme,
0 AS id_unite,
u.remarques,
u.date_insert,
u.date_update,
c.id_profil AS id_droit,
c.id_application
FROM utilisateurs.t_roles u
JOIN utilisateurs.cor_roles g ON g.id_role_utilisateur = u.id_role OR g.id_role_groupe = u.id_role
JOIN utilisateurs.cor_role_app_profil c ON c.id_role = g.id_role_groupe
LEFT JOIN utilisateurs.bib_organismes o ON o.id_organisme = u.id_organisme
) a
WHERE a.active = true
GROUP BY a.groupe, a.active, a.id_role, a.identifiant, a.nom_role, a.prenom_role, a.desc_role, a.pass, a.pass_plus, a.email, a.id_organisme, a.organisme, a.id_unite, a.remarques, a.date_insert, a.date_update, a.id_application;

-- Fix temp_users.organisme field, increase size to 200 characters (32 is really to short)
ALTER TABLE utilisateurs.temp_users ALTER COLUMN organisme TYPE varchar(200);

COMMIT;
Loading

0 comments on commit 2c845e2

Please sign in to comment.