Skip to content

Commit

Permalink
Merge pull request #125 from JacksonChen666/account-locking
Browse files Browse the repository at this point in the history
implement user (un)locking
  • Loading branch information
JacksonChen666 authored Sep 4, 2023
2 parents 7b97388 + 5cf6c3f commit 5521cdd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 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
8 changes: 6 additions & 2 deletions synadm/cli/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,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. Feature first present in Synapse 1.91.0.""")
@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 +484,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 5521cdd

Please sign in to comment.