From fd799c8fbcb660d300d9e47a40c0cfbcb424bfbe Mon Sep 17 00:00:00 2001 From: msramalho <19508417+msramalho@users.noreply.github.com> Date: Thu, 3 Apr 2025 15:13:58 +0100 Subject: [PATCH] fix orchestrator file presence check based on enabled group permissions --- app/shared/user_groups.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/app/shared/user_groups.py b/app/shared/user_groups.py index 764cbca..444fd6b 100644 --- a/app/shared/user_groups.py +++ b/app/shared/user_groups.py @@ -94,20 +94,31 @@ class GroupPermissions(BaseModel): class GroupModel(BaseModel): description: str - orchestrator: str - orchestrator_sheet: str + orchestrator: str | None = None + orchestrator_sheet: str | None = None permissions: GroupPermissions @classmethod - @field_validator("orchestrator", "orchestrator_sheet", mode="before") + @field_validator("orchestrator", mode="before") def validate_orchestrator(cls, v): - if not os.path.exists(v): + # orchestrator is only needed if the group has archive_url permission + if cls.permissions.archive_url and not os.path.exists(v): + raise ValueError(f"Orchestrator file not found with this path: {v}") + return v + + @classmethod + @field_validator("orchestrator_sheet", mode="before") + def validate_orchestrator_sheet(cls, v): + # orchestrator_sheet is only needed if the group has archive_sheet permission + if cls.permissions.archive_sheet and not os.path.exists(v): raise ValueError(f"Orchestrator file not found with this path: {v}") return v @computed_field @property def service_account_email(self) -> str: + if self.orchestrator_sheet is None: + return "" if hasattr(self, "_service_account_email"): return self._service_account_email orch = yaml.safe_load(open(self.orchestrator_sheet))