mirror of
https://github.com/bellingcat/auto-archiver-api.git
synced 2026-06-12 05:28:34 +03:00
fix orchestrator file presence check based on enabled group permissions
This commit is contained in:
@@ -94,20 +94,31 @@ class GroupPermissions(BaseModel):
|
|||||||
|
|
||||||
class GroupModel(BaseModel):
|
class GroupModel(BaseModel):
|
||||||
description: str
|
description: str
|
||||||
orchestrator: str
|
orchestrator: str | None = None
|
||||||
orchestrator_sheet: str
|
orchestrator_sheet: str | None = None
|
||||||
permissions: GroupPermissions
|
permissions: GroupPermissions
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@field_validator("orchestrator", "orchestrator_sheet", mode="before")
|
@field_validator("orchestrator", mode="before")
|
||||||
def validate_orchestrator(cls, v):
|
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}")
|
raise ValueError(f"Orchestrator file not found with this path: {v}")
|
||||||
return v
|
return v
|
||||||
|
|
||||||
@computed_field
|
@computed_field
|
||||||
@property
|
@property
|
||||||
def service_account_email(self) -> str:
|
def service_account_email(self) -> str:
|
||||||
|
if self.orchestrator_sheet is None:
|
||||||
|
return ""
|
||||||
if hasattr(self, "_service_account_email"):
|
if hasattr(self, "_service_account_email"):
|
||||||
return self._service_account_email
|
return self._service_account_email
|
||||||
orch = yaml.safe_load(open(self.orchestrator_sheet))
|
orch = yaml.safe_load(open(self.orchestrator_sheet))
|
||||||
|
|||||||
Reference in New Issue
Block a user