@@ -394,14 +394,18 @@ def name_extra(self):
394
394
help = "Set display name. defaults to the value of user_id" )
395
395
@optgroup .option (
396
396
"--threepid" , "-t" , type = str , multiple = True , nargs = 2 ,
397
- help = """Add a third-party identifier. This can be an email address or a
398
- phone number. Threepids are used for several things: For use when
399
- logging in, as an alternative to the user id. In the case of email, as
400
- an alternative contact to help with account recovery, as well as
401
- to receive notifications of missed messages. Format: medium
402
- value (eg. --threepid email <user@example.org>). This option can also
403
- be stated multiple times, i.e. a user can have multiple threepids
404
- configured.""" )
397
+ help = """Set a third-party identifier (email address or phone number). Pass
398
+ two arguments: `medium value` (eg. `--threepid email <user@example.org>`).
399
+ This option can be passed multiple times, which allows setting multiple
400
+ entries for a user. When modifying existing users, all threepids are
401
+ replaced by what's passed in all given `--threepid` options. Threepids are
402
+ used for several things: For use when logging in, as an alternative to the
403
+ user id; in the case of email, as an alternative contact to help with
404
+ account recovery, as well as to receive notifications of missed
405
+ messages.""" )
406
+ @optgroup .option (
407
+ "--clear-threepids" , is_flag = True , default = None ,
408
+ help = "Remove all threepids of an existing user." )
405
409
@optgroup .option (
406
410
"--avatar-url" , "-v" , type = str ,
407
411
help = """Set avatar URL. Must be a MXC URI
@@ -435,7 +439,8 @@ def name_extra(self):
435
439
@click .pass_obj
436
440
@click .pass_context
437
441
def modify (ctx , helper , user_id , password , password_prompt , display_name ,
438
- threepid , avatar_url , admin , deactivation , user_type , lock ):
442
+ threepid , clear_threepids , avatar_url , admin , deactivation ,
443
+ user_type , lock ):
439
444
""" Create or modify a local user. Provide matrix user ID (@user:server)
440
445
as argument.
441
446
"""
@@ -453,17 +458,21 @@ def modify(ctx, helper, user_id, password, password_prompt, display_name,
453
458
ctx .invoke (user_details_cmd , user_id = mxid )
454
459
click .echo ("User account settings to be modified:" )
455
460
for key , value in ctx .params .items ():
456
- if key in ["user_id" , "password" , "password_prompt" ]: # skip these
461
+ # skip these, they get special treatment or can't be changed
462
+ if key in ["user_id" , "password" , "password_prompt" ,
463
+ "clear_threepids" ]:
457
464
continue
458
465
if key == "threepid" :
459
- if value != ():
460
- for t_key , t_val in value :
461
- click .echo (f"{ key } : { t_key } { t_val } " )
462
- if t_key not in ["email" , "msisdn" ]:
463
- helper .log .warning (
464
- f"{ t_key } is probably not a supported medium "
465
- "type. Threepid medium types according to the "
466
- "current matrix spec are: email, msisdn." )
466
+ if value == (('' , '' ),) or clear_threepids :
467
+ click .echo ("threepid: All entries will be cleared!" )
468
+ continue
469
+ for t_key , t_val in value :
470
+ click .echo (f"{ key } : { t_key } { t_val } " )
471
+ if t_key not in ["email" , "msisdn" ]:
472
+ helper .log .warning (
473
+ f"{ t_key } is probably not a supported medium "
474
+ "type. Threepid medium types according to the "
475
+ "current matrix spec are: email, msisdn." )
467
476
elif key == "user_type" and value == 'regular' :
468
477
click .echo ("user_type: null" )
469
478
elif value not in [None , {}, []]: # only show non-empty (aka changed)
@@ -482,21 +491,27 @@ def modify(ctx, helper, user_id, password, password_prompt, display_name,
482
491
password = None
483
492
sure = (
484
493
helper .no_confirm or
485
- click .prompt ("Are you sure you want to modify user? (y/N)" ,
494
+ click .prompt ("Are you sure you want to modify/create user? (y/N)" ,
486
495
type = bool , default = False , show_default = False )
487
496
)
488
497
if sure :
489
498
modified = helper .api .user_modify (
490
- mxid , password , display_name , threepid ,
491
- avatar_url , admin , deactivation ,
492
- 'null' if user_type == 'regular' else user_type , lock )
499
+ mxid ,
500
+ password ,
501
+ display_name ,
502
+ (('' , '' ),) if clear_threepids else threepid ,
503
+ avatar_url ,
504
+ admin ,
505
+ deactivation ,
506
+ 'null' if user_type == 'regular' else user_type , lock
507
+ )
493
508
if modified is None :
494
- click .echo ("User could not be modified." )
509
+ click .echo ("User could not be modified/created ." )
495
510
raise SystemExit (1 )
496
511
if helper .output_format == "human" :
497
512
if modified != {}:
498
513
helper .output (modified )
499
- click .echo ("User successfully modified." )
514
+ click .echo ("User successfully modified/created ." )
500
515
else :
501
516
click .echo ("Synapse returned: {}" .format (modified ))
502
517
else :
0 commit comments