fix import utilisateurs

This commit is contained in:
Emmanuel Viennet 2021-08-22 16:41:19 +02:00
parent 8f4b8ccdf6
commit 1cde233060

View File

@ -24,6 +24,10 @@ def import_scodoc7_user_db(scodoc7_db="dbname=SCOUSERS"):
cursor.execute("SELECT * FROM sco_users;") cursor.execute("SELECT * FROM sco_users;")
for u7 in cursor: for u7 in cursor:
user_name = u7["user_name"].strip().replace(" ", "_") user_name = u7["user_name"].strip().replace(" ", "_")
if user_name != u7["user_name"]:
current_app.logger.warning(
f"""Changin login '{u7["user_name"]}' to '{user_name}'"""
)
if User.query.filter_by(user_name=user_name).first(): if User.query.filter_by(user_name=user_name).first():
# user with same name exists ! # user with same name exists !
current_app.logger.warning( current_app.logger.warning(
@ -31,7 +35,7 @@ def import_scodoc7_user_db(scodoc7_db="dbname=SCOUSERS"):
) )
else: else:
u = User( u = User(
user_name=u7["user_name"], user_name=user_name,
email=u7["email"], email=u7["email"],
date_modif_passwd=u7["date_modif_passwd"], date_modif_passwd=u7["date_modif_passwd"],
nom=u7["nom"], nom=u7["nom"],
@ -55,9 +59,7 @@ def import_scodoc7_user_db(scodoc7_db="dbname=SCOUSERS"):
# Cas général: eg EnsRT # Cas général: eg EnsRT
m = re.match(r"^(-?[A-Za-z0-9]+?)([A-Z][A-Za-z0-9]*?)$", role_dept) m = re.match(r"^(-?[A-Za-z0-9]+?)([A-Z][A-Za-z0-9]*?)$", role_dept)
if not m: if not m:
msg = ( msg = f"User {user_name}: invalid role '{role_dept}' (ignoring)"
f"User {u7['user_name']}: invalid role '{role_dept}' (ignoring)"
)
current_app.logger.warning(msg) current_app.logger.warning(msg)
messages.append(msg) messages.append(msg)
else: else:
@ -71,7 +73,7 @@ def import_scodoc7_user_db(scodoc7_db="dbname=SCOUSERS"):
dept = m.group(2) dept = m.group(2)
role = Role.query.filter_by(name=role_name).first() role = Role.query.filter_by(name=role_name).first()
if not role: if not role:
msg = f"User {u7['user_name']}: ignoring role '{role_dept}'" msg = f"User {user_name}: ignoring role '{role_dept}'"
current_app.logger.warning(msg) current_app.logger.warning(msg)
messages.append(msg) messages.append(msg)
else: else: