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