update: scripts.py api
This commit is contained in:
@@ -11,6 +11,7 @@ from common.config import settings
|
||||
from common.db.models import (
|
||||
Scripts,
|
||||
StorageObjects,
|
||||
Users,
|
||||
Versions,
|
||||
)
|
||||
from common.ids import new_ulid
|
||||
@@ -182,6 +183,8 @@ def validate_script_content(content: str, script_type: str) -> bytes:
|
||||
def script_payload(
|
||||
script: Scripts,
|
||||
storage_object: StorageObjects | dict[str, Any] | None,
|
||||
*,
|
||||
owner_display_name: str | None = None,
|
||||
) -> dict[str, Any]:
|
||||
if storage_object is None:
|
||||
relative_path = None
|
||||
@@ -212,6 +215,7 @@ def script_payload(
|
||||
"workspace_id": script.workspace_id,
|
||||
"current_object_id": script.current_object_id,
|
||||
"owner_user_id": script.owner_user_id,
|
||||
"owner_display_name": owner_display_name,
|
||||
"script_name": script.script_name,
|
||||
"script_type": script.script_type,
|
||||
"visibility": script.visibility,
|
||||
@@ -921,11 +925,12 @@ async def list_scripts(
|
||||
session: AsyncSession = Depends(database_session),
|
||||
) -> dict[str, Any]:
|
||||
statement = (
|
||||
select(Scripts, StorageObjects)
|
||||
select(Scripts, StorageObjects, Users.display_name)
|
||||
.join(
|
||||
StorageObjects,
|
||||
StorageObjects.storage_object_id == Scripts.current_object_id,
|
||||
)
|
||||
.outerjoin(Users, Users.user_id == Scripts.owner_user_id)
|
||||
.where(
|
||||
Scripts.workspace_id == context.workspace.workspace_id,
|
||||
Scripts.status == "active",
|
||||
@@ -936,7 +941,8 @@ async def list_scripts(
|
||||
return {
|
||||
"request_id": context.request_id,
|
||||
"data": [
|
||||
script_payload(script, storage_object) for script, storage_object in rows
|
||||
script_payload(script, storage_object, owner_display_name=owner_display_name)
|
||||
for script, storage_object, owner_display_name in rows
|
||||
],
|
||||
"meta": {"count": len(rows)},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user