Allow changing username

This commit is contained in:
CasVT
2025-04-24 16:15:38 +02:00
parent 4f77435801
commit cefc1a9593
3 changed files with 15 additions and 13 deletions

View File

@@ -208,7 +208,7 @@ def api_add_user(inputs: Dict[str, str]):
def api_manage_user(inputs: Dict[str, Any]):
user = api_key_map[g.hashed_api_key].user_data
if request.method == 'PUT':
user.update(None, inputs['new_password'])
user.update(inputs['new_username'], inputs['new_password'])
return return_api({})
elif request.method == 'DELETE':
@@ -581,7 +581,7 @@ def api_admin_users(inputs: Dict[str, Any]):
def api_admin_user(inputs: Dict[str, Any], u_id: int):
user = users.get_one(u_id)
if request.method == 'PUT':
user.update(None, inputs['new_password'])
user.update(inputs['new_username'], inputs['new_password'])
return return_api({})
elif request.method == 'DELETE':

View File

@@ -137,10 +137,16 @@ class CreateUsernameVariable(UsernameVariable):
]
class NewPasswordVariable(InputVariable):
class NewUsernameVariable(NonRequiredInputVariable):
name = "new_username"
description = "The new username of the user account"
related_exceptions = [InvalidKeyValue, UsernameInvalid, UsernameTaken]
class NewPasswordVariable(NonRequiredInputVariable):
name = "new_password"
description = "The new password of the user account"
related_exceptions = [KeyNotFound]
related_exceptions = [InvalidKeyValue]
class TitleVariable(InputVariable):
@@ -470,7 +476,7 @@ class UsersData(EndpointData):
methods = Methods(
put=(
"Change the password of the user account",
[NewPasswordVariable]
[NewUsernameVariable, NewPasswordVariable]
),
delete=(
"Delete the user account",
@@ -732,7 +738,7 @@ class UserManagementData(EndpointData):
methods = Methods(
put=(
"Change the password of the user account",
[NewPasswordVariable]
[NewUsernameVariable, NewPasswordVariable]
),
delete=(
"Delete the user account",