Development

This commit is contained in:
Matthew Grotke 2026-06-07 01:43:04 -04:00
parent 2bb876ed97
commit c01e240bd7
2 changed files with 9 additions and 9 deletions

View file

@ -104,13 +104,13 @@ def _hash_password(plaintext, hash_type):
def _parse_valid_for(value_str, unit_str): def _parse_valid_for(value_str, unit_str):
"""Return valid_for in seconds (int) or None for no expiry.""" """Return valid_for in seconds (int) or None for no expiry. Value of 0 means no expiry."""
unit_str = (unit_str or '').strip() unit_str = (unit_str or '').strip()
if unit_str == 'never' or not value_str or not value_str.strip(): if not value_str or not value_str.strip():
return None return None
try: try:
n = int(value_str.strip()) n = int(value_str.strip())
if n < 1: if n <= 0:
return None return None
except (ValueError, TypeError): except (ValueError, TypeError):
return None return None
@ -124,7 +124,7 @@ def _parse_valid_for(value_str, unit_str):
def _valid_for_to_display(valid_for): def _valid_for_to_display(valid_for):
"""Return (value_str, unit_str) for form pre-population.""" """Return (value_str, unit_str) for form pre-population."""
if valid_for is None: if valid_for is None:
return '', 'never' return '0', 'hours'
if valid_for % 86400 == 0: if valid_for % 86400 == 0:
return str(valid_for // 86400), 'days' return str(valid_for // 86400), 'days'
if valid_for % 3600 == 0: if valid_for % 3600 == 0:

View file

@ -160,8 +160,9 @@
"label": "Valid For", "label": "Valid For",
"name": "valid_for_value", "name": "valid_for_value",
"input_type": "number", "input_type": "number",
"min": 1, "min": 0,
"hint": "How long this credential is valid after creation. Leave blank for no expiry." "value": "0",
"hint": "How long this credential is valid after creation. 0 = no expiration."
}, },
{ {
"type": "field", "type": "field",
@ -169,9 +170,8 @@
"name": "valid_for_unit", "name": "valid_for_unit",
"input_type": "select", "input_type": "select",
"options": [ "options": [
{"value": "never", "label": "Never (no expiry)"}, {"value": "hours", "label": "Hours"},
{"value": "hours", "label": "Hours"}, {"value": "days", "label": "Days"}
{"value": "days", "label": "Days"}
] ]
} }
] ]