diff --git a/.gitignore b/.gitignore index 1553305..e43c631 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ log/ usershub2.pid -config.py +config/config.py venv *.pyc __pycache__ diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 0000000..a4e2544 --- /dev/null +++ b/.readthedocs.yaml @@ -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 diff --git a/Dockerfile b/Dockerfile index 095caa9..cde139f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 . @@ -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"] diff --git a/VERSION b/VERSION index 69c4861..005119b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.3.5.dev0 +2.4.1 diff --git a/app/api/route_register.py b/app/api/route_register.py index 15c3d71..7efede7 100644 --- a/app/api/route_register.py +++ b/app/api/route_register.py @@ -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__) @@ -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 diff --git a/app/models.py b/app/models.py index a335bba..e607fc5 100644 --- a/app/models.py +++ b/app/models.py @@ -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 diff --git a/app/t_roles/route.py b/app/t_roles/route.py index bf0a315..8856a7a 100644 --- a/app/t_roles/route.py +++ b/app/t_roles/route.py @@ -8,6 +8,7 @@ flash, current_app, ) +import re from pypnusershub import routes as fnauth from pypnusershub.db.models import check_and_encrypt_password @@ -269,6 +270,7 @@ 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) @@ -276,6 +278,7 @@ def info(id_role): "info_user.html", user=user, organisme=organisme, + fullname=fullname, groups=groups, lists=lists, rights=rights, @@ -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 diff --git a/app/temp_users/routes.py b/app/temp_users/routes.py index 3d9cf49..f3a695f 100644 --- a/app/temp_users/routes.py +++ b/app/temp_users/routes.py @@ -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: diff --git a/app/templates/info_user.html b/app/templates/info_user.html index eb1f317..b3a14b0 100644 --- a/app/templates/info_user.html +++ b/app/templates/info_user.html @@ -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 %}