Create access profiles from HTML5 workspace
CI / python (push) Has been cancelled
CI / rust (push) Has been cancelled

This commit is contained in:
2026-05-21 19:35:04 +03:00
parent 2f7db03001
commit 87236606d1
5 changed files with 206 additions and 2 deletions
@@ -7,9 +7,12 @@ from fastapi import HTTPException
from api_server.html5_access import (
render_html5_access_page,
render_html5_access_profile_apply_result,
render_html5_access_profile_preview,
render_html5_access_publish_plan,
render_html5_access_publish_result,
)
from api_server.html5_forms import form_value, html5_csv_values
def html5_access_page(
@@ -70,6 +73,39 @@ async def html5_access_publish_dry_run(
return render_html5_access_publish_result(project_id=project_id, result=result)
async def html5_access_profile_preview(
*,
project_id: str,
form: dict[str, list[str]],
preview_profile: Callable[[str, object], Awaitable[Any]],
draft_request: Callable[..., object],
) -> str:
draft = await preview_profile(project_id, _draft_request_from_form(form, draft_request))
return render_html5_access_profile_preview(draft=draft)
async def html5_access_profile_apply(
*,
project_id: str,
form: dict[str, list[str]],
apply_profile: Callable[[str, object], Awaitable[Any]],
apply_request: Callable[..., object],
normalized_project: Callable[[str], object],
access_profile_by_name: Callable[[object, str], object | None],
access_publish_plan: Callable[[object, object], object],
) -> str:
request = _draft_request_from_form(form, apply_request, author="html5")
response = await apply_profile(project_id, request)
profile_name = str(response.profile.get("name") or response.profile.get("qualified_name") or "")
plan = None
if profile_name:
normalized = normalized_project(project_id)
profile = access_profile_by_name(normalized, profile_name)
if profile is not None:
plan = access_publish_plan(normalized, profile)
return render_html5_access_profile_apply_result(project_id=project_id, response=response, plan=plan)
def _selected_profile(
normalized: object,
profile_name: str | None,
@@ -82,3 +118,17 @@ def _selected_profile(
if not profile_name:
return profiles[0]
return access_profile_by_name(normalized, profile_name) or profiles[0]
def _draft_request_from_form(form: dict[str, list[str]], request_factory: Callable[..., object], **extra: object) -> object:
name = form_value(form, "name")
if not name:
raise HTTPException(status_code=400, detail="Access profile name is required")
payload = {
"name": name,
"target_objects": html5_csv_values(form_value(form, "target_objects") or ""),
"permissions": html5_csv_values(form_value(form, "permissions") or "read"),
"source_user": form_value(form, "source_user"),
**extra,
}
return request_factory(**payload)