From e16b974761004a4178b61af4446d8d663b54507d Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 15 Jun 2021 15:38:38 +0200 Subject: [PATCH] WIP changed has_permission --- app/auth/models.py | 6 +++-- app/decorators.py | 10 ++++---- app/scodoc/ZScoUsers.py | 10 +------- app/scodoc/debug.py | 2 +- app/scodoc/html_sco_header.py | 5 +++- app/scodoc/html_sidebar.py | 18 ++++++--------- app/scodoc/notesdb.py | 2 ++ app/scodoc/sco_abs_views.py | 2 +- app/scodoc/sco_archives_etud.py | 2 +- app/scodoc/sco_bulletins.py | 8 +++---- app/scodoc/sco_debouche.py | 2 +- app/scodoc/sco_dept.py | 4 ++-- app/scodoc/sco_edit_ue.py | 6 ++--- app/scodoc/sco_find_etud.py | 2 +- app/scodoc/sco_formsemestre_edit.py | 6 ++--- app/scodoc/sco_formsemestre_status.py | 28 +++++++++++------------ app/scodoc/sco_groups.py | 2 +- app/scodoc/sco_groups_view.py | 8 +++---- app/scodoc/sco_moduleimpl.py | 4 ++-- app/scodoc/sco_moduleimpl_inscriptions.py | 3 +-- app/scodoc/sco_moduleimpl_status.py | 2 +- app/scodoc/sco_page_etud.py | 26 ++++++++++----------- app/scodoc/sco_permissions.py | 19 +++++++-------- app/scodoc/sco_saisie_notes.py | 4 ++-- app/scodoc/sco_synchro_etuds.py | 2 +- app/scodoc/sco_tag_module.py | 2 +- app/scodoc/sco_ue_external.py | 4 ++-- app/scodoc/sco_utils.py | 2 +- 28 files changed, 94 insertions(+), 97 deletions(-) diff --git a/app/auth/models.py b/app/auth/models.py index 57622ba8f..85b9243b7 100644 --- a/app/auth/models.py +++ b/app/auth/models.py @@ -10,7 +10,7 @@ import json import os from time import time -from flask import current_app, url_for +from flask import current_app, url_for, g from flask_login import UserMixin, AnonymousUserMixin from werkzeug.security import generate_password_hash, check_password_hash @@ -127,7 +127,7 @@ class User(UserMixin, db.Model): return user # Permissions management: - def has_permission(self, perm, dept): + def has_permission(self, perm, dept=False): """Check if user has permission `perm` in given `dept`. Emulate Zope `has_permission`` @@ -135,6 +135,8 @@ class User(UserMixin, db.Model): perm: integer, one of the value defined in Permission class. context: """ + if dept is False: + dept = g.scodoc_dept # les role liés à ce département, et les roles avec dept=None (super-admin) roles_in_dept = ( UserRole.query.filter_by(user_id=self.id) diff --git a/app/decorators.py b/app/decorators.py index 93feccc71..e4867cd21 100644 --- a/app/decorators.py +++ b/app/decorators.py @@ -37,11 +37,13 @@ class ZRequest(object): "Emulating Zope 2 REQUEST" def __init__(self): - self.URL = request.base_url + self.URL = request.base_url.encode( + "utf-8" + ) # necessaire pour ScoDoc 8 en Python 2 self.URL0 = self.URL - self.BASE0 = request.url_root - self.QUERY_STRING = request.query_string - self.REQUEST_METHOD = request.method + self.BASE0 = request.url_root.encode("utf-8") + self.QUERY_STRING = request.query_string.encode("utf-8") + self.REQUEST_METHOD = request.method.encode("utf-8") self.AUTHENTICATED_USER = current_user if request.method == "POST": self.form = request.form diff --git a/app/scodoc/ZScoUsers.py b/app/scodoc/ZScoUsers.py index 8429bd662..6f226a941 100644 --- a/app/scodoc/ZScoUsers.py +++ b/app/scodoc/ZScoUsers.py @@ -49,15 +49,7 @@ from gen_tables import GenTable import scolars import sco_cache import sco_users -from sco_permissions import ( - ScoEditAllEvals, - ScoEditAllNotes, - ScoImplement, - ScoSuperAdmin, - ScoUsersAdmin, - ScoUsersView, - ScoView, -) + from sco_exceptions import ( AccessDenied, ScoException, diff --git a/app/scodoc/debug.py b/app/scodoc/debug.py index 48e992b7b..feb315eeb 100644 --- a/app/scodoc/debug.py +++ b/app/scodoc/debug.py @@ -86,7 +86,7 @@ class FakeUser: def __str__(self): return self.name - def has_permission(self, op, context): + def has_permission(self, op, dept): return True def has_role(self, role): diff --git a/app/scodoc/html_sco_header.py b/app/scodoc/html_sco_header.py index c45b25bb0..13ad4186b 100644 --- a/app/scodoc/html_sco_header.py +++ b/app/scodoc/html_sco_header.py @@ -28,6 +28,7 @@ import cgi import sco_utils as scu +from notes_log import log import html_sidebar import VERSION @@ -312,7 +313,9 @@ def sco_header( # Avertissement si mot de passe à changer if user_check: authuser = REQUEST.AUTHENTICATED_USER - passwd_temp = context.Users.user_info(user_name=str(authuser))["passwd_temp"] + # passwd_temp = context.Users.user_info(user_name=str(authuser))["passwd_temp"] + log("XXX TODO: Users.user_info") + passwd_temp = False # XXX TODO if passwd_temp: H.append( """
diff --git a/app/scodoc/html_sidebar.py b/app/scodoc/html_sidebar.py index 49569cc88..ef3973454 100644 --- a/app/scodoc/html_sidebar.py +++ b/app/scodoc/html_sidebar.py @@ -28,12 +28,8 @@ import sco_utils as scu import sco_preferences from sco_abs import getAbsSemEtud -from sco_permissions import ( - ScoUsersAdmin, - ScoUsersView, - ScoChangePreferences, - ScoAbsChange, -) +from app.scodoc.sco_permissions import Permission + """ Génération de la "sidebar" (marge gauche des pages HTML) @@ -63,14 +59,14 @@ def sidebar_common(context, REQUEST=None): % params, ] - if authuser.has_permission( - Permission.ScoUsersAdmin, context - ) or authuser.has_permission(ScoUsersView, context): + if authuser.has_permission(Permission.ScoUsersAdmin) or authuser.has_permission( + Permission.ScoUsersView + ): H.append( """Utilisateurs
""" % params ) - if authuser.has_permission(Permission.ScoChangePreferences, context): + if authuser.has_permission(Permission.ScoChangePreferences): H.append( """Paramétrage
""" % params @@ -121,7 +117,7 @@ def sidebar(context, REQUEST=None): ) H.append("") - if authuser.has_permission(Permission.ScoImplement, context): + if authuser.has_permission(Permission.ScoImplement): H.append( """