kanidmd_core/https/views/
apps.rs

1use askama::Template;
2use axum::{
3    extract::State,
4    http::uri::Uri,
5    response::{IntoResponse, Response},
6    Extension,
7};
8use axum_htmx::HxPushUrl;
9
10use kanidm_proto::internal::AppLink;
11
12use super::constants::Urls;
13use super::navbar::NavbarCtx;
14use crate::https::views::errors::HtmxError;
15use crate::https::{
16    extractors::DomainInfo, extractors::VerifiedClientInformation, middleware::KOpId, ServerState,
17};
18
19#[derive(Template)]
20#[template(path = "apps.html")]
21struct AppsView {
22    navbar_ctx: NavbarCtx,
23    apps_partial: AppsPartialView,
24}
25
26#[derive(Template)]
27#[template(path = "apps_partial.html")]
28struct AppsPartialView {
29    apps: Vec<AppLink>,
30}
31
32pub(crate) async fn view_apps_get(
33    State(state): State<ServerState>,
34    Extension(kopid): Extension<KOpId>,
35    VerifiedClientInformation(client_auth_info): VerifiedClientInformation,
36    DomainInfo(domain_info): DomainInfo,
37) -> axum::response::Result<Response> {
38    // Because this is the route where the login page can land, we need to actually alter
39    // our response as a result. If the user comes here directly we need to render the full
40    // page, otherwise we need to render the partial.
41
42    let app_links = state
43        .qe_r_ref
44        .handle_list_applinks(client_auth_info, kopid.eventid)
45        .await
46        .map_err(|old| HtmxError::new(&kopid, old, domain_info.clone()))?;
47
48    let apps_partial = AppsPartialView { apps: app_links };
49
50    Ok({
51        let apps_view = AppsView {
52            navbar_ctx: NavbarCtx { domain_info },
53
54            apps_partial,
55        };
56        (HxPushUrl(Uri::from_static(Urls::Apps.as_ref())), apps_view).into_response()
57    })
58}