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.
This commit is contained in:
ReturnFI
2025-10-28 16:34:41 +00:00
parent ea75084eeb
commit dce23100a1
3 changed files with 14 additions and 5 deletions

View File

@ -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('--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('--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.') @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: try:
cli_api.kick_users_by_name(username) cli_api.kick_users_by_name(username)
cli_api.traffic_status(display_output=False) 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, unlimited_ip) renew_password, renew_creation_date, blocked, unlimited_ip, note)
click.echo(f"User '{username}' updated successfully.") click.echo(f"User '{username}' updated successfully.")
except Exception as e: except Exception as e:
click.echo(f'{e}', err=True) click.echo(f'{e}', err=True)

View File

@ -311,7 +311,7 @@ def bulk_user_add(traffic_gb: float, expiration_days: int, count: int, prefix: s
run_cmd(command) 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. 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: if unlimited_ip is not None:
command_args.extend(['--unlimited', 'true' if unlimited_ip else 'false']) command_args.extend(['--unlimited', 'true' if unlimited_ip else 'false'])
if note is not None:
command_args.extend(['--note', note])
run_cmd(command_args) run_cmd(command_args)

View File

@ -8,7 +8,7 @@ import re
from datetime import datetime from datetime import datetime
from db.database import db 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: if db is None:
print("Error: Database connection failed.", file=sys.stderr) print("Error: Database connection failed.", file=sys.stderr)
return 1 return 1
@ -46,6 +46,9 @@ def edit_user(username, new_username=None, new_password=None, traffic_gb=None, e
if unlimited_user is not None: if unlimited_user is not None:
updates['unlimited_user'] = unlimited_user updates['unlimited_user'] = unlimited_user
if note is not None:
updates['note'] = note
try: try:
if updates: if updates:
db.update_user(username_lower, updates) db.update_user(username_lower, 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("--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("--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("--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() args = parser.parse_args()
@ -119,5 +123,6 @@ if __name__ == "__main__":
expiration_days=args.expiration_days, expiration_days=args.expiration_days,
creation_date=args.creation_date, creation_date=args.creation_date,
blocked=args.blocked, blocked=args.blocked,
unlimited_user=args.unlimited_user unlimited_user=args.unlimited_user,
note=args.note
)) ))