From fdd7af6a8aaa64b58f464855aa185f463dd73ec9 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sun, 10 Oct 2021 21:03:18 +0200 Subject: [PATCH] =?UTF-8?q?Am=C3=A9liore=20page=20erreur=20403=20(permissi?= =?UTF-8?q?on=20refus=C3=A9e)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/__init__.py | 12 +++++++++++- app/scodoc/sco_exceptions.py | 8 ++++---- app/scodoc/sco_import_users.py | 7 +++++-- app/views/scodoc.py | 1 + sco_version.py | 2 +- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 11d728a39..65707c26c 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -25,7 +25,12 @@ from flask_moment import Moment from flask_caching import Cache import sqlalchemy -from app.scodoc.sco_exceptions import ScoGenError, ScoValueError, APIInvalidParams +from app.scodoc.sco_exceptions import ( + AccessDenied, + ScoGenError, + ScoValueError, + APIInvalidParams, +) from config import DevConfig import sco_version @@ -51,6 +56,10 @@ def handle_sco_value_error(exc): return render_template("sco_value_error.html", exc=exc), 404 +def handle_access_denied(exc): + return render_template("error_access_denied.html", exc=exc), 403 + + def internal_server_error(e): """Bugs scodoc, erreurs 500""" # note that we set the 500 status explicitly @@ -181,6 +190,7 @@ def create_app(config_class=DevConfig): app.register_error_handler(ScoGenError, handle_sco_value_error) app.register_error_handler(ScoValueError, handle_sco_value_error) + app.register_error_handler(AccessDenied, handle_access_denied) app.register_error_handler(500, internal_server_error) app.register_error_handler(503, postgresql_server_error) app.register_error_handler(APIInvalidParams, handle_invalid_usage) diff --git a/app/scodoc/sco_exceptions.py b/app/scodoc/sco_exceptions.py index ec487b099..1ae86e65f 100644 --- a/app/scodoc/sco_exceptions.py +++ b/app/scodoc/sco_exceptions.py @@ -45,10 +45,6 @@ class InvalidEtudId(NoteProcessError): pass -class AccessDenied(ScoException): - pass - - class InvalidNoteValue(ScoException): pass @@ -92,6 +88,10 @@ class ScoGenError(ScoException): ScoException.__init__(self, msg) +class AccessDenied(ScoGenError): + pass + + class ScoInvalidDateError(ScoValueError): pass diff --git a/app/scodoc/sco_import_users.py b/app/scodoc/sco_import_users.py index 89ac9989a..cb98ddbeb 100644 --- a/app/scodoc/sco_import_users.py +++ b/app/scodoc/sco_import_users.py @@ -109,8 +109,11 @@ def import_excel_file(datafile): if not exceldata: raise ScoValueError("Ficher excel vide ou invalide") _, data = sco_excel.excel_bytes_to_list(exceldata) - if not data: # probably a bug - raise ScoException("import_excel_file: empty file !") + if not data: + raise ScoValueError( + """Le fichier xlsx attendu semble vide ! + """ + ) # 1- --- check title line fs = [scu.stripquotes(s).lower() for s in data[0]] log("excel: fs='%s'\ndata=%s" % (str(fs), str(data))) diff --git a/app/views/scodoc.py b/app/views/scodoc.py index aad2e919f..2ccac9283 100644 --- a/app/views/scodoc.py +++ b/app/views/scodoc.py @@ -61,6 +61,7 @@ from app.decorators import ( scodoc, permission_required_compat_scodoc7, ) +from app.scodoc.sco_exceptions import AccessDenied from app.scodoc.sco_permissions import Permission from app.views import scodoc_bp as bp diff --git a/sco_version.py b/sco_version.py index 714ef9fd0..1505aa7a3 100644 --- a/sco_version.py +++ b/sco_version.py @@ -1,7 +1,7 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "9.0.51" +SCOVERSION = "9.0.52" SCONAME = "ScoDoc"