import utilisateurs à compléter: titre page de diagnostic et sendmail à cabler

This commit is contained in:
Jean-Marie Place 2021-08-22 15:25:25 +02:00
parent 96788d588e
commit edadbdf113

View File

@ -141,75 +141,79 @@ def import_users(users, auth_dept=""):
def append_msg(msg): def append_msg(msg):
msg_list.append("Ligne %s : %s" % (line, msg)) msg_list.append("Ligne %s : %s" % (line, msg))
created = [] # liste de uid créés if len(users) == 0:
msg_list = [] ok = False
line = 1 # satr from excel line #2 msg_list = ["Feuilles vide ou illisible"]
ok = True else:
try: created = [] # liste de uid créés
for u in users: msg_list = []
line = line + 1 line = 1 # satr from excel line #2
ok, msg = sco_users.check_modif_user( ok = True
0, try:
user_name=u["user_name"], for u in users:
nom=u["nom"], line = line + 1
prenom=u["prenom"], ok, msg = sco_users.check_modif_user(
email=u["email"], 0,
roles=u["roles"], user_name=u["user_name"],
) nom=u["nom"],
if not ok: prenom=u["prenom"],
append_msg("identifiant '%s' %s" % (u["user_name"], msg)) email=u["email"],
# raise ScoValueError( roles=u["roles"],
# "données invalides pour %s: %s" % (u["user_name"], msg)
# )
u["passwd"] = generate_password()
#
# check identifiant
if not re.match(r"^[a-zA-Z0-9@\\\-_\\\.]*$", u["user_name"]):
ok = False
append_msg(
"identifiant '%s' invalide (pas d'accents ni de caractères spéciaux)"
% u["user_name"]
) )
elif len(u["user_name"]) > 64: if not ok:
ok = False append_msg("identifiant '%s' %s" % (u["user_name"], msg))
append_msg( # raise ScoValueError(
"identifiant '%s' trop long (64 caractères)" % u["user_name"] # "données invalides pour %s: %s" % (u["user_name"], msg)
) # )
if len(u["nom"]) > 64: u["passwd"] = generate_password()
ok = False #
append_msg("nom '%s' trop long (64 caractères)" % u["nom"]) # check identifiant
if len(u["prenom"]) > 64: if not re.match(r"^[a-zA-Z0-9@\\\-_\\\.]*$", u["user_name"]):
ok = False
append_msg("prenom '%s' trop long (64 caractères)" % u["prenom"])
if len(u["email"]) > 120:
ok = False
append_msg("email '%s' trop long (120 caractères)" % u["email"])
# check département
if u["dept"] != "":
dept = Departement.query.filter_by(acronym=u["dept"]).first()
if dept is None:
ok = False ok = False
append_msg("département '%s' inexistant" % u["dept"]) append_msg(
for role in u["roles"].split(","): "identifiant '%s' invalide (pas d'accents ni de caractères spéciaux)"
try: % u["user_name"]
_, _ = UserRole.role_dept_from_string(role) )
except ScoValueError as value_error: elif len(u["user_name"]) > 64:
ok = False ok = False
append_msg("role : %s " % role) append_msg(
# Création de l'utilisateur (via SQLAlchemy) "identifiant '%s' trop long (64 caractères)" % u["user_name"]
if ok: )
user = User() if len(u["nom"]) > 64:
user.from_dict(u, new_user=True) ok = False
db.session.add(user) append_msg("nom '%s' trop long (64 caractères)" % u["nom"])
created.append(u["user_name"]) if len(u["prenom"]) > 64:
db.session.commit() ok = False
except ScoValueError as value_error: append_msg("prenom '%s' trop long (64 caractères)" % u["prenom"])
log("import_users: exception: abort create %s" % str(created)) if len(u["email"]) > 120:
db.session.rollback() ok = False
raise ScoValueError(msg) # re-raise exception append_msg("email '%s' trop long (120 caractères)" % u["email"])
# check département
if u["dept"] != "":
dept = Departement.query.filter_by(acronym=u["dept"]).first()
if dept is None:
ok = False
append_msg("département '%s' inexistant" % u["dept"])
for role in u["roles"].split(","):
try:
_, _ = UserRole.role_dept_from_string(role)
except ScoValueError as value_error:
ok = False
append_msg("role : %s " % role)
# Création de l'utilisateur (via SQLAlchemy)
if ok:
user = User()
user.from_dict(u, new_user=True)
db.session.add(user)
created.append(u["user_name"])
db.session.commit()
except ScoValueError as value_error:
log("import_users: exception: abort create %s" % str(created))
db.session.rollback()
raise ScoValueError(msg) # re-raise exception
for user in users: for user in users:
mail_password(user) mail_password(user)
return ok, msg_list return ok, msg_list