diff --git a/app/auth/models.py b/app/auth/models.py index 4b411c35..7b0b2052 100644 --- a/app/auth/models.py +++ b/app/auth/models.py @@ -243,6 +243,15 @@ class User(UserMixin, db.Model): self.user_name, ) + @staticmethod + def get_user_name_from_nomplogin(nomplogin): + """Returns user_name from the string "Dupont Pierre (dupont)" """ + m = re.match(r".*\((.*)\)", nomplogin.strip()) + if m: + return m.group(1) + else: + return None + class AnonymousUser(AnonymousUserMixin): def has_permission(self, perm, dept=None): diff --git a/app/scodoc/html_sco_header.py b/app/scodoc/html_sco_header.py index 991fa6fa..656a8e63 100644 --- a/app/scodoc/html_sco_header.py +++ b/app/scodoc/html_sco_header.py @@ -30,6 +30,8 @@ import cgi +from flask_login import current_user + import app.scodoc.sco_utils as scu from app.scodoc.notes_log import log from app.scodoc import html_sidebar @@ -314,18 +316,14 @@ 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"] - log("XXX TODO: Users.user_info") - passwd_temp = False # XXX TODO - if passwd_temp: + if current_user.passwd_temp: H.append( """
Attention !
Vous avez reçu un mot de passe temporaire.
- Vous devez le changer: cliquez ici + Vous devez le changer: cliquez ici
""" - % (scu.ScoURL(), str(authuser)) + % (scu.UsersURL, current_user.user_name) ) # if head_message: diff --git a/app/scodoc/html_sidebar.py b/app/scodoc/html_sidebar.py index 7a426a12..bcd4face 100644 --- a/app/scodoc/html_sidebar.py +++ b/app/scodoc/html_sidebar.py @@ -28,6 +28,7 @@ """ Génération de la "sidebar" (marge gauche des pages HTML) """ +from flask import url_for import app.scodoc.sco_utils as scu from app.scodoc import sco_preferences @@ -35,19 +36,19 @@ from app.scodoc.sco_permissions import Permission def sidebar_common(context, REQUEST=None): - "partie commune a toutes les sidebar" + "partie commune à toutes les sidebar" authuser = REQUEST.AUTHENTICATED_USER params = { "ScoURL": scu.ScoURL(), "UsersURL": scu.UsersURL(), "NotesURL": scu.NotesURL(), "AbsencesURL": scu.AbsencesURL(), - # XXX TODO "LogoutURL" : , + "LogoutURL": url_for("auth.logout"), "authuser": str(authuser), } H = [ 'ScoDoc 8', - '
%(authuser)s
déconnexion
' + '
%(authuser)s
déconnexion
' % params, sidebar_dept(context, REQUEST), """

Scolarité

diff --git a/app/scodoc/sco_abs_notification.py b/app/scodoc/sco_abs_notification.py index 272bbd46..37a997d4 100644 --- a/app/scodoc/sco_abs_notification.py +++ b/app/scodoc/sco_abs_notification.py @@ -42,9 +42,10 @@ import app.scodoc.notesdb as ndb import app.scodoc.sco_utils as scu from app.scodoc.notes_log import log from app.scodoc.scolog import logdb +from app.scodoc import sco_etud from app.scodoc import sco_formsemestre from app.scodoc import sco_preferences -from app.scodoc import sco_etud +from app.scodoc import sco_users def abs_notify(context, etudid, date): @@ -147,7 +148,7 @@ def abs_notify_get_destinations(context, sem, prefs, etudid, date, nbabs, nbabsj if sem and prefs["abs_notify_respsem"]: # notifie chaque responsable du semestre for responsable_id in sem["responsables"]: - u = context.Users.user_info(responsable_id) + u = sco_users.user_info(responsable_id) if u["email"]: destinations.append(u["email"]) if prefs["abs_notify_chief"] and prefs["email_chefdpt"]: @@ -165,7 +166,7 @@ def abs_notify_get_destinations(context, sem, prefs, etudid, date, nbabs, nbabsj if sem and prefs["abs_notify_respeval"]: mods = mod_with_evals_at_date(context, date, etudid) for mod in mods: - u = context.Users.user_info(mod["responsable_id"]) + u = sco_users.user_info(mod["responsable_id"]) if u["email"]: destinations.append(u["email"]) diff --git a/app/scodoc/sco_bulletins.py b/app/scodoc/sco_bulletins.py index f1175fb4..f0a97c7f 100644 --- a/app/scodoc/sco_bulletins.py +++ b/app/scodoc/sco_bulletins.py @@ -83,7 +83,7 @@ def make_context_dict(context, sem, etud): C = sem.copy() C["responsable"] = " ,".join( [ - context.Users.user_info(user_name=responsable_id)["prenomnom"] + sco_users.user_info(user_name=responsable_id)["prenomnom"] for responsable_id in sem["responsables"] ] ) @@ -492,7 +492,7 @@ def _ue_mod_bulletin(context, etudid, formsemestre_id, ue_id, modimpls, nt, vers mod["mod_descr_txt"] = "Module %s, coef. %s (%s)" % ( modimpl["module"]["titre"], scu.fmt_coef(modimpl["module"]["coefficient"]), - context.Users.user_info(modimpl["responsable_id"])["nomcomplet"], + sco_users.user_info(modimpl["responsable_id"])["nomcomplet"], ) link_mod = ( '' @@ -513,7 +513,7 @@ def _ue_mod_bulletin(context, etudid, formsemestre_id, ue_id, modimpls, nt, vers mod_descr = "Module %s, coef. %s (%s)" % ( modimpl["module"]["titre"], scu.fmt_coef(modimpl["module"]["coefficient"]), - context.Users.user_info(modimpl["responsable_id"])["nomcomplet"], + sco_users.user_info(modimpl["responsable_id"])["nomcomplet"], ) link_mod = ( '' diff --git a/app/scodoc/sco_dump_db.py b/app/scodoc/sco_dump_db.py index e682c5e3..78481968 100644 --- a/app/scodoc/sco_dump_db.py +++ b/app/scodoc/sco_dump_db.py @@ -57,6 +57,7 @@ import app.scodoc.sco_utils as scu from app.scodoc.notes_log import log from app.scodoc import html_sco_header from app.scodoc import sco_preferences +from app.scodoc import sco_users from app.scodoc import VERSION from app.scodoc.sco_exceptions import ScoValueError @@ -192,7 +193,7 @@ def _send_db(context, REQUEST, ano_db_name): "dept_name": sco_preferences.get_preference(context, "DeptName"), "serial": _get_scodoc_serial(context), "sco_user": str(REQUEST.AUTHENTICATED_USER), - "sent_by": context.Users.user_info(str(REQUEST.AUTHENTICATED_USER))[ + "sent_by": sco_users.user_info(str(REQUEST.AUTHENTICATED_USER))[ "nomcomplet" ], "sco_version": VERSION.SCOVERSION, diff --git a/app/scodoc/sco_evaluations.py b/app/scodoc/sco_evaluations.py index 00b07971..51e03d12 100644 --- a/app/scodoc/sco_evaluations.py +++ b/app/scodoc/sco_evaluations.py @@ -52,6 +52,7 @@ from app.scodoc import sco_moduleimpl from app.scodoc import sco_news from app.scodoc import sco_permissions_check from app.scodoc import sco_preferences +from app.scodoc import sco_users # -------------------------------------------------------------------- @@ -899,7 +900,7 @@ def formsemestre_evaluations_delai_correction( ) e["module_titre"] = Mod["titre"] e["responsable_id"] = M["responsable_id"] - e["responsable_nomplogin"] = context.Users.user_info(M["responsable_id"])[ + e["responsable_nomplogin"] = sco_users.user_info(M["responsable_id"])[ "nomplogin" ] e["_jour_target"] = "evaluation_listenotes?evaluation_id=" + e["evaluation_id"] @@ -1057,7 +1058,7 @@ def evaluation_describe(context, evaluation_id="", edit_in_place=True, REQUEST=N M = sco_moduleimpl.do_moduleimpl_list(context, moduleimpl_id=moduleimpl_id)[0] Mod = sco_edit_module.do_module_list(context, args={"module_id": M["module_id"]})[0] formsemestre_id = M["formsemestre_id"] - u = context.Users.user_info(M["responsable_id"]) + u = sco_users.user_info(M["responsable_id"]) resp = u["prenomnom"] nomcomplet = u["nomcomplet"] can_edit = sco_permissions_check.can_edit_notes( diff --git a/app/scodoc/sco_formsemestre.py b/app/scodoc/sco_formsemestre.py index 0c173b3d..51dd9759 100644 --- a/app/scodoc/sco_formsemestre.py +++ b/app/scodoc/sco_formsemestre.py @@ -33,6 +33,7 @@ from scodoc_manager import sco_mgr from app.scodoc import sco_codes_parcours from app.scodoc import sco_core from app.scodoc import sco_preferences +from app.scodoc import sco_users from app.scodoc.gen_tables import GenTable from app.scodoc.notes_log import log from app.scodoc.sco_codes_parcours import NO_SEMESTRE_ID @@ -459,7 +460,7 @@ def sem_set_responsable_name(context, sem): "ajoute champs responsable_name" sem["responsable_name"] = ", ".join( [ - context.Users.user_info(responsable_id)["nomprenom"] + sco_users.user_info(responsable_id)["nomprenom"] for responsable_id in sem["responsables"] ] ) diff --git a/app/scodoc/sco_formsemestre_edit.py b/app/scodoc/sco_formsemestre_edit.py index 1ac8a6b9..cf5e0e15 100644 --- a/app/scodoc/sco_formsemestre_edit.py +++ b/app/scodoc/sco_formsemestre_edit.py @@ -27,6 +27,7 @@ """Form choix modules / responsables et creation formsemestre """ +from app.auth.models import User import app.scodoc.notesdb as ndb import app.scodoc.sco_utils as scu @@ -685,10 +686,10 @@ def do_formsemestre_createwithmodules(context, REQUEST=None, edit=False): tf[2]["bul_hide_xml"] = 1 # remap les identifiants de responsables: - tf[2]["responsable_id"] = context.Users.get_user_name_from_nomplogin( + tf[2]["responsable_id"] = User.get_user_name_from_nomplogin( tf[2]["responsable_id"] ) - tf[2]["responsable_id2"] = context.Users.get_user_name_from_nomplogin( + tf[2]["responsable_id2"] = User.get_user_name_from_nomplogin( tf[2]["responsable_id2"] ) tf[2]["responsables"] = [tf[2]["responsable_id"]] @@ -696,7 +697,7 @@ def do_formsemestre_createwithmodules(context, REQUEST=None, edit=False): tf[2]["responsables"].append(tf[2]["responsable_id2"]) for module_id in tf[2]["tf-checked"]: - mod_resp_id = context.Users.get_user_name_from_nomplogin(tf[2][module_id]) + mod_resp_id = User.get_user_name_from_nomplogin(tf[2][module_id]) if mod_resp_id is None: # Si un module n'a pas de responsable (ou inconnu), l'affecte au 1er directeur des etudes: mod_resp_id = tf[2]["responsable_id"] @@ -875,10 +876,10 @@ def formsemestre_clone(context, formsemestre_id, REQUEST=None): """ sem = sco_formsemestre.get_formsemestre(context, formsemestre_id) # Liste des enseignants avec forme pour affichage / saisie avec suggestion - userlist = context.Users.get_userlist() + userlist = sco_users.get_user_list() login2display = {} # user_name : forme pour affichage = "NOM Prenom (login)" for u in userlist: - login2display[u["user_name"]] = u["nomplogin"] + login2display[u.user_name] = u.get_nomplogin() allowed_user_names = login2display.values() + [""] initvalues = { @@ -981,7 +982,7 @@ def formsemestre_clone(context, formsemestre_id, REQUEST=None): new_formsemestre_id = do_formsemestre_clone( context, formsemestre_id, - context.Users.get_user_name_from_nomplogin(tf[2]["responsable_id"]), + User.get_user_name_from_nomplogin(tf[2]["responsable_id"]), tf[2]["date_debut"], tf[2]["date_fin"], clone_evaluations=tf[2]["clone_evaluations"], diff --git a/app/scodoc/sco_formsemestre_status.py b/app/scodoc/sco_formsemestre_status.py index 86ab3557..abd019c9 100644 --- a/app/scodoc/sco_formsemestre_status.py +++ b/app/scodoc/sco_formsemestre_status.py @@ -58,6 +58,7 @@ from app.scodoc import sco_groups from app.scodoc import sco_moduleimpl from app.scodoc import sco_permissions_check from app.scodoc import sco_preferences +from app.scodoc import sco_users from app.scodoc.gen_tables import GenTable from app.scodoc.sco_formsemestre_custommenu import formsemestre_custommenu_html @@ -601,8 +602,7 @@ def fill_formsemestre(context, sem, REQUEST=None): ) sem["nbinscrits"] = len(inscrits) uresps = [ - context.Users.user_info(responsable_id) - for responsable_id in sem["responsables"] + sco_users.user_info(responsable_id) for responsable_id in sem["responsables"] ] sem["resp"] = ", ".join([u["prenomnom"] for u in uresps]) sem["nomcomplet"] = ", ".join([u["nomcomplet"] for u in uresps]) @@ -659,10 +659,7 @@ def formsemestre_description_table( context, moduleimpl_id=M["moduleimpl_id"] ) enseignants = ", ".join( - [ - context.Users.user_info(m["ens_id"], REQUEST)["nomprenom"] - for m in M["ens"] - ] + [sco_users.user_info(m["ens_id"], REQUEST)["nomprenom"] for m in M["ens"]] ) l = { "UE": M["ue"]["acronyme"], @@ -670,7 +667,7 @@ def formsemestre_description_table( "Module": M["module"]["abbrev"] or M["module"]["titre"], "_Module_class": "scotext", "Inscrits": len(ModInscrits), - "Responsable": context.Users.user_info(M["responsable_id"])["nomprenom"], + "Responsable": sco_users.user_info(M["responsable_id"])["nomprenom"], "_Responsable_class": "scotext", "Enseignants": enseignants, "_Enseignants_class": "scotext", @@ -1039,7 +1036,7 @@ def formsemestre_status(context, formsemestre_id=None, REQUEST=None): ) mails_enseignants = set( [ - context.Users.user_info(ens_id, REQUEST)["email"] + sco_users.user_info(ens_id, REQUEST)["email"] for ens_id in sem["responsables"] ] ) # adr. mail des enseignants @@ -1051,19 +1048,19 @@ def formsemestre_status(context, formsemestre_id=None, REQUEST=None): + ", coef. " + str(M["module"]["coefficient"]) ) - ModEns = context.Users.user_info(M["responsable_id"])["nomcomplet"] + ModEns = sco_users.user_info(M["responsable_id"])["nomcomplet"] if M["ens"]: ModEns += " (resp.), " + ", ".join( - [context.Users.user_info(e["ens_id"])["nomcomplet"] for e in M["ens"]] + [sco_users.user_info(e["ens_id"])["nomcomplet"] for e in M["ens"]] ) ModInscrits = sco_moduleimpl.do_moduleimpl_inscription_list( context, moduleimpl_id=M["moduleimpl_id"] ) mails_enseignants.add( - context.Users.user_info(M["responsable_id"], REQUEST)["email"] + sco_users.user_info(M["responsable_id"], REQUEST)["email"] ) mails_enseignants |= set( - [context.Users.user_info(m["ens_id"], REQUEST)["email"] for m in M["ens"]] + [sco_users.user_info(m["ens_id"], REQUEST)["email"] for m in M["ens"]] ) ue = M["ue"] if prev_ue_id != ue["ue_id"]: @@ -1137,7 +1134,7 @@ def formsemestre_status(context, formsemestre_id=None, REQUEST=None): % ( M["moduleimpl_id"], ModEns, - context.Users.user_info(M["responsable_id"])["prenomnom"], + sco_users.user_info(M["responsable_id"])["prenomnom"], ) ) diff --git a/app/scodoc/sco_moduleimpl_status.py b/app/scodoc/sco_moduleimpl_status.py index b9f35586..51c47834 100644 --- a/app/scodoc/sco_moduleimpl_status.py +++ b/app/scodoc/sco_moduleimpl_status.py @@ -47,6 +47,7 @@ from app.scodoc import sco_groups from app.scodoc import sco_moduleimpl from app.scodoc import sco_permissions_check from app.scodoc import sco_saisie_notes +from app.scodoc import sco_users # ported from old DTML code in oct 2009 @@ -197,7 +198,7 @@ def moduleimpl_status(context, moduleimpl_id=None, partition_id=None, REQUEST=No
Responsable: """, - context.Users.user_info(M["responsable_id"])["nomprenom"], + sco_users.user_info(M["responsable_id"])["nomprenom"], """(%(responsable_id)s)""" % M, ] try: @@ -210,7 +211,7 @@ def moduleimpl_status(context, moduleimpl_id=None, partition_id=None, REQUEST=No pass H.append("""""") H.append( - ", ".join([context.Users.user_info(m["ens_id"])["nomprenom"] for m in M["ens"]]) + ", ".join([sco_users.user_info(m["ens_id"])["nomprenom"] for m in M["ens"]]) ) H.append("""""") try: diff --git a/app/scodoc/sco_news.py b/app/scodoc/sco_news.py index e99309c4..c9ffe606 100644 --- a/app/scodoc/sco_news.py +++ b/app/scodoc/sco_news.py @@ -45,6 +45,7 @@ from app.scodoc.sco_utils import SCO_ENCODING, SCO_ANNONCES_WEBSITE from app.scodoc import sco_formsemestre from app.scodoc import sco_moduleimpl from app.scodoc import sco_preferences +from app.scodoc import sco_users _scolar_news_editor = ndb.EditableTable( "scolar_news", @@ -85,7 +86,7 @@ def add(context, REQUEST, typ, object=None, text="", url=None, max_frequency=Fal cnx = ndb.GetDBConnexion() args = { "authenticated_user": authuser_name, - "user_info": context.Users.user_info(user_name=authuser_name), + "user_info": sco_users.user_info(user_name=authuser_name), "type": typ, "object": object, "text": text, @@ -153,7 +154,7 @@ def scolar_news_summary(context, n=5): ) n["text"] += ( " par " - + context.Users.user_info(user_name=n["authenticated_user"])["nomcomplet"] + + sco_users.user_info(user_name=n["authenticated_user"])["nomcomplet"] ) return news diff --git a/app/scodoc/sco_recapcomplet.py b/app/scodoc/sco_recapcomplet.py index 43a6f40c..db61c9f3 100644 --- a/app/scodoc/sco_recapcomplet.py +++ b/app/scodoc/sco_recapcomplet.py @@ -49,6 +49,7 @@ from app.scodoc import sco_permissions from app.scodoc import sco_permissions_check from app.scodoc import sco_preferences from app.scodoc import sco_etud +from app.scodoc import sco_users from app.scodoc.sco_codes_parcours import DEF, UE_SPORT @@ -621,7 +622,7 @@ def make_formsemestre_recapcomplet( cls, mod["moduleimpl_id"], mod["module"]["titre"], - context.Users.user_info(mod["responsable_id"])["nomcomplet"], + sco_users.user_info(mod["responsable_id"])["nomcomplet"], F[0][i], ) else: diff --git a/app/scodoc/sco_undo_notes.py b/app/scodoc/sco_undo_notes.py index 4ae468fa..3649120a 100644 --- a/app/scodoc/sco_undo_notes.py +++ b/app/scodoc/sco_undo_notes.py @@ -54,6 +54,7 @@ from app.scodoc import sco_evaluations from app.scodoc import sco_formsemestre from app.scodoc import sco_moduleimpl from app.scodoc import sco_preferences +from app.scodoc import sco_users from app.scodoc import VERSION from app.scodoc.gen_tables import GenTable @@ -243,7 +244,7 @@ def get_note_history(context, evaluation_id, etudid, REQUEST=None, fmt=""): # et cherche nom complet de l'enseignant: for x in history: x["comment"] = x["comment"] or "" - x["user_name"] = context.Users.user_info(x["uid"])["nomcomplet"] + x["user_name"] = sco_users.user_info(x["uid"])["nomcomplet"] if fmt == "json": return scu.sendJSON(REQUEST, history) diff --git a/app/scodoc/sco_users.py b/app/scodoc/sco_users.py index 7a7173f0..fb6416d6 100644 --- a/app/scodoc/sco_users.py +++ b/app/scodoc/sco_users.py @@ -54,7 +54,6 @@ from app.scodoc import sco_excel from app.scodoc import sco_preferences from app.scodoc.gen_tables import GenTable from app.scodoc.notes_log import log -from app.scodoc.sco_permissions_check import can_handle_passwd from app.scodoc.scolog import logdb from app.scodoc.sco_etud import format_prenom, format_nom from app.scodoc.TrivialFormulator import TrivialFormulator, tf_error_message @@ -160,6 +159,8 @@ def list_users( REQUEST=None, ): "List users, returns a table in the specified format" + from app.scodoc.sco_permissions_check import can_handle_passwd + if dept and not all_depts: users = get_user_list(dept=dept, with_inactives=with_inactives) comm = "dept. %s" % dept.encode(scu.SCO_ENCODING) # sco8 @@ -325,6 +326,8 @@ def user_info_page(context, user_name=None, REQUEST=None): """Display page of info about given user. If user_name not specified, user current_user """ + from app.scodoc.sco_permissions_check import can_handle_passwd + # peut on divulguer ces infos ? if not can_handle_passwd(current_user, allow_admindepts=True): raise AccessDenied("Vous n'avez pas la permission de voir cette page") diff --git a/app/views/notes.py b/app/views/notes.py index 9fcae794..5aea9d88 100644 --- a/app/views/notes.py +++ b/app/views/notes.py @@ -41,6 +41,9 @@ from flask import current_app from config import Config import scodoc_manager + +from app.auth.models import User + from app.decorators import ( scodoc7func, ScoDoc7Context, @@ -779,7 +782,7 @@ def edit_enseignants_form(context, REQUEST, moduleimpl_id): "moduleimpl_status?moduleimpl_id=" + moduleimpl_id ) else: - ens_id = context.Users.get_user_name_from_nomplogin(tf[2]["ens_id"]) + ens_id = User.get_user_name_from_nomplogin(tf[2]["ens_id"]) if not ens_id: H.append( '

Pour ajouter un enseignant, choisissez un nom dans le menu

' @@ -875,9 +878,7 @@ def edit_moduleimpl_resp(context, REQUEST, moduleimpl_id): "moduleimpl_status?moduleimpl_id=" + moduleimpl_id ) else: - responsable_id = context.Users.get_user_name_from_nomplogin( - tf[2]["responsable_id"] - ) + responsable_id = User.get_user_name_from_nomplogin(tf[2]["responsable_id"]) if ( not responsable_id ): # presque impossible: tf verifie les valeurs (mais qui peuvent changer entre temps) @@ -1194,7 +1195,7 @@ def formsemestre_enseignants_list(context, REQUEST, formsemestre_id, format="htm # ajoute infos sur enseignant: for ens in sem_ens: - sem_ens[ens].update(context.Users.user_info(ens)) + sem_ens[ens].update(sco_users.user_info(ens)) if sem_ens[ens]["email"]: sem_ens[ens]["_email_target"] = "mailto:%s" % sem_ens[ens]["email"] @@ -2566,5 +2567,3 @@ sco_publish( ) context.populate(globals()) - -context.Users = scodoc_manager.FakeUsers() diff --git a/app/views/scolar.py b/app/views/scolar.py index b5e36dfa..1eb53271 100644 --- a/app/views/scolar.py +++ b/app/views/scolar.py @@ -2006,5 +2006,3 @@ sco_publish( ) context.populate(globals()) - -context.Users = scodoc_manager.FakeUsers() diff --git a/app/views/users.py b/app/views/users.py index 5551629c..c7512aac 100644 --- a/app/views/users.py +++ b/app/views/users.py @@ -169,8 +169,6 @@ def create_user_form(context, REQUEST, user_name=None, edit=0): if displayed_roles_strings[i] not in editable_roles_strings: disabled_roles[i] = True - # stop() # XXX - descr = [ ("edit", {"input_type": "hidden", "default": edit}), ("nom", {"title": "Nom", "size": 20, "allow_null": False}), @@ -315,7 +313,6 @@ def create_user_form(context, REQUEST, user_name=None, edit=0): }, ), ] - # stop() # XXX if "tf-submitted" in REQUEST.form and not "roles" in REQUEST.form: REQUEST.form["roles"] = [] if "tf-submitted" in REQUEST.form: @@ -337,7 +334,7 @@ def create_user_form(context, REQUEST, user_name=None, edit=0): if tf[0] == 0: return "\n".join(H) + "\n" + tf[1] + F elif tf[0] == -1: - return REQUEST.RESPONSE.redirect(context.UsersURL()) + return REQUEST.RESPONSE.redirect(scu.UsersURL()) else: vals = tf[2] roles = set(vals["roles"]).intersection(editable_roles_strings) @@ -366,7 +363,6 @@ def create_user_form(context, REQUEST, user_name=None, edit=0): return "\n".join(H) + "\n" + tf[1] + F if not force: - # XXX x = stop() ok, msg = sco_users.check_modif_user( edit, user_name=user_name, diff --git a/scotests/sco_fake_gen.py b/scotests/sco_fake_gen.py index 0d297ae0..e312d310 100644 --- a/scotests/sco_fake_gen.py +++ b/scotests/sco_fake_gen.py @@ -433,4 +433,4 @@ class ScoFake: # band aid for #sco8 dev (temporaire en attendant Users) class Sco8Context(object): - Users = scodoc_manager.FakeUsers() + pass diff --git a/scotests/test_scenario1_app.py b/scotests/test_scenario1_app.py index 1d88e9b1..714c991e 100644 --- a/scotests/test_scenario1_app.py +++ b/scotests/test_scenario1_app.py @@ -1,8 +1,15 @@ +# -*- mode: python -*- +# -*- coding: utf-8 -*- + +# XXX A REVOIR POUR SCODOC8 + import random -# La variable context est définie par le script de lancement -# l'affecte ainsi pour évietr les warnins pylint: -context = context # pylint: disable=undefined-variable -REQUEST = REQUEST # pylint: disable=undefined-variable +from app import db +from app.auth.models import User +from app.auth.models import Role + +DEPT = "TEST" + import scotests.sco_fake_gen as sco_fake_gen # pylint: disable=import-error G = sco_fake_gen.ScoFake(context.Notes) @@ -11,10 +18,12 @@ G.verbose = False # --- Création d'étudiants etuds = [G.create_etud(code_nip=None) for _ in range(10)] -# --- Création de l'utilisateur responsable du semestres, des modules etc.... - -arg = {"passwd": "scodocpass", "user_name" : "unutil", "roles" :"Ens,RespPe"} -user = context.Users.create_user(args=arg, REQUEST=REQUEST) +# --- Création de l'utilisateur responsable du semestre, des modules etc.... +user = User(user_name="unutil") +user.set_password("scodocpass") +user.add_role(Role.get_named_role("Ens"), DEPT) +db.session.add(u) +db.session.commit() print(user) # --- Création formation et de deux UE @@ -75,9 +84,13 @@ for module_id, formsemestre_id, responsable_id in [ (mod11["module_id"], sem["formsemestre_id"], "bach"), (mod12["module_id"], sem["formsemestre_id"], "bach"), (mod21["module_id"], sem["formsemestre_id"], "bach"), - (mod22["module_id"], sem["formsemestre_id"], "bach") -] : - mi = G.create_moduleimpl(module_id=module_id, formsemestre_id=formsemestre_id, responsable_id=responsable_id) + (mod22["module_id"], sem["formsemestre_id"], "bach"), +]: + mi = G.create_moduleimpl( + module_id=module_id, + formsemestre_id=formsemestre_id, + responsable_id=responsable_id, + ) mods.append(mi) @@ -88,7 +101,7 @@ for etud in etuds: # --- Création d'évaluations (2 par modules) -evals=[] +evals = [] for moduleimpl_id, jour, description, coefficient in [ (mods[0]["moduleimpl_id"], "01/02/2021", "e1", 1.0), @@ -99,19 +112,20 @@ for moduleimpl_id, jour, description, coefficient in [ (mods[2]["moduleimpl_id"], "06/02/2021", "e6", 1.0), (mods[3]["moduleimpl_id"], "07/02/2021", "e7", 1.0), (mods[3]["moduleimpl_id"], "08/02/2021", "e8", 1.0), -] : - e = G.create_evaluation(moduleimpl_id=moduleimpl_id, jour=jour, description=description, coefficient=coefficient) +]: + e = G.create_evaluation( + moduleimpl_id=moduleimpl_id, + jour=jour, + description=description, + coefficient=coefficient, + ) evals.append(e) # --- Saisie des notes aléatoires -for eval in evals : +for eval in evals: for etud in etuds: nb_changed, nb_suppress, existing_decisions = G.create_note( evaluation=eval, etud=etud, note=float(random.randint(0, 20)) ) - - - - diff --git a/scotests/test_user.py b/scotests/test_user.py deleted file mode 100644 index eb803620..00000000 --- a/scotests/test_user.py +++ /dev/null @@ -1,75 +0,0 @@ -""" Créer un utilisateur, recupérer ses infos, changer son mdp, le supprimer """ - -import random - -# La variable context est définie par le script de lancement -# l'affecte ainsi pour évietr les warnins pylint: -context = context # pylint: disable=undefined-variable -REQUEST = REQUEST # pylint: disable=undefined-variable -import scotests.sco_fake_gen as sco_fake_gen # pylint: disable=import-error -import ZScoUsers -import ZScoDoc -import ZScolar - -nomdept = raw_input( - "Quel est le nom de votre département test? ATTENTION A NE PAS VOUS TROMPER : " -) - -# --- Création d'un utilisateur - -arg = { - "passwd": "scodocpass", - "user_name": "unutil", - "nom": "unnom", - "prenom": "unprenom", - "email": "unemail@mail.fr", - "roles": "Ens" + nomdept + ",RespPe" + nomdept, -} -# user1 = context.Users.create_user(args=arg, REQUEST=REQUEST) -user_info1 = context.Users.user_info(user_name="unutil") - -assert user_info1["email"] == arg["email"] -assert user_info1["user_name"] == arg["user_name"] -assert user_info1["nom"] == "unnom" -assert user_info1["prenom"] == "unprenom" -assert user_info1["roles"] == arg["roles"] - - -# --- Récupération de la liste des Users - -liste_xml = context.Users.get_user_list_xml(REQUEST=REQUEST) -print(liste_xml) - -liste_user = context.Users.get_userlist() -len_liu1 = len(liste_user) - -assert user_info1 in liste_user # le nouvel utilisateur est bien dans la liste ! - -# --- Récupérer user_name à partir de nomplogin - -user_name1 = context.Users.get_user_name_from_nomplogin( - nomplogin=user_info1["nomplogin"] -) -assert user_name1 == "unutil" - -# --- Changement du mot de passe de l'utilisateur - -context.Users.do_change_password(user_name="unutil", password="scodocpass2") -# vérification du mdp changé directement sur scodoc web car je ne trouve pas comment récupérer le mdp en python -# Vérification : ok! - -# --- Supression d'un utilisateur - -# context.Users.delete_user_form(REQUEST=REQUEST, user_name="unutil") - -# --- Test de la récupération de l'URL - -url = context.Users.UsersURL() -assert url == "ScoDoc/" + nomdept + "/Scolarite/Users" - -""" -Commentaire : - -La supression d'un utilisateur ne fonctionne pas car nécessite l'envoie d'un formulaire. - -""" \ No newline at end of file