Compare commits

...

3 commits

Author SHA1 Message Date
Merlijn 6e41b4663e
Merge 3077d86aa1 into ad012cd6fd 2025-04-06 02:23:02 +00:00
ToxicMushroom 3077d86aa1
final fixes 2025-04-06 04:22:56 +02:00
ToxicMushroom 9b3f814b67
cargo fmt 2025-04-06 01:29:26 +02:00
3 changed files with 103 additions and 75 deletions
proto/src/scim_v1
server/core
src/https/views
templates/user_settings

View file

@ -71,7 +71,7 @@ pub enum ScimSchema {
}
#[serde_as]
#[derive(Deserialize, Serialize, Debug, Clone, ToSchema)]
#[derive(Deserialize, Serialize, PartialEq, Eq, Debug, Clone, ToSchema)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct ScimMail {
#[serde(default)]

View file

@ -17,7 +17,7 @@ use axum_extra::extract::Form;
use axum_htmx::{HxEvent, HxPushUrl, HxResponseTrigger};
use futures_util::TryFutureExt;
use kanidm_proto::attribute::Attribute;
use kanidm_proto::constants::{ATTR_DISPLAYNAME, ATTR_MAIL};
use kanidm_proto::constants::{ATTR_DISPLAYNAME, ATTR_MAIL, ATTR_NAME};
use kanidm_proto::internal::UserAuthToken;
use kanidm_proto::scim_v1::server::{ScimEffectiveAccess, ScimPerson};
use kanidm_proto::scim_v1::ScimMail;
@ -63,13 +63,13 @@ pub(crate) struct SaveProfileQuery {
#[derive(Clone, Debug, Serialize, Deserialize)]
pub(crate) struct CommitSaveProfileQuery {
#[serde(rename = "account_name")]
account_name: String,
account_name: Option<String>,
#[serde(rename = "display_name")]
display_name: String,
display_name: Option<String>,
#[serde(rename = "emails[]")]
emails: Vec<String>,
#[serde(rename = "new_primary_mail")]
new_primary_mail: Option<String>
new_primary_mail: Option<String>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
@ -88,6 +88,7 @@ struct ProfileChangesPartialView {
primary_mail: Option<String>,
new_attrs: ProfileAttributes,
new_primary_mail: Option<String>,
emails_are_same: bool,
}
#[derive(Template, Clone)]
@ -163,7 +164,8 @@ pub(crate) async fn view_profile_diff_start_save_post(
state,
&kopid,
client_auth_info.clone(),
).await?;
)
.await?;
let primary_index = query
.emails_indexes
@ -179,10 +181,13 @@ pub(crate) async fn view_profile_diff_start_save_post(
value: email.to_string(),
})
.collect();
let old_primary_mail = scim_person.mails.iter()
let old_primary_mail = scim_person
.mails
.iter()
.find(|sm| sm.primary)
.map(|sm| sm.value.clone());
let emails_are_same = scim_person.mails == new_mails;
let profile_view = ProfileChangesPartialView {
menu_active_item: ProfileMenuItems::UserProfile,
@ -194,13 +199,15 @@ pub(crate) async fn view_profile_diff_start_save_post(
display_name: query.display_name,
emails: new_mails,
},
emails_are_same,
new_primary_mail: query.emails.get(primary_index).cloned(),
};
Ok((
HxPushUrl(Uri::from_static("/ui/profile/diff")),
profile_view,
).into_response())
)
.into_response())
}
pub(crate) async fn view_profile_diff_confirm_save_post(
@ -216,24 +223,37 @@ pub(crate) async fn view_profile_diff_confirm_save_post(
.handle_whoami_uat(client_auth_info.clone(), kopid.eventid)
.map_err(|op_err| HtmxError::new(&kopid, op_err, domain_info.clone()))
.await?;
dbg!(&query);
let filter = filter_all!(f_and!([f_id(uat.uuid.to_string().as_str())]));
if let Some(account_name) = query.account_name {
state
.qe_w_ref
.handle_setattribute(
client_auth_info.clone(),
uat.uuid.to_string(),
ATTR_NAME.to_string(),
vec![account_name],
filter.clone(),
kopid.eventid,
)
.map_err(|op_err| HtmxError::new(&kopid, op_err, domain_info.clone()))
.await?;
}
if let Some(display_name) = query.display_name {
state
.qe_w_ref
.handle_setattribute(
client_auth_info.clone(),
uat.uuid.to_string(),
ATTR_DISPLAYNAME.to_string(),
vec![query.display_name],
vec![display_name],
filter.clone(),
kopid.eventid,
)
.map_err(|op_err| HtmxError::new(&kopid, op_err, domain_info.clone()))
.await?;
}
let mut emails = query.emails;
if let Some(primary) = query.new_primary_mail {
emails.insert(0, primary);

View file

@ -9,9 +9,13 @@ Profile Difference
(% block settings_window %)
<form>
(% if person.name != new_attrs.account_name %)
<input type="hidden" name="account_name" value="(( new_attrs.account_name ))"/>
(% endif %)
(% if person.displayname != new_attrs.display_name %)
<input type="hidden" name="display_name" value="(( new_attrs.display_name ))"/>
<!-- <input type="hidden" name="legal_name" value=" new_attrs.legal_name "/>-->
(% endif %)
(% for email in new_attrs.emails %)
(% if !email.primary %)
<input type="hidden" name="emails[]" value="(( email.value ))"/>
@ -44,7 +48,7 @@ Profile Difference
<td class="text-break">(( new_attrs.display_name ))</td>
</tr>
(% endif %)
<!-- TODO: List new items with +, same items with . -->
(% if !emails_are_same %)
<tr>
<th scope="row">Primary Emails</th>
<td class="text-nowrap">
@ -75,13 +79,17 @@ Profile Difference
</ul>
</td>
</tr>
(% endif %)
</table>
<!-- Edit button -->
<div class="pt-4" hx-target="#user_settings_container" hx-swap="outerHTML">
(% if can_rw %)
<button class="btn btn-danger" type="button" hx-get="/ui/profile" hx-target="body" hx-swap="outerHTML">Discard Changes</button>
<button class="btn btn-primary" type="button" hx-post="/ui/api/user_settings/confirm_profile" hx-target="body" hx-swap="outerHTML">Confirm Changes</button>
<button class="btn btn-danger" type="button" hx-get="/ui/profile" hx-target="body" hx-swap="outerHTML">Discard
Changes
</button>
<button class="btn btn-primary" type="button" hx-post="/ui/api/user_settings/confirm_profile" hx-target="body"
hx-swap="outerHTML">Confirm Changes
</button>
(% else %)
<a href="/ui/profile/unlock" hx-boost="false">
<!-- TODO: at the moment, session expiring here means progress is lost. Do we just show an error screen ? We can't pass the update state through the reauth session, and we don't have profile update sessions like cred update. -->