Test / test (pull_request) Successful in 51s
Every person a page names as responsible gets a Kanidm account at start if they have none, and a mail saying they are listed as responsible for asking that question, with the link to sign in; RESPONSIBLE_GROUP puts them in one group. SEED_ADMIN_EMAIL invites the first person into the most privileged group - the one whose desk may invite into the most - once. Signed in, a responsible person may suggest a change to their own pages; checked on the server, kept, published, and mailed to the site's inbox. Fixes an invite of someone new on a Kanidm with only the onboarding account: the person is created with their address in one call, since idm_people_on_boarding may create but not modify (it answered 403). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GT37Z1Xtfd9pUuQtMTg6Yt
35 lines
1.2 KiB
Rust
35 lines
1.2 KiB
Rust
use leptos::prelude::*;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
/// The authenticated user, as established by the Kanidm OIDC flow and
|
|
/// stored in the server-side session. Ported from cnats' `auth.rs` -
|
|
/// same shape, same provider.
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct User {
|
|
pub sub: String,
|
|
pub username: String,
|
|
pub display_name: String,
|
|
/// Kanidm group membership, from the `groups` OIDC claim (see
|
|
/// `oauth2 update-claim-map`). Fixed at login time - not re-checked
|
|
/// live, so a group change only takes effect on the next login.
|
|
#[serde(default)]
|
|
pub groups: Vec<String>,
|
|
/// The address Kanidm holds for them (the `email` claim), so a page
|
|
/// can know it is talking to the person it names as responsible.
|
|
#[serde(default)]
|
|
pub email: Option<String>,
|
|
}
|
|
|
|
pub const SESSION_USER_KEY: &str = "user";
|
|
|
|
/// Returns the currently signed-in user, if any.
|
|
#[server(endpoint = "current_user")]
|
|
pub async fn current_user() -> Result<Option<User>, ServerFnError> {
|
|
let session: tower_sessions::Session = leptos_axum::extract().await?;
|
|
let user = session
|
|
.get::<User>(SESSION_USER_KEY)
|
|
.await
|
|
.map_err(|e| ServerFnError::new(e.to_string()))?;
|
|
Ok(user)
|
|
}
|