Display role vocabulary, migration commit fix, stale enforcement reports
This commit is contained in:
@@ -9,7 +9,8 @@ from flask_jwt_extended import jwt_required
|
||||
|
||||
from shopdb.extensions import db
|
||||
from shopdb.core.models import DashboardDefault, BusinessUnit, AuditLog
|
||||
from shopdb.core.models.dashboarddefault import DISPLAY_ROLES, DISPLAY_ROLE_PATHS
|
||||
from shopdb.core.models.dashboarddefault import (
|
||||
DISPLAY_ROLES, DISPLAY_ROLE_PATHS, normalize_display_role)
|
||||
from shopdb.utils.responses import success_response, error_response, ErrorCodes
|
||||
from shopdb.utils.authz import require_role
|
||||
|
||||
@@ -117,17 +118,19 @@ def create_default():
|
||||
data = request.get_json() or {}
|
||||
fqdn = (data.get('fqdn') or '').strip().lower() or None
|
||||
ipaddress = (data.get('ipaddress') or '').strip() or None
|
||||
role = (data.get('displayrole') or 'dashboard').strip()
|
||||
# Accept any casing and the retired spellings, store the canonical one, so a
|
||||
# caller matching the kiosk's own file is never turned away over a capital.
|
||||
role = normalize_display_role(data.get('displayrole') or 'Dashboard')
|
||||
businessunitid = data.get('businessunitid')
|
||||
|
||||
if not fqdn and not ipaddress:
|
||||
return error_response(ErrorCodes.VALIDATION_ERROR,
|
||||
'fqdn or ipaddress is required')
|
||||
if role not in DISPLAY_ROLES:
|
||||
if not role:
|
||||
return error_response(ErrorCodes.VALIDATION_ERROR,
|
||||
f'displayrole must be one of {", ".join(DISPLAY_ROLES)}')
|
||||
# Only the dashboard role needs a business unit (location).
|
||||
if role == 'dashboard':
|
||||
# Only the Dashboard role needs a business unit (location).
|
||||
if role == 'Dashboard':
|
||||
if not businessunitid:
|
||||
return error_response(ErrorCodes.VALIDATION_ERROR,
|
||||
'a location is required for the dashboard role')
|
||||
@@ -167,8 +170,8 @@ def update_default(default_id):
|
||||
|
||||
data = request.get_json() or {}
|
||||
if 'displayrole' in data:
|
||||
role = (data.get('displayrole') or '').strip()
|
||||
if role not in DISPLAY_ROLES:
|
||||
role = normalize_display_role(data.get('displayrole'))
|
||||
if not role:
|
||||
return error_response(ErrorCodes.VALIDATION_ERROR,
|
||||
f'displayrole must be one of {", ".join(DISPLAY_ROLES)}')
|
||||
default.displayrole = role
|
||||
@@ -187,8 +190,8 @@ def update_default(default_id):
|
||||
if not default.fqdn and not default.ipaddress:
|
||||
return error_response(ErrorCodes.VALIDATION_ERROR,
|
||||
'fqdn or ipaddress is required')
|
||||
# Non-dashboard roles carry no location; dashboard needs one.
|
||||
if default.displayrole != 'dashboard':
|
||||
# Non-Dashboard roles carry no location; Dashboard needs one.
|
||||
if normalize_display_role(default.displayrole) != 'Dashboard':
|
||||
default.businessunitid = None
|
||||
elif not default.businessunitid:
|
||||
return error_response(ErrorCodes.VALIDATION_ERROR,
|
||||
|
||||
Reference in New Issue
Block a user