From dce23100a17ba42379187390b58efdbdd9059df0 Mon Sep 17 00:00:00 2001 From: ReturnFI <151555003+ReturnFI@users.noreply.github.com> Date: Tue, 28 Oct 2025 16:34:41 +0000 Subject: [PATCH] feat(core): add note editing functionality - Updated `edit_user.py` to accept a `--note` argument, allowing user notes to be modified or cleared. - Extended the `edit-user` command in `cli.py` with a `--note` option. - Modified the `edit_user` function in `cli_api.py` to pass the new note argument to the underlying script. --- core/cli.py | 5 +++-- core/cli_api.py | 5 ++++- core/scripts/hysteria2/edit_user.py | 9 +++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/core/cli.py b/core/cli.py index 4751658..bab7f88 100644 --- a/core/cli.py +++ b/core/cli.py @@ -163,12 +163,13 @@ def bulk_user_add(traffic_gb: float, expiration_days: int, count: int, prefix: s @click.option('--renew-creation-date', '-rc', is_flag=True, help='Renew creation date for the user') @click.option('--blocked/--unblocked', 'blocked', '-b', default=None, help='Block or unblock the user.') @click.option('--unlimited-ip/--limited-ip', 'unlimited_ip', default=None, help='Set user to be exempt from or subject to IP limits.') -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 | None, unlimited_ip: bool | None): +@click.option('--note', '-n', required=False, help='New note for the user.', type=str) +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 | None, unlimited_ip: bool | None, note: str | None): try: cli_api.kick_users_by_name(username) cli_api.traffic_status(display_output=False) cli_api.edit_user(username, new_username, new_traffic_limit, new_expiration_days, - renew_password, renew_creation_date, blocked, unlimited_ip) + renew_password, renew_creation_date, blocked, unlimited_ip, note) click.echo(f"User '{username}' updated successfully.") except Exception as e: click.echo(f'{e}', err=True) diff --git a/core/cli_api.py b/core/cli_api.py index 3f17654..0baf749 100644 --- a/core/cli_api.py +++ b/core/cli_api.py @@ -311,7 +311,7 @@ def bulk_user_add(traffic_gb: float, expiration_days: int, count: int, prefix: s run_cmd(command) -def edit_user(username: str, new_username: str | None, new_traffic_limit: int | None, new_expiration_days: int | None, renew_password: bool, renew_creation_date: bool, blocked: bool | None, unlimited_ip: bool | None): +def edit_user(username: str, new_username: str | None, new_traffic_limit: int | None, new_expiration_days: int | None, renew_password: bool, renew_creation_date: bool, blocked: bool | None, unlimited_ip: bool | None, note: str | None): ''' Edits an existing user's details by calling the new edit_user.py script with named flags. ''' @@ -347,6 +347,9 @@ def edit_user(username: str, new_username: str | None, new_traffic_limit: int | if unlimited_ip is not None: command_args.extend(['--unlimited', 'true' if unlimited_ip else 'false']) + if note is not None: + command_args.extend(['--note', note]) + run_cmd(command_args) diff --git a/core/scripts/hysteria2/edit_user.py b/core/scripts/hysteria2/edit_user.py index 1573913..12d2e55 100644 --- a/core/scripts/hysteria2/edit_user.py +++ b/core/scripts/hysteria2/edit_user.py @@ -8,7 +8,7 @@ import re from datetime import datetime from db.database import db -def edit_user(username, new_username=None, new_password=None, traffic_gb=None, expiration_days=None, creation_date=None, blocked=None, unlimited_user=None): +def edit_user(username, new_username=None, new_password=None, traffic_gb=None, expiration_days=None, creation_date=None, blocked=None, unlimited_user=None, note=None): if db is None: print("Error: Database connection failed.", file=sys.stderr) return 1 @@ -45,6 +45,9 @@ def edit_user(username, new_username=None, new_password=None, traffic_gb=None, e if unlimited_user is not None: updates['unlimited_user'] = unlimited_user + + if note is not None: + updates['note'] = note try: if updates: @@ -108,6 +111,7 @@ if __name__ == "__main__": parser.add_argument("--creation-date", dest="creation_date", type=validate_date, help="New creation date in YYYY-MM-DD format, or 'null' to reset to On-hold.") parser.add_argument("--blocked", type=str_to_bool, help="Set blocked status (true/false).") parser.add_argument("--unlimited", dest="unlimited_user", type=str_to_bool, help="Set unlimited user status for IP limits (true/false).") + parser.add_argument("--note", help="New note for the user. To clear the note, provide an empty string.") args = parser.parse_args() @@ -119,5 +123,6 @@ if __name__ == "__main__": expiration_days=args.expiration_days, creation_date=args.creation_date, blocked=args.blocked, - unlimited_user=args.unlimited_user + unlimited_user=args.unlimited_user, + note=args.note )) \ No newline at end of file