in: grant-scoped read-only folder browse + honest view-only copy
Browse files at this commit78bdc8cd1af91344cb0047a92d4d807120678f24Parent: 3133ade6 changed files +641 -17
- crates/in-web/src/drive.rs +248 -4
- crates/in-web/src/files.rs +6 -1
- crates/in-web/src/i18n.rs +12 -2
- crates/in-web/src/settings.rs +3 -0
- crates/in-web/src/share.rs +13 -3
- crates/in-web/tests/http.rs +359 -7
crates/in-web/src/drive.rsmodified+248 -4
| @@ -8,6 +8,11 @@ | |||
| 8 | //! itself is refused. Anything naming another owner's tree answers 404, | 8 | //! itself is refused. Anything naming another owner's tree answers 404, |
| 9 | //! never 403. | 9 | //! never 403. |
| 10 | //! | 10 | //! |
| 11 | +//! A folder opened by grant renders read-only at the same address for the | ||
| 12 | +//! grantee: the listing loses every write affordance, the trail stops at | ||
| 13 | +//! the granted folder, and anything the grant does not cover answers the | ||
| 14 | +//! same 404 a stranger's tree does. | ||
| 15 | +//! | ||
| 11 | //! `GET /drive?q=<text>` keeps the same page and swaps the folder list | 16 | //! `GET /drive?q=<text>` keeps the same page and swaps the folder list |
| 12 | //! for library-wide name hits — the filterbar's search box, submitted as a | 17 | //! for library-wide name hits — the filterbar's search box, submitted as a |
| 13 | //! plain GET form. The old `GET /search?q=` address 303s here, so old links | 18 | //! plain GET form. The old `GET /search?q=` address 303s here, so old links |
| @@ -15,7 +20,7 @@ | |||
| 15 | 20 | ||
| 16 | use std::collections::HashSet; | 21 | use std::collections::HashSet; |
| 17 | 22 | ||
| 18 | -use in_core::store::{Folder, ShareKind, Store, StoreError}; | 23 | +use in_core::store::{Folder, ShareKind, Store, StoreError, User}; |
| 19 | use topcoat::router::request::uri; | 24 | use topcoat::router::request::uri; |
| 20 | use topcoat::router::{HeaderName, HeaderValue, StatusCode, header, page, query_params, route}; | 25 | use topcoat::router::{HeaderName, HeaderValue, StatusCode, header, page, query_params, route}; |
| 21 | 26 | ||
| @@ -23,9 +28,9 @@ use topcoat::Result; | |||
| 23 | use topcoat::context::Cx; | 28 | use topcoat::context::Cx; |
| 24 | use topcoat::router::content::{Form, Json}; | 29 | use topcoat::router::content::{Form, Json}; |
| 25 | use topcoat::router::error::not_found; | 30 | use topcoat::router::error::not_found; |
| 26 | -use topcoat::view::{View, ViewExt, view}; | 31 | +use topcoat::view::{BoxView, View, ViewExt, view}; |
| 27 | 32 | ||
| 28 | -use crate::i18n::{Key, lang, t}; | 33 | +use crate::i18n::{Key, Lang, lang, t}; |
| 29 | use crate::layout::{NavPage, topbar}; | 34 | use crate::layout::{NavPage, topbar}; |
| 30 | use crate::server::{Refusal, app, back_to, refusal_of, require_user, share_origin}; | 35 | use crate::server::{Refusal, app, back_to, refusal_of, require_user, share_origin}; |
| 31 | 36 | ||
| @@ -99,6 +104,75 @@ async fn current_folder( | |||
| 99 | Ok(Some(folder)) | 104 | Ok(Some(folder)) |
| 100 | } | 105 | } |
| 101 | 106 | ||
| 107 | +/// The folder the query names for a grantee: not one of the account's own, | ||
| 108 | +/// but one a live folder grant covers — the grant may sit on the folder | ||
| 109 | +/// itself or on any live folder above it, the same chain the file pages | ||
| 110 | +/// ride. The owner's reachability rule holds unchanged: the folder and | ||
| 111 | +/// every ancestor must be live, or the address is not found. `None` — | ||
| 112 | +/// never an error — leaves the caller answering the plain 404, so a | ||
| 113 | +/// stranger learns nothing about which ids exist. | ||
| 114 | +async fn granted_folder( | ||
| 115 | + store: &dyn Store, | ||
| 116 | + user_id: &str, | ||
| 117 | + folder_id: Option<&str>, | ||
| 118 | +) -> Result<Option<Folder>, topcoat::Error> { | ||
| 119 | + let Some(id) = folder_id.filter(|id| !id.is_empty()) else { | ||
| 120 | + return Ok(None); | ||
| 121 | + }; | ||
| 122 | + let Ok(Some(folder)) = store.folder(id).await else { | ||
| 123 | + return Ok(None); | ||
| 124 | + }; | ||
| 125 | + if folder.owner_id == user_id || folder.deleted_at.is_some() { | ||
| 126 | + return Ok(None); | ||
| 127 | + } | ||
| 128 | + // Unreachable while any ancestor is trashed — the drive shows no path | ||
| 129 | + // back into it, grant or no grant. Ancestors of a folder share its | ||
| 130 | + // owner: moves never cross owners, so liveness is all that is checked. | ||
| 131 | + let mut parent = folder.parent_id.clone(); | ||
| 132 | + while let Some(id) = parent { | ||
| 133 | + match store.folder(&id).await { | ||
| 134 | + Ok(Some(next)) if next.deleted_at.is_none() => parent = next.parent_id.clone(), | ||
| 135 | + _ => return Ok(None), | ||
| 136 | + } | ||
| 137 | + } | ||
| 138 | + // The grant itself, looked up the one way the store answers it: a row | ||
| 139 | + // on the folder or any live folder above it. | ||
| 140 | + if !store | ||
| 141 | + .can_see(ShareKind::Folder, id, user_id) | ||
| 142 | + .await | ||
| 143 | + .unwrap_or(false) | ||
| 144 | + { | ||
| 145 | + return Ok(None); | ||
| 146 | + } | ||
| 147 | + Ok(Some(folder)) | ||
| 148 | +} | ||
| 149 | + | ||
| 150 | +/// The crumb trail a grantee follows: the open folder and its ancestors | ||
| 151 | +/// while the grant still covers them, root-most first. It stops of itself | ||
| 152 | +/// above the granted folder — that page is not the account's to open, so | ||
| 153 | +/// the trail never names it. | ||
| 154 | +async fn granted_crumbs(store: &dyn Store, user_id: &str, folder: &Folder) -> Vec<Folder> { | ||
| 155 | + let mut chain = Vec::new(); | ||
| 156 | + let mut next = Some(folder.clone()); | ||
| 157 | + while let Some(current) = next { | ||
| 158 | + if !store | ||
| 159 | + .can_see(ShareKind::Folder, ¤t.id, user_id) | ||
| 160 | + .await | ||
| 161 | + .unwrap_or(false) | ||
| 162 | + { | ||
| 163 | + break; | ||
| 164 | + } | ||
| 165 | + let parent = match ¤t.parent_id { | ||
| 166 | + Some(id) => store.folder(id).await.ok().flatten(), | ||
| 167 | + None => None, | ||
| 168 | + }; | ||
| 169 | + chain.push(current); | ||
| 170 | + next = parent; | ||
| 171 | + } | ||
| 172 | + chain.reverse(); | ||
| 173 | + chain | ||
| 174 | +} | ||
| 175 | + | ||
| 102 | /// The breadcrumb path, root first, for the open folder. | 176 | /// The breadcrumb path, root first, for the open folder. |
| 103 | async fn breadcrumbs(store: &dyn Store, folder: Option<&Folder>) -> Vec<Folder> { | 177 | async fn breadcrumbs(store: &dyn Store, folder: Option<&Folder>) -> Vec<Folder> { |
| 104 | let mut chain = Vec::new(); | 178 | let mut chain = Vec::new(); |
| @@ -469,7 +543,20 @@ async fn drive(cx: &Cx) -> Result<impl View> { | |||
| 469 | let caption = asked | 543 | let caption = asked |
| 470 | .as_deref() | 544 | .as_deref() |
| 471 | .map(|query| format!("{} “{query}”", t(language, Key::SearchResults))); | 545 | .map(|query| format!("{} “{query}”", t(language, Key::SearchResults))); |
| 472 | - let current = current_folder(store.as_ref(), &user.id, wanted.as_deref()).await?; | 546 | + let current = match current_folder(store.as_ref(), &user.id, wanted.as_deref()).await { |
| 547 | + Ok(current) => current, | ||
| 548 | + Err(error) => { | ||
| 549 | + // Not one of the account's own folders — a folder grant may | ||
| 550 | + // still open it, read-only: the view the shared page's folder | ||
| 551 | + // rows link to. Anything else keeps the owner path's answer. | ||
| 552 | + if let Some(folder) = | ||
| 553 | + granted_folder(store.as_ref(), &user.id, wanted.as_deref()).await? | ||
| 554 | + { | ||
| 555 | + return drive_shared(cx, user.clone(), language, &store, folder, params).await; | ||
| 556 | + } | ||
| 557 | + return Err(error); | ||
| 558 | + } | ||
| 559 | + }; | ||
| 473 | let crumbs = breadcrumbs(store.as_ref(), current.as_ref()).await; | 560 | let crumbs = breadcrumbs(store.as_ref(), current.as_ref()).await; |
| 474 | let mut listing = match store | 561 | let mut listing = match store |
| 475 | .list_children(&user.id, current.as_ref().map(|folder| folder.id.as_str())) | 562 | .list_children(&user.id, current.as_ref().map(|folder| folder.id.as_str())) |
| @@ -883,6 +970,163 @@ async fn drive(cx: &Cx) -> Result<impl View> { | |||
| 883 | }.boxed()) | 970 | }.boxed()) |
| 884 | } | 971 | } |
| 885 | 972 | ||
| 973 | +/// `GET /drive?folder=<id>` through a grant: the read-only browse where the | ||
| 974 | +/// owner's drive would be. Everything the owner page mutates with is gone — | ||
| 975 | +/// no + menu, no upload, no drop, no row options, no rename — and the trail | ||
| 976 | +/// stops at the granted folder, because nothing above it is the account's | ||
| 977 | +/// to open. Subfolder rows descend into the same address deeper, file rows | ||
| 978 | +/// into the viewer, whose own grant checks gate every preview and download | ||
| 979 | +/// as before. What the grant opens here is told plainly, the shared page's | ||
| 980 | +/// chip: download, or view alone. | ||
| 981 | +async fn drive_shared<'a>( | ||
| 982 | + cx: &'a Cx, | ||
| 983 | + user: User, | ||
| 984 | + language: Lang, | ||
| 985 | + store: &std::sync::Arc<dyn Store>, | ||
| 986 | + folder: Folder, | ||
| 987 | + params: Option<&DriveQuery>, | ||
| 988 | +) -> Result<BoxView<'a>> { | ||
| 989 | + // The listing controls keep working — read-only re-orderings of the | ||
| 990 | + // same list, never a different surface. The search box does not: it | ||
| 991 | + // ranges over the grantee's own library, not this one. | ||
| 992 | + let sorting = params.and_then(|query| parse_sort(query.sort.as_deref())); | ||
| 993 | + let kind = params | ||
| 994 | + .map(|query| parse_kind(query.kind.as_deref())) | ||
| 995 | + .unwrap_or(KindFilter::All); | ||
| 996 | + let mut listing = match store | ||
| 997 | + .list_children(&folder.owner_id, Some(&folder.id)) | ||
| 998 | + .await | ||
| 999 | + { | ||
| 1000 | + Ok(listing) => listing, | ||
| 1001 | + Err(_) => return Err(not_found().into()), | ||
| 1002 | + }; | ||
| 1003 | + if let Some((key, dir)) = sorting { | ||
| 1004 | + sort_folders(&mut listing.folders, key, dir); | ||
| 1005 | + sort_files(&mut listing.files, key, dir); | ||
| 1006 | + } | ||
| 1007 | + match kind { | ||
| 1008 | + KindFilter::All => {} | ||
| 1009 | + KindFilter::Folders => listing.files.clear(), | ||
| 1010 | + KindFilter::Files => listing.folders.clear(), | ||
| 1011 | + } | ||
| 1012 | + // The trail runs granted-root first and stops there, whatever depth the | ||
| 1013 | + // open folder sits at inside the granted subtree. | ||
| 1014 | + let crumbs = granted_crumbs(store.as_ref(), &user.id, &folder).await; | ||
| 1015 | + // The honest tell, the shared page's own chip: a grantee who can look | ||
| 1016 | + // but not take reads exactly that. | ||
| 1017 | + let may_download = store | ||
| 1018 | + .can_download(ShareKind::Folder, &folder.id, &user.id) | ||
| 1019 | + .await | ||
| 1020 | + .unwrap_or(false); | ||
| 1021 | + // The value the sort dropdown shows as selected: the parsed pair, or | ||
| 1022 | + // the visual default when the standing order is on. | ||
| 1023 | + let sort_value = sorting | ||
| 1024 | + .map(|(key, dir)| format!("{}:{}", key.as_str(), dir.as_str())) | ||
| 1025 | + .unwrap_or_else(|| "name:asc".to_string()); | ||
| 1026 | + | ||
| 1027 | + Ok(view! { | ||
| 1028 | + cx => | ||
| 1029 | + (topcoat::view::Child::new(topbar(cx, NavPage::Drive, &user, language).await?)) | ||
| 1030 | + <main class="settings-stage stage-wide"> | ||
| 1031 | + <h1 class="settings-title">(folder.name.clone())</h1> | ||
| 1032 | + <p class="field-note">(format!( | ||
| 1033 | + "{} · {}", | ||
| 1034 | + t(language, Key::SharedWithYou), | ||
| 1035 | + crate::share::access_chip(language, may_download) | ||
| 1036 | + ))</p> | ||
| 1037 | + <div class="filterbar drive-bar"> | ||
| 1038 | + if crumbs.len() > 1 { | ||
| 1039 | + <nav class="detail-crumbs" aria-label=(folder.name.clone())> | ||
| 1040 | + for (index, crumb) in crumbs.iter().enumerate() { | ||
| 1041 | + if index > 0 { | ||
| 1042 | + <span class="detail-crumb-sep">"/"</span> | ||
| 1043 | + } | ||
| 1044 | + <a class="detail-crumb" href=(format!("/drive?folder={}", crumb.id))>(crumb.name.clone())</a> | ||
| 1045 | + } | ||
| 1046 | + </nav> | ||
| 1047 | + } | ||
| 1048 | + <form class="field-box field-box-sort" method="get" action="/drive"> | ||
| 1049 | + <select class="status-select" name="sort" data-autosubmit="" aria-label=(t(language, Key::Sort))> | ||
| 1050 | + <option value="name:asc" selected=(sort_value == "name:asc")>(t(language, Key::SortNameAZ))</option> | ||
| 1051 | + <option value="name:desc" selected=(sort_value == "name:desc")>(t(language, Key::SortNameZA))</option> | ||
| 1052 | + <option value="uploaded:desc" selected=(sort_value == "uploaded:desc")>(t(language, Key::SortNewest))</option> | ||
| 1053 | + <option value="uploaded:asc" selected=(sort_value == "uploaded:asc")>(t(language, Key::SortOldest))</option> | ||
| 1054 | + <option value="size:desc" selected=(sort_value == "size:desc")>(t(language, Key::SortLargest))</option> | ||
| 1055 | + <option value="size:asc" selected=(sort_value == "size:asc")>(t(language, Key::SortSmallest))</option> | ||
| 1056 | + <option value="downloads:desc" selected=(sort_value == "downloads:desc")>(t(language, Key::SortMostDownloads))</option> | ||
| 1057 | + <option value="downloads:asc" selected=(sort_value == "downloads:asc")>(t(language, Key::SortLeastDownloads))</option> | ||
| 1058 | + </select> | ||
| 1059 | + <input type="hidden" name="folder" value=(folder.id.clone())> | ||
| 1060 | + if kind != KindFilter::All { | ||
| 1061 | + <input type="hidden" name="kind" value=(kind.as_str())> | ||
| 1062 | + } | ||
| 1063 | + <button class="quiet" type="submit" aria-label=(t(language, Key::Sort))>"→"</button> | ||
| 1064 | + </form> | ||
| 1065 | + <form class="field-box field-box-sort" method="get" action="/drive"> | ||
| 1066 | + <select class="status-select" name="kind" data-autosubmit="" aria-label=(t(language, Key::Kind))> | ||
| 1067 | + <option value="all" selected=(kind == KindFilter::All)>(t(language, Key::KindAll))</option> | ||
| 1068 | + <option value="folders" selected=(kind == KindFilter::Folders)>(t(language, Key::KindFolders))</option> | ||
| 1069 | + <option value="files" selected=(kind == KindFilter::Files)>(t(language, Key::KindFiles))</option> | ||
| 1070 | + </select> | ||
| 1071 | + <input type="hidden" name="folder" value=(folder.id.clone())> | ||
| 1072 | + if sorting.is_some() { | ||
| 1073 | + <input type="hidden" name="sort" value=(sort_value.clone())> | ||
| 1074 | + } | ||
| 1075 | + <button class="quiet" type="submit" aria-label=(t(language, Key::Kind))>"→"</button> | ||
| 1076 | + </form> | ||
| 1077 | + </div> | ||
| 1078 | + <section class="panel drive-panel"> | ||
| 1079 | + if listing.folders.is_empty() && listing.files.is_empty() { | ||
| 1080 | + <div class="drive-empty"> | ||
| 1081 | + <span class="drive-empty-glyph" aria-hidden="true">"▤"</span> | ||
| 1082 | + <p class="drive-empty-text">(t(language, Key::SharedFolderEmpty))</p> | ||
| 1083 | + </div> | ||
| 1084 | + } else { | ||
| 1085 | + <div class="drive-head"> | ||
| 1086 | + <span class="drive-cols"> | ||
| 1087 | + <span class="drive-col-ico" aria-hidden="true"></span> | ||
| 1088 | + <span>(t(language, Key::NameColumn))</span> | ||
| 1089 | + <span class="drive-col-num drive-col-size">(t(language, Key::SizeColumn))</span> | ||
| 1090 | + <span class="drive-col-date">(t(language, Key::ModifiedColumn))</span> | ||
| 1091 | + <span class="drive-col-num drive-col-dl">(t(language, Key::DownloadsLabel))</span> | ||
| 1092 | + </span> | ||
| 1093 | + <span class="drive-head-options" aria-hidden="true"></span> | ||
| 1094 | + </div> | ||
| 1095 | + <div class="drive-list"> | ||
| 1096 | + for child in listing.folders.iter() { | ||
| 1097 | + <div class="drive-row"> | ||
| 1098 | + <a class="drive-open" href=(format!("/drive?folder={}", child.id))> | ||
| 1099 | + <span class="file-chip file-chip-folder" aria-hidden="true">"▤"</span> | ||
| 1100 | + <span class="dep-name-cell"> | ||
| 1101 | + <span class="dep-title">(child.name.clone())</span> | ||
| 1102 | + </span> | ||
| 1103 | + <span class="drive-meta" aria-hidden="true"></span> | ||
| 1104 | + <span class="drive-meta drive-date">(child.created_at.date().to_string())</span> | ||
| 1105 | + <span class="drive-meta" aria-hidden="true"></span> | ||
| 1106 | + </a> | ||
| 1107 | + </div> | ||
| 1108 | + } | ||
| 1109 | + for file in listing.files.iter() { | ||
| 1110 | + <div class="drive-row"> | ||
| 1111 | + <a class="drive-open" href=(format!("/view/{}", file.id))> | ||
| 1112 | + (topcoat::view::Child::new(crate::files::entry_chip(cx, file).await?)) | ||
| 1113 | + <span class="dep-name-cell"> | ||
| 1114 | + <span class="dep-title">(file.name.clone())</span> | ||
| 1115 | + </span> | ||
| 1116 | + <span class="drive-meta drive-size">(human_size(file.size_bytes))</span> | ||
| 1117 | + <span class="drive-meta drive-date">(file.created_at.date().to_string())</span> | ||
| 1118 | + <span class="drive-meta drive-dl">(file.download_count.to_string())</span> | ||
| 1119 | + </a> | ||
| 1120 | + </div> | ||
| 1121 | + } | ||
| 1122 | + </div> | ||
| 1123 | + } | ||
| 1124 | + </section> | ||
| 1125 | + </main> | ||
| 1126 | + (topcoat::view::Child::new(crate::dropdown::dropdown_script(cx).await?)) | ||
| 1127 | + }.boxed()) | ||
| 1128 | +} | ||
| 1129 | + | ||
| 886 | /// `GET /search`: the old address — a 303 to the drive's search box, keeping | 1130 | /// `GET /search`: the old address — a 303 to the drive's search box, keeping |
| 887 | /// the query so old links land on their results. Nothing renders here. | 1131 | /// the query so old links land on their results. Nothing renders here. |
| 888 | #[page("/search")] | 1132 | #[page("/search")] |
crates/in-web/src/files.rsmodified+6 -1
| @@ -500,7 +500,9 @@ fn is_archive_mime(mime: &str) -> bool { | |||
| 500 | /// the media elements carry no save affordance (no download in the | 500 | /// the media elements carry no save affordance (no download in the |
| 501 | /// controls, no drag, no context menu — `viewer_guard_script`), the | 501 | /// controls, no drag, no context menu — `viewer_guard_script`), the |
| 502 | /// Download link shows only while the reader may download, and `?dl=1` | 502 | /// Download link shows only while the reader may download, and `?dl=1` |
| 503 | -/// stays gated on the byte route. A trashed row previews for its owner | 503 | +/// stays gated on the byte route. A view-only reader's page says so in |
| 504 | +/// its chrome: viewing happens in the browser, and anything viewable | ||
| 505 | +/// can be saved from the viewer. A trashed row previews for its owner | ||
| 504 | /// alone, download-dead until restored. Documents (PDF, text) frame the | 506 | /// alone, download-dead until restored. Documents (PDF, text) frame the |
| 505 | /// bytes in the browser's own chrome, whose toolbar downloads — they | 507 | /// bytes in the browser's own chrome, whose toolbar downloads — they |
| 506 | /// preview only under the grant. Bytes for another owner's file answer | 508 | /// preview only under the grant. Bytes for another owner's file answer |
| @@ -569,6 +571,9 @@ async fn view_file(cx: &Cx) -> Result<impl View> { | |||
| 569 | </div> | 571 | </div> |
| 570 | <h1 class="settings-title viewer-title">(topcoat::view::Child::new(entry_chip(cx, &file).await?)) (file.name.clone())</h1> | 572 | <h1 class="settings-title viewer-title">(topcoat::view::Child::new(entry_chip(cx, &file).await?)) (file.name.clone())</h1> |
| 571 | <p class="field-note">(meta)</p> | 573 | <p class="field-note">(meta)</p> |
| 574 | + if !may_download && file.owner_id != user.id { | ||
| 575 | + <p class="field-note">(t(language, Key::ViewOnlyNote))</p> | ||
| 576 | + } | ||
| 572 | <div class="viewer-stage"> | 577 | <div class="viewer-stage"> |
| 573 | // Media previews for every reader; documents only under the | 578 | // Media previews for every reader; documents only under the |
| 574 | // download grant (their browser chrome saves the file). | 579 | // download grant (their browser chrome saves the file). |
crates/in-web/src/i18n.rsmodified+12 -2
| @@ -192,6 +192,7 @@ pub enum Key { | |||
| 192 | ExpiresLabel, | 192 | ExpiresLabel, |
| 193 | NeverExpires, | 193 | NeverExpires, |
| 194 | ViewOnly, | 194 | ViewOnly, |
| 195 | + ViewOnlyNote, | ||
| 195 | NoLinks, | 196 | NoLinks, |
| 196 | ManageLinks, | 197 | ManageLinks, |
| 197 | UiLabel, | 198 | UiLabel, |
| @@ -267,6 +268,9 @@ pub enum Key { | |||
| 267 | Shared, | 268 | Shared, |
| 268 | LegacyLinkNote, | 269 | LegacyLinkNote, |
| 269 | RemintLink, | 270 | RemintLink, |
| 271 | + // Granted-folder browse. | ||
| 272 | + SharedWithYou, | ||
| 273 | + SharedFolderEmpty, | ||
| 270 | } | 274 | } |
| 271 | 275 | ||
| 272 | pub fn t(lang: Lang, key: Key) -> &'static str { | 276 | pub fn t(lang: Lang, key: Key) -> &'static str { |
| @@ -387,7 +391,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | |||
| 387 | CopyLinkOnce => "Copy it now. The full address also stays on your Share links panel.", | 391 | CopyLinkOnce => "Copy it now. The full address also stays on your Share links panel.", |
| 388 | ExpiresLabel => "Expires", | 392 | ExpiresLabel => "Expires", |
| 389 | NeverExpires => "Never", | 393 | NeverExpires => "Never", |
| 390 | - ViewOnly => "View only: preview, no downloads", | 394 | + ViewOnly => "View only", |
| 395 | + ViewOnlyNote => "Viewing in the browser; anything viewable can be saved.", | ||
| 391 | NoLinks => "No share links yet.", | 396 | NoLinks => "No share links yet.", |
| 392 | ManageLinks => "Share links", | 397 | ManageLinks => "Share links", |
| 393 | UiLabel => "Interface", | 398 | UiLabel => "Interface", |
| @@ -448,6 +453,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | |||
| 448 | "This link predates re-viewable addresses — revoke and mint a new one to carry it forward." | 453 | "This link predates re-viewable addresses — revoke and mint a new one to carry it forward." |
| 449 | } | 454 | } |
| 450 | RemintLink => "Mint a new link", | 455 | RemintLink => "Mint a new link", |
| 456 | + SharedWithYou => "Shared with you", | ||
| 457 | + SharedFolderEmpty => "Nothing has been shared in this folder yet.", | ||
| 451 | ServiceKeysTitle => "Service keys", | 458 | ServiceKeysTitle => "Service keys", |
| 452 | ServiceKeyName => "Name", | 459 | ServiceKeyName => "Name", |
| 453 | ServiceKeyService => "Service", | 460 | ServiceKeyService => "Service", |
| @@ -579,7 +586,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | |||
| 579 | } | 586 | } |
| 580 | ExpiresLabel => "Bitiş", | 587 | ExpiresLabel => "Bitiş", |
| 581 | NeverExpires => "Süresiz", | 588 | NeverExpires => "Süresiz", |
| 582 | - ViewOnly => "Yalnızca görüntüleme: önizleme, indirme yok", | 589 | + ViewOnly => "Yalnızca görüntüleme", |
| 590 | + ViewOnlyNote => "Tarayıcıda görüntülenir; görüntülenebilen her şey kaydedilebilir.", | ||
| 583 | NoLinks => "Henüz paylaşım bağlantısı yok.", | 591 | NoLinks => "Henüz paylaşım bağlantısı yok.", |
| 584 | ManageLinks => "Paylaşım bağlantıları", | 592 | ManageLinks => "Paylaşım bağlantıları", |
| 585 | UiLabel => "Arayüz", | 593 | UiLabel => "Arayüz", |
| @@ -653,6 +661,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | |||
| 653 | "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." | 661 | "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." |
| 654 | } | 662 | } |
| 655 | RemintLink => "Yeni bağlantı oluştur", | 663 | RemintLink => "Yeni bağlantı oluştur", |
| 664 | + SharedWithYou => "Seninle paylaşıldı", | ||
| 665 | + SharedFolderEmpty => "Bu klasörde henüz paylaşılan bir şey yok.", | ||
| 656 | }, | 666 | }, |
| 657 | } | 667 | } |
| 658 | } | 668 | } |
crates/in-web/src/settings.rsmodified+3 -0
| @@ -762,6 +762,9 @@ async fn settings(cx: &Cx) -> Result<impl View> { | |||
| 762 | if link_names.is_empty() { | 762 | if link_names.is_empty() { |
| 763 | <p class="field-note">(t(language, Key::NoLinks))</p> | 763 | <p class="field-note">(t(language, Key::NoLinks))</p> |
| 764 | } | 764 | } |
| 765 | + if link_names.iter().any(|(link, _, _)| !link.can_download) { | ||
| 766 | + <p class="field-note">(t(language, Key::ViewOnlyNote))</p> | ||
| 767 | + } | ||
| 765 | for (link, target_name, url) in &link_names { | 768 | for (link, target_name, url) in &link_names { |
| 766 | <div class="member-row"> | 769 | <div class="member-row"> |
| 767 | <span class="member-name">(format!("{} · {}", t(language, if link.kind == ShareKind::Folder { Key::KindFolder } else { Key::KindFile }), target_name.clone()))</span> | 770 | <span class="member-name">(format!("{} · {}", t(language, if link.kind == ShareKind::Folder { Key::KindFolder } else { Key::KindFile }), target_name.clone()))</span> |
crates/in-web/src/share.rsmodified+13 -3
| @@ -1170,7 +1170,7 @@ async fn file_card( | |||
| 1170 | if link.can_download { | 1170 | if link.can_download { |
| 1171 | <p><a class="primary" href=(format!("{token_path}?dl=1"))>(t(language, Key::Download))</a></p> | 1171 | <p><a class="primary" href=(format!("{token_path}?dl=1"))>(t(language, Key::Download))</a></p> |
| 1172 | } else { | 1172 | } else { |
| 1173 | - <p class="field-note">(t(language, Key::ViewOnly))</p> | 1173 | + <p class="field-note">(format!("{} · {}", t(language, Key::ViewOnly), t(language, Key::ViewOnlyNote)))</p> |
| 1174 | } | 1174 | } |
| 1175 | </main> | 1175 | </main> |
| 1176 | (topcoat::view::Child::new(media_player_script(cx).await?)) | 1176 | (topcoat::view::Child::new(media_player_script(cx).await?)) |
| @@ -1251,6 +1251,9 @@ async fn folder_card( | |||
| 1251 | <h1 class="settings-title">(here.name.clone())</h1> | 1251 | <h1 class="settings-title">(here.name.clone())</h1> |
| 1252 | <section class="panel"> | 1252 | <section class="panel"> |
| 1253 | <div class="panel-body"> | 1253 | <div class="panel-body"> |
| 1254 | + if !link.can_download { | ||
| 1255 | + <p class="field-note">(t(language, Key::ViewOnlyNote))</p> | ||
| 1256 | + } | ||
| 1254 | if rows.is_empty() { | 1257 | if rows.is_empty() { |
| 1255 | <p class="field-note">(t(language, Key::EmptyFolder))</p> | 1258 | <p class="field-note">(t(language, Key::EmptyFolder))</p> |
| 1256 | } | 1259 | } |
| @@ -1505,6 +1508,9 @@ async fn shared(cx: &Cx) -> Result<impl View> { | |||
| 1505 | <input type="hidden" name="q" value=(box_text.clone())> | 1508 | <input type="hidden" name="q" value=(box_text.clone())> |
| 1506 | </form> | 1509 | </form> |
| 1507 | </div> | 1510 | </div> |
| 1511 | + if rows.iter().any(|row| !row.item.can_download) { | ||
| 1512 | + <p class="field-note">(t(language, Key::ViewOnlyNote))</p> | ||
| 1513 | + } | ||
| 1508 | <section class="panel drive-panel drive-owner"> | 1514 | <section class="panel drive-panel drive-owner"> |
| 1509 | if rows.is_empty() { | 1515 | if rows.is_empty() { |
| 1510 | <div class="drive-empty"> | 1516 | <div class="drive-empty"> |
| @@ -1558,7 +1564,7 @@ async fn shared(cx: &Cx) -> Result<impl View> { | |||
| 1558 | } | 1564 | } |
| 1559 | 1565 | ||
| 1560 | /// What the grant opens: the download, or the view alone. | 1566 | /// What the grant opens: the download, or the view alone. |
| 1561 | -fn access_chip(language: Lang, can_download: bool) -> &'static str { | 1567 | +pub(crate) fn access_chip(language: Lang, can_download: bool) -> &'static str { |
| 1562 | if can_download { | 1568 | if can_download { |
| 1563 | t(language, Key::CanDownload) | 1569 | t(language, Key::CanDownload) |
| 1564 | } else { | 1570 | } else { |
| @@ -1626,7 +1632,9 @@ pub(crate) async fn share_modal<'a>( | |||
| 1626 | link.kind == kind | 1632 | link.kind == kind |
| 1627 | && link.target_id == target_id | 1633 | && link.target_id == target_id |
| 1628 | && link.revoked_at.is_none() | 1634 | && link.revoked_at.is_none() |
| 1629 | - && link.expires_at.is_none_or(|at| at > OffsetDateTime::now_utc()) | 1635 | + && link |
| 1636 | + .expires_at | ||
| 1637 | + .is_none_or(|at| at > OffsetDateTime::now_utc()) | ||
| 1630 | }) | 1638 | }) |
| 1631 | .collect(); | 1639 | .collect(); |
| 1632 | let grants = match store.shares_for_target(&user.id, kind, target_id).await { | 1640 | let grants = match store.shares_for_target(&user.id, kind, target_id).await { |
| @@ -1742,6 +1750,7 @@ pub(crate) async fn share_modal<'a>( | |||
| 1742 | </select> | 1750 | </select> |
| 1743 | <button class="quiet" type="submit">(t(language, Key::Share))</button> | 1751 | <button class="quiet" type="submit">(t(language, Key::Share))</button> |
| 1744 | </form> | 1752 | </form> |
| 1753 | + <p class="field-note share-modal-note">(t(language, Key::ViewOnlyNote))</p> | ||
| 1745 | <p class="share-section">(t(language, Key::WhoHasAccess))</p> | 1754 | <p class="share-section">(t(language, Key::WhoHasAccess))</p> |
| 1746 | <div class="member-row share-owner"> | 1755 | <div class="member-row share-owner"> |
| 1747 | <span class="member-name">(format!("{} {}", user.display_name.clone(), t(language, Key::YouSuffix)))</span> | 1756 | <span class="member-name">(format!("{} {}", user.display_name.clone(), t(language, Key::YouSuffix)))</span> |
| @@ -1778,6 +1787,7 @@ pub(crate) async fn share_modal<'a>( | |||
| 1778 | <input class="field-input share-expiry" type="password" name="password" autocomplete="new-password" placeholder=(t(language, Key::PasswordOptional)) aria-label=(t(language, Key::PasswordOptional))> | 1787 | <input class="field-input share-expiry" type="password" name="password" autocomplete="new-password" placeholder=(t(language, Key::PasswordOptional)) aria-label=(t(language, Key::PasswordOptional))> |
| 1779 | <button class="quiet" type="submit">(t(language, Key::CreateLink))</button> | 1788 | <button class="quiet" type="submit">(t(language, Key::CreateLink))</button> |
| 1780 | </form> | 1789 | </form> |
| 1790 | + <p class="field-note share-modal-note">(t(language, Key::ViewOnlyNote))</p> | ||
| 1781 | } | 1791 | } |
| 1782 | for link in live.iter().take(1) { | 1792 | for link in live.iter().take(1) { |
| 1783 | // away. A link from before the sealing — or one whose key is gone — | 1793 | // away. A link from before the sealing — or one whose key is gone — |
crates/in-web/tests/http.rsmodified+359 -7
| @@ -2864,6 +2864,29 @@ async fn view_only_reader_previews_media_but_cannot_download() { | |||
| 2864 | assert!(page.text().contains("viewer-media"), "{}", page.text()); | 2864 | assert!(page.text().contains("viewer-media"), "{}", page.text()); |
| 2865 | assert!(!page.text().contains("No preview"), "{}", page.text()); | 2865 | assert!(!page.text().contains("No preview"), "{}", page.text()); |
| 2866 | assert!(!page.text().contains("?dl=1"), "{}", page.text()); | 2866 | assert!(!page.text().contains("?dl=1"), "{}", page.text()); |
| 2867 | + // The chrome names the grant honestly — viewing in the browser, | ||
| 2868 | + // anything viewable savable — and the retired "no downloads" claim | ||
| 2869 | + // is gone. | ||
| 2870 | + assert!( | ||
| 2871 | + page.text().contains("anything viewable can be saved"), | ||
| 2872 | + "{}", | ||
| 2873 | + page.text() | ||
| 2874 | + ); | ||
| 2875 | + assert!( | ||
| 2876 | + !page.text().contains("preview, no downloads"), | ||
| 2877 | + "{}", | ||
| 2878 | + page.text() | ||
| 2879 | + ); | ||
| 2880 | + // The owner's own viewer names no grant: the note is for the reader | ||
| 2881 | + // the grant limits. | ||
| 2882 | + let own = app.get(&format!("/view/{file}"), Some(&admin)).await; | ||
| 2883 | + assert_eq!(own.status, StatusCode::OK, "{}", own.text()); | ||
| 2884 | + assert!( | ||
| 2885 | + !own.text().contains("anything viewable can be saved"), | ||
| 2886 | + "{}", | ||
| 2887 | + own.text() | ||
| 2888 | + ); | ||
| 2889 | + assert!(own.text().contains("?dl=1"), "{}", own.text()); | ||
| 2867 | // The back link names the origin: opened from the shared page (the | 2890 | // The back link names the origin: opened from the shared page (the |
| 2868 | // `from=shared` its rows carry) it returns there, a plain opening to | 2891 | // `from=shared` its rows carry) it returns there, a plain opening to |
| 2869 | // the drive. | 2892 | // the drive. |
| @@ -3338,7 +3361,10 @@ async fn the_family_flyout_marks_siblings_with_health_dots() { | |||
| 3338 | ); | 3361 | ); |
| 3339 | assert!(nav.contains(">im</a>"), "the dark sibling renders: {nav}"); | 3362 | assert!(nav.contains(">im</a>"), "the dark sibling renders: {nav}"); |
| 3340 | assert!(!nav.contains(">in</a>"), "in's own row stays out: {nav}"); | 3363 | assert!(!nav.contains(">in</a>"), "in's own row stays out: {nav}"); |
| 3341 | - assert!(!body.contains("ok dev"), "the flyout carries dots only: {body}"); | 3364 | + assert!( |
| 3365 | + !body.contains("ok dev"), | ||
| 3366 | + "the flyout carries dots only: {body}" | ||
| 3367 | + ); | ||
| 3342 | assert!(!nav.contains(" ms"), "the flyout carries no latency: {nav}"); | 3368 | assert!(!nav.contains(" ms"), "the flyout carries no latency: {nav}"); |
| 3343 | } | 3369 | } |
| 3344 | 3370 | ||
| @@ -3354,7 +3380,15 @@ fn the_family_flyout_marks_pure_html() { | |||
| 3354 | use in_web::health::Probe; | 3380 | use in_web::health::Probe; |
| 3355 | 3381 | ||
| 3356 | let marks = in_web::layout::switcher_marks([ | 3382 | let marks = in_web::layout::switcher_marks([ |
| 3357 | - ("iz", "http://127.0.0.1:9001", "Board", Probe::Up { body: "ok dev".into(), ms: 12 }), | 3383 | + ( |
| 3384 | + "iz", | ||
| 3385 | + "http://127.0.0.1:9001", | ||
| 3386 | + "Board", | ||
| 3387 | + Probe::Up { | ||
| 3388 | + body: "ok dev".into(), | ||
| 3389 | + ms: 12, | ||
| 3390 | + }, | ||
| 3391 | + ), | ||
| 3358 | ("im", "http://127.0.0.1:9002", "Account", Probe::Down), | 3392 | ("im", "http://127.0.0.1:9002", "Account", Probe::Down), |
| 3359 | ]); | 3393 | ]); |
| 3360 | assert!( | 3394 | assert!( |
| @@ -3367,14 +3401,26 @@ fn the_family_flyout_marks_pure_html() { | |||
| 3367 | marks.contains("health-dot health-on"), | 3401 | marks.contains("health-dot health-on"), |
| 3368 | "the ok sibling reads on: {marks}" | 3402 | "the ok sibling reads on: {marks}" |
| 3369 | ); | 3403 | ); |
| 3370 | - assert!(marks.contains(">iz</a>"), "the live sibling renders: {marks}"); | 3404 | + assert!( |
| 3405 | + marks.contains(">iz</a>"), | ||
| 3406 | + "the live sibling renders: {marks}" | ||
| 3407 | + ); | ||
| 3371 | assert!( | 3408 | assert!( |
| 3372 | marks.contains("health-dot health-off"), | 3409 | marks.contains("health-dot health-off"), |
| 3373 | "the dark sibling reads off: {marks}" | 3410 | "the dark sibling reads off: {marks}" |
| 3374 | ); | 3411 | ); |
| 3375 | - assert!(marks.contains(">im</a>"), "the dark sibling renders: {marks}"); | 3412 | + assert!( |
| 3376 | - assert!(!marks.contains("ok dev"), "the flyout carries dots only: {marks}"); | 3413 | + marks.contains(">im</a>"), |
| 3377 | - assert!(!marks.contains(" ms"), "the flyout carries no latency: {marks}"); | 3414 | + "the dark sibling renders: {marks}" |
| 3415 | + ); | ||
| 3416 | + assert!( | ||
| 3417 | + !marks.contains("ok dev"), | ||
| 3418 | + "the flyout carries dots only: {marks}" | ||
| 3419 | + ); | ||
| 3420 | + assert!( | ||
| 3421 | + !marks.contains(" ms"), | ||
| 3422 | + "the flyout carries no latency: {marks}" | ||
| 3423 | + ); | ||
| 3378 | assert!( | 3424 | assert!( |
| 3379 | marks.contains(r#"<span class="app-switcher-sep">·</span>"#), | 3425 | marks.contains(r#"<span class="app-switcher-sep">·</span>"#), |
| 3380 | "the marks join on middots: {marks}" | 3426 | "the marks join on middots: {marks}" |
| @@ -4589,6 +4635,18 @@ async fn view_only_public_thumb_serves_webp() { | |||
| 4589 | "card must not point at the raw bytes: {}", | 4635 | "card must not point at the raw bytes: {}", |
| 4590 | page.text() | 4636 | page.text() |
| 4591 | ); | 4637 | ); |
| 4638 | + // The card names the grant honestly: viewing happens in the browser | ||
| 4639 | + // and anything viewable can be saved — never a "no downloads" claim. | ||
| 4640 | + assert!( | ||
| 4641 | + page.text().contains("anything viewable can be saved"), | ||
| 4642 | + "{}", | ||
| 4643 | + page.text() | ||
| 4644 | + ); | ||
| 4645 | + assert!( | ||
| 4646 | + !page.text().contains("preview, no downloads"), | ||
| 4647 | + "{}", | ||
| 4648 | + page.text() | ||
| 4649 | + ); | ||
| 4592 | 4650 | ||
| 4593 | // View-only still grants the 512px preview: webp bytes, etag revalidates. | 4651 | // View-only still grants the 512px preview: webp bytes, etag revalidates. |
| 4594 | let thumb = app.get(&format!("/s/{token}?thumb=1"), None).await; | 4652 | let thumb = app.get(&format!("/s/{token}?thumb=1"), None).await; |
| @@ -6127,7 +6185,12 @@ async fn the_me_probe_answers_204_while_signed_in_and_401_the_moment_not() { | |||
| 6127 | assert_eq!(in_answer.status, StatusCode::NO_CONTENT); | 6185 | assert_eq!(in_answer.status, StatusCode::NO_CONTENT); |
| 6128 | assert!(in_answer.bytes.is_empty(), "no body on 204 either"); | 6186 | assert!(in_answer.bytes.is_empty(), "no body on 204 either"); |
| 6129 | 6187 | ||
| 6130 | - let user = app.store.user_by_oidc_sub("sub-probe").await.unwrap().unwrap(); | 6188 | + let user = app |
| 6189 | + .store | ||
| 6190 | + .user_by_oidc_sub("sub-probe") | ||
| 6191 | + .await | ||
| 6192 | + .unwrap() | ||
| 6193 | + .unwrap(); | ||
| 6131 | app.store.set_user_disabled(&user.id, true).await.unwrap(); | 6194 | app.store.set_user_disabled(&user.id, true).await.unwrap(); |
| 6132 | let disabled = app.get("/api/me", Some(&cookie)).await; | 6195 | let disabled = app.get("/api/me", Some(&cookie)).await; |
| 6133 | assert_eq!(disabled.status, StatusCode::UNAUTHORIZED); | 6196 | assert_eq!(disabled.status, StatusCode::UNAUTHORIZED); |
| @@ -6200,3 +6263,292 @@ async fn a_user_level_kill_orders_its_own_tabs_out_and_nobody_else() { | |||
| 6200 | } | 6263 | } |
| 6201 | assert!(bob.next_frame().await.is_none(), "bob's stream ends too"); | 6264 | assert!(bob.next_frame().await.is_none(), "bob's stream ends too"); |
| 6202 | } | 6265 | } |
| 6266 | +/// The finding's surface, end to end: a folder grant turns the shared | ||
| 6267 | +/// page's `/drive?folder=` link into a read-only browse — the listing with | ||
| 6268 | +/// its subfolder and file rows, descent into the subtree, the honest | ||
| 6269 | +/// access tell — with no write affordance anywhere, no sibling named, the | ||
| 6270 | +/// owner's own page for the same folder untouched, and a 404 the moment | ||
| 6271 | +/// the grant is gone. | ||
| 6272 | +#[tokio::test] | ||
| 6273 | +async fn granted_folder_browses_read_only() { | ||
| 6274 | + let app = TestApp::build().await; | ||
| 6275 | + let ada = app.sign_in("sub-ada", "ada-grant@in.test", "Ada").await; | ||
| 6276 | + let bob = app.sign_in("sub-bob", "bob-grant@in.test", "Bob").await; | ||
| 6277 | + let cara = app.sign_in("sub-cara", "cara-grant@in.test", "Cara").await; | ||
| 6278 | + let owner = owner_of(&app, "sub-ada").await; | ||
| 6279 | + | ||
| 6280 | + // Ada's tree: `trip` holding `inner` and a note, `secret` beside it. | ||
| 6281 | + let answer = app | ||
| 6282 | + .post( | ||
| 6283 | + "/api/folder/create", | ||
| 6284 | + Some(&ada), | ||
| 6285 | + &[("parent_id", ""), ("name", "trip")], | ||
| 6286 | + ) | ||
| 6287 | + .await; | ||
| 6288 | + assert!(answer.accepted(), "create refused: {:?}", answer.location); | ||
| 6289 | + let trip = folder_id(&app, &owner, None, "trip").await; | ||
| 6290 | + let answer = app | ||
| 6291 | + .post( | ||
| 6292 | + "/api/folder/create", | ||
| 6293 | + Some(&ada), | ||
| 6294 | + &[("parent_id", &trip), ("name", "inner")], | ||
| 6295 | + ) | ||
| 6296 | + .await; | ||
| 6297 | + assert!(answer.accepted(), "create refused: {:?}", answer.location); | ||
| 6298 | + let inner = folder_id(&app, &owner, Some(&trip), "inner").await; | ||
| 6299 | + let note = app | ||
| 6300 | + .store | ||
| 6301 | + .insert_file(&owner, Some(&trip), "note.txt", b"note bytes") | ||
| 6302 | + .await | ||
| 6303 | + .unwrap() | ||
| 6304 | + .id; | ||
| 6305 | + app.post( | ||
| 6306 | + "/api/folder/create", | ||
| 6307 | + Some(&ada), | ||
| 6308 | + &[("parent_id", ""), ("name", "secret")], | ||
| 6309 | + ) | ||
| 6310 | + .await; | ||
| 6311 | + let secret = folder_id(&app, &owner, None, "secret").await; | ||
| 6312 | + | ||
| 6313 | + let answer = app | ||
| 6314 | + .post( | ||
| 6315 | + "/api/share/user/add", | ||
| 6316 | + Some(&ada), | ||
| 6317 | + &[ | ||
| 6318 | + ("kind", "folder"), | ||
| 6319 | + ("target_id", &trip), | ||
| 6320 | + ("email", "bob-grant@in.test"), | ||
| 6321 | + ("can_download", "1"), | ||
| 6322 | + ], | ||
| 6323 | + ) | ||
| 6324 | + .await; | ||
| 6325 | + assert!(answer.accepted(), "grant refused: {:?}", answer.location); | ||
| 6326 | + | ||
| 6327 | + // The grant opens the browse where a stranger's tree would 404. | ||
| 6328 | + let page = app.get(&format!("/drive?folder={trip}"), Some(&bob)).await; | ||
| 6329 | + assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | ||
| 6330 | + let body = page.text(); | ||
| 6331 | + assert!(body.contains("inner"), "{body}"); | ||
| 6332 | + assert!(body.contains("note.txt"), "{body}"); | ||
| 6333 | + assert!(body.contains(&format!("/drive?folder={inner}")), "{body}"); | ||
| 6334 | + assert!(body.contains(&format!("/view/{note}")), "{body}"); | ||
| 6335 | + // The honest tell names the grant's reach. | ||
| 6336 | + assert!(body.contains("Shared with you"), "{body}"); | ||
| 6337 | + assert!(body.contains("May download"), "{body}"); | ||
| 6338 | + // And the page offers nothing to write with: no + menu, no upload, no | ||
| 6339 | + // row options, no rename, move, share, or delete anywhere on it. | ||
| 6340 | + for absent in [ | ||
| 6341 | + "/api/folder/create", | ||
| 6342 | + "/api/folder/rename", | ||
| 6343 | + "/api/folder/delete", | ||
| 6344 | + "/api/file/rename", | ||
| 6345 | + "/api/file/delete", | ||
| 6346 | + "share=folder:", | ||
| 6347 | + "share=file:", | ||
| 6348 | + "move=folder:", | ||
| 6349 | + "move=file:", | ||
| 6350 | + "&edit=", | ||
| 6351 | + "?dl=1", | ||
| 6352 | + "upload-form", | ||
| 6353 | + "drive-upload-input", | ||
| 6354 | + "drop-overlay", | ||
| 6355 | + "drive-add", | ||
| 6356 | + "entry-options", | ||
| 6357 | + ] { | ||
| 6358 | + assert!( | ||
| 6359 | + !body.contains(absent), | ||
| 6360 | + "grantee page offers {absent}: {body}" | ||
| 6361 | + ); | ||
| 6362 | + } | ||
| 6363 | + // Nothing beside the grant is named, let alone linked. | ||
| 6364 | + assert!( | ||
| 6365 | + !body.contains(&format!("/drive?folder={secret}")), | ||
| 6366 | + "grantee page links the ungranted sibling: {body}" | ||
| 6367 | + ); | ||
| 6368 | + assert!( | ||
| 6369 | + !body.contains(">secret</span>"), | ||
| 6370 | + "grantee page renders the ungranted sibling: {body}" | ||
| 6371 | + ); | ||
| 6372 | + | ||
| 6373 | + // Descent into the granted subtree is the same read-only browse one | ||
| 6374 | + // level down, and the trail stops at the granted folder: `trip` is | ||
| 6375 | + // named, the drive root above it never is. | ||
| 6376 | + let deep = app | ||
| 6377 | + .store | ||
| 6378 | + .insert_file(&owner, Some(&inner), "deep.txt", b"deep") | ||
| 6379 | + .await | ||
| 6380 | + .unwrap() | ||
| 6381 | + .id; | ||
| 6382 | + let page = app.get(&format!("/drive?folder={inner}"), Some(&bob)).await; | ||
| 6383 | + assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | ||
| 6384 | + let body = page.text(); | ||
| 6385 | + assert!(body.contains("deep.txt"), "{body}"); | ||
| 6386 | + assert!(body.contains(&format!("/view/{deep}")), "{body}"); | ||
| 6387 | + assert!(body.contains(&format!("/drive?folder={trip}")), "{body}"); | ||
| 6388 | + assert!( | ||
| 6389 | + !body.contains("detail-crumb\" href=\"/drive\""), | ||
| 6390 | + "grantee trail climbs out of the grant: {body}" | ||
| 6391 | + ); | ||
| 6392 | + | ||
| 6393 | + // The owner's own page for the same folder is exactly what it was. | ||
| 6394 | + let page = app.get(&format!("/drive?folder={trip}"), Some(&ada)).await; | ||
| 6395 | + assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | ||
| 6396 | + assert!(page.text().contains("upload-form"), "{}", page.text()); | ||
| 6397 | + | ||
| 6398 | + // A bystander without the grant sees nothing at all. | ||
| 6399 | + let page = app.get(&format!("/drive?folder={trip}"), Some(&cara)).await; | ||
| 6400 | + assert_eq!(page.status, StatusCode::NOT_FOUND, "{}", page.text()); | ||
| 6401 | + let page = app | ||
| 6402 | + .get(&format!("/drive?folder={secret}"), Some(&bob)) | ||
| 6403 | + .await; | ||
| 6404 | + assert_eq!(page.status, StatusCode::NOT_FOUND, "{}", page.text()); | ||
| 6405 | + | ||
| 6406 | + // Revoke and the same address is the plain not-found again. | ||
| 6407 | + let answer = app | ||
| 6408 | + .post( | ||
| 6409 | + "/api/share/user/remove", | ||
| 6410 | + Some(&ada), | ||
| 6411 | + &[ | ||
| 6412 | + ("kind", "folder"), | ||
| 6413 | + ("target_id", &trip), | ||
| 6414 | + ("email", "bob-grant@in.test"), | ||
| 6415 | + ], | ||
| 6416 | + ) | ||
| 6417 | + .await; | ||
| 6418 | + assert!(answer.accepted(), "remove refused: {:?}", answer.location); | ||
| 6419 | + let page = app.get(&format!("/drive?folder={trip}"), Some(&bob)).await; | ||
| 6420 | + assert_eq!(page.status, StatusCode::NOT_FOUND, "{}", page.text()); | ||
| 6421 | +} | ||
| 6422 | + | ||
| 6423 | +/// The grant's edge is exactly the granted subtree: a folder granted deeper | ||
| 6424 | +/// opens while its parent and siblings do not, the trail never climbs out, | ||
| 6425 | +/// a view-only grant says so while its files preview but stay download-dead, | ||
| 6426 | +/// and a trashed branch closes the path until the owner restores it. | ||
| 6427 | +#[tokio::test] | ||
| 6428 | +async fn grant_edges_close_the_browse() { | ||
| 6429 | + let app = TestApp::build().await; | ||
| 6430 | + let ada = app.sign_in("sub-ada", "ada-edges@in.test", "Ada").await; | ||
| 6431 | + let bob = app.sign_in("sub-bob", "bob-edges@in.test", "Bob").await; | ||
| 6432 | + let owner = owner_of(&app, "sub-ada").await; | ||
| 6433 | + | ||
| 6434 | + // outer/inner with `beside` off the path; only `inner` is granted. | ||
| 6435 | + let answer = app | ||
| 6436 | + .post( | ||
| 6437 | + "/api/folder/create", | ||
| 6438 | + Some(&ada), | ||
| 6439 | + &[("parent_id", ""), ("name", "outer")], | ||
| 6440 | + ) | ||
| 6441 | + .await; | ||
| 6442 | + assert!(answer.accepted(), "create refused: {:?}", answer.location); | ||
| 6443 | + let outer = folder_id(&app, &owner, None, "outer").await; | ||
| 6444 | + let answer = app | ||
| 6445 | + .post( | ||
| 6446 | + "/api/folder/create", | ||
| 6447 | + Some(&ada), | ||
| 6448 | + &[("parent_id", &outer), ("name", "inner")], | ||
| 6449 | + ) | ||
| 6450 | + .await; | ||
| 6451 | + assert!(answer.accepted(), "create refused: {:?}", answer.location); | ||
| 6452 | + let inner = folder_id(&app, &owner, Some(&outer), "inner").await; | ||
| 6453 | + app.post( | ||
| 6454 | + "/api/folder/create", | ||
| 6455 | + Some(&ada), | ||
| 6456 | + &[("parent_id", ""), ("name", "beside")], | ||
| 6457 | + ) | ||
| 6458 | + .await; | ||
| 6459 | + let beside = folder_id(&app, &owner, None, "beside").await; | ||
| 6460 | + let pic = app | ||
| 6461 | + .store | ||
| 6462 | + .insert_file(&owner, Some(&inner), "pic.png", &tiny_png()) | ||
| 6463 | + .await | ||
| 6464 | + .unwrap() | ||
| 6465 | + .id; | ||
| 6466 | + | ||
| 6467 | + let answer = app | ||
| 6468 | + .post( | ||
| 6469 | + "/api/share/user/add", | ||
| 6470 | + Some(&ada), | ||
| 6471 | + &[ | ||
| 6472 | + ("kind", "folder"), | ||
| 6473 | + ("target_id", &inner), | ||
| 6474 | + ("email", "bob-edges@in.test"), | ||
| 6475 | + ("can_download", "0"), | ||
| 6476 | + ], | ||
| 6477 | + ) | ||
| 6478 | + .await; | ||
| 6479 | + assert!(answer.accepted(), "grant refused: {:?}", answer.location); | ||
| 6480 | + | ||
| 6481 | + // The granted folder opens, view-only on its face; the parent, a | ||
| 6482 | + // sibling, and the trail above the grant all stay closed. | ||
| 6483 | + let page = app.get(&format!("/drive?folder={inner}"), Some(&bob)).await; | ||
| 6484 | + assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | ||
| 6485 | + let body = page.text(); | ||
| 6486 | + assert!(body.contains("View only"), "{body}"); | ||
| 6487 | + assert!(!body.contains("May download"), "{body}"); | ||
| 6488 | + assert!( | ||
| 6489 | + !body.contains(&format!("/drive?folder={outer}")), | ||
| 6490 | + "trail names the ungranted parent: {body}" | ||
| 6491 | + ); | ||
| 6492 | + let page = app.get(&format!("/drive?folder={outer}"), Some(&bob)).await; | ||
| 6493 | + assert_eq!(page.status, StatusCode::NOT_FOUND, "{}", page.text()); | ||
| 6494 | + let page = app | ||
| 6495 | + .get(&format!("/drive?folder={beside}"), Some(&bob)) | ||
| 6496 | + .await; | ||
| 6497 | + assert_eq!(page.status, StatusCode::NOT_FOUND, "{}", page.text()); | ||
| 6498 | + | ||
| 6499 | + // The file previews through the folder grant, but taking it away is | ||
| 6500 | + // refused — the view-only grant opens the page, not the bytes. | ||
| 6501 | + let view = app.get(&format!("/view/{pic}"), Some(&bob)).await; | ||
| 6502 | + assert_eq!(view.status, StatusCode::OK, "{}", view.text()); | ||
| 6503 | + assert!( | ||
| 6504 | + !view.text().contains("?dl=1"), | ||
| 6505 | + "view-only viewer offers a download: {}", | ||
| 6506 | + view.text() | ||
| 6507 | + ); | ||
| 6508 | + let bytes = app.get(&format!("/file/{pic}?dl=1"), Some(&bob)).await; | ||
| 6509 | + assert_eq!(bytes.status, StatusCode::NOT_FOUND); | ||
| 6510 | + let preview = app.get(&format!("/file/{pic}"), Some(&bob)).await; | ||
| 6511 | + assert_eq!(preview.status, StatusCode::OK); | ||
| 6512 | + | ||
| 6513 | + // The same grant refreshed with download opens the bytes too. | ||
| 6514 | + let answer = app | ||
| 6515 | + .post( | ||
| 6516 | + "/api/share/user/add", | ||
| 6517 | + Some(&ada), | ||
| 6518 | + &[ | ||
| 6519 | + ("kind", "folder"), | ||
| 6520 | + ("target_id", &inner), | ||
| 6521 | + ("email", "bob-edges@in.test"), | ||
| 6522 | + ("can_download", "1"), | ||
| 6523 | + ], | ||
| 6524 | + ) | ||
| 6525 | + .await; | ||
| 6526 | + assert!(answer.accepted(), "re-grant refused: {:?}", answer.location); | ||
| 6527 | + let page = app.get(&format!("/drive?folder={inner}"), Some(&bob)).await; | ||
| 6528 | + assert!(page.text().contains("May download"), "{}", page.text()); | ||
| 6529 | + let bytes = app.get(&format!("/file/{pic}?dl=1"), Some(&bob)).await; | ||
| 6530 | + assert_eq!(bytes.status, StatusCode::OK); | ||
| 6531 | + assert!( | ||
| 6532 | + bytes | ||
| 6533 | + .disposition | ||
| 6534 | + .as_deref() | ||
| 6535 | + .is_some_and(|value| value.starts_with("attachment")), | ||
| 6536 | + "download did not land as a file: {:?}", | ||
| 6537 | + bytes.disposition | ||
| 6538 | + ); | ||
| 6539 | + | ||
| 6540 | + // Trashing the granted folder closes the whole path — the grant row | ||
| 6541 | + // survives, but trash is unreachable — and restoring reopens it. | ||
| 6542 | + let answer = app | ||
| 6543 | + .post("/api/folder/delete", Some(&ada), &[("id", &inner)]) | ||
| 6544 | + .await; | ||
| 6545 | + assert!(answer.accepted(), "delete refused: {:?}", answer.location); | ||
| 6546 | + let page = app.get(&format!("/drive?folder={inner}"), Some(&bob)).await; | ||
| 6547 | + assert_eq!(page.status, StatusCode::NOT_FOUND, "{}", page.text()); | ||
| 6548 | + let view = app.get(&format!("/view/{pic}"), Some(&bob)).await; | ||
| 6549 | + assert_eq!(view.status, StatusCode::NOT_FOUND, "{}", view.text()); | ||
| 6550 | + app.store.restore_folder(&inner).await.unwrap(); | ||
| 6551 | + let page = app.get(&format!("/drive?folder={inner}"), Some(&bob)).await; | ||
| 6552 | + assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | ||
| 6553 | + assert!(page.text().contains("pic.png"), "{}", page.text()); | ||
| 6554 | +} | ||