Skip to content

Commit

Permalink
implement user (un)locking
Browse files Browse the repository at this point in the history
fixes JOJ0#121

References: JOJ0#121
  • Loading branch information
JacksonChen666 committed Sep 3, 2023
1 parent cb14af9 commit 82f16c8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion synadm/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ 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):
avatar_url, admin, deactivation, user_type, lock):
""" Create or update information about a given user
Threepid should be passed as a tuple in a tuple
Expand All @@ -613,6 +613,8 @@ def user_modify(self, user_id, password, display_name, threepid,
data.update({"avatar_url": avatar_url})
if admin is not None:
data.update({"admin": admin})
if lock is not None:
data.update({"locked": lock})
if deactivation == "deactivate":
data.update({"deactivated": True})
if deactivation == "activate":
Expand Down
9 changes: 6 additions & 3 deletions synadm/cli/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def list_user_cmd(helper, from_, limit, guests, deactivated, name, user_id):
else:
helper.output(users)


@user.command()
@click.argument("user_id", type=str)
@click.option(
Expand Down Expand Up @@ -423,10 +422,14 @@ 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(
"--lock/--unlock", "-l/-L", default=None, show_default=False,
help="""Whether to lock or unlock the account, preventing or allowing
logins respectively.""")
@click.pass_obj
@click.pass_context
def modify(ctx, helper, user_id, password, password_prompt, display_name,
threepid, avatar_url, admin, deactivation, user_type):
threepid, avatar_url, admin, deactivation, user_type, lock):
""" Create or modify a local user. Provide matrix user ID (@user:server)
as argument.
"""
Expand Down Expand Up @@ -480,7 +483,7 @@ def modify(ctx, helper, user_id, password, password_prompt, display_name,
modified = helper.api.user_modify(
mxid, password, display_name, threepid,
avatar_url, admin, deactivation,
'null' if user_type == 'regular' else user_type)
'null' if user_type == 'regular' else user_type, lock)
if modified is None:
click.echo("User could not be modified.")
raise SystemExit(1)
Expand Down

0 comments on commit 82f16c8

Please sign in to comment.