Skip to content

Commit

Permalink
Merge pull request #29 from nebulabroadcast/develop
Browse files Browse the repository at this point in the history
Nebula 6.0.1
  • Loading branch information
martastain committed May 15, 2023
2 parents de90902 + 8eef292 commit b00931d
Show file tree
Hide file tree
Showing 25 changed files with 704 additions and 197 deletions.
14 changes: 9 additions & 5 deletions backend/api/auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastapi import Depends, Header, Response
from fastapi import Depends, Header, Response, Request
from pydantic import Field

import nebula
Expand All @@ -18,7 +18,7 @@ class LoginRequestModel(RequestModel):
...,
title="Username",
example="admin",
regex=r"^[a-zA-Z0-9_\-\.]{3,}$",
regex=r"^[a-zA-Z0-9_\-\.]{2,}$",
)
password: str = Field(
...,
Expand Down Expand Up @@ -53,9 +53,13 @@ class LoginRequest(APIRequest):
name: str = "login"
response_model = LoginResponseModel

async def handle(self, request: LoginRequestModel) -> LoginResponseModel:
user = await nebula.User.login(request.username, request.password)
session = await Session.create(user)
async def handle(
self,
request: Request,
payload: LoginRequestModel,
) -> LoginResponseModel:
user = await nebula.User.login(payload.username, payload.password)
session = await Session.create(user, request)
return LoginResponseModel(access_token=session.token)


Expand Down
5 changes: 5 additions & 0 deletions backend/api/browse.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"ctime",
"mtime",
"video/fps_f",
"subclips",
]

#
Expand Down Expand Up @@ -221,6 +222,10 @@ def build_query(
c2 = f"meta->'assignees' @> '[{user.id}]'::JSONB"
cond_list.append(f"({c1} OR {c2})")

if can_view := user["can/asset_view"]:
if type(can_view) is list:
cond_list.append(f"id_folder IN {sql_list(can_view)}")

# Build conditions

if cond_list:
Expand Down
26 changes: 25 additions & 1 deletion backend/api/jobs/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ class JobsRequestModel(ResponseModel):
title="Restart",
description="Restart job with given id",
)
priority: tuple[int, int] | None = Field(
None,
title="Priority",
descriprion="Set priority of job with given id. "
"First value is job id, second is priority",
example=[42, 3],
)


class JobsItemModel(RequestModel):
Expand All @@ -66,7 +73,8 @@ class JobsItemModel(RequestModel):
title="User ID",
description="ID of the user who started the job",
)
message: str = Field(None, title="Status description", example="Encoding 24%")
priority: int = Field(3, title="Priority", example=3)
message: str = Field(..., title="Status description", example="Encoding 24%")
ctime: int | None = Field(None, title="Created at", example=f"{int(time.time())}")
stime: int | None = Field(None, title="Started at", example=f"{int(time.time())}")
etime: int | None = Field(None, title="Finished at", example=f"{int(time.time())}")
Expand Down Expand Up @@ -161,6 +169,18 @@ async def abort_job(id_job: int, user: nebula.User) -> None:
)


async def set_priority(id_job: int, priority: int, user: nebula.User) -> None:
if not await can_user_control_job(user, id_job):
raise nebula.ForbiddenException("You cannot set priority of this job")
nebula.log.info(f"Setting priority of job {id_job} to {priority}", user=user.name)
query = """
UPDATE jobs SET
priority = $1
WHERE id = $2
"""
await nebula.db.execute(query, priority, id_job)


class JobsRequest(APIRequest):
"""List and control jobs"""

Expand All @@ -180,6 +200,9 @@ async def handle(
if request.restart:
await restart_job(request.restart, user)

if request.priority is not None:
await set_priority(request.priority[0], request.priority[1], user)

# Return a list of jobs if requested

conds = []
Expand Down Expand Up @@ -223,6 +246,7 @@ async def handle(
j.id_user AS id_user,
j.status AS status,
j.progress AS progress,
j.priority AS priority,
j.message AS message,
j.creation_time AS ctime,
j.start_time AS stime,
Expand Down
2 changes: 2 additions & 0 deletions backend/api/rundown/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class RundownRow(ResponseModel):
id: int = Field(...)
type: Literal["item", "event"] = Field(...)
id_bin: int = Field(...)
id_event: int = Field(...)
scheduled_time: float = Field(...)
broadcast_time: float = Field(...)
meta: dict[str, Any] | None = Field(None)
Expand All @@ -35,6 +36,7 @@ class RundownRow(ResponseModel):
loop: bool | None = Field(None)
item_role: ItemMode | None = Field(None)
is_empty: bool = Field(True)
is_primary: bool = Field(False)


class RundownResponseModel(ResponseModel):
Expand Down
18 changes: 16 additions & 2 deletions backend/api/rundown/rundown.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ async def get_rundown(request: RundownRequestModel) -> RundownResponseModel:
subtitle=event.get("subtitle"),
id_asset=event.get("id_asset"),
id_bin=id_bin,
id_event=id_event,
meta=emeta,
)

Expand Down Expand Up @@ -151,10 +152,21 @@ async def get_rundown(request: RundownRequestModel) -> RundownResponseModel:
if asset:
for key in channel.rundown_columns:
if (key in asset.meta) and (
key not in ["title", "subtitle", "id_asset", "duration", "status"]
key
not in [
"title",
"subtitle",
"id_asset",
"duration",
"status",
"mark_in",
"mark_out",
]
):
meta[key] = asset.meta[key]

id_asset = imeta.get("id_asset")
primary = bool(event.get("id_asset") and (event["id_asset"] == id_asset))
row = RundownRow(
id=id_item,
row_number=len(rows),
Expand All @@ -166,15 +178,17 @@ async def get_rundown(request: RundownRequestModel) -> RundownResponseModel:
item_role=imeta.get("item_role"),
title=item["title"],
subtitle=item["subtitle"],
id_asset=imeta.get("id_asset"),
id_asset=id_asset,
id_bin=id_bin,
id_event=id_event,
duration=duration,
status=istatus,
transfer_progress=transfer_progress,
asset_mtime=ameta.get("mtime", 0),
mark_in=mark_in,
mark_out=mark_out,
is_empty=False,
is_primary=primary,
meta=meta,
)

Expand Down
5 changes: 3 additions & 2 deletions backend/api/scheduler/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ async def scheduler(
# update the event
event_at_position["id_asset"] = event_data.id_asset
for field in channel.fields:
if field.name in asset.meta:
event_at_position[field.name] = asset.meta[field.name]
if field.name in ["color", "start", "stop", "promoted"]:
continue
event_at_position[field.name] = asset[field.name]
affected_events.append(event_at_position.id)
await ex_bin.save()
await event_at_position.save()
Expand Down
41 changes: 41 additions & 0 deletions backend/api/sessions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import nebula

from fastapi import Query
from server.session import SessionModel, Session
from server.dependencies import CurrentUser
from server.request import APIRequest
from server.models import RequestModel

class SessionsRequest(RequestModel):
id_user: int = Query(..., example=1)


class Sessions(APIRequest):
name = "sessions"
title = "List sessions"
response_model = list[SessionModel]

async def handle(
self,
request: SessionsRequest,
user: CurrentUser,
) -> list[SessionModel]:
"""Create or update an object."""

id_user = request.id_user

if id_user != user.id and (not user.is_admin):
raise nebula.ForbiddenException()

result = []
async for session in Session.list():

if (id_user is not None) and (id_user != session.user["id"]):
continue

if (not user.is_admin) and (id_user != session.user["id"]):
continue

result.append(session)

return result
Loading

0 comments on commit b00931d

Please sign in to comment.