Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquesfize committed Apr 11, 2024
2 parents 2dadf77 + af5873d commit 8eb077f
Show file tree
Hide file tree
Showing 15 changed files with 155 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
log/

usershub2.pid
config.py
config/config.py
venv
*.pyc
__pycache__
Expand Down
35 changes: 35 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Read the Docs configuration file for Sphinx projects
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.12"
# You can also specify other tool versions:
# nodejs: "20"
# rust: "1.70"
# golang: "1.20"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/conf.py
# You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs
# builder: "dirhtml"
# Fail on all warnings to avoid broken references
# fail_on_warning: true

# Optionally build your docs in additional formats such as PDF and ePub
# formats:
# - pdf
# - epub

# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
python:
install:
- requirements: docs/requirements.readthedocs.txt
3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ RUN --mount=type=cache,target=/root/.cache \
pip install --upgrade pip setuptools wheel

COPY /setup.py .
COPY --chmod=755 /docker_healthcheck.sh .
COPY /requirements-common.in .
COPY /requirements-dependencies.in .
COPY /VERSION .
Expand Down Expand Up @@ -114,8 +113,6 @@ ENV PYTHONPATH=/dist/config/
ENV USERSHUB_SETTINGS=config.py
ENV USERSHUB_STATIC_FOLDER=/dist/static

COPY --chmod=755 /docker_healthcheck.sh .

EXPOSE 5001

CMD ["gunicorn", "app.app:create_app()", "--bind=0.0.0.0:5001", "--access-logfile=-", "--error-logfile=-", "--reload", "--reload-extra-file=config/config.py"]
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.5.dev0
2.4.1
16 changes: 10 additions & 6 deletions app/api/route_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from app.utils.utilssqlalchemy import json_resp
from app.models import TRoles, CorRoleAppProfil, TProfils, CorRoles

import sqlalchemy as sa

route = Blueprint("api_register", __name__)

Expand Down Expand Up @@ -85,15 +86,18 @@ def create_temp_user():
return {"msg": msg}, 400

# Delete duplicate entries
db.session.query(TempUser).filter(
TempUser.identifiant == temp_user.identifiant
).delete()
db.session.execute(
sa.delete(TempUser).where(TempUser.identifiant == temp_user.identifiant)
)
db.session.commit()

# Delete old entries (cleaning)
db.session.query(TempUser).filter(
TempUser.date_insert <= (datetime.now() - timedelta(days=7))
).delete()
days = 7 if not "AUTO_ACCOUNT_DELETION_DAYS" in current_app.config else 7
db.session.execute(
sa.delete(TempUser).where(
TempUser.date_insert <= (datetime.now() - timedelta(days=days))
)
)
db.session.commit()

# Update attributes
Expand Down
4 changes: 4 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ class TRoles(GenericRepository):
pass5 = db.Column("pass", db.Unicode)
pass_plus = db.Column(db.Unicode)
champs_addi = db.Column(JSONB)
date_insert = db.Column(db.DateTime, default=db.func.now(), nullable=False)
date_update = db.Column(
db.DateTime, default=db.func.now(), nullable=False, onupdate=db.func.now()
)

# Add synonym for column pass
# Hack because pass is an python reserved word
Expand Down
8 changes: 8 additions & 0 deletions app/t_roles/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
flash,
current_app,
)
import re

from pypnusershub import routes as fnauth
from pypnusershub.db.models import check_and_encrypt_password
Expand Down Expand Up @@ -269,13 +270,15 @@ def info(id_role):
organisme = (
Bib_Organismes.get_one(user["id_organisme"]) if user["id_organisme"] else None
)
fullname = buildUserFullName(user)
groups = TRoles.get_user_groups(id_role)
lists = TRoles.get_user_lists(id_role)
rights = TRoles.get_user_app_profils(id_role)
return render_template(
"info_user.html",
user=user,
organisme=organisme,
fullname=fullname,
groups=groups,
lists=lists,
rights=rights,
Expand All @@ -292,6 +295,11 @@ def buildUserFullName(user):
return " ".join(fullname)


@route.app_template_filter()
def pretty_json_key(key):
return re.sub("([a-z])([A-Z])", "\g<1> \g<2>", key)


def pops(form, with_group=True):
"""
Methode qui supprime les éléments indésirables du formulaires
Expand Down
2 changes: 1 addition & 1 deletion app/temp_users/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def temp_users_list():
temp_users = []
for d in data:
temp_user = d.as_dict()
temp_user["full_name"] = temp_user["nom_role"] + " " + temp_user["prenom_role"]
temp_user["full_name"] = f"{temp_user['nom_role']} {temp_user['prenom_role']}"
app = db.session.query(TApplications).get(temp_user["id_application"])
temp_user["app_name"] = None
if app:
Expand Down
45 changes: 44 additions & 1 deletion app/templates/info_user.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@
{%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_orga_champ_addi = user['champs_addi']['organisme'] is not none
and user['champs_addi']['organisme'] != '' %}
{%set is_date_insert = user['date_insert'] is not none and user['date_insert'] != '' %}
{%set is_date_update = user['date_update'] is not none and user['date_update'] != '' %}
{%set is_champs_addi = user['champs_addi'] is not none and user['champs_addi'] != '' %}
{%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['fullname']}}"</h3>
<h3>Utilisateur "{{fullname}}"</h3>
<div class="ml-5">
<small>
{% if is_desc %}
Expand All @@ -28,10 +33,48 @@ <h3>Utilisateur "{{user['fullname']}}"</h3>
{% endif %}
{% if is_organisme %}
<br /><strong>Organisme :</strong> {{organisme.nom_organisme}}
{% elif is_orga_champ_addi %}
<br /><strong>Organisme :</strong> {{user['champs_addi']['organisme']}}
{% endif %}
{% if is_remarques %}
<br /><strong>Remarques :</strong> {{user['remarques']}}
{% endif %}


<br /><strong>Mot de passe Plus :</strong> {{"Non" if user['pass_plus'] == "" or user["pass_plus"] is none else "Oui"}}
<br /><strong>Mot de passe Md5 :</strong> {{"Non" if user['pass_md5'] == "" or user["pass_md5"] is none else "Oui"}}
<br /><strong>Compte Actif :</strong> {{"Oui" if user["active"] else "Non" }}
{% if is_date_insert %}
<br /><strong>Date de création :</strong> {{user['date_insert']|truncate(10, True, '', 0)}}
{% endif %}
{% if is_date_update %}
<br /><strong>Date de mise à jour :</strong> {{user['date_update']|truncate(10, True, '', 0)}}
{% endif %}
{% if is_champs_addi %}
<dl class="list-def-inline">
{% for key, value in user.champs_addi.items() %}
<dt>{{ key|pretty_json_key|capitalize }}&nbsp;:&nbsp;</dt>
<dd>
{% if value is iterable and (value is not string and value is not mapping) %}
<ul>
{% for item in value %}
<li>{{ item }}</li>
{% endfor %}
</ul>
{% elif value is mapping %}
<dl class="list-def-inline">
{% for key, value in value.items() %}
<dt>{{ key|e|capitalize }}&nbsp;:&nbsp;</dt>
<dd>{{ value }} </dd>
{% endfor %}
</dl>
{% else %}
{{ value }}
{% endif %}
</dd>
{% endfor %}
</dl>
{% endif %}
</small>
</div>

Expand Down
32 changes: 22 additions & 10 deletions app/templates/librairies.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,20 @@
{% block title %}UsersHub V2{% endblock %}

{% block styles %}

<style type="text/css">
dl.list-def-inline {
display: grid;
grid-template-columns: max-content auto;
}

dl.list-def-inline dt {
grid-column-start: 1;
}

dl.list-def-inline dd {
grid-column-start: 2;
}

#add {
-ms-transform: rotate(180deg); /* IE 9 */
Expand All @@ -19,7 +31,7 @@
.font-medium {
font-size: 25px !important;
}

.forms {
padding: 40px !important;
}
Expand Down Expand Up @@ -65,20 +77,20 @@


{% block scripts %}
<script
<script
src="{{ url_for('static', filename='node_modules/jquery/dist/jquery.min.js') }}"
type="text/javascript"
></script>
<script
></script>
<script
src="{{ url_for('static', filename='node_modules/bootstrap/dist/js/bootstrap.js') }}"
type="text/javascript"
></script>
<script
></script>
<script
src=" {{url_for('static', filename='node_modules/datatables.net/js/jquery.dataTables.min.js')}} "
type="text/javascript"
></script>
<script src="{{ url_for('constants_js') }} " type="text/javascript"></script>
<script
></script>
<script src="{{ url_for('constants_js') }} " type="text/javascript"></script>
<script
src="{{ url_for('static', filename='transfer.js') }}"
type="text/javascript"
></script>
Expand Down
3 changes: 3 additions & 0 deletions config/config.py.sample
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ URL_APPLICATION = 'http://localhost:5001'

SECRET_KEY = 'super secret key'

# Number of days befoe automatic deletion of account creation request
AUTO_ACCOUNT_DELETION_DAYS = 7

# Authentification crypting method (hash or md5)
PASS_METHOD = 'hash'

Expand Down
7 changes: 0 additions & 7 deletions docker_healthcheck.sh

This file was deleted.

16 changes: 16 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@
CHANGELOG
=========

2.4.1 (2024-04-11)
------------------

**🚀 Nouveautés**

- Ajout du paramètre ``AUTO_ACCOUNT_DELETION_DAYS`` pour pouvoir définir la durée limite du stockage d'un utilisateur temporaire (#136)
- Affichage complet des informations utilisateurs stockées en base de données (#203)
- Affichage des champs additionnels liés à l'utilisateur dans l'interface (#197)

**🐛 Corrections**

- Problème d'affichage du nom et prénom dans la page d'informations utilisateur (#198)
- Correction du déploiement automatique de la documentation sur Read the Docs (#200)
- Suppression des scripts spécifiques healthcheck Docker (#196)


2.4.0 (2024-01-30)
------------------

Expand Down
9 changes: 9 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import sphinx_rtd_theme # noqa

extensions = [
"sphinx_rtd_theme",
]

project = "UsersHub"
html_theme = "sphinx_rtd_theme"
pygments_style = "sphinx"
1 change: 1 addition & 0 deletions docs/requirements.readthedocs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sphinx-rtd-theme>=1.0.0

0 comments on commit 8eb077f

Please sign in to comment.