-
Notifications
You must be signed in to change notification settings - Fork 27
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
Rewriting the user modify command #126
base: master
Are you sure you want to change the base?
Changes from all commits
e14cf47
a765775
6316036
6bebbd4
e2839bc
b8d7cd0
ad40728
9aa5fbe
70fdb89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -505,6 +505,122 @@ def modify(ctx, helper, user_id, password, password_prompt, display_name, | |
click.echo("Abort.") | ||
|
||
|
||
# for these placeholders, function similarly to the modify command, but in | ||
# it's own command. | ||
# TODO: find 3pid modify command | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a 3pid command already, but it's for displaying only: https://synadm.readthedocs.io/en/latest/synadm.cli.user.html#synadm-user-3pid That I guess is what you are thinking about? Where should we put / and how should we name the modify command for 3pid modify? Currently 3pid modify is included with the original |
||
|
||
|
||
@user.command() | ||
@click.argument("user_id", type=str) | ||
@click.argument("user_type", type=str) | ||
@click.pass_obj | ||
def set_user_type(helper, user_id, user_type): | ||
"""Set a user type. | ||
|
||
For the user_type argument, the accepted values are "null" (to | ||
clear/remove the user type), or any other value that synapse accepts | ||
("bot" and "support"). | ||
""" | ||
if user_type == "null": | ||
user_type = None | ||
helper.output(helper.api.user_set_type(user_id, user_type)) | ||
|
||
|
||
@user.command() | ||
@click.argument("user_id", type=str) | ||
@click.argument("mxc_uri", type=str) | ||
@click.pass_obj | ||
def set_profile_picture(helper, user_id, mxc_uri): | ||
""" | ||
Set a profile picture for a user by the MXC URI. | ||
|
||
Setting the MXC URI to an empty strings removes the profile picture. | ||
""" | ||
modified = helper.user_set_profile_picture(user_id, mxc_uri) | ||
if modified is None: | ||
click.echo("Could not set profile picture.", err=True) | ||
raise SystemExit(1) | ||
helper.output(modified) | ||
|
||
|
||
@user.command() | ||
@click.argument("user_id", type=str) | ||
@click.argument("display_name", type=str) | ||
@click.pass_obj | ||
def set_display_name(helper, user_id, display_name): | ||
""" | ||
Set the display name of a user. | ||
|
||
Display name can be set to an empty string to remove it. | ||
""" | ||
mxid = helper.generate_mxid(user_id) | ||
modified = helper.api.user_set_display_name(mxid, display_name) | ||
if modified is None: | ||
click.echo("Could not set display name.", err=True) | ||
raise SystemExit(1) | ||
if helper.output_format == "human": | ||
new_display_name = modified["displayname"] | ||
if new_display_name is None: | ||
click.echo(f"Removed display name for {mxid}") | ||
else: | ||
click.echo(f"Set display name for {mxid} to {new_display_name}") | ||
else: | ||
helper.output(modified) | ||
|
||
|
||
@user.command() | ||
@click.argument("user_id", type=str) | ||
# TODO: check compatibility with --batch | ||
@click.password_option( | ||
required=False, | ||
help="""The new password to set to. This is required when reactivating a | ||
user on a Synapse installation with passwords enabled.""") | ||
@click.pass_obj | ||
def reactivate(helper, user_id, password): | ||
result = helper.api.user_reactivate(user_id, password) | ||
helper.output(result) | ||
|
||
|
||
@user.command() | ||
@click.argument("user_id", type=str) | ||
@click.pass_obj | ||
def lock(helper, user_id): | ||
""" | ||
Lock a user account, preventing them from logging in or using the | ||
account. | ||
""" | ||
result = helper.api.user_set_lock(user_id, True) | ||
helper.output(result) | ||
|
||
|
||
@user.command() | ||
@click.argument("user_id", type=str) | ||
@click.pass_obj | ||
def unlock(helper, user_id): | ||
""" | ||
Unlock a user account, allowing a locked account to log in and use the | ||
account. | ||
""" | ||
result = helper.api.user_set_lock(user_id, False) | ||
helper.output(result) | ||
|
||
|
||
@user.command() | ||
@click.argument("user_id", type=str) | ||
@click.pass_obj | ||
def admin_grant(helper, user_id): | ||
result = helper.api.user_set_admin(user_id, True) | ||
helper.output(result) | ||
|
||
|
||
@user.command() | ||
@click.argument("user_id", type=str) | ||
@click.pass_obj | ||
def admin_revoke(helper, user_id): | ||
result = helper.api.user_set_admin(user_id, False) | ||
helper.output(result) | ||
|
||
|
||
@user.command() | ||
@click.argument("user_id", type=str) | ||
@click.pass_obj | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree we should deprecate
synadm user modify
within this PR, or actually I'd like to achieve this: As soon as everything fromuser modify
has its own command or the user should be warned - best with a literal log.warning.But I'm not sure anymore wether we'd like to keep some parts of
user modify
as-is and not invent new commands. Can't recall what was the outcome of that discussion, please help me remember! :-)If we would keep parts of
modify
as-is and do not plan to change, then probably it would be better that exactly when these options are used, a log.warning is spit out. Not sure though what's best....There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think deprecating by warning the user is the best option, and we could remove the modify command in the future.
We also do not add any new functions to the modify command to discourage use of it.