feat(cli): Add IP limit exemption to edit-user command

This commit is contained in:
Whispering Wind
2025-08-11 23:32:39 +03:30
committed by GitHub
parent 32f0f8c8d4
commit ba6d0db590
2 changed files with 20 additions and 13 deletions

View File

@ -146,13 +146,14 @@ def add_user(username: str, traffic_limit: int, expiration_days: int, password:
@click.option('--new-expiration-days', '-ne', required=False, help='Expiration days for the new user', type=int) @click.option('--new-expiration-days', '-ne', required=False, help='Expiration days for the new user', type=int)
@click.option('--renew-password', '-rp', is_flag=True, help='Renew password for the user') @click.option('--renew-password', '-rp', is_flag=True, help='Renew password for the user')
@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', '-b', is_flag=True, help='Block the user') @click.option('--blocked/--unblocked', 'blocked', default=None, help='Block or unblock 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): @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):
try: try:
cli_api.kick_user_by_name(username) cli_api.kick_user_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) renew_password, renew_creation_date, blocked, unlimited_ip)
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

@ -285,7 +285,7 @@ def add_user(username: str, traffic_limit: int, expiration_days: int, password:
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): 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):
''' '''
Edits an existing user's details. Edits an existing user's details.
''' '''
@ -297,15 +297,20 @@ def edit_user(username: str, new_username: str | None, new_traffic_limit: int |
if new_expiration_days is not None and new_expiration_days < 0: if new_expiration_days is not None and new_expiration_days < 0:
raise InvalidInputError('Error: expiration days must be a non-negative number.') raise InvalidInputError('Error: expiration days must be a non-negative number.')
if renew_password: password = generate_password() if renew_password else ''
password = generate_password() creation_date = datetime.now().strftime('%Y-%m-%d') if renew_creation_date else ''
else:
password = ''
if renew_creation_date: blocked_str = ''
creation_date = datetime.now().strftime('%Y-%m-%d') if blocked is True:
else: blocked_str = 'true'
creation_date = '' elif blocked is False:
blocked_str = 'false'
unlimited_str = ''
if unlimited_ip is True:
unlimited_str = 'true'
elif unlimited_ip is False:
unlimited_str = 'false'
command_args = [ command_args = [
'bash', 'bash',
@ -316,7 +321,8 @@ def edit_user(username: str, new_username: str | None, new_traffic_limit: int |
str(new_expiration_days) if new_expiration_days is not None else '', str(new_expiration_days) if new_expiration_days is not None else '',
password, password,
creation_date, creation_date,
'true' if blocked else 'false' blocked_str,
unlimited_str
] ]
run_cmd(command_args) run_cmd(command_args)