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