From f59308b863060396e11269c5230f6b6b6157a031 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sun, 3 Oct 2021 18:19:51 +0200 Subject: [PATCH] =?UTF-8?q?enregistre=20date=20derni=C3=A8re=20connexion.?= =?UTF-8?q?=20+=20fix=20liste=20users?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scodoc/sco_users.py | 31 ++++++++++++++++++------------- app/views/__init__.py | 9 +++++++++ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/app/scodoc/sco_users.py b/app/scodoc/sco_users.py index b766908c..d9beb7ba 100644 --- a/app/scodoc/sco_users.py +++ b/app/scodoc/sco_users.py @@ -171,21 +171,25 @@ def list_users( if not can_modify: d["date_modif_passwd"] = "(non visible)" + columns_ids = [ + "user_name", + "nom_fmt", + "prenom_fmt", + "email", + "dept", + "roles_string", + "date_expiration", + "date_modif_passwd", + "passwd_temp", + "status_txt", + ] + # Seul l'admin peut voir les dates de dernière connexion + if current_user.is_administrator(): + columns_ids.append("last_seen") title = "Utilisateurs définis dans ScoDoc" tab = GenTable( rows=r, - columns_ids=( - "user_name", - "nom_fmt", - "prenom_fmt", - "email", - "dept", - "roles_string", - "date_expiration", - "date_modif_passwd", - "passwd_temp", - "status_txt", - ), + columns_ids=columns_ids, titles={ "user_name": "Login", "nom_fmt": "Nom", @@ -195,6 +199,7 @@ def list_users( "roles_string": "Rôles", "date_expiration": "Expiration", "date_modif_passwd": "Modif. mot de passe", + "last_seen": "Dernière cnx.", "passwd_temp": "Temp.", "status_txt": "Etat", }, @@ -206,7 +211,7 @@ def list_users( html_class="table_leftalign list_users", html_with_td_classes=True, html_sortable=True, - base_url="%s?all=%s" % (request.base_url, all), + base_url="%s?all_depts=%s" % (request.base_url, 1 if all_depts else 0), pdf_link=False, # table is too wide to fit in a paper page => disable pdf preferences=sco_preferences.SemPreferences(), ) diff --git a/app/views/__init__.py b/app/views/__init__.py index 7dc6c417..1c20f46c 100644 --- a/app/views/__init__.py +++ b/app/views/__init__.py @@ -1,8 +1,13 @@ # -*- coding: UTF-8 -* """ScoDoc Flask views """ +import datetime + from flask import Blueprint from flask import g, current_app +from flask_login import current_user + +from app import db from app.scodoc import notesdb as ndb scodoc_bp = Blueprint("scodoc", __name__) @@ -20,7 +25,11 @@ from app.views import scodoc, notes, scolar, absences, users @scodoc_bp.before_app_request def start_scodoc_request(): """Affecte toutes les requêtes, de tous les blueprints""" + current_app.logger.info(f"start_scodoc_request") ndb.open_db_connection() + if current_user.is_authenticated: + current_user.last_seen = datetime.datetime.utcnow() + db.session.commit() @scodoc_bp.teardown_app_request