From c279fcd0503aad6ad64cf7a3a237dc12219105c5 Mon Sep 17 00:00:00 2001 From: ilona Date: Fri, 3 Jan 2025 17:13:33 +0100 Subject: [PATCH] New command line: user-edit --- scodoc.py | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/scodoc.py b/scodoc.py index 562c67fb7..82bea3cd0 100755 --- a/scodoc.py +++ b/scodoc.py @@ -430,6 +430,91 @@ def user_change_login(user_name, new_user_name): user.change_user_name(new_user_name) +@app.cli.command() +@click.argument("username") +@click.option( + "-d", + "--deactivate", + "deactivate", + is_flag=True, + help="désactive ce compte", +) +@click.option( + "-a", + "--activate", + "activate", + is_flag=True, + help="(ré)active ce compte", +) +@click.option("-c", "--cas-id", "cas_id") +@click.option( + "--allow-cas-login", + "allow_cas_login", + is_flag=True, + help="autorise login via CAS", +) +@click.option( + "--disable-cas-login", + "disable_cas_login", + is_flag=True, + help="interdit login via CAS", +) +@click.option( + "--allow-scodoc-login", + "allow_scodoc_login", + is_flag=True, + help="autorise login via ScoDoc", +) +@click.option( + "--disable-scodoc-login", + "disable_scodoc_login", + is_flag=True, + help="interdit login via ScoDoc", +) +@click.option( + "-v", + "--verbose", + "verbose", + is_flag=True, + help="verbose: affiche l'état après modif.", +) +def user_edit( + username, + cas_id: str = None, + allow_cas_login=None, + allow_scodoc_login=None, + disable_cas_login=None, + disable_scodoc_login=None, + activate=None, + deactivate=None, + verbose=False, +): + """Add or remove a role to the given user in the given dept""" + user: User = User.query.filter_by(user_name=username).first() + if not user: + sys.stderr.write(f"user_role: user {username} does not exists\n") + return 1 + if cas_id: + user.cas_id = cas_id + if allow_cas_login: + user.cas_allow_login = True + if disable_cas_login: + user.cas_allow_login = False + if allow_scodoc_login: + user.cas_allow_scodoc_login = True + if disable_scodoc_login: + user.cas_allow_scodoc_login = False + if activate: + user.active = True + if deactivate: + user.active = False + db.session.add(user) + db.session.commit() + if verbose: + for k, v in sorted(user.to_dict().items()): + print(f"{k} : {v}") + + def abort_if_false(ctx, param, value): if not value: ctx.abort()