normalize a null proxy default_role to none

/config drops null fields, so the settings form filled in viewer for a null default_role while /auth denied those users. The config now stores a null default_role as none, which the API returns and the widget shows, and the unreachable null branch in the widget is removed.
This commit is contained in:
Josh Hawkins
2026-11-23 09:53:35 -06:00
parent 47fcb90893
commit f0e76645ea
3 changed files with 7 additions and 11 deletions
+3 -4
View File
@@ -55,10 +55,9 @@ class ProxyConfig(FrigateBaseModel):
@field_validator("default_role", mode="before") @field_validator("default_role", mode="before")
@classmethod @classmethod
def normalize_deny_sentinel(cls, v): def normalize_deny_sentinel(cls, v):
# Fail closed on capitalization: an unnormalized "None" would miss the # Fail closed: "none" in any casing and a null default both deny.
# sentinel and fall back to viewer, granting the access it was meant to # Normalizing null keeps the value through /config, which drops nulls
# deny. Other role names stay case-sensitive. if v is None or (isinstance(v, str) and v.strip().lower() == "none"):
if isinstance(v, str) and v.strip().lower() == "none":
return "none" return "none"
return v return v
+3
View File
@@ -226,6 +226,9 @@ class TestDefaultRoleNone(unittest.TestCase):
) )
self.assertEqual(role, "none") self.assertEqual(role, "none")
def test_null_default_role_normalizes_to_none(self):
self.assertEqual(ProxyConfig(default_role=None).default_role, "none")
def test_other_role_names_stay_case_sensitive(self): def test_other_role_names_stay_case_sensitive(self):
"""Only the deny sentinel is normalized; role names are untouched.""" """Only the deny sentinel is normalized; role names are untouched."""
config = ProxyConfig(default_role="Operator") config = ProxyConfig(default_role="Operator")
@@ -29,13 +29,7 @@ export function DefaultRoleWidget(props: WidgetProps) {
return [...BUILT_IN_ROLES, ...custom, NONE_ROLE]; return [...BUILT_IN_ROLES, ...custom, NONE_ROLE];
}, [formContext]); }, [formContext]);
// A null default denies access, so it displays as none const selectedValue = typeof value === "string" && value ? value : "viewer";
const selectedValue =
value === null
? NONE_ROLE
: typeof value === "string" && value
? value
: "viewer";
const getLabel = (role: string) => const getLabel = (role: string) =>
BUILT_IN_ROLES.includes(role) || role === NONE_ROLE BUILT_IN_ROLES.includes(role) || role === NONE_ROLE