From 83f47c57661878e48d43ae3649560caa50945dcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 7 Sep 2026 04:34:50 +0300 Subject: [PATCH] feat(share): the modal offers im's directory as a dropdown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Opening the share modal fetches im's /directory (client credentials, new in_client::directory), mirrors each member into a local user row via provision_user, and replaces the typed-address field with a select of the shareable people — owner, current grantees and locally-disabled accounts filtered out. A directory that does not answer, or answers nobody new, leaves the typed field exactly as it was. The add handler's contract is untouched: the option values are the addresses it already takes. --- crates/in-client/src/lib.rs | 35 +++++++ crates/in-web/src/i18n.rs | 3 + crates/in-web/src/share.rs | 34 ++++++- crates/in-web/tests/http.rs | 183 +++++++++++++++++++++++++++++++++--- 4 files changed, 241 insertions(+), 14 deletions(-) diff --git a/crates/in-client/src/lib.rs b/crates/in-client/src/lib.rs index 7b55400..0a3cf3a 100644 --- a/crates/in-client/src/lib.rs +++ b/crates/in-client/src/lib.rs @@ -147,6 +147,41 @@ pub async fn photo_for(cx: &Cx, user_id: &str) -> Option<(Vec, String)> { Some((bytes, mime)) } +/// One entry of im's directory: the stable subject, the address, the +/// display name, and whether im calls the person an admin — exactly what +/// mirroring the directory into local user rows needs. +#[derive(Debug, Clone, Deserialize)] +pub struct DirectoryMember { + pub sub: String, + pub email: String, + pub name: String, + pub admin: bool, +} + +/// im's family phonebook: every person im knows, fetched as the app +/// (`Authorization: Basic base64(client_id ":" client_secret)`, the same +/// credentials the photo route and the introspection round-trip take) from +/// `{issuer}/directory`. Only a registered app gets an answer at all. +/// +/// `None` on anything that is not a readable list — a refused pair, a +/// dropped connection, a body that is not the array — because a missed +/// beat must never look like an empty directory: the caller keeps the +/// rows it has and asks again next time. +pub async fn directory(cx: &Cx) -> Option> { + let state = client(cx); + let reply = state + .http + .get(format!("{}/directory", state.config.issuer)) + .basic_auth(&state.config.client_id, Some(&state.config.client_secret)) + .send() + .await + .ok()?; + if !reply.status().is_success() { + return None; + } + reply.json().await.ok() +} + /// Path of im's RFC 7662 introspection endpoint, relative to the issuer. const INTROSPECT_PATH: &str = "/introspect"; diff --git a/crates/in-web/src/i18n.rs b/crates/in-web/src/i18n.rs index 98f7f82..026b411 100644 --- a/crates/in-web/src/i18n.rs +++ b/crates/in-web/src/i18n.rs @@ -144,6 +144,7 @@ pub enum Key { SharedWith, ShareWithUser, SharePlaceholder, + SharePickPerson, CanDownload, RemoveAccess, NoSharedItems, @@ -296,6 +297,7 @@ pub fn t(lang: Lang, key: Key) -> &'static str { SharedWith => "Shared with", ShareWithUser => "Share with someone", SharePlaceholder => "Name or address", + SharePickPerson => "Pick a person", CanDownload => "May download", RemoveAccess => "Remove access", NoSharedItems => "Nothing is shared with you yet.", @@ -437,6 +439,7 @@ pub fn t(lang: Lang, key: Key) -> &'static str { SharedWith => "Paylaşılanlar", ShareWithUser => "Biriyle paylaş", SharePlaceholder => "Ad ya da adres", + SharePickPerson => "Birini seç", CanDownload => "İndirebilir", RemoveAccess => "Erişimi kaldır", NoSharedItems => "Seninle henüz bir şey paylaşılmadı.", diff --git a/crates/in-web/src/share.rs b/crates/in-web/src/share.rs index eabc8fe..d9f50f8 100644 --- a/crates/in-web/src/share.rs +++ b/crates/in-web/src/share.rs @@ -1137,6 +1137,29 @@ pub(crate) async fn share_modal( people.push((grantee.display_name, grantee.email, grant.can_download)); } } + // The shareable people come from im's directory: each entry mirrored + // into a local user row here, so the address the form posts resolves + // the way a typed one would — then the owner, anyone already on the + // list above, and any locally-disabled account are taken back out + // (im's directory not naming someone disabled here must not offer + // them). A directory that does not answer, or answers nobody new, + // leaves the typed-address field in place below. + let default_quota = app(cx).config.default_quota_bytes; + let mut candidates: Vec = Vec::new(); + if let Some(members) = in_client::directory(cx).await { + for member in members { + let row = store + .provision_user(&member.sub, &member.email, &member.name, default_quota) + .await?; + if !row.disabled + && row.id != user.id + && !people.iter().any(|(_, email, _)| *email == row.email) + { + candidates.push(row); + } + } + } + candidates.sort_by(|a, b| a.display_name.cmp(&b.display_name)); let refusal = query_value(uri(cx).query().unwrap_or(""), "refusal") .and_then(|code| Refusal::from_code(&code)); Ok(Some(view! { @@ -1169,7 +1192,16 @@ pub(crate) async fn share_modal(