feat : Optimize user edit workflow and eliminate service restart delay
This commit is contained in:
@ -148,6 +148,8 @@ def add_user(username: str, traffic_limit: int, expiration_days: int, password:
|
|||||||
@click.option('--blocked', '-b', is_flag=True, help='Block the user')
|
@click.option('--blocked', '-b', is_flag=True, help='Block the user')
|
||||||
def edit_user(username: str, new_username: str, new_traffic_limit: int, new_expiration_days: int, renew_password: bool, renew_creation_date: bool, blocked: bool):
|
def edit_user(username: str, new_username: str, new_traffic_limit: int, new_expiration_days: int, renew_password: bool, renew_creation_date: bool, blocked: bool):
|
||||||
try:
|
try:
|
||||||
|
cli_api.kick_user_by_name(username)
|
||||||
|
cli_api.traffic_status(display_output=False)
|
||||||
cli_api.edit_user(username, new_username, new_traffic_limit, new_expiration_days,
|
cli_api.edit_user(username, new_username, new_traffic_limit, new_expiration_days,
|
||||||
renew_password, renew_creation_date, blocked)
|
renew_password, renew_creation_date, blocked)
|
||||||
click.echo(f"User '{username}' updated successfully.")
|
click.echo(f"User '{username}' updated successfully.")
|
||||||
|
|||||||
@ -224,7 +224,7 @@ edit_user() {
|
|||||||
new_creation_date=${new_creation_date:-$creation_date}
|
new_creation_date=${new_creation_date:-$creation_date}
|
||||||
new_blocked=$(convert_blocked_status "${new_blocked:-$blocked}")
|
new_blocked=$(convert_blocked_status "${new_blocked:-$blocked}")
|
||||||
|
|
||||||
python3 $CLI_PATH restart-hysteria2
|
# python3 $CLI_PATH restart-hysteria2
|
||||||
|
|
||||||
if ! update_user_info "$username" "$new_username" "$new_password" "$new_traffic_limit" "$new_expiration_days" "$new_creation_date" "$new_blocked"; then
|
if ! update_user_info "$username" "$new_username" "$new_password" "$new_traffic_limit" "$new_expiration_days" "$new_creation_date" "$new_blocked"; then
|
||||||
return 1 # Update user failed
|
return 1 # Update user failed
|
||||||
|
|||||||
@ -85,6 +85,8 @@ async def edit_user_api(username: str, body: EditUserInputBody):
|
|||||||
HTTPException: if an error occurs while editing the user.
|
HTTPException: if an error occurs while editing the user.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
cli_api.kick_user_by_name(username)
|
||||||
|
cli_api.traffic_status(display_output=False)
|
||||||
cli_api.edit_user(username, body.new_username, body.new_traffic_limit, body.new_expiration_days,
|
cli_api.edit_user(username, body.new_username, body.new_traffic_limit, body.new_expiration_days,
|
||||||
body.renew_password, body.renew_creation_date, body.blocked)
|
body.renew_password, body.renew_creation_date, body.blocked)
|
||||||
return DetailResponse(detail=f'User {username} has been edited.')
|
return DetailResponse(detail=f'User {username} has been edited.')
|
||||||
|
|||||||
Reference in New Issue
Block a user