From c9578a7c02d019210c30937180b38cfb70202e27 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Tue, 9 Sep 2025 10:40:18 -0500 Subject: [PATCH] add class method to user to retrieve all allowed cameras --- frigate/models.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/frigate/models.py b/frigate/models.py index 61889fd1e..59188128b 100644 --- a/frigate/models.py +++ b/frigate/models.py @@ -135,6 +135,18 @@ class User(Model): password_hash = CharField(null=False, max_length=120) notification_tokens = JSONField() + @classmethod + def get_allowed_cameras( + cls, role: str, roles_dict: dict[str, list[str]], all_camera_names: set[str] + ) -> list[str]: + if role not in roles_dict: + return [] # Invalid role grants no access + allowed = roles_dict[role] + if not allowed: # Empty list means all cameras + return list(all_camera_names) + + return [cam for cam in allowed if cam in all_camera_names] + class Trigger(Model): camera = CharField(max_length=20)