phonograph/interim-server/src/routes/relations_single/portal_settings_handler.rs

90 lines
2.4 KiB
Rust
Raw Normal View History

2025-10-01 22:36:19 -07:00
use askama::Template;
use axum::{
debug_handler,
extract::{Path, State},
response::{Html, IntoResponse},
};
use interim_models::{
accessors::{Accessor, Actor, portal::PortalAccessor},
portal::Portal,
workspace::Workspace,
};
2025-10-01 22:36:19 -07:00
use serde::Deserialize;
use sqlx::postgres::types::Oid;
use uuid::Uuid;
use crate::{
app::{App, AppDbConn},
2025-10-22 00:43:53 -07:00
errors::AppError,
2025-10-01 22:36:19 -07:00
navigator::{Navigator, NavigatorPage as _},
settings::Settings,
user::CurrentUser,
workspace_nav::{NavLocation, RelLocation, WorkspaceNav},
workspace_pooler::{RoleAssignment, WorkspacePooler},
};
#[derive(Debug, Deserialize)]
pub(super) struct PathParams {
portal_id: Uuid,
rel_oid: u32,
workspace_id: Uuid,
}
/// HTTP GET handler for portal settings, including renaming and deletion.
#[debug_handler(state = App)]
pub(super) async fn get(
State(settings): State<Settings>,
CurrentUser(user): CurrentUser,
AppDbConn(mut app_db): AppDbConn,
Path(PathParams {
portal_id,
rel_oid,
workspace_id,
}): Path<PathParams>,
navigator: Navigator,
State(mut pooler): State<WorkspacePooler>,
) -> Result<impl IntoResponse, AppError> {
let mut workspace_client = pooler
.acquire_for(workspace_id, RoleAssignment::User(user.id))
2025-10-01 22:36:19 -07:00
.await?;
let portal = PortalAccessor::new()
.id(portal_id)
.as_actor(Actor::User(user.id))
.verify_workspace_id(workspace_id)
.verify_rel_oid(Oid(rel_oid))
.verify_rel_ownership()
.using_app_db(&mut app_db)
.using_workspace_client(&mut workspace_client)
.fetch_one()
2025-10-01 22:36:19 -07:00
.await?;
let workspace = Workspace::with_id(workspace_id)
.fetch_one(&mut app_db)
.await?;
2025-10-01 22:36:19 -07:00
#[derive(Debug, Template)]
#[template(path = "relations_single/portal_settings.html")]
struct ResponseTemplate {
navigator: Navigator,
portal: Portal,
settings: Settings,
workspace_nav: WorkspaceNav,
}
Ok(Html(
ResponseTemplate {
workspace_nav: WorkspaceNav::builder()
.navigator(navigator.clone())
.workspace(workspace)
.populate_rels(&mut app_db, &mut workspace_client)
.await?
.current(NavLocation::Rel(Oid(rel_oid), Some(RelLocation::Sharing)))
.build()?,
navigator,
portal,
settings,
}
.render()?,
))
}