forked from retoor/devplacepy
feat: restrict backup archive download to primary admin and hide admin-hidden projects from other admins
- Add `get_admin_uids()` and `get_primary_admin_uid()` to database.py for resolving the earliest-created admin - Modify `can_view_project()` in content.py so a project hidden by an admin is invisible to other admins (both web UI and REST API) - Update `_download_url()` and `_backup_payload()` in admin/backups.py to accept a `can_download` flag, gating the download endpoint with `is_primary_admin()` - Remove `role` from `_user_facts()` in docs_live.py to avoid leaking admin status in live docs - Update doc summaries in docs_api.py to reflect the new admin-visibility and backup-download semantics
This commit is contained in:
@@ -62,7 +62,9 @@ class DeepsearchService(JobService):
|
||||
database.update_deepsearch_session(uid, {"status": "running"})
|
||||
|
||||
try:
|
||||
summary = await self._run_worker(uid, payload_path, output_dir)
|
||||
summary = await self._run_worker(
|
||||
uid, payload_path, output_dir, actor_kind, job.get("owner_id") or ""
|
||||
)
|
||||
except Exception as exc:
|
||||
hub.publish(uid, {"type": "failed", "message": str(exc)[:300]})
|
||||
database.update_deepsearch_session(uid, {"status": "failed"})
|
||||
@@ -161,7 +163,26 @@ class DeepsearchService(JobService):
|
||||
int(entry.get("byte_size") or 0),
|
||||
)
|
||||
|
||||
async def _run_worker(self, uid: str, payload_path: Path, output_dir: Path) -> dict:
|
||||
def _ledger_rsearch(self, owner_kind: str, owner_id: str, frame: dict) -> None:
|
||||
from devplacepy.services.openai_gateway.usage import record_rsearch_call
|
||||
|
||||
success = bool(frame.get("success"))
|
||||
record_rsearch_call(
|
||||
owner_kind,
|
||||
owner_id,
|
||||
frame.get("endpoint") or "/search",
|
||||
success,
|
||||
200 if success else 0,
|
||||
)
|
||||
|
||||
async def _run_worker(
|
||||
self,
|
||||
uid: str,
|
||||
payload_path: Path,
|
||||
output_dir: Path,
|
||||
owner_kind: str = "system",
|
||||
owner_id: str = "",
|
||||
) -> dict:
|
||||
proc = await asyncio.create_subprocess_exec(
|
||||
sys.executable,
|
||||
"-m",
|
||||
@@ -186,6 +207,8 @@ class DeepsearchService(JobService):
|
||||
hub.publish(uid, frame)
|
||||
if frame.get("type") == "report_ready":
|
||||
summary = frame
|
||||
elif frame.get("type") == "rsearch":
|
||||
self._ledger_rsearch(owner_kind, owner_id, frame)
|
||||
elif frame.get("type") == "error":
|
||||
worker_error = frame.get("message", "worker error")
|
||||
err = (await proc.stderr.read()).decode("utf-8", "replace")
|
||||
|
||||
Reference in New Issue
Block a user