forge
Explore
Log in

Don't you dare go Hollow

The viewer's back link names its origin — shared, not just the drive

Browse files at this commit

ef74392af33182ec50957ccdf3eea5ac68a8467aAhmet Kaan GümüşParent: a6fa637
  • fix
    • the viewer's back link names its origin — shared, not just the drive
Show full message
fix(web): the viewer's back link names its origin — shared, not just the drive
crates/in-web/src/files.rsmodified+19 -2
@@ -173,6 +173,15 @@ struct DownloadQuery {
173173 dl: Option<String>,
174174 }
175175
176+/// The viewer's origin: `from` is `shared` when the shared page's row sent
177+/// the reader over, and anything else — absent included — is a drive
178+/// opening. The back link names the page you came from; an unknown value
179+/// keeps the standing drive answer, never a refusal.
180+#[query_params]
181+struct ViewQuery {
182+ from: Option<String>,
183+}
184+
176185 /// The file row this account may open: its owner may, and anyone holding a
177186 /// live grant onto it may. Trashed files open for nobody here — the trash
178187 /// has its own screen. `None` folds "no such file" and "not shared" into
@@ -474,7 +483,9 @@ fn is_archive_mime(mime: &str) -> bool {
474483 /// only while the reader may download, and `?dl=1` stays gated on the
475484 /// byte route. Documents (PDF, text) frame the bytes in the browser's own
476485 /// chrome, whose toolbar downloads — they preview only under the grant.
477-/// Bytes for another owner's file answer 404, not 403.
486+/// Bytes for another owner's file answer 404, not 403. The head's back
487+/// link names the origin: `?from=shared`, the pair the shared page's rows
488+/// carry, returns there; anything else back to the drive.
478489 #[page("/view/{id}")]
479490 async fn view_file(cx: &Cx) -> Result {
480491 let id: &str = path_param::<Id>(cx);
@@ -491,6 +502,10 @@ async fn view_file(cx: &Cx) -> Result {
491502 }
492503 };
493504 let language = lang(cx).await;
505+ let from_shared = query_params::<ViewQuery>(cx)
506+ .ok()
507+ .and_then(|query| query.from.clone())
508+ .is_some_and(|from| from == "shared");
494509
495510 let store = app(cx).store.clone();
496511 let Some(file) = visible_file(store.as_ref(), &user.id, id).await else {
@@ -515,7 +530,9 @@ async fn view_file(cx: &Cx) -> Result {
515530 (topbar(cx, NavPage::Drive, &user, language).await?)
516531 <main class="settings-stage stage-wide">
517532 <div class="viewer-head">
518- <a class="quiet" href="/drive">(t(language, Key::BackToDrive))</a>
533+ <a class="quiet" href=(if from_shared { "/shared" } else { "/drive" })>
534+ (t(language, if from_shared { Key::BackToShared } else { Key::BackToDrive }))
535+ </a>
519536 <div class="spacer"></div>
520537 if may_download {
521538 <a class="primary" href=(download_href) download="">(t(language, Key::Download))</a>
crates/in-web/src/i18n.rsmodified+18 -5
@@ -83,6 +83,7 @@ pub enum Key {
8383 SomethingWentWrong,
8484 NothingAtThisAddress,
8585 BackToDrive,
86+ BackToShared,
8687 // Landing.
8788 WelcomeTitle,
8889 WelcomeBlurb,
@@ -255,6 +256,7 @@ pub fn t(lang: Lang, key: Key) -> &'static str {
255256 SomethingWentWrong => "Something went wrong.",
256257 NothingAtThisAddress => "There is nothing at this address.",
257258 BackToDrive => "Back to the drive",
259+ BackToShared => "Back to shared",
258260 WelcomeTitle => "In: your files",
259261 WelcomeBlurb => "Your folders and files, shared on your terms.",
260262 SignIn => "Sign in",
@@ -390,9 +392,13 @@ pub fn t(lang: Lang, key: Key) -> &'static str {
390392 ServerAddress => "Server address",
391393 EffectiveOrigin => "Effective origin",
392394 BaseUrlLabel => "Public base URL",
393- BaseUrlNote => "The origin share links carry: a saved value wins, an empty one falls back to the configured base_url, then the bind address.",
395+ BaseUrlNote => {
396+ "The origin share links carry: a saved value wins, an empty one falls back to the configured base_url, then the bind address."
397+ }
394398 Shared => "Shared",
395- LegacyLinkNote => "This link predates re-viewable addresses — revoke and mint a new one to carry it forward.",
399+ LegacyLinkNote => {
400+ "This link predates re-viewable addresses — revoke and mint a new one to carry it forward."
401+ }
396402 },
397403 Lang::Tr => match key {
398404 Cancel => "Vazgeç",
@@ -409,6 +415,7 @@ pub fn t(lang: Lang, key: Key) -> &'static str {
409415 SomethingWentWrong => "Bir şeyler ters gitti.",
410416 NothingAtThisAddress => "Bu adreste bir şey yok.",
411417 BackToDrive => "Sürücüye dön",
418+ BackToShared => "Paylaşılanlara dön",
412419 WelcomeTitle => "In: dosyaların",
413420 WelcomeBlurb => "Klasörlerin ve dosyaların, senin kurallarınla.",
414421 SignIn => "Oturum aç",
@@ -492,7 +499,9 @@ pub fn t(lang: Lang, key: Key) -> &'static str {
492499 EnableUser => "Etkinleştir",
493500 DisabledBadge => "devre dışı",
494501 LinkCreated => "Bağlantı oluşturuldu.",
495- CopyLinkOnce => "Şimdi kopyala. Tam adres, Paylaşım bağlantıları panelinde de görünür kalır.",
502+ CopyLinkOnce => {
503+ "Şimdi kopyala. Tam adres, Paylaşım bağlantıları panelinde de görünür kalır."
504+ }
496505 ExpiresLabel => "Bitiş",
497506 NeverExpires => "Süresiz",
498507 ViewOnly => "Yalnızca görüntüleme: önizleme, indirme yok",
@@ -544,9 +553,13 @@ pub fn t(lang: Lang, key: Key) -> &'static str {
544553 ServerAddress => "Sunucu adresi",
545554 EffectiveOrigin => "Etkin kök adres",
546555 BaseUrlLabel => "Herkese açık kök adres",
547- BaseUrlNote => "Paylaşım bağlantılarının taşıdığı kök adres: kaydedilen değer önceliklidir, boş bırakılırsa yapılandırılmış base_url'e, sonra bağlanılan adrese dönülür.",
556+ BaseUrlNote => {
557+ "Paylaşım bağlantılarının taşıdığı kök adres: kaydedilen değer önceliklidir, boş bırakılırsa yapılandırılmış base_url'e, sonra bağlanılan adrese dönülür."
558+ }
548559 Shared => "Paylaşılmış",
549- LegacyLinkNote => "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.",
560+ LegacyLinkNote => {
561+ "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."
562+ }
550563 },
551564 }
552565 }
crates/in-web/src/share.rsmodified+58 -14
@@ -223,10 +223,17 @@ struct CreateLinkForm {
223223 async fn create_link(cx: &Cx, Form(input): Form<CreateLinkForm>) -> Redirect {
224224 let user = match require_user(cx).await {
225225 Ok(user) => user,
226- Err(refusal) => return redirect_back(cx, "/settings?section=links", "create", Some(refusal)),
226+ Err(refusal) => {
227+ return redirect_back(cx, "/settings?section=links", "create", Some(refusal));
228+ }
227229 };
228230 let Some(kind) = parse_kind(&input.kind) else {
229- return redirect_back(cx, "/settings?section=links", "create", Some(Refusal::NotFound));
231+ return redirect_back(
232+ cx,
233+ "/settings?section=links",
234+ "create",
235+ Some(Refusal::NotFound),
236+ );
230237 };
231238 if let Err(refusal) = owned_target(app(cx).store.as_ref(), &user, kind, &input.target_id).await
232239 {
@@ -234,7 +241,9 @@ async fn create_link(cx: &Cx, Form(input): Form<CreateLinkForm>) -> Redirect {
234241 }
235242 let expires_at = match parse_expiry(input.expires_in_days.as_deref()) {
236243 Ok(expires_at) => expires_at,
237- Err(refusal) => return redirect_back(cx, "/settings?section=links", "create", Some(refusal)),
244+ Err(refusal) => {
245+ return redirect_back(cx, "/settings?section=links", "create", Some(refusal));
246+ }
238247 };
239248 // An optional password on the link: a trimmed empty field is no
240249 // password at all. Argon2id is CPU-slow on purpose, so the hash runs
@@ -244,7 +253,14 @@ async fn create_link(cx: &Cx, Form(input): Form<CreateLinkForm>) -> Redirect {
244253 Some(password) => {
245254 match tokio::task::spawn_blocking(move || hash_link_password(&password)).await {
246255 Ok(Ok(hash)) => Some(hash),
247- _ => return redirect_back(cx, "/settings?section=links", "create", Some(Refusal::Unavailable)),
256+ _ => {
257+ return redirect_back(
258+ cx,
259+ "/settings?section=links",
260+ "create",
261+ Some(Refusal::Unavailable),
262+ );
263+ }
248264 }
249265 }
250266 None => None,
@@ -280,7 +296,12 @@ async fn create_link(cx: &Cx, Form(input): Form<CreateLinkForm>) -> Redirect {
280296 let location = format!("{back}{separator}created={}", minted.token);
281297 Ok((StatusCode::SEE_OTHER, [(header::LOCATION, location)]))
282298 }
283- Err(error) => redirect_back(cx, "/settings?section=links", "create", Some(refusal_of(error))),
299+ Err(error) => redirect_back(
300+ cx,
301+ "/settings?section=links",
302+ "create",
303+ Some(refusal_of(error)),
304+ ),
284305 }
285306 }
286307
@@ -295,7 +316,9 @@ struct RevokeLinkForm {
295316 async fn revoke_link(cx: &Cx, Form(input): Form<RevokeLinkForm>) -> Redirect {
296317 let user = match require_user(cx).await {
297318 Ok(user) => user,
298- Err(refusal) => return redirect_back(cx, "/settings?section=links", "revoke", Some(refusal)),
319+ Err(refusal) => {
320+ return redirect_back(cx, "/settings?section=links", "revoke", Some(refusal));
321+ }
299322 };
300323 let store = app(cx).store;
301324 let mine = store
@@ -303,13 +326,23 @@ async fn revoke_link(cx: &Cx, Form(input): Form<RevokeLinkForm>) -> Redirect {
303326 .await
304327 .map_err(|_| Refusal::Unavailable);
305328 let Ok(links) = mine else {
306- return redirect_back(cx, "/settings?section=links", "revoke", Some(Refusal::Unavailable));
329+ return redirect_back(
330+ cx,
331+ "/settings?section=links",
332+ "revoke",
333+ Some(Refusal::Unavailable),
334+ );
307335 };
308336 if !links
309337 .iter()
310338 .any(|link| link.id == input.id && link.created_by == user.id)
311339 {
312- return redirect_back(cx, "/settings?section=links", "revoke", Some(Refusal::NotFound));
340+ return redirect_back(
341+ cx,
342+ "/settings?section=links",
343+ "revoke",
344+ Some(Refusal::NotFound),
345+ );
313346 }
314347 match store.revoke_share_link(&input.id).await {
315348 Ok(()) => {
@@ -322,12 +355,20 @@ async fn revoke_link(cx: &Cx, Form(input): Form<RevokeLinkForm>) -> Redirect {
322355 .await
323356 {
324357 Ok(()) => redirect_back(cx, "/settings?section=links", "revoke", None),
325- Err(error) => {
326- redirect_back(cx, "/settings?section=links", "revoke", Some(refusal_of(error)))
327- }
358+ Err(error) => redirect_back(
359+ cx,
360+ "/settings?section=links",
361+ "revoke",
362+ Some(refusal_of(error)),
363+ ),
328364 }
329365 }
330- Err(error) => redirect_back(cx, "/settings?section=links", "revoke", Some(refusal_of(error))),
366+ Err(error) => redirect_back(
367+ cx,
368+ "/settings?section=links",
369+ "revoke",
370+ Some(refusal_of(error)),
371+ ),
331372 }
332373 }
333374
@@ -473,7 +514,10 @@ fn has_flag(query: &str, key: &str) -> bool {
473514 /// `/s` surface stays a `#[route]` and wraps its views itself — in
474515 /// `document_shell`, the same shell every `#[page]` under `/` wears, never
475516 /// a hand-copied head.
476-async fn public_page(cx: &Cx, page: Result) -> topcoat::Result<topcoat::router::response::Response> {
517+async fn public_page(
518+ cx: &Cx,
519+ page: Result,
520+) -> topcoat::Result<topcoat::router::response::Response> {
477521 Ok(document_shell(cx, page).await?.into_response(cx)?)
478522 }
479523
@@ -1317,7 +1361,7 @@ async fn shared(cx: &Cx) -> Result {
13171361 <div class="drive-row">
13181362 <a class="drive-open" href=(match row.item.kind {
13191363 ShareKind::Folder => format!("/drive?folder={}", row.item.target_id),
1320- ShareKind::File => format!("/view/{}", row.item.target_id),
1364+ ShareKind::File => format!("/view/{}?from=shared", row.item.target_id),
13211365 })>
13221366 if row.item.kind == ShareKind::Folder {
13231367 <span class="file-chip file-chip-folder" aria-hidden="true">"▤"</span>
crates/in-web/tests/http.rsmodified+72 -16
@@ -1868,6 +1868,13 @@ async fn per_user_share_lands_in_shared_with_me() {
18681868 let bobs = app.get("/shared", Some(&bob)).await;
18691869 assert_eq!(bobs.status, StatusCode::OK, "{}", bobs.text());
18701870 assert!(bobs.text().contains("joint.txt"), "{}", bobs.text());
1871+ // The row opens the viewer marked with its origin, so the back link
1872+ // can name the shared page.
1873+ assert!(
1874+ bobs.text().contains(&format!("/view/{file}?from=shared")),
1875+ "{}",
1876+ bobs.text()
1877+ );
18711878
18721879 let caras = app.get("/shared", Some(&cara)).await;
18731880 assert_eq!(caras.status, StatusCode::OK, "{}", caras.text());
@@ -2018,7 +2025,11 @@ async fn created_link_is_revisible_and_copyable_everywhere() {
20182025 .post(
20192026 "/api/share/link/create",
20202027 Some(&ada),
2021- &[("kind", "file"), ("target_id", &file), ("can_download", "1")],
2028+ &[
2029+ ("kind", "file"),
2030+ ("target_id", &file),
2031+ ("can_download", "1"),
2032+ ],
20222033 )
20232034 .await;
20242035 assert!(answer.accepted(), "create refused: {:?}", answer.location);
@@ -2179,7 +2190,11 @@ async fn drive_marks_shared_rows() {
21792190 &[("parent_id", ""), ("name", "Dossier")],
21802191 )
21812192 .await;
2182- assert!(answer.accepted(), "folder create refused: {:?}", answer.location);
2193+ assert!(
2194+ answer.accepted(),
2195+ "folder create refused: {:?}",
2196+ answer.location
2197+ );
21832198 let folder = folder_id(&app, &owner, None, "Dossier").await;
21842199
21852200 // A live public link onto the file, another onto the folder.
@@ -2264,6 +2279,24 @@ async fn view_only_reader_previews_media_but_cannot_download() {
22642279 assert!(page.text().contains("viewer-media"), "{}", page.text());
22652280 assert!(!page.text().contains("No preview"), "{}", page.text());
22662281 assert!(!page.text().contains("?dl=1"), "{}", page.text());
2282+ // The back link names the origin: opened from the shared page (the
2283+ // `from=shared` its rows carry) it returns there, a plain opening to
2284+ // the drive.
2285+ let from_shared = app
2286+ .get(&format!("/view/{file}?from=shared"), Some(&bob))
2287+ .await;
2288+ assert_eq!(from_shared.status, StatusCode::OK, "{}", from_shared.text());
2289+ assert!(
2290+ from_shared.text().contains("Back to shared"),
2291+ "{}",
2292+ from_shared.text()
2293+ );
2294+ assert!(
2295+ !from_shared.text().contains("Back to the drive"),
2296+ "{}",
2297+ from_shared.text()
2298+ );
2299+ assert!(page.text().contains("Back to the drive"), "{}", page.text());
22672300
22682301 // The inline bytes serve for the preview...
22692302 let inline = app.get(&format!("/file/{file}"), Some(&bob)).await;
@@ -2477,13 +2510,14 @@ async fn drive_search_results_merge_into_one_panel() {
24772510 let file = file_id(&app, &owner, "holiday report.txt", b"sun").await;
24782511
24792512 let page = app.get("/drive?q=holiday", Some(&cookie)).await;
2480- assert_eq!(page.status, StatusCode::OK, "{}", page.text());
24812513 let body = page.text();
24822514 // Both hits render in one shared list, folders first, wired to their surfaces.
24832515 assert!(body.contains("holiday photos"), "{body}");
24842516 assert!(body.contains("holiday report.txt"), "{body}");
24852517 assert!(body.contains(&format!("/drive?folder={folder}")), "{body}");
24862518 assert!(body.contains(&format!("/view/{file}")), "{body}");
2519+ // Drive rows stay unmarked: only the shared page names an origin.
2520+ assert!(!body.contains("from=shared"), "{body}");
24872521 let folder_at = body.find("holiday photos").expect("no folder hit");
24882522 let file_at = body.find("holiday report.txt").expect("no file hit");
24892523 assert!(folder_at < file_at, "file hit precedes folder hit: {body}");
@@ -2728,7 +2762,10 @@ async fn share_links_carry_the_configured_base_url() {
27282762
27292763 // The banner the mint redirects back to.
27302764 let page = app
2731- .get(&format!("/settings?section=links&created={token}"), Some(&admin))
2765+ .get(
2766+ &format!("/settings?section=links&created={token}"),
2767+ Some(&admin),
2768+ )
27322769 .await;
27332770 assert_eq!(page.status, StatusCode::OK, "{}", page.text());
27342771 assert!(
@@ -2789,7 +2826,10 @@ async fn share_links_follow_the_bind_without_a_base_url() {
27892826 // No `base_url`: the links say the address bound, as they always
27902827 // have.
27912828 let page = app
2792- .get(&format!("/settings?section=links&created={token}"), Some(&admin))
2829+ .get(
2830+ &format!("/settings?section=links&created={token}"),
2831+ Some(&admin),
2832+ )
27932833 .await;
27942834 assert_eq!(page.status, StatusCode::OK, "{}", page.text());
27952835 assert!(
@@ -2883,26 +2923,38 @@ async fn admin_settings_sections_render_alone() {
28832923 .await
28842924 .unwrap();
28852925
2886- let body = app.get("/settings?section=profile", Some(&admin)).await.text();
2926+ let body = app
2927+ .get("/settings?section=profile", Some(&admin))
2928+ .await
2929+ .text();
28872930 assert!(body.contains("name=\"ui\""), "{body}");
28882931 assert!(!body.contains("/api/share/link/revoke"), "{body}");
28892932 assert!(!body.contains("member-table"), "{body}");
28902933 assert!(!body.contains("/api/settings/base_url"), "{body}");
28912934
2892- let body = app.get("/settings?section=links", Some(&admin)).await.text();
2935+ let body = app
2936+ .get("/settings?section=links", Some(&admin))
2937+ .await
2938+ .text();
28932939 assert!(body.contains("action=\"/api/share/link/revoke\""), "{body}");
28942940 assert!(!body.contains("name=\"ui\""), "{body}");
28952941 assert!(!body.contains("member-table"), "{body}");
28962942 assert!(!body.contains("/api/settings/base_url"), "{body}");
28972943
2898- let body = app.get("/settings?section=everyone", Some(&admin)).await.text();
2944+ let body = app
2945+ .get("/settings?section=everyone", Some(&admin))
2946+ .await
2947+ .text();
28992948 assert!(body.contains("member-table"), "{body}");
29002949 assert!(body.contains("ada@in.test"), "{body}");
29012950 assert!(!body.contains("name=\"ui\""), "{body}");
29022951 assert!(!body.contains("/api/share/link/revoke"), "{body}");
29032952 assert!(!body.contains("/api/settings/base_url"), "{body}");
29042953
2905- let body = app.get("/settings?section=server", Some(&admin)).await.text();
2954+ let body = app
2955+ .get("/settings?section=server", Some(&admin))
2956+ .await
2957+ .text();
29062958 assert!(body.contains("action=\"/api/settings/base_url\""), "{body}");
29072959 // The effective origin shows before anything is stored: the bind.
29082960 assert!(body.contains("http://127.0.0.1:7655"), "{body}");
@@ -2965,8 +3017,7 @@ async fn server_address_setting_drives_share_links() {
29653017 )
29663018 .await;
29673019 assert!(
2968- page
2969- .text()
3020+ page.text()
29703021 .contains(&format!("https://files.example.com/s/{token}")),
29713022 "{}",
29723023 page.text()
@@ -3038,8 +3089,7 @@ async fn cleared_setting_falls_back_to_the_configured_base_url() {
30383089 )
30393090 .await;
30403091 assert!(
3041- page
3042- .text()
3092+ page.text()
30433093 .contains(&format!("https://override.example.com/s/{token}")),
30443094 "{}",
30453095 page.text()
@@ -3071,7 +3121,11 @@ async fn revoke_redirects_land_on_the_links_section() {
30713121 let app = TestApp::build().await;
30723122 let admin = app.sign_in("sub-admin", "ada@in.test", "Ada").await;
30733123 let answer = app
3074- .post("/api/share/link/revoke", Some(&admin), &[("id", "never-real")])
3124+ .post(
3125+ "/api/share/link/revoke",
3126+ Some(&admin),
3127+ &[("id", "never-real")],
3128+ )
30753129 .await;
30763130 assert!(
30773131 answer
@@ -3096,7 +3150,10 @@ async fn the_settings_revoke_button_sits_inline_in_its_row() {
30963150 .await
30973151 .unwrap();
30983152
3099- let body = app.get("/settings?section=links", Some(&admin)).await.text();
3153+ let body = app
3154+ .get("/settings?section=links", Some(&admin))
3155+ .await
3156+ .text();
31003157 let row_at = body
31013158 .find("<div class=\"member-row\">")
31023159 .expect("no share-link row");
@@ -4699,4 +4756,3 @@ async fn an_empty_folder_says_how_to_fill_it() {
46994756 assert!(body.contains("id=\"upload-form\""), "{body}");
47004757 assert!(body.contains("__inDrop"), "{body}");
47014758 }
4702-