From e23224b124de7a22b69240a145fa95458be80191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 9 Sep 2026 00:02:19 +0300 Subject: [PATCH] =?UTF-8?q?the=20share=20picker=20takes=20a=20whole=20crow?= =?UTF-8?q?d=20at=20once:=20the=20one-person=20select=20becomes=20a=20chec?= =?UTF-8?q?kbox=20list=20with=20an=20Everyone=20row=20that=20checks=20ever?= =?UTF-8?q?y=20candidate=20in=20one=20click,=20one=20Share=20posts=20every?= =?UTF-8?q?=20checked=20address=20with=20the=20one=20permission=20chosen,?= =?UTF-8?q?=20and=20the=20typed-email=20fallback=20stays=20for=20the=20emp?= =?UTF-8?q?ty=20directory;=20the=20shared=20page's=20owner=20column=20wide?= =?UTF-8?q?ns=20to=20take=20the=20name=20it=20truncated=20(a=20Muhammet=20?= =?UTF-8?q?=C3=96zdemediro=C4=9Flu=20no=20longer=20dies=20at=20Muhammet=20?= =?UTF-8?q?=C3=96zd=E2=80=A6),=20the=20legacy-link=20note=20moves=20out=20?= =?UTF-8?q?from=20between=20the=20link=20field=20and=20its=20revoke=20butt?= =?UTF-8?q?on=20into=20its=20own=20full-width=20sentence=20under=20the=20r?= =?UTF-8?q?ow,=20every=20dropdown=20lands=20on=20the=20iz=20house=20style?= =?UTF-8?q?=20(chevron=20scoping,=20status-trigger=20padding,=20panel=20an?= =?UTF-8?q?d=20menu=20radii=20and=20insets,=20viewport-capped=20panel=20wi?= =?UTF-8?q?dth,=20the=20>7-option=20search=20rule)=20=E2=80=94=20and=20the?= =?UTF-8?q?=20enhancement=20itself=20no=20longer=20dies=20on=20the=20first?= =?UTF-8?q?=20select=20whose=20form=20has=20no=20submit=20button:=20the=20?= =?UTF-8?q?missing=20var=20declaration=20aborted=20the=20whole=20sweep,=20?= =?UTF-8?q?which=20is=20why=20theme,=20language=20and=20the=20kind=20filte?= =?UTF-8?q?rs=20were=20still=20showing=20the=20browser's=20own=20popup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/in-web/src/drive.rs | 4 +- crates/in-web/src/dropdown.rs | 14 ++- crates/in-web/src/i18n.rs | 3 + crates/in-web/src/settings.rs | 4 +- crates/in-web/src/share.rs | 169 ++++++++++++++++++++++++++-------- crates/in-web/src/trash.rs | 4 +- crates/in-web/tests/http.rs | 88 ++++++++++++++++-- style/main.scss | 130 +++++++++++++++++++++----- 8 files changed, 335 insertions(+), 81 deletions(-) diff --git a/crates/in-web/src/drive.rs b/crates/in-web/src/drive.rs index 0ef838b..7a911d9 100644 --- a/crates/in-web/src/drive.rs +++ b/crates/in-web/src/drive.rs @@ -598,7 +598,7 @@ async fn drive(cx: &Cx) -> Result { }
- diff --git a/crates/in-web/src/dropdown.rs b/crates/in-web/src/dropdown.rs index 7bcb339..31a52d6 100644 --- a/crates/in-web/src/dropdown.rs +++ b/crates/in-web/src/dropdown.rs @@ -62,6 +62,10 @@ use topcoat::view::{Unescaped, view}; /// with `?task=` registered it first and the modal chain won, closing /// the whole modal over an open dropdown — the registry pins the correct /// order; the whole table lives in `layout.rs`'s `escape_manager_script`). +/// A panel's rows are `white-space: nowrap`, so a long option never wraps — +/// `place` caps the open panel's width at `innerWidth − 8`, shaving off the +/// padding and borders a `max-width` does not cover, or its right edge would +/// clip on a 320px phone no matter where the left clamp puts it. pub async fn dropdown_script(cx: &Cx) -> Result { const JS: &str = "\ (function () {\ @@ -76,6 +80,11 @@ pub async fn dropdown_script(cx: &Cx) -> Result { }\ function place(panel, trigger) {\ var r = trigger.getBoundingClientRect();\ + var maxW = window.innerWidth - 8;\ + panel.style.maxWidth = '';\ + if (panel.offsetWidth > maxW) { panel.style.maxWidth = maxW + 'px'; }\ + var over = panel.offsetWidth - maxW;\ + if (over > 0) { panel.style.maxWidth = (maxW - over) + 'px'; }\ var h = panel.offsetHeight;\ var w = panel.offsetWidth;\ var top = r.bottom + 4;\ @@ -84,7 +93,7 @@ pub async fn dropdown_script(cx: &Cx) -> Result { var left = Math.max(4, Math.min(r.left, window.innerWidth - w - 4));\ panel.style.left = left + 'px';\ panel.style.top = top + 'px';\ - panel.style.minWidth = r.width + 'px';\ + panel.style.minWidth = Math.min(r.width, maxW) + 'px';\ }\ function visibleRows(panel) { return Array.prototype.slice.call(panel.querySelectorAll('.dd-option:not(.dd-option-hidden)')); }\ function activate(panel, row) {\ @@ -192,6 +201,7 @@ pub async fn dropdown_script(cx: &Cx) -> Result { A select without autosubmit still needs its button — hiding \ it then strands the form with no way to post at all. */ \ var sibs = select.parentNode.children; \ + var go = null; \ for (var si = 0; si < sibs.length; si++) { \ if (sibs[si].tagName === 'BUTTON' && sibs[si].type === 'submit' && !sibs[si].classList.contains('dd-trigger')) { go = sibs[si]; break; } \ } \ @@ -206,7 +216,7 @@ pub async fn dropdown_script(cx: &Cx) -> Result { select.__ddPanel = panel;\ var allOpts = opts(select);\ var search = null;\ - if ((allOpts.length > 7 && !select.hasAttribute('data-nosearch')) || select.hasAttribute('data-search')) {\ + if (allOpts.length > 7 || select.hasAttribute('data-search')) {\ search = document.createElement('input');\ search.type = 'text';\ search.className = 'dd-search';\ diff --git a/crates/in-web/src/i18n.rs b/crates/in-web/src/i18n.rs index 899d3cc..5b693c1 100644 --- a/crates/in-web/src/i18n.rs +++ b/crates/in-web/src/i18n.rs @@ -147,6 +147,7 @@ pub enum Key { ShareWithUser, SharePlaceholder, SharePickPerson, + ShareEveryone, CanDownload, RemoveAccess, NoSharedItems, @@ -317,6 +318,7 @@ pub fn t(lang: Lang, key: Key) -> &'static str { ShareWithUser => "Share with someone", SharePlaceholder => "Name or address", SharePickPerson => "Pick a person", + ShareEveryone => "Everyone", CanDownload => "May download", RemoveAccess => "Remove access", NoSharedItems => "Nothing is shared with you yet.", @@ -477,6 +479,7 @@ pub fn t(lang: Lang, key: Key) -> &'static str { ShareWithUser => "Biriyle paylaş", SharePlaceholder => "Ad ya da adres", SharePickPerson => "Birini seç", + ShareEveryone => "Herkes", CanDownload => "İndirebilir", RemoveAccess => "Erişimi kaldır", NoSharedItems => "Seninle henüz bir şey paylaşılmadı.", diff --git a/crates/in-web/src/settings.rs b/crates/in-web/src/settings.rs index 9837997..3687ad2 100644 --- a/crates/in-web/src/settings.rs +++ b/crates/in-web/src/settings.rs @@ -481,9 +481,11 @@ async fn settings(cx: &Cx) -> Result { } else { -

(t(language, Key::LegacyLinkNote))

} + if url.is_none() { + + } } diff --git a/crates/in-web/src/share.rs b/crates/in-web/src/share.rs index 572e1ce..ac0899b 100644 --- a/crates/in-web/src/share.rs +++ b/crates/in-web/src/share.rs @@ -22,7 +22,8 @@ use in_core::store::{File, ShareKind, Store, StoreError, ThumbState, User}; use in_core::{hash_link_password, hash_share_token, link_password_matches, link_unlock_proof}; -use serde::Deserialize; +use serde::de::{IgnoredAny, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer}; use time::OffsetDateTime; use topcoat::Result; use topcoat::context::Cx; @@ -393,18 +394,62 @@ async fn under_target(store: &dyn Store, owner_id: &str, target_id: &str, at: &s } } } -#[derive(Deserialize)] +/// The share form. The picker posts one `email` field per person, and +/// serde_urlencoded hands a map visitor one pair at a time — a `Vec` field +/// cannot see the repeats — so the impl below collects them itself. The +/// typed-address fallback posts a single `email`, which lands the same way. struct ShareUserForm { kind: String, target_id: String, - #[serde(default)] - email: String, - #[serde(default)] + email: Vec, can_download: Option, } -/// Shares one file or folder with one named person. The address is folded to -/// lowercase before lookup; an unknown address is not-found. +impl<'de> Deserialize<'de> for ShareUserForm { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct FormVisitor; + impl<'de> Visitor<'de> for FormVisitor { + type Value = ShareUserForm; + + fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + f.write_str("the share form") + } + + fn visit_map>(self, mut map: A) -> Result { + let mut form = ShareUserForm { + kind: String::new(), + target_id: String::new(), + email: Vec::new(), + can_download: None, + }; + while let Some(key) = map.next_key::()? { + match key.as_str() { + "kind" => form.kind = map.next_value()?, + "target_id" => form.target_id = map.next_value()?, + // The repeats are the point: every checked row is + // one pair, collected in post order. + "email" => form.email.push(map.next_value()?), + // Absent means the checkbox came unchecked. + "can_download" => form.can_download = map.next_value()?, + _ => { + let _: IgnoredAny = map.next_value()?; + } + } + } + Ok(form) + } + } + deserializer.deserialize_map(FormVisitor) + } +} + +/// Shares one file or folder with the people the form names: one `email` +/// field per person, so the picker's multi-select posts them all in one +/// submit. Each address is folded to lowercase before lookup; an unknown +/// address is not-found. #[route(POST "/api/share/user/add")] async fn add_share(cx: &Cx, Form(input): Form) -> Redirect { let user = match require_user(cx).await { @@ -419,28 +464,31 @@ async fn add_share(cx: &Cx, Form(input): Form) -> Redirect { return redirect_back(cx, "/settings", "add", Some(refusal)); } let store = app(cx).store; - let grantee = store - .user_by_email(&input.email.trim().to_lowercase()) - .await - .map_err(|_| Refusal::Unavailable); - let Ok(Some(grantee)) = grantee else { + // Absent means the checkbox came unchecked: view-only, like the + // sibling link creator above. One setting covers the whole submit. + let can_download = parse_flag(input.can_download.as_deref(), false); + // Nothing checked resolves to nobody, like a typed empty address. + if input.email.is_empty() { return redirect_back(cx, "/settings", "add", Some(Refusal::NotFound)); - }; - match store - .add_share_user( - &user.id, - kind, - &input.target_id, - &grantee.id, - // Absent means the checkbox came unchecked: view-only, like the - // sibling link creator above. - parse_flag(input.can_download.as_deref(), false), - ) - .await - { - Ok(()) => redirect_back(cx, "/settings", "add", None), - Err(error) => redirect_back(cx, "/settings", "add", Some(refusal_of(error))), } + for email in &input.email { + let grantee = store + .user_by_email(&email.trim().to_lowercase()) + .await + .map_err(|_| Refusal::Unavailable); + let Ok(Some(grantee)) = grantee else { + return redirect_back(cx, "/settings", "add", Some(Refusal::NotFound)); + }; + // Re-sharing updates the same row — the store upserts — so a name + // the list already carries cannot refuse here. + if let Err(error) = store + .add_share_user(&user.id, kind, &input.target_id, &grantee.id, can_download) + .await + { + return redirect_back(cx, "/settings", "add", Some(refusal_of(error))); + } + } + redirect_back(cx, "/settings", "add", None) } /// Unshares. Removing what was never shared is not an error; only the @@ -460,8 +508,10 @@ async fn remove_share(cx: &Cx, Form(input): Form) -> Redirect { return redirect_back(cx, "/settings", "remove", Some(refusal)); } let store = app(cx).store; + // The remove form posts exactly one address. + let email = input.email.first().map(String::as_str).unwrap_or(""); let grantee = store - .user_by_email(&input.email.trim().to_lowercase()) + .user_by_email(&email.trim().to_lowercase()) .await .map_err(|_| Refusal::Unavailable); let Ok(Some(grantee)) = grantee else { @@ -1302,7 +1352,7 @@ async fn shared(cx: &Cx) -> Result { (t(language, Key::NavSearch)) Result {
(t(language, Key::Sort)) - @@ -1338,7 +1388,7 @@ async fn shared(cx: &Cx) -> Result {
-
+
if rows.is_empty() {
@@ -1526,14 +1576,23 @@ pub(crate) async fn share_modal( if candidates.is_empty() { } else { - + } - @@ -1581,6 +1640,7 @@ pub(crate) async fn share_modal( // away. A link from before the sealing — or one whose key is gone — // keeps the masked value and carries the carry-forward note. let url = share_link_url(cx, *link).await; + let legacy = url.is_none();
(t(language, Key::AnyoneWithLink))
@@ -1596,17 +1656,20 @@ pub(crate) async fn share_modal( } else { -

(t(language, Key::LegacyLinkNote))

}
+ if legacy { + + } }
(share_copy_script(cx).await?) + (share_pick_script(cx).await?) }?)) } @@ -1632,6 +1695,34 @@ pub(crate) async fn share_copy_script(cx: &Cx) -> Result { view! { cx => } } +/// The people picker's client half: the All row checks and unchecks every +/// candidate, and hand-checking rows keeps the All row honest. One delegated +/// listener, idempotent across the modal's re-renders (`window.__inSharePick` +/// guards it), so the `in:wire` morph needs no per-element re-init. +pub(crate) async fn share_pick_script(cx: &Cx) -> Result { + use topcoat::view::Unescaped; + const JS: &str = "\ + (function () { \ + if (window.__inSharePick) { return; } \ + window.__inSharePick = true; \ + function rows(box) { return Array.prototype.slice.call(box.querySelectorAll('.pop-list input[type=checkbox]')); } \ + document.addEventListener('change', function (e) { \ + var t = e.target; \ + if (!t || !t.closest) { return; } \ + var box = t.closest('.share-picker'); \ + if (!box) { return; } \ + if (t.classList.contains('share-all-toggle')) { \ + rows(box).forEach(function (cb) { cb.checked = t.checked; }); \ + } else { \ + var all = box.querySelector('.share-all-toggle'); \ + var list = rows(box); \ + if (all) { all.checked = list.length > 0 && list.every(function (cb) { return cb.checked; }); } \ + } \ + }); \ + })();"; + view! { cx => } +} + /// When the link stops opening, or never on its own. Twins the settings /// page's helper; the share page renders the same expiry line. fn expiry_line(language: Lang, expires_at: Option) -> String { diff --git a/crates/in-web/src/trash.rs b/crates/in-web/src/trash.rs index b7ac340..2a827ec 100644 --- a/crates/in-web/src/trash.rs +++ b/crates/in-web/src/trash.rs @@ -312,7 +312,7 @@ async fn trash(cx: &Cx) -> Result {
(t(language, Key::Sort)) - diff --git a/crates/in-web/tests/http.rs b/crates/in-web/tests/http.rs index 6f213a1..25ea09a 100644 --- a/crates/in-web/tests/http.rs +++ b/crates/in-web/tests/http.rs @@ -1996,7 +1996,7 @@ async fn share_modal_offers_the_im_directory() { // The owner as im knows her: never offered to share with herself. serde_json::json!({"sub": "sub-admin", "email": "ada@in.test", "name": "Ada", "admin": true}), // Valid in im but disabled here: sharing with her is sharing with - // nobody, so the dropdown never offers her. + // nobody, so the picker never offers her. serde_json::json!({"sub": "sub-gonca", "email": "gonca@in.test", "name": "Gonca", "admin": false}), ]); let admin = app.sign_in("sub-admin", "ada@in.test", "Ada").await; @@ -2017,22 +2017,31 @@ async fn share_modal_offers_the_im_directory() { assert_eq!(page.status, StatusCode::OK, "{}", page.text()); let text = page.text(); assert!( - text.contains("