From 285d9fc69cf6cee811ffe6aa1b54c15df1d9a785 Mon Sep 17 00:00:00 2001 From: Jackson Date: Wed, 22 Jan 2025 15:17:15 +0100 Subject: [PATCH] --no-logout on synadm user modify Fixes: https://github.com/JOJ0/synadm/issues/153 --- synadm/api.py | 5 ++++- synadm/cli/user.py | 14 ++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/synadm/api.py b/synadm/api.py index ee6c65f3..198ff371 100644 --- a/synadm/api.py +++ b/synadm/api.py @@ -600,7 +600,8 @@ def user_login(self, user_id, expire_days, expire, _expire_ts): user_id=user_id) def user_modify(self, user_id, password, display_name, threepid, - avatar_url, admin, deactivation, user_type, lock): + avatar_url, admin, deactivation, user_type, lock, + logout_devices): """ Create or update information about a given user The threepid argument must be passed as a tuple in a tuple (which is @@ -631,6 +632,8 @@ def user_modify(self, user_id, password, display_name, threepid, if user_type: data.update({"user_type": None if user_type == 'null' else user_type}) + if logout_devices: + data.update({"logout_devices": logout_devices}) return self.query("put", "v2/users/{user_id}", data=data, user_id=user_id) diff --git a/synadm/cli/user.py b/synadm/cli/user.py index db247afc..891cc8d0 100644 --- a/synadm/cli/user.py +++ b/synadm/cli/user.py @@ -385,10 +385,10 @@ def name_extra(self): @optgroup.group(cls=UserModifyOptionGroup) @optgroup.option( "--password-prompt", "-p", is_flag=True, - help="Set password interactively.") + help="Set password interactively. See also the --no-logout option.") @optgroup.option( "--password", "-P", type=str, - help="Set password on command line.") + help="Set password on command line. See also the --no-logout option.") @optgroup.option( "--display-name", "-n", type=str, help="Set display name. defaults to the value of user_id") @@ -432,6 +432,11 @@ def name_extra(self): is omitted when modifying an existing user, the user-type will not be manipulated. If the --user-type option is omitted when creating a new user, a regular user will be created.""") +@optgroup.option( + "--no-logout", "logout_devices", type=bool, default=False, is_flag=True, + help="""When setting a password, the user is logged out on all devices + by default (unspecified). When --no-logout is specified, devices are not + logged out even when the password is changed.""") @optgroup.option( "--lock/--unlock", "-l/-L", default=None, show_default=False, help="""Whether to lock or unlock the account, preventing or allowing @@ -440,7 +445,7 @@ def name_extra(self): @click.pass_context def modify(ctx, helper, user_id, password, password_prompt, display_name, threepid, clear_threepids, avatar_url, admin, deactivation, - user_type, lock): + user_type, lock, logout_devices): """ Create or modify a local user. Provide matrix user ID (@user:server) as argument. """ @@ -503,7 +508,8 @@ def modify(ctx, helper, user_id, password, password_prompt, display_name, avatar_url, admin, deactivation, - 'null' if user_type == 'regular' else user_type, lock + 'null' if user_type == 'regular' else user_type, lock, + logout_devices ) if modified is None: click.echo("User could not be modified/created.")