@@ -37,14 +37,14 @@ const check_new_azure_connection_timeout = 20 * 1000;
3737 *
3838 */
3939async function create_account ( req ) {
40- const action = IAM_ACTIONS . CREATE_USER ;
4140 let iam_arn ;
4241 if ( req . rpc_params . owner ) {
43- const user_name = account_util . get_iam_username ( req . rpc_params . email . unwrap ( ) ) ;
42+ const action = IAM_ACTIONS . CREATE_USER ;
4443 account_util . _check_if_requesting_account_is_root_account ( action , req . account ,
45- { username : user_name , path : req . rpc_params . iam_path } ) ;
46- account_util . _check_username_already_exists ( action , req . rpc_params . email , user_name ) ;
47- iam_arn = iam_utils . create_arn_for_user ( req . account . _id . toString ( ) , user_name ,
44+ { username : req . rpc_params . username , path : req . rpc_params . iam_path } ) ;
45+ account_util . _check_username_already_exists ( action , req . rpc_params . email ,
46+ req . rpc_params . username ) ;
47+ iam_arn = iam_utils . create_arn_for_user ( req . account . _id . toString ( ) , req . rpc_params . username ,
4848 req . rpc_params . iam_path || IAM_DEFAULT_PATH ) ;
4949 } else {
5050 account_util . validate_create_account_permissions ( req ) ;
@@ -1234,8 +1234,14 @@ async function update_user(req) {
12341234 let iam_path = requested_account . iam_path ;
12351235 let user_name = account_util . get_iam_username ( requested_account . name . unwrap ( ) ) ;
12361236 // Change to complete user name
1237- const new_username = account_util . get_account_name_from_username ( req . rpc_params . new_username , requesting_account . _id . toString ( ) ) ;
1238- account_util . _check_username_already_exists ( action , new_username , req . rpc_params . new_username ) ;
1237+ const is_username_update = req . rpc_params . new_username !== undefined &&
1238+ req . rpc_params . new_username !== req . rpc_params . username ;
1239+ if ( is_username_update ) {
1240+ const email_new_username_wrapped = account_util . get_account_name_from_username (
1241+ req . rpc_params . new_username ,
1242+ requesting_account . _id . toString ( ) ) ;
1243+ account_util . _check_username_already_exists ( action , email_new_username_wrapped , req . rpc_params . new_username ) ;
1244+ }
12391245 account_util . _check_if_requested_account_is_root_account_or_IAM_user ( action , requesting_account , requested_account ) ;
12401246 account_util . _check_if_requested_is_owned_by_root_account ( action , requesting_account , requested_account ) ;
12411247 if ( req . rpc_params . new_iam_path ) iam_path = req . rpc_params . new_iam_path ;
0 commit comments