forked from ScoDoc/ScoDoc
import utilisateurs à compléter: titre page de diagnostic et sendmail à cabler
This commit is contained in:
parent
96788d588e
commit
edadbdf113
@ -141,75 +141,79 @@ def import_users(users, auth_dept=""):
|
||||
def append_msg(msg):
|
||||
msg_list.append("Ligne %s : %s" % (line, msg))
|
||||
|
||||
created = [] # liste de uid créés
|
||||
msg_list = []
|
||||
line = 1 # satr from excel line #2
|
||||
ok = True
|
||||
try:
|
||||
for u in users:
|
||||
line = line + 1
|
||||
ok, msg = sco_users.check_modif_user(
|
||||
0,
|
||||
user_name=u["user_name"],
|
||||
nom=u["nom"],
|
||||
prenom=u["prenom"],
|
||||
email=u["email"],
|
||||
roles=u["roles"],
|
||||
)
|
||||
if not ok:
|
||||
append_msg("identifiant '%s' %s" % (u["user_name"], msg))
|
||||
# raise ScoValueError(
|
||||
# "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"]
|
||||
if len(users) == 0:
|
||||
ok = False
|
||||
msg_list = ["Feuilles vide ou illisible"]
|
||||
else:
|
||||
created = [] # liste de uid créés
|
||||
msg_list = []
|
||||
line = 1 # satr from excel line #2
|
||||
ok = True
|
||||
try:
|
||||
for u in users:
|
||||
line = line + 1
|
||||
ok, msg = sco_users.check_modif_user(
|
||||
0,
|
||||
user_name=u["user_name"],
|
||||
nom=u["nom"],
|
||||
prenom=u["prenom"],
|
||||
email=u["email"],
|
||||
roles=u["roles"],
|
||||
)
|
||||
elif len(u["user_name"]) > 64:
|
||||
ok = False
|
||||
append_msg(
|
||||
"identifiant '%s' trop long (64 caractères)" % u["user_name"]
|
||||
)
|
||||
if len(u["nom"]) > 64:
|
||||
ok = False
|
||||
append_msg("nom '%s' trop long (64 caractères)" % u["nom"])
|
||||
if len(u["prenom"]) > 64:
|
||||
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:
|
||||
if not ok:
|
||||
append_msg("identifiant '%s' %s" % (u["user_name"], msg))
|
||||
# raise ScoValueError(
|
||||
# "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("département '%s' inexistant" % u["dept"])
|
||||
for role in u["roles"].split(","):
|
||||
try:
|
||||
_, _ = UserRole.role_dept_from_string(role)
|
||||
except ScoValueError as value_error:
|
||||
append_msg(
|
||||
"identifiant '%s' invalide (pas d'accents ni de caractères spéciaux)"
|
||||
% u["user_name"]
|
||||
)
|
||||
elif len(u["user_name"]) > 64:
|
||||
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
|
||||
append_msg(
|
||||
"identifiant '%s' trop long (64 caractères)" % u["user_name"]
|
||||
)
|
||||
if len(u["nom"]) > 64:
|
||||
ok = False
|
||||
append_msg("nom '%s' trop long (64 caractères)" % u["nom"])
|
||||
if len(u["prenom"]) > 64:
|
||||
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
|
||||
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:
|
||||
mail_password(user)
|
||||
for user in users:
|
||||
mail_password(user)
|
||||
return ok, msg_list
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user