diff --git a/crates/in-web/src/drive.rs b/crates/in-web/src/drive.rs index 42ce9d8..6dfd9c7 100644 --- a/crates/in-web/src/drive.rs +++ b/crates/in-web/src/drive.rs @@ -8,6 +8,11 @@ //! itself is refused. Anything naming another owner's tree answers 404, //! never 403. //! +//! A folder opened by grant renders read-only at the same address for the +//! grantee: the listing loses every write affordance, the trail stops at +//! the granted folder, and anything the grant does not cover answers the +//! same 404 a stranger's tree does. +//! //! `GET /drive?q=` keeps the same page and swaps the folder list //! for library-wide name hits — the filterbar's search box, submitted as a //! plain GET form. The old `GET /search?q=` address 303s here, so old links @@ -15,7 +20,7 @@ use std::collections::HashSet; -use in_core::store::{Folder, ShareKind, Store, StoreError}; +use in_core::store::{Folder, ShareKind, Store, StoreError, User}; use topcoat::router::request::uri; use topcoat::router::{HeaderName, HeaderValue, StatusCode, header, page, query_params, route}; @@ -23,9 +28,9 @@ use topcoat::Result; use topcoat::context::Cx; use topcoat::router::content::{Form, Json}; use topcoat::router::error::not_found; -use topcoat::view::{View, ViewExt, view}; +use topcoat::view::{BoxView, View, ViewExt, view}; -use crate::i18n::{Key, lang, t}; +use crate::i18n::{Key, Lang, lang, t}; use crate::layout::{NavPage, topbar}; use crate::server::{Refusal, app, back_to, refusal_of, require_user, share_origin}; @@ -99,6 +104,75 @@ async fn current_folder( Ok(Some(folder)) } +/// The folder the query names for a grantee: not one of the account's own, +/// but one a live folder grant covers — the grant may sit on the folder +/// itself or on any live folder above it, the same chain the file pages +/// ride. The owner's reachability rule holds unchanged: the folder and +/// every ancestor must be live, or the address is not found. `None` — +/// never an error — leaves the caller answering the plain 404, so a +/// stranger learns nothing about which ids exist. +async fn granted_folder( + store: &dyn Store, + user_id: &str, + folder_id: Option<&str>, +) -> Result, topcoat::Error> { + let Some(id) = folder_id.filter(|id| !id.is_empty()) else { + return Ok(None); + }; + let Ok(Some(folder)) = store.folder(id).await else { + return Ok(None); + }; + if folder.owner_id == user_id || folder.deleted_at.is_some() { + return Ok(None); + } + // Unreachable while any ancestor is trashed — the drive shows no path + // back into it, grant or no grant. Ancestors of a folder share its + // owner: moves never cross owners, so liveness is all that is checked. + let mut parent = folder.parent_id.clone(); + while let Some(id) = parent { + match store.folder(&id).await { + Ok(Some(next)) if next.deleted_at.is_none() => parent = next.parent_id.clone(), + _ => return Ok(None), + } + } + // The grant itself, looked up the one way the store answers it: a row + // on the folder or any live folder above it. + if !store + .can_see(ShareKind::Folder, id, user_id) + .await + .unwrap_or(false) + { + return Ok(None); + } + Ok(Some(folder)) +} + +/// The crumb trail a grantee follows: the open folder and its ancestors +/// while the grant still covers them, root-most first. It stops of itself +/// above the granted folder — that page is not the account's to open, so +/// the trail never names it. +async fn granted_crumbs(store: &dyn Store, user_id: &str, folder: &Folder) -> Vec { + let mut chain = Vec::new(); + let mut next = Some(folder.clone()); + while let Some(current) = next { + if !store + .can_see(ShareKind::Folder, ¤t.id, user_id) + .await + .unwrap_or(false) + { + break; + } + let parent = match ¤t.parent_id { + Some(id) => store.folder(id).await.ok().flatten(), + None => None, + }; + chain.push(current); + next = parent; + } + chain.reverse(); + chain +} + /// The breadcrumb path, root first, for the open folder. async fn breadcrumbs(store: &dyn Store, folder: Option<&Folder>) -> Vec { let mut chain = Vec::new(); @@ -469,7 +543,20 @@ async fn drive(cx: &Cx) -> Result { let caption = asked .as_deref() .map(|query| format!("{} “{query}”", t(language, Key::SearchResults))); - let current = current_folder(store.as_ref(), &user.id, wanted.as_deref()).await?; + let current = match current_folder(store.as_ref(), &user.id, wanted.as_deref()).await { + Ok(current) => current, + Err(error) => { + // Not one of the account's own folders — a folder grant may + // still open it, read-only: the view the shared page's folder + // rows link to. Anything else keeps the owner path's answer. + if let Some(folder) = + granted_folder(store.as_ref(), &user.id, wanted.as_deref()).await? + { + return drive_shared(cx, user.clone(), language, &store, folder, params).await; + } + return Err(error); + } + }; let crumbs = breadcrumbs(store.as_ref(), current.as_ref()).await; let mut listing = match store .list_children(&user.id, current.as_ref().map(|folder| folder.id.as_str())) @@ -883,6 +970,163 @@ async fn drive(cx: &Cx) -> Result { }.boxed()) } +/// `GET /drive?folder=` through a grant: the read-only browse where the +/// owner's drive would be. Everything the owner page mutates with is gone — +/// no + menu, no upload, no drop, no row options, no rename — and the trail +/// stops at the granted folder, because nothing above it is the account's +/// to open. Subfolder rows descend into the same address deeper, file rows +/// into the viewer, whose own grant checks gate every preview and download +/// as before. What the grant opens here is told plainly, the shared page's +/// chip: download, or view alone. +async fn drive_shared<'a>( + cx: &'a Cx, + user: User, + language: Lang, + store: &std::sync::Arc, + folder: Folder, + params: Option<&DriveQuery>, +) -> Result> { + // The listing controls keep working — read-only re-orderings of the + // same list, never a different surface. The search box does not: it + // ranges over the grantee's own library, not this one. + let sorting = params.and_then(|query| parse_sort(query.sort.as_deref())); + let kind = params + .map(|query| parse_kind(query.kind.as_deref())) + .unwrap_or(KindFilter::All); + let mut listing = match store + .list_children(&folder.owner_id, Some(&folder.id)) + .await + { + Ok(listing) => listing, + Err(_) => return Err(not_found().into()), + }; + if let Some((key, dir)) = sorting { + sort_folders(&mut listing.folders, key, dir); + sort_files(&mut listing.files, key, dir); + } + match kind { + KindFilter::All => {} + KindFilter::Folders => listing.files.clear(), + KindFilter::Files => listing.folders.clear(), + } + // The trail runs granted-root first and stops there, whatever depth the + // open folder sits at inside the granted subtree. + let crumbs = granted_crumbs(store.as_ref(), &user.id, &folder).await; + // The honest tell, the shared page's own chip: a grantee who can look + // but not take reads exactly that. + let may_download = store + .can_download(ShareKind::Folder, &folder.id, &user.id) + .await + .unwrap_or(false); + // The value the sort dropdown shows as selected: the parsed pair, or + // the visual default when the standing order is on. + let sort_value = sorting + .map(|(key, dir)| format!("{}:{}", key.as_str(), dir.as_str())) + .unwrap_or_else(|| "name:asc".to_string()); + + Ok(view! { + cx => + (topcoat::view::Child::new(topbar(cx, NavPage::Drive, &user, language).await?)) +
+

(folder.name.clone())

+

(format!( + "{} · {}", + t(language, Key::SharedWithYou), + crate::share::access_chip(language, may_download) + ))

+
+ if crumbs.len() > 1 { + + } +
+ + + if kind != KindFilter::All { + + } + +
+
+ + + if sorting.is_some() { + + } + +
+
+
+ if listing.folders.is_empty() && listing.files.is_empty() { +
+ +

(t(language, Key::SharedFolderEmpty))

+
+ } else { +
+ + + (t(language, Key::NameColumn)) + (t(language, Key::SizeColumn)) + (t(language, Key::ModifiedColumn)) + (t(language, Key::DownloadsLabel)) + + +
+ + } +
+
+ (topcoat::view::Child::new(crate::dropdown::dropdown_script(cx).await?)) + }.boxed()) +} + /// `GET /search`: the old address — a 303 to the drive's search box, keeping /// the query so old links land on their results. Nothing renders here. #[page("/search")] diff --git a/crates/in-web/src/files.rs b/crates/in-web/src/files.rs index c1d6021..6a4424f 100644 --- a/crates/in-web/src/files.rs +++ b/crates/in-web/src/files.rs @@ -500,7 +500,9 @@ fn is_archive_mime(mime: &str) -> bool { /// the media elements carry no save affordance (no download in the /// controls, no drag, no context menu — `viewer_guard_script`), the /// Download link shows only while the reader may download, and `?dl=1` -/// stays gated on the byte route. A trashed row previews for its owner +/// stays gated on the byte route. A view-only reader's page says so in +/// its chrome: viewing happens in the browser, and anything viewable +/// can be saved from the viewer. A trashed row previews for its owner /// alone, download-dead until restored. Documents (PDF, text) frame the /// bytes in the browser's own chrome, whose toolbar downloads — they /// preview only under the grant. Bytes for another owner's file answer @@ -569,6 +571,9 @@ async fn view_file(cx: &Cx) -> Result {

(topcoat::view::Child::new(entry_chip(cx, &file).await?)) (file.name.clone())

(meta)

+ if !may_download && file.owner_id != user.id { +

(t(language, Key::ViewOnlyNote))

+ }
// Media previews for every reader; documents only under the // download grant (their browser chrome saves the file). diff --git a/crates/in-web/src/i18n.rs b/crates/in-web/src/i18n.rs index 2b7dd06..f80e051 100644 --- a/crates/in-web/src/i18n.rs +++ b/crates/in-web/src/i18n.rs @@ -192,6 +192,7 @@ pub enum Key { ExpiresLabel, NeverExpires, ViewOnly, + ViewOnlyNote, NoLinks, ManageLinks, UiLabel, @@ -267,6 +268,9 @@ pub enum Key { Shared, LegacyLinkNote, RemintLink, + // Granted-folder browse. + SharedWithYou, + SharedFolderEmpty, } pub fn t(lang: Lang, key: Key) -> &'static str { @@ -387,7 +391,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str { CopyLinkOnce => "Copy it now. The full address also stays on your Share links panel.", ExpiresLabel => "Expires", NeverExpires => "Never", - ViewOnly => "View only: preview, no downloads", + ViewOnly => "View only", + ViewOnlyNote => "Viewing in the browser; anything viewable can be saved.", NoLinks => "No share links yet.", ManageLinks => "Share links", UiLabel => "Interface", @@ -448,6 +453,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str { "This link predates re-viewable addresses — revoke and mint a new one to carry it forward." } RemintLink => "Mint a new link", + SharedWithYou => "Shared with you", + SharedFolderEmpty => "Nothing has been shared in this folder yet.", ServiceKeysTitle => "Service keys", ServiceKeyName => "Name", ServiceKeyService => "Service", @@ -579,7 +586,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str { } ExpiresLabel => "Bitiş", NeverExpires => "Süresiz", - ViewOnly => "Yalnızca görüntüleme: önizleme, indirme yok", + ViewOnly => "Yalnızca görüntüleme", + ViewOnlyNote => "Tarayıcıda görüntülenir; görüntülenebilen her şey kaydedilebilir.", NoLinks => "Henüz paylaşım bağlantısı yok.", ManageLinks => "Paylaşım bağlantıları", UiLabel => "Arayüz", @@ -653,6 +661,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str { "Bu bağlantı, adreslerin yeniden görüntülenebildiği dönemden önce oluşturuldu — devam ettirmek için iptal edip yeni bir tane oluşturun." } RemintLink => "Yeni bağlantı oluştur", + SharedWithYou => "Seninle paylaşıldı", + SharedFolderEmpty => "Bu klasörde henüz paylaşılan bir şey yok.", }, } } diff --git a/crates/in-web/src/settings.rs b/crates/in-web/src/settings.rs index cd12fa5..472c6d0 100644 --- a/crates/in-web/src/settings.rs +++ b/crates/in-web/src/settings.rs @@ -762,6 +762,9 @@ async fn settings(cx: &Cx) -> Result { if link_names.is_empty() {

(t(language, Key::NoLinks))

} + if link_names.iter().any(|(link, _, _)| !link.can_download) { +

(t(language, Key::ViewOnlyNote))

+ } for (link, target_name, url) in &link_names {
(format!("{} · {}", t(language, if link.kind == ShareKind::Folder { Key::KindFolder } else { Key::KindFile }), target_name.clone())) diff --git a/crates/in-web/src/share.rs b/crates/in-web/src/share.rs index 052a7a1..c282b08 100644 --- a/crates/in-web/src/share.rs +++ b/crates/in-web/src/share.rs @@ -1170,7 +1170,7 @@ async fn file_card( if link.can_download {

(t(language, Key::Download))

} else { -

(t(language, Key::ViewOnly))

+

(format!("{} · {}", t(language, Key::ViewOnly), t(language, Key::ViewOnlyNote)))

} (topcoat::view::Child::new(media_player_script(cx).await?)) @@ -1251,6 +1251,9 @@ async fn folder_card(

(here.name.clone())

+ if !link.can_download { +

(t(language, Key::ViewOnlyNote))

+ } if rows.is_empty() {

(t(language, Key::EmptyFolder))

} @@ -1505,6 +1508,9 @@ async fn shared(cx: &Cx) -> Result {
+ if rows.iter().any(|row| !row.item.can_download) { +

(t(language, Key::ViewOnlyNote))

+ }
if rows.is_empty() {
@@ -1558,7 +1564,7 @@ async fn shared(cx: &Cx) -> Result { } /// What the grant opens: the download, or the view alone. -fn access_chip(language: Lang, can_download: bool) -> &'static str { +pub(crate) fn access_chip(language: Lang, can_download: bool) -> &'static str { if can_download { t(language, Key::CanDownload) } else { @@ -1626,7 +1632,9 @@ pub(crate) async fn share_modal<'a>( link.kind == kind && link.target_id == target_id && link.revoked_at.is_none() - && link.expires_at.is_none_or(|at| at > OffsetDateTime::now_utc()) + && link + .expires_at + .is_none_or(|at| at > OffsetDateTime::now_utc()) }) .collect(); let grants = match store.shares_for_target(&user.id, kind, target_id).await { @@ -1742,6 +1750,7 @@ pub(crate) async fn share_modal<'a>( +