basyx commited on
Commit
b76032c
·
verified ·
1 Parent(s): c0ee361

Validate generation project ownership before enqueue

Browse files
app/generation/services/generation_service.py CHANGED
@@ -170,6 +170,20 @@ class GenerationService:
170
  key = idempotency_key.strip()
171
  if not key:
172
  raise GenerationValidationError("Idempotency-Key must not be blank.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
 
174
  base_spec = self._request_spec(payload)
175
  requested_fingerprint = self._fingerprint(
 
170
  key = idempotency_key.strip()
171
  if not key:
172
  raise GenerationValidationError("Idempotency-Key must not be blank.")
173
+ if project_id is not None and payload.project_id is not None and project_id != payload.project_id:
174
+ raise GenerationValidationError("Conflicting project_id values were supplied.")
175
+ project_id = project_id or payload.project_id
176
+ if project_id is not None:
177
+ async with self.database.tenant_session(workspace_id=workspace_id, user_id=user_id) as session:
178
+ project_exists = await session.scalar(
179
+ select(Project.id).where(
180
+ Project.id == project_id,
181
+ Project.workspace_id == workspace_id,
182
+ Project.status == "active",
183
+ )
184
+ )
185
+ if project_exists is None:
186
+ raise GenerationValidationError("Project was not found in this workspace or is archived.")
187
 
188
  base_spec = self._request_spec(payload)
189
  requested_fingerprint = self._fingerprint(