@@ -88,6 +88,9 @@ def privstr():
8888 cli .print (" " * indent + "aliases:" + (cli .col (" (none)" , attrs = ["dark" ]) if len (user .aliases ) == 0 else "" ))
8989 for alias in user .aliases :
9090 cli .print (" " * indent + " " + alias .aliasname )
91+ cli .print (" " * indent + "altnames:" + (cli .col (" (none)" , attrs = ["dark" ]) if len (user .altnames ) == 0 else "" ))
92+ for altname in user .altnames :
93+ cli .print (" " * indent + " " + altname .altname )
9194 cli .print (" " * indent + "roles:" + (cli .col (" (none)" , attrs = ["dark" ]) if len (user .roles ) == 0 else "" ))
9295 for role in user .roles :
9396 cli .print (" " * indent + " " + role .name )
@@ -127,6 +130,8 @@ def _splitData(args):
127130 "instead." , "yellow" ))
128131 data ["aliases" ] = attributes .pop ("alias" , None ) or ()
129132 data ["aliases_rm" ] = attributes .pop ("remove_alias" , None ) or ()
133+ data ["altnames" ] = attributes .pop ("altname" , None ) or {}
134+ data ["altnames_rm" ] = attributes .pop ("remove_altname" , None ) or {}
130135 data ["props" ] = attributes .pop ("property" , []) + attributes .pop ("storeprop" , [])
131136 data ["props_rm" ] = attributes .pop ("remove_property" , []) + attributes .pop ("remove_storeprop" , [])
132137 data ["noldap" ] = attributes .pop ("no_ldap" , False )
@@ -185,6 +190,7 @@ def cliUserCreate(args):
185190 props .update (data ["attributes" ])
186191 props ["username" ] = args .username
187192 props ["aliases" ] = data ["aliases" ]
193+ props ["altnames" ] = data ["altnames" ]
188194 properties = data ["properties" ] = {}
189195 if args .domain :
190196 from .common import domainCandidates
@@ -400,7 +406,7 @@ def cliUserModify(args):
400406 cli = args ._cli
401407 cli .require ("DB" )
402408 from orm import DB
403- from orm .users import Aliases
409+ from orm .users import Aliases , Altnames
404410 ret , user = _getUser (args )
405411 if ret :
406412 return ret
@@ -427,6 +433,11 @@ def cliUserModify(args):
427433 [Aliases (alias , user ) for alias in data ["aliases" ] if alias not in existing ]
428434 if data ["aliases_rm" ]:
429435 user .aliases = [alias for alias in user .aliases if alias .aliasname not in data ["aliases_rm" ]]
436+ if data ["altnames" ]:
437+ existing = {a .altname for a in user .altnames }
438+ [Altnames (altname , user ) for altname in data ["altnames" ] if altname not in existing ]
439+ if data ["altnames_rm" ]:
440+ user .altnames = [altname for altname in user .altnames if altname .altname not in data ["altnames_rm" ]]
430441 except ValueError as err :
431442 cli .print (cli .col ("Failed to update user: " + err .args [0 ], "red" ))
432443 return 1
@@ -524,6 +535,7 @@ def proptagAssignCompleter(*args, **kwargs):
524535 parser .add_argument ("--status" , type = _cliParseStatus , help = "User address status" )
525536
526537 parser .add_argument ("--alias" , action = "append" , help = "Add alias" )
538+ parser .add_argument ("--altname" , action = "append" , help = "Add alternative name" )
527539 parser .add_argument ("--property" , action = "append" , type = assignment , metavar = "propspec=value" ,
528540 help = "Set property defined by propspec to value" ).completer = proptagAssignCompleter
529541 parser .add_argument ("--storeprop" , action = "append" , type = assignment , metavar = "propspec=value" ,
@@ -583,6 +595,7 @@ def deviceParser(parent, action, handler, **kwargs):
583595 modify .add_argument ("--delete-chat-user" , action = "store_true" , help = "Permanently delete chat user" )
584596 modify .add_argument ("--no-ldap" , action = "store_true" , help = "Unlink user from ldap object" )
585597 modify .add_argument ("--remove-alias" , metavar = "ALIAS" , action = "append" , help = "Remove alias" )
598+ modify .add_argument ("--remove-altname" , metavar = "ALTNAME" , action = "append" , help = "Remove alternative name" )
586599 modify .add_argument ("--remove-property" , action = "append" , metavar = "propspec" , help = "Remove property from user" )
587600 modify .add_argument ("--remove-storeprop" , action = "append" , metavar = "propspec" , help = "Remove property from user's store" )
588601 modify .add_argument ("--username" , help = "Rename user" )
0 commit comments