Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to change user type #90

Merged
merged 7 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion synadm/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def user_login(self, user_id, expire_days, expire, _expire_ts):
return self.query("post", f"v1/users/{user_id}/login", data=data)

def user_modify(self, user_id, password, display_name, threepid,
avatar_url, admin, deactivation):
avatar_url, admin, deactivation, user_type):
""" Create or update information about a given user

Threepid should be passed as a tuple in a tuple
Expand All @@ -556,6 +556,8 @@ def user_modify(self, user_id, password, display_name, threepid,
data.update({"deactivated": True})
if deactivation == "activate":
data.update({"deactivated": False})
if user_type:
data.update({"user_type": None if 'null' else user_type})
JOJ0 marked this conversation as resolved.
Show resolved Hide resolved
return self.query("put", f"v2/users/{user_id}", data=data)

def user_whois(self, user_id):
Expand Down
15 changes: 13 additions & 2 deletions synadm/cli/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,18 @@ def name_extra(self):
removes their active access tokens, resets their password, kicks them out
of all rooms and deletes third-party identifiers (to prevent the user
requesting a password reset). See also "user deactivate" command.""")
@optgroup.option(
"--user-type", type=str, default=None, show_default=True,
help="""Change the type of the user. Currently understood by the Admin API
are 'bot' and 'support'. Use 'regular' to create a regular Matrix user
(which effectively sets the user-type to 'null'). If the --user-type option
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,
JacksonChen666 marked this conversation as resolved.
Show resolved Hide resolved
a regular user will be created.""")
@click.pass_obj
@click.pass_context
def modify(ctx, helper, user_id, password, password_prompt, display_name,
threepid, avatar_url, admin, deactivation):
threepid, avatar_url, admin, deactivation, user_type):
""" Create or modify a local user. Provide matrix user ID (@user:server)
as argument.
"""
Expand Down Expand Up @@ -390,6 +398,8 @@ def modify(ctx, helper, user_id, password, password_prompt, display_name,
f"{t_key} is probably not a supported medium "
"type. Threepid medium types according to the "
"current matrix spec are: email, msisdn.")
elif key == "user_type" and value == 'regular':
click.echo("user_type: null")
elif value not in [None, {}, []]: # only show non-empty (aka changed)
click.echo(f"{key}: {value}")

Expand All @@ -411,7 +421,8 @@ def modify(ctx, helper, user_id, password, password_prompt, display_name,
if sure:
modified = helper.api.user_modify(
mxid, password, display_name, threepid,
avatar_url, admin, deactivation)
avatar_url, admin, deactivation,
'null' if user_type == 'regular' else user_type)
if modified is None:
click.echo("User could not be modified.")
raise SystemExit(1)
Expand Down