New command line: user-edit

This commit is contained in:
ilona 2025-01-03 17:13:33 +01:00
parent ea6307ac92
commit c279fcd050

View File

@ -430,6 +430,91 @@ def user_change_login(user_name, new_user_name):
user.change_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): def abort_if_false(ctx, param, value):
if not value: if not value:
ctx.abort() ctx.abort()