The address stays reachable, shared objects wear their mark
Browse files at this commita6fa637580824cef5638e819656b997aa6213a65Parent: 1e00f66- feat
- the address stays reachable, shared objects wear their mark
11 changed files +555 -40
- crates/in-core/src/store/mod.rs +17 -5
- crates/in-core/src/store/turso_store.rs +50 -1
- crates/in-core/tests/store.rs +88 -0
- crates/in-web/src/drive.rs +36 -5
- crates/in-web/src/i18n.rs +9 -2
- crates/in-web/src/main.rs +5 -2
- crates/in-web/src/server.rs +25 -0
- crates/in-web/src/settings.rs +27 -6
- crates/in-web/src/share.rs +52 -13
- crates/in-web/tests/http.rs +231 -5
- style/main.scss +15 -1
crates/in-core/src/store/mod.rsmodified+17 -5
| @@ -193,7 +193,7 @@ impl ThumbState { | |||
| 193 | 193 | ||
| 194 | /// Which table a share points at — one file, or one folder and everything | 194 | /// Which table a share points at — one file, or one folder and everything |
| 195 | /// under it. | 195 | /// under it. |
| 196 | -#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] | 196 | +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] |
| 197 | #[serde(rename_all = "lowercase")] | 197 | #[serde(rename_all = "lowercase")] |
| 198 | pub enum ShareKind { | 198 | pub enum ShareKind { |
| 199 | File, | 199 | File, |
| @@ -218,7 +218,9 @@ impl ShareKind { | |||
| 218 | } | 218 | } |
| 219 | 219 | ||
| 220 | /// A public share link. The row holds only the token's hash; the plaintext | 220 | /// A public share link. The row holds only the token's hash; the plaintext |
| 221 | -/// is shown once at creation and never again. An owner may also give the | 221 | +/// never sits in this table — the web layer seals it onto a |
| 222 | +/// `share_token:{id}` setting row with the app key, so the full address can | ||
| 223 | +/// be re-shown later. An owner may also give the | ||
| 222 | /// link a password: the row then keeps the password's Argon2id PHC string, | 224 | /// link a password: the row then keeps the password's Argon2id PHC string, |
| 223 | /// and a visitor answers the gate once per browser — the proof lives in a | 225 | /// and a visitor answers the gate once per browser — the proof lives in a |
| 224 | /// cookie, never in a server-side session. | 226 | /// cookie, never in a server-side session. |
| @@ -244,7 +246,7 @@ impl ShareLink { | |||
| 244 | } | 246 | } |
| 245 | 247 | ||
| 246 | /// A freshly created link, with the one thing the row does not keep: the | 248 | /// A freshly created link, with the one thing the row does not keep: the |
| 247 | -/// plaintext token, shown once and then forgotten. | 249 | +/// plaintext token, which the web layer seals away for later re-display. |
| 248 | #[derive(Debug, Clone, PartialEq, Eq)] | 250 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 249 | pub struct CreatedLink { | 251 | pub struct CreatedLink { |
| 250 | pub link: ShareLink, | 252 | pub link: ShareLink, |
| @@ -531,9 +533,9 @@ pub trait Store: 'static + Send + Sync { | |||
| 531 | async fn empty_trash(&self, owner_id: &str) -> Result<u64>; | 533 | async fn empty_trash(&self, owner_id: &str) -> Result<u64>; |
| 532 | 534 | ||
| 533 | // -- share links ------------------------------------------------------- | 535 | // -- share links ------------------------------------------------------- |
| 534 | - | ||
| 535 | /// Creates a public link onto one file or folder. Returns the row and the | 536 | /// Creates a public link onto one file or folder. Returns the row and the |
| 536 | - /// plaintext token — the only moment the token exists outside its hash. | 537 | + /// plaintext token — the only moment it exists unsealed; the web layer |
| 538 | + /// seals it onto a setting row at once. | ||
| 537 | /// `password_hash` is stored as given: the caller hashes the password | 539 | /// `password_hash` is stored as given: the caller hashes the password |
| 538 | /// with [`hash_link_password`], because Argon2id is CPU-slow on | 540 | /// with [`hash_link_password`], because Argon2id is CPU-slow on |
| 539 | /// purpose and only the caller knows whether the hash belongs off the | 541 | /// purpose and only the caller knows whether the hash belongs off the |
| @@ -565,6 +567,12 @@ pub trait Store: 'static + Send + Sync { | |||
| 565 | now: OffsetDateTime, | 567 | now: OffsetDateTime, |
| 566 | ) -> Result<Option<ShareLink>>; | 568 | ) -> Result<Option<ShareLink>>; |
| 567 | 569 | ||
| 570 | + /// Every target the person shares today, as `(kind, target_id)` with | ||
| 571 | + /// duplicates folded away: the live public links they minted — | ||
| 572 | + /// unrevoked and unexpired — plus the targets they granted to other | ||
| 573 | + /// people. The drive page marks these rows as shared. | ||
| 574 | + async fn shared_target_ids(&self, owner_id: &str) -> Result<Vec<(ShareKind, String)>>; | ||
| 575 | + | ||
| 568 | // -- per-person shares ------------------------------------------------- | 576 | // -- per-person shares ------------------------------------------------- |
| 569 | 577 | ||
| 570 | /// Shares one file or folder with one person. The caller must own the | 578 | /// Shares one file or folder with one person. The caller must own the |
| @@ -680,6 +688,10 @@ pub trait Store: 'static + Send + Sync { | |||
| 680 | /// Keys are free-form; the web layer is the only writer today. | 688 | /// Keys are free-form; the web layer is the only writer today. |
| 681 | async fn set_setting(&self, key: &str, value: &str) -> Result<()>; | 689 | async fn set_setting(&self, key: &str, value: &str) -> Result<()>; |
| 682 | 690 | ||
| 691 | + /// Removes one instance-level setting. A key never set is not an error: | ||
| 692 | + /// deleting what is not there leaves exactly what was asked for. | ||
| 693 | + async fn delete_setting(&self, key: &str) -> Result<()>; | ||
| 694 | + | ||
| 683 | // -- search ------------------------------------------------------------ | 695 | // -- search ------------------------------------------------------------ |
| 684 | 696 | ||
| 685 | /// Owner-scoped substring search over live file and folder names, files | 697 | /// Owner-scoped substring search over live file and folder names, files |
crates/in-core/src/store/turso_store.rsmodified+50 -1
| @@ -554,7 +554,7 @@ fn like_pattern(query: &str) -> String { | |||
| 554 | } | 554 | } |
| 555 | 555 | ||
| 556 | /// A fresh public-link token: 32 random bytes, base64url without padding. | 556 | /// A fresh public-link token: 32 random bytes, base64url without padding. |
| 557 | -/// Shown once at creation; only its hash is stored. | 557 | +/// Shown at creation and sealed by the web layer; only its hash is stored here. |
| 558 | fn new_token() -> String { | 558 | fn new_token() -> String { |
| 559 | use base64::Engine as _; | 559 | use base64::Engine as _; |
| 560 | let mut bytes = [0u8; 32]; | 560 | let mut bytes = [0u8; 32]; |
| @@ -1641,6 +1641,14 @@ impl Store for TursoStore { | |||
| 1641 | Ok(()) | 1641 | Ok(()) |
| 1642 | } | 1642 | } |
| 1643 | 1643 | ||
| 1644 | + async fn delete_setting(&self, key: &str) -> Result<()> { | ||
| 1645 | + let conn = self.conn.lock().await; | ||
| 1646 | + conn.execute("DELETE FROM setting WHERE key = ?1", params![key]) | ||
| 1647 | + .await | ||
| 1648 | + .map_err(backend)?; | ||
| 1649 | + Ok(()) | ||
| 1650 | + } | ||
| 1651 | + | ||
| 1644 | async fn thumb_bytes(&self, id: &str) -> Result<Option<Vec<u8>>> { | 1652 | async fn thumb_bytes(&self, id: &str) -> Result<Option<Vec<u8>>> { |
| 1645 | let conn = self.conn.lock().await; | 1653 | let conn = self.conn.lock().await; |
| 1646 | let mut rows = conn | 1654 | let mut rows = conn |
| @@ -2156,6 +2164,47 @@ impl Store for TursoStore { | |||
| 2156 | } | 2164 | } |
| 2157 | } | 2165 | } |
| 2158 | 2166 | ||
| 2167 | + async fn shared_target_ids(&self, owner_id: &str) -> Result<Vec<(ShareKind, String)>> { | ||
| 2168 | + let now = OffsetDateTime::now_utc(); | ||
| 2169 | + let mut found: std::collections::HashSet<(ShareKind, String)> = | ||
| 2170 | + std::collections::HashSet::new(); | ||
| 2171 | + let conn = self.conn.lock().await; | ||
| 2172 | + // Link liveness is decided here rather than in SQL, the way | ||
| 2173 | + // resolve_share_link decides it: one definition of live, the row's | ||
| 2174 | + // own timestamps. | ||
| 2175 | + let mut rows = conn | ||
| 2176 | + .query( | ||
| 2177 | + &format!("SELECT {LINK_COLUMNS} FROM share_link WHERE created_by = ?1"), | ||
| 2178 | + params![owner_id], | ||
| 2179 | + ) | ||
| 2180 | + .await | ||
| 2181 | + .map_err(backend)?; | ||
| 2182 | + while let Some(row) = rows.next().await.map_err(backend)? { | ||
| 2183 | + let link = link_from(&row)?; | ||
| 2184 | + if link.is_live(now) { | ||
| 2185 | + found.insert((link.kind, link.target_id)); | ||
| 2186 | + } | ||
| 2187 | + } | ||
| 2188 | + drop(rows); | ||
| 2189 | + // Grants name no owner — the target's own row does — so the ids are | ||
| 2190 | + // matched against the person's files and folders directly. | ||
| 2191 | + let mut rows = conn | ||
| 2192 | + .query( | ||
| 2193 | + "SELECT DISTINCT kind, target_id FROM share_user \ | ||
| 2194 | + WHERE (kind = 'file' AND target_id IN (SELECT id FROM file WHERE owner_id = ?1)) \ | ||
| 2195 | + OR (kind = 'folder' AND target_id IN (SELECT id FROM folder WHERE owner_id = ?1))", | ||
| 2196 | + params![owner_id], | ||
| 2197 | + ) | ||
| 2198 | + .await | ||
| 2199 | + .map_err(backend)?; | ||
| 2200 | + while let Some(row) = rows.next().await.map_err(backend)? { | ||
| 2201 | + found.insert((ShareKind::parse(&text(&row, 0)?)?, text(&row, 1)?)); | ||
| 2202 | + } | ||
| 2203 | + drop(rows); | ||
| 2204 | + drop(conn); | ||
| 2205 | + Ok(found.into_iter().collect()) | ||
| 2206 | + } | ||
| 2207 | + | ||
| 2159 | async fn add_share_user( | 2208 | async fn add_share_user( |
| 2160 | &self, | 2209 | &self, |
| 2161 | caller_id: &str, | 2210 | caller_id: &str, |
crates/in-core/tests/store.rsmodified+88 -0
| @@ -680,6 +680,94 @@ async fn share_links_open_until_revoked_or_expired() { | |||
| 680 | assert_eq!(scratch.store.share_links(&user.id).await.unwrap().len(), 2); | 680 | assert_eq!(scratch.store.share_links(&user.id).await.unwrap().len(), 2); |
| 681 | } | 681 | } |
| 682 | 682 | ||
| 683 | +/// The drive page's Shared mark reads its set from here: live links and | ||
| 684 | +/// given grants are in, revoked and expired links are out, and another | ||
| 685 | +/// owner's grants never leak in. | ||
| 686 | +#[tokio::test] | ||
| 687 | +async fn shared_target_ids_holds_live_links_and_own_grants() { | ||
| 688 | + let scratch = Scratch::open().await; | ||
| 689 | + let user = alice(&scratch.store).await; | ||
| 690 | + let friend = bob(&scratch.store).await; | ||
| 691 | + let linked = scratch.store.insert_file(&user.id, None, "linked", b"d").await.unwrap(); | ||
| 692 | + let granted = scratch.store.insert_file(&user.id, None, "granted", b"d").await.unwrap(); | ||
| 693 | + let folder = scratch.store.create_folder(&user.id, None, "dossier").await.unwrap(); | ||
| 694 | + let strangers = scratch.store.insert_file(&friend.id, None, "theirs", b"d").await.unwrap(); | ||
| 695 | + | ||
| 696 | + // Empty while nothing is shared. | ||
| 697 | + assert!(scratch.store.shared_target_ids(&user.id).await.unwrap().is_empty()); | ||
| 698 | + | ||
| 699 | + let file_link = scratch | ||
| 700 | + .store | ||
| 701 | + .create_share_link(&user.id, ShareKind::File, &linked.id, true, None, None) | ||
| 702 | + .await | ||
| 703 | + .unwrap(); | ||
| 704 | + scratch | ||
| 705 | + .store | ||
| 706 | + .add_share_user(&user.id, ShareKind::File, &granted.id, &friend.id, false) | ||
| 707 | + .await | ||
| 708 | + .unwrap(); | ||
| 709 | + scratch | ||
| 710 | + .store | ||
| 711 | + .add_share_user(&user.id, ShareKind::Folder, &folder.id, &friend.id, true) | ||
| 712 | + .await | ||
| 713 | + .unwrap(); | ||
| 714 | + | ||
| 715 | + let shared: std::collections::HashSet<_> = scratch | ||
| 716 | + .store | ||
| 717 | + .shared_target_ids(&user.id) | ||
| 718 | + .await | ||
| 719 | + .unwrap() | ||
| 720 | + .into_iter() | ||
| 721 | + .collect(); | ||
| 722 | + let expected: std::collections::HashSet<_> = vec![ | ||
| 723 | + (ShareKind::File, granted.id.clone()), | ||
| 724 | + (ShareKind::File, linked.id.clone()), | ||
| 725 | + (ShareKind::Folder, folder.id.clone()), | ||
| 726 | + ] | ||
| 727 | + .into_iter() | ||
| 728 | + .collect(); | ||
| 729 | + assert_eq!(shared, expected); | ||
| 730 | + // The friend shares nothing of their own: a grant received is not a | ||
| 731 | + // grant given. | ||
| 732 | + assert!(scratch.store.shared_target_ids(&friend.id).await.unwrap().is_empty()); | ||
| 733 | + | ||
| 734 | + // A revoked link drops out; the grant stays. | ||
| 735 | + scratch.store.revoke_share_link(&file_link.link.id).await.unwrap(); | ||
| 736 | + let shared = scratch.store.shared_target_ids(&user.id).await.unwrap(); | ||
| 737 | + assert_eq!(shared.len(), 2); | ||
| 738 | + assert!(!shared.contains(&(ShareKind::File, linked.id.clone()))); | ||
| 739 | + | ||
| 740 | + // An expired link drops out too. | ||
| 741 | + let past = scratch | ||
| 742 | + .store | ||
| 743 | + .create_share_link( | ||
| 744 | + &user.id, | ||
| 745 | + ShareKind::File, | ||
| 746 | + &linked.id, | ||
| 747 | + true, | ||
| 748 | + Some(OffsetDateTime::now_utc() - Duration::hours(1)), | ||
| 749 | + None, | ||
| 750 | + ) | ||
| 751 | + .await | ||
| 752 | + .unwrap(); | ||
| 753 | + let shared = scratch.store.shared_target_ids(&user.id).await.unwrap(); | ||
| 754 | + assert!(!shared.contains(&(ShareKind::File, past.link.target_id.clone()))); | ||
| 755 | + assert!(!shared.contains(&(ShareKind::File, strangers.id.clone()))); | ||
| 756 | + | ||
| 757 | + // Deleting the grant removes the last mark its target had. | ||
| 758 | + scratch | ||
| 759 | + .store | ||
| 760 | + .remove_share_user(ShareKind::File, &granted.id, &friend.id) | ||
| 761 | + .await | ||
| 762 | + .unwrap(); | ||
| 763 | + let shared = scratch.store.shared_target_ids(&user.id).await.unwrap(); | ||
| 764 | + assert_eq!( | ||
| 765 | + shared, | ||
| 766 | + vec![(ShareKind::Folder, folder.id.clone())], | ||
| 767 | + "the folder link is all that is left" | ||
| 768 | + ); | ||
| 769 | +} | ||
| 770 | + | ||
| 683 | #[tokio::test] | 771 | #[tokio::test] |
| 684 | async fn a_password_link_round_trips_its_hash() { | 772 | async fn a_password_link_round_trips_its_hash() { |
| 685 | let scratch = Scratch::open().await; | 773 | let scratch = Scratch::open().await; |
crates/in-web/src/drive.rsmodified+36 -5
| @@ -13,7 +13,9 @@ | |||
| 13 | //! plain GET form. The old `GET /search?q=` address 303s here, so old links | 13 | //! plain GET form. The old `GET /search?q=` address 303s here, so old links |
| 14 | //! keep working. | 14 | //! keep working. |
| 15 | 15 | ||
| 16 | -use in_core::store::{Folder, Store, StoreError}; | 16 | +use std::collections::HashSet; |
| 17 | + | ||
| 18 | +use in_core::store::{Folder, ShareKind, Store, StoreError}; | ||
| 17 | use topcoat::router::request::uri; | 19 | use topcoat::router::request::uri; |
| 18 | use topcoat::router::{HeaderName, HeaderValue, StatusCode, header, page, query_params, route}; | 20 | use topcoat::router::{HeaderName, HeaderValue, StatusCode, header, page, query_params, route}; |
| 19 | 21 | ||
| @@ -511,6 +513,15 @@ async fn drive(cx: &Cx) -> Result { | |||
| 511 | .as_ref() | 513 | .as_ref() |
| 512 | .map(|folder| folder.id.clone()) | 514 | .map(|folder| folder.id.clone()) |
| 513 | .unwrap_or_default(); | 515 | .unwrap_or_default(); |
| 516 | + // The rows this account shares today — live public links it minted and | ||
| 517 | + // grants it gave — marked on the listing. A failure reads as nothing | ||
| 518 | + // marked: the chip is garnish, and the listing itself is the meal. | ||
| 519 | + let shared: HashSet<(ShareKind, String)> = store | ||
| 520 | + .shared_target_ids(&user.id) | ||
| 521 | + .await | ||
| 522 | + .unwrap_or_default() | ||
| 523 | + .into_iter() | ||
| 524 | + .collect(); | ||
| 514 | let current_name = current | 525 | let current_name = current |
| 515 | .as_ref() | 526 | .as_ref() |
| 516 | .map(|folder| folder.name.clone()) | 527 | .map(|folder| folder.name.clone()) |
| @@ -706,7 +717,12 @@ async fn drive(cx: &Cx) -> Result { | |||
| 706 | <div class="drive-row"> | 717 | <div class="drive-row"> |
| 707 | <a class="drive-open" href=(format!("/drive?folder={}", folder.id))> | 718 | <a class="drive-open" href=(format!("/drive?folder={}", folder.id))> |
| 708 | <span class="file-chip file-chip-folder" aria-hidden="true">"▤"</span> | 719 | <span class="file-chip file-chip-folder" aria-hidden="true">"▤"</span> |
| 709 | - <span class="dep-title">(folder.name.clone())</span> | 720 | + <span class="dep-name-cell"> |
| 721 | + <span class="dep-title">(folder.name.clone())</span> | ||
| 722 | + if shared.contains(&(ShareKind::Folder, folder.id.clone())) { | ||
| 723 | + <span class="chip chip-shared">(t(language, Key::Shared))</span> | ||
| 724 | + } | ||
| 725 | + </span> | ||
| 710 | <span class="drive-meta" aria-hidden="true"></span> | 726 | <span class="drive-meta" aria-hidden="true"></span> |
| 711 | <span class="drive-meta drive-date">(folder.created_at.date().to_string())</span> | 727 | <span class="drive-meta drive-date">(folder.created_at.date().to_string())</span> |
| 712 | <span class="drive-meta" aria-hidden="true"></span> | 728 | <span class="drive-meta" aria-hidden="true"></span> |
| @@ -717,7 +733,12 @@ async fn drive(cx: &Cx) -> Result { | |||
| 717 | <div class="drive-row"> | 733 | <div class="drive-row"> |
| 718 | <a class="drive-open" href=(format!("/view/{}", file.id))> | 734 | <a class="drive-open" href=(format!("/view/{}", file.id))> |
| 719 | (crate::files::entry_chip(cx, file).await?) | 735 | (crate::files::entry_chip(cx, file).await?) |
| 720 | - <span class="dep-title">(file.name.clone())</span> | 736 | + <span class="dep-name-cell"> |
| 737 | + <span class="dep-title">(file.name.clone())</span> | ||
| 738 | + if shared.contains(&(ShareKind::File, file.id.clone())) { | ||
| 739 | + <span class="chip chip-shared">(t(language, Key::Shared))</span> | ||
| 740 | + } | ||
| 741 | + </span> | ||
| 721 | <span class="drive-meta drive-size">(human_size(file.size_bytes))</span> | 742 | <span class="drive-meta drive-size">(human_size(file.size_bytes))</span> |
| 722 | <span class="drive-meta drive-date">(file.created_at.date().to_string())</span> | 743 | <span class="drive-meta drive-date">(file.created_at.date().to_string())</span> |
| 723 | <span class="drive-meta drive-dl">(file.download_count.to_string())</span> | 744 | <span class="drive-meta drive-dl">(file.download_count.to_string())</span> |
| @@ -762,7 +783,12 @@ async fn drive(cx: &Cx) -> Result { | |||
| 762 | } else { | 783 | } else { |
| 763 | <a class="drive-open" href=(format!("/drive?folder={}", folder.id))> | 784 | <a class="drive-open" href=(format!("/drive?folder={}", folder.id))> |
| 764 | <span class="file-chip file-chip-folder" aria-hidden="true">"▤"</span> | 785 | <span class="file-chip file-chip-folder" aria-hidden="true">"▤"</span> |
| 765 | - <span class="dep-title">(folder.name.clone())</span> | 786 | + <span class="dep-name-cell"> |
| 787 | + <span class="dep-title">(folder.name.clone())</span> | ||
| 788 | + if shared.contains(&(ShareKind::Folder, folder.id.clone())) { | ||
| 789 | + <span class="chip chip-shared">(t(language, Key::Shared))</span> | ||
| 790 | + } | ||
| 791 | + </span> | ||
| 766 | <span class="drive-meta" aria-hidden="true"></span> | 792 | <span class="drive-meta" aria-hidden="true"></span> |
| 767 | <span class="drive-meta drive-date">(folder.created_at.date().to_string())</span> | 793 | <span class="drive-meta drive-date">(folder.created_at.date().to_string())</span> |
| 768 | <span class="drive-meta" aria-hidden="true"></span> | 794 | <span class="drive-meta" aria-hidden="true"></span> |
| @@ -801,7 +827,12 @@ async fn drive(cx: &Cx) -> Result { | |||
| 801 | } else { | 827 | } else { |
| 802 | <a class="drive-open" href=(format!("/view/{}", file.id))> | 828 | <a class="drive-open" href=(format!("/view/{}", file.id))> |
| 803 | (crate::files::entry_chip(cx, file).await?) | 829 | (crate::files::entry_chip(cx, file).await?) |
| 804 | - <span class="dep-title">(file.name.clone())</span> | 830 | + <span class="dep-name-cell"> |
| 831 | + <span class="dep-title">(file.name.clone())</span> | ||
| 832 | + if shared.contains(&(ShareKind::File, file.id.clone())) { | ||
| 833 | + <span class="chip chip-shared">(t(language, Key::Shared))</span> | ||
| 834 | + } | ||
| 835 | + </span> | ||
| 805 | <span class="drive-meta drive-size">(human_size(file.size_bytes))</span> | 836 | <span class="drive-meta drive-size">(human_size(file.size_bytes))</span> |
| 806 | <span class="drive-meta drive-date">(file.created_at.date().to_string())</span> | 837 | <span class="drive-meta drive-date">(file.created_at.date().to_string())</span> |
| 807 | <span class="drive-meta drive-dl">(file.download_count.to_string())</span> | 838 | <span class="drive-meta drive-dl">(file.download_count.to_string())</span> |
crates/in-web/src/i18n.rsmodified+9 -2
| @@ -232,6 +232,9 @@ pub enum Key { | |||
| 232 | EffectiveOrigin, | 232 | EffectiveOrigin, |
| 233 | BaseUrlLabel, | 233 | BaseUrlLabel, |
| 234 | BaseUrlNote, | 234 | BaseUrlNote, |
| 235 | + // Re-viewable share links (LinkVisible owns this block). | ||
| 236 | + Shared, | ||
| 237 | + LegacyLinkNote, | ||
| 235 | } | 238 | } |
| 236 | 239 | ||
| 237 | pub fn t(lang: Lang, key: Key) -> &'static str { | 240 | pub fn t(lang: Lang, key: Key) -> &'static str { |
| @@ -335,7 +338,7 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | |||
| 335 | EnableUser => "Enable", | 338 | EnableUser => "Enable", |
| 336 | DisabledBadge => "disabled", | 339 | DisabledBadge => "disabled", |
| 337 | LinkCreated => "Link created.", | 340 | LinkCreated => "Link created.", |
| 338 | - CopyLinkOnce => "Copy it now. It is shown once and never again.", | 341 | + CopyLinkOnce => "Copy it now. The full address also stays on your Share links panel.", |
| 339 | ExpiresLabel => "Expires", | 342 | ExpiresLabel => "Expires", |
| 340 | NeverExpires => "Never", | 343 | NeverExpires => "Never", |
| 341 | ViewOnly => "View only: preview, no downloads", | 344 | ViewOnly => "View only: preview, no downloads", |
| @@ -388,6 +391,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | |||
| 388 | EffectiveOrigin => "Effective origin", | 391 | EffectiveOrigin => "Effective origin", |
| 389 | BaseUrlLabel => "Public base URL", | 392 | BaseUrlLabel => "Public base URL", |
| 390 | BaseUrlNote => "The origin share links carry: a saved value wins, an empty one falls back to the configured base_url, then the bind address.", | 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.", |
| 394 | + Shared => "Shared", | ||
| 395 | + LegacyLinkNote => "This link predates re-viewable addresses — revoke and mint a new one to carry it forward.", | ||
| 391 | }, | 396 | }, |
| 392 | Lang::Tr => match key { | 397 | Lang::Tr => match key { |
| 393 | Cancel => "Vazgeç", | 398 | Cancel => "Vazgeç", |
| @@ -487,7 +492,7 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | |||
| 487 | EnableUser => "Etkinleştir", | 492 | EnableUser => "Etkinleştir", |
| 488 | DisabledBadge => "devre dışı", | 493 | DisabledBadge => "devre dışı", |
| 489 | LinkCreated => "Bağlantı oluşturuldu.", | 494 | LinkCreated => "Bağlantı oluşturuldu.", |
| 490 | - CopyLinkOnce => "Şimdi kopyala. Bir kez gösterilir, bir daha gösterilmez.", | 495 | + CopyLinkOnce => "Şimdi kopyala. Tam adres, Paylaşım bağlantıları panelinde de görünür kalır.", |
| 491 | ExpiresLabel => "Bitiş", | 496 | ExpiresLabel => "Bitiş", |
| 492 | NeverExpires => "Süresiz", | 497 | NeverExpires => "Süresiz", |
| 493 | ViewOnly => "Yalnızca görüntüleme: önizleme, indirme yok", | 498 | ViewOnly => "Yalnızca görüntüleme: önizleme, indirme yok", |
| @@ -540,6 +545,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | |||
| 540 | EffectiveOrigin => "Etkin kök adres", | 545 | EffectiveOrigin => "Etkin kök adres", |
| 541 | BaseUrlLabel => "Herkese açık kök adres", | 546 | BaseUrlLabel => "Herkese açık kök adres", |
| 542 | 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.", | 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.", |
| 548 | + 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.", | ||
| 543 | }, | 550 | }, |
| 544 | } | 551 | } |
| 545 | } | 552 | } |
crates/in-web/src/main.rsmodified+5 -2
| @@ -134,8 +134,10 @@ async fn main() { | |||
| 134 | }); | 134 | }); |
| 135 | let store: Arc<dyn in_core::store::Store> = store; | 135 | let store: Arc<dyn in_core::store::Store> = store; |
| 136 | 136 | ||
| 137 | - // The key sealing the OIDC session cookies, kept beside the database as | 137 | + // The `in.key` loaded here seals two things: the OIDC session cookies |
| 138 | - // `in.key` — one key per deployment, never in the repository. | 138 | + // below, and — through the app context — the share-link tokens their |
| 139 | + // creation seals onto setting rows, so the full link addresses can be | ||
| 140 | + // re-shown later. One key per deployment, never in the repository. | ||
| 139 | let key_path = std::path::Path::new(&config.database) | 141 | let key_path = std::path::Path::new(&config.database) |
| 140 | .parent() | 142 | .parent() |
| 141 | .map(|parent| parent.join("in.key")) | 143 | .map(|parent| parent.join("in.key")) |
| @@ -180,6 +182,7 @@ async fn main() { | |||
| 180 | store, | 182 | store, |
| 181 | config, | 183 | config, |
| 182 | shutdown: in_web::live::Shutdown(stopping), | 184 | shutdown: in_web::live::Shutdown(stopping), |
| 185 | + link_key: cookie_key, | ||
| 183 | }) | 186 | }) |
| 184 | .app_context(in_web::live::LiveWindow(std::time::Duration::from_secs( | 187 | .app_context(in_web::live::LiveWindow(std::time::Duration::from_secs( |
| 185 | live_seconds, | 188 | live_seconds, |
crates/in-web/src/server.rsmodified+25 -0
| @@ -35,6 +35,12 @@ pub struct App { | |||
| 35 | /// Told when the process is stopping, so the live streams end instead of | 35 | /// Told when the process is stopping, so the live streams end instead of |
| 36 | /// being waited out. | 36 | /// being waited out. |
| 37 | pub shutdown: crate::live::Shutdown, | 37 | pub shutdown: crate::live::Shutdown, |
| 38 | + /// The `in.key` loaded at boot — the same key that seals the session | ||
| 39 | + /// cookies. Share-link creation seals the minted token with it onto a | ||
| 40 | + /// setting row, so the full link address can be re-shown later; a | ||
| 41 | + /// database copy without the key file carries links that open but can | ||
| 42 | + /// no longer be re-viewed. | ||
| 43 | + pub link_key: in_core::store::secret::Key, | ||
| 38 | } | 44 | } |
| 39 | 45 | ||
| 40 | /// The application context this request runs under. | 46 | /// The application context this request runs under. |
| @@ -54,6 +60,25 @@ pub async fn share_origin(cx: &Cx) -> String { | |||
| 54 | } | 60 | } |
| 55 | } | 61 | } |
| 56 | 62 | ||
| 63 | +/// The full public address of a share link — `{origin}/s/{token}` — | ||
| 64 | +/// re-derived from the token its creation sealed onto the | ||
| 65 | +/// `share_token:{id}` setting row. | ||
| 66 | +/// | ||
| 67 | +/// `None` when the address cannot be told again: a link minted before the | ||
| 68 | +/// sealing carries no row, and a key lost since minting opens nothing. Both | ||
| 69 | +/// callers degrade the same way — the masked value plus the legacy note — | ||
| 70 | +/// so the option is the whole contract. | ||
| 71 | +pub async fn share_link_url(cx: &Cx, link: &in_core::store::ShareLink) -> Option<String> { | ||
| 72 | + let app = app(cx); | ||
| 73 | + let sealed = app | ||
| 74 | + .store | ||
| 75 | + .get_setting(&format!("share_token:{}", link.id)) | ||
| 76 | + .await | ||
| 77 | + .ok()??; | ||
| 78 | + let token = in_core::store::secret::open(&app.link_key, &sealed)?; | ||
| 79 | + Some(format!("{}/s/{token}", share_origin(cx).await)) | ||
| 80 | +} | ||
| 81 | + | ||
| 57 | /// A stable-enough label for the client, for rate limiting. A proxy header is | 82 | /// A stable-enough label for the client, for rate limiting. A proxy header is |
| 58 | /// only trusted because In is meant to sit behind one; the address bucket is | 83 | /// only trusted because In is meant to sit behind one; the address bucket is |
| 59 | /// the limit that actually protects the login round-trip either way. | 84 | /// the limit that actually protects the login round-trip either way. |
crates/in-web/src/settings.rsmodified+27 -6
| @@ -21,11 +21,12 @@ use topcoat::router::content::Form; | |||
| 21 | use topcoat::router::request::uri; | 21 | use topcoat::router::request::uri; |
| 22 | use topcoat::router::{HeaderName, StatusCode, header, page, route}; | 22 | use topcoat::router::{HeaderName, StatusCode, header, page, route}; |
| 23 | use topcoat::view::view; | 23 | use topcoat::view::view; |
| 24 | - | 24 | +use crate::server::{ |
| 25 | + Refusal, app, back_to, require_admin, require_user, share_link_url, share_origin, | ||
| 26 | +}; | ||
| 27 | +use crate::share::{refusal_banner, refusal_of, share_copy_script}; | ||
| 25 | use crate::i18n::{Key, lang, t}; | 28 | use crate::i18n::{Key, lang, t}; |
| 26 | use crate::layout::{NavPage, topbar}; | 29 | use crate::layout::{NavPage, topbar}; |
| 27 | -use crate::server::{Refusal, app, back_to, require_admin, require_user, share_origin}; | ||
| 28 | -use crate::share::{refusal_banner, refusal_of}; | ||
| 29 | 30 | ||
| 30 | /// Bytes in human units: `512 B`, `1.5 KiB`, `2.0 GiB`. One decimal past | 31 | /// Bytes in human units: `512 B`, `1.5 KiB`, `2.0 GiB`. One decimal past |
| 31 | /// bytes so a quota line reads at a glance. | 32 | /// bytes so a quota line reads at a glance. |
| @@ -315,7 +316,7 @@ async fn settings(cx: &Cx) -> Result { | |||
| 315 | // Only the section on show pays for its rows: the links panel names | 316 | // Only the section on show pays for its rows: the links panel names |
| 316 | // each live link's target, Everyone lists the accounts, and the server | 317 | // each live link's target, Everyone lists the accounts, and the server |
| 317 | // panel needs the origin — nothing else reads them. | 318 | // panel needs the origin — nothing else reads them. |
| 318 | - let mut link_names: Vec<(&in_core::store::ShareLink, String)> = Vec::new(); | 319 | + let mut link_names: Vec<(&in_core::store::ShareLink, String, Option<String>)> = Vec::new(); |
| 319 | let links = if section == Section::Links { | 320 | let links = if section == Section::Links { |
| 320 | store.share_links(&user.id).await? | 321 | store.share_links(&user.id).await? |
| 321 | } else { | 322 | } else { |
| @@ -343,7 +344,10 @@ async fn settings(cx: &Cx) -> Result { | |||
| 343 | .map(|folder| folder.name), | 344 | .map(|folder| folder.name), |
| 344 | } | 345 | } |
| 345 | .unwrap_or_else(|| link.target_id.clone()); | 346 | .unwrap_or_else(|| link.target_id.clone()); |
| 346 | - link_names.push((link, name)); | 347 | + // The full address, re-derived from the token the creation |
| 348 | + // sealed away; `None` keeps the row masked with the note. | ||
| 349 | + let url = share_link_url(cx, link).await; | ||
| 350 | + link_names.push((link, name, url)); | ||
| 347 | } | 351 | } |
| 348 | } | 352 | } |
| 349 | let users = if administers && section == Section::Everyone { | 353 | let users = if administers && section == Section::Everyone { |
| @@ -455,7 +459,7 @@ async fn settings(cx: &Cx) -> Result { | |||
| 455 | if link_names.is_empty() { | 459 | if link_names.is_empty() { |
| 456 | <p class="field-note">(t(language, Key::NoLinks))</p> | 460 | <p class="field-note">(t(language, Key::NoLinks))</p> |
| 457 | } | 461 | } |
| 458 | - for (link, target_name) in &link_names { | 462 | + for (link, target_name, url) in &link_names { |
| 459 | <div class="member-row"> | 463 | <div class="member-row"> |
| 460 | <span class="member-name">(format!("{} · {}", link.kind.as_str(), target_name.clone()))</span> | 464 | <span class="member-name">(format!("{} · {}", link.kind.as_str(), target_name.clone()))</span> |
| 461 | <span class="field-note">(expiry_line(language, link.expires_at))</span> | 465 | <span class="field-note">(expiry_line(language, link.expires_at))</span> |
| @@ -466,9 +470,26 @@ async fn settings(cx: &Cx) -> Result { | |||
| 466 | <button class="quiet quiet-danger" type="submit">(t(language, Key::RevokeLink))</button> | 470 | <button class="quiet quiet-danger" type="submit">(t(language, Key::RevokeLink))</button> |
| 467 | </form> | 471 | </form> |
| 468 | </div> | 472 | </div> |
| 473 | + // The same affordance the modal's live row | ||
| 474 | + // carries: the full address with its copy | ||
| 475 | + // button, or the masked value plus the | ||
| 476 | + // carry-forward note for a link from before | ||
| 477 | + // the sealing. | ||
| 478 | + <div class="share-link-row"> | ||
| 479 | + if let Some(url) = url { | ||
| 480 | + <input class="field-input share-link-url" readonly="" value=(url.clone()) aria-label=(t(language, Key::ShareLink))> | ||
| 481 | + <button class="quiet share-copy" type="button" data-copied-label=(t(language, Key::Copied))>(t(language, Key::CopyLink))</button> | ||
| 482 | + } else { | ||
| 483 | + <input class="field-input share-link-url" readonly="" value=(format!("{origin}/s/…")) aria-label=(t(language, Key::ShareLink))> | ||
| 484 | + <p class="field-note">(t(language, Key::LegacyLinkNote))</p> | ||
| 485 | + } | ||
| 486 | + </div> | ||
| 469 | } | 487 | } |
| 470 | </div> | 488 | </div> |
| 471 | </section> | 489 | </section> |
| 490 | + // One delegated listener serves every row's copy button | ||
| 491 | + // above; the script is idempotent across re-renders. | ||
| 492 | + (share_copy_script(cx).await?) | ||
| 472 | } | 493 | } |
| 473 | if section == Section::Everyone { | 494 | if section == Section::Everyone { |
| 474 | <section class="panel"> | 495 | <section class="panel"> |
crates/in-web/src/share.rsmodified+52 -13
| @@ -13,10 +13,12 @@ | |||
| 13 | //! | 13 | //! |
| 14 | //! Every mutation answers the way `board.rs` in iz does: a 303 back to the | 14 | //! Every mutation answers the way `board.rs` in iz does: a 303 back to the |
| 15 | //! page the form was posted from, the refusal (if any) on the redirect's | 15 | //! page the form was posted from, the refusal (if any) on the redirect's |
| 16 | -//! query. The one exception is link creation, whose plaintext token exists | 16 | +//! query. The one exception is link creation, whose plaintext token is |
| 17 | -//! only at creation: the redirect carries it once as `?created=<token>` so | 17 | +//! sealed with the app key onto the `share_token:{id}` setting row and |
| 18 | -//! a browser without script can copy it, and the drive and settings pages | 18 | +//! shown in the redirect's `?created=<token>` pair, so a browser without |
| 19 | -//! render the copy-once banner off that pair. | 19 | +//! script can copy it; the drive and settings pages render the copy-once |
| 20 | +//! banner off that pair, and re-derive the full address for the live-link | ||
| 21 | +//! rows from the sealed one. | ||
| 20 | 22 | ||
| 21 | use in_core::store::{File, ShareKind, Store, StoreError, ThumbState, User}; | 23 | use in_core::store::{File, ShareKind, Store, StoreError, ThumbState, User}; |
| 22 | use in_core::{hash_link_password, hash_share_token, link_password_matches, link_unlock_proof}; | 24 | use in_core::{hash_link_password, hash_share_token, link_password_matches, link_unlock_proof}; |
| @@ -34,7 +36,7 @@ use topcoat::view::view; | |||
| 34 | use crate::files::{ViewerKind, entry_chip, media_player, media_player_script, viewer_kind}; | 36 | use crate::files::{ViewerKind, entry_chip, media_player, media_player_script, viewer_kind}; |
| 35 | use crate::i18n::{Key, Lang, lang, t}; | 37 | use crate::i18n::{Key, Lang, lang, t}; |
| 36 | use crate::layout::{NavPage, document_shell, topbar, wordmark}; | 38 | use crate::layout::{NavPage, document_shell, topbar, wordmark}; |
| 37 | -use crate::server::{Refusal, app, back_to, require_user, share_origin}; | 39 | +use crate::server::{Refusal, app, back_to, require_user, share_link_url, share_origin}; |
| 38 | 40 | ||
| 39 | path_param!(token); | 41 | path_param!(token); |
| 40 | path_param!(kind); | 42 | path_param!(kind); |
| @@ -212,9 +214,11 @@ struct CreateLinkForm { | |||
| 212 | password: Option<String>, | 214 | password: Option<String>, |
| 213 | } | 215 | } |
| 214 | 216 | ||
| 215 | -/// Mints a bearer link. The token is shown once — in the redirect's | 217 | +/// Mints a bearer link. The token rides the redirect's `?created=` pair — |
| 216 | -/// `?created=` pair, which the drive and settings pages render as the | 218 | +/// which the drive and settings pages render as the copy-once banner — and |
| 217 | -/// copy-once banner — and never again; only its hash is stored. | 219 | +/// is sealed with the app key onto the `share_token:{id}` setting row, so |
| 220 | +/// the full address can be re-shown later; the row itself keeps only the | ||
| 221 | +/// token's hash. | ||
| 218 | #[route(POST "/api/share/link/create")] | 222 | #[route(POST "/api/share/link/create")] |
| 219 | async fn create_link(cx: &Cx, Form(input): Form<CreateLinkForm>) -> Redirect { | 223 | async fn create_link(cx: &Cx, Form(input): Form<CreateLinkForm>) -> Redirect { |
| 220 | let user = match require_user(cx).await { | 224 | let user = match require_user(cx).await { |
| @@ -259,10 +263,21 @@ async fn create_link(cx: &Cx, Form(input): Form<CreateLinkForm>) -> Redirect { | |||
| 259 | ) | 263 | ) |
| 260 | .await; | 264 | .await; |
| 261 | match created { | 265 | match created { |
| 262 | - Ok(link) => { | 266 | + Ok(minted) => { |
| 267 | + // The token is sealed onto its own setting row — the same | ||
| 268 | + // `in.key` that seals the session cookies — so the share modal | ||
| 269 | + // and the settings panel can re-show the full address later. A | ||
| 270 | + // failed seal is lived with, not refused: refusing now would | ||
| 271 | + // leave a live link whose token the one-time banner never | ||
| 272 | + // showed, the worse half of that bargain. | ||
| 273 | + let sealed = in_core::store::secret::seal(&app(cx).link_key, &minted.token); | ||
| 274 | + let _ = app(cx) | ||
| 275 | + .store | ||
| 276 | + .set_setting(&format!("share_token:{}", minted.link.id), &sealed) | ||
| 277 | + .await; | ||
| 263 | let back = back_to(cx, "/settings?section=links"); | 278 | let back = back_to(cx, "/settings?section=links"); |
| 264 | let separator = if back.contains('?') { '&' } else { '?' }; | 279 | let separator = if back.contains('?') { '&' } else { '?' }; |
| 265 | - let location = format!("{back}{separator}created={}", link.token); | 280 | + let location = format!("{back}{separator}created={}", minted.token); |
| 266 | Ok((StatusCode::SEE_OTHER, [(header::LOCATION, location)])) | 281 | Ok((StatusCode::SEE_OTHER, [(header::LOCATION, location)])) |
| 267 | } | 282 | } |
| 268 | Err(error) => redirect_back(cx, "/settings?section=links", "create", Some(refusal_of(error))), | 283 | Err(error) => redirect_back(cx, "/settings?section=links", "create", Some(refusal_of(error))), |
| @@ -297,7 +312,21 @@ async fn revoke_link(cx: &Cx, Form(input): Form<RevokeLinkForm>) -> Redirect { | |||
| 297 | return redirect_back(cx, "/settings?section=links", "revoke", Some(Refusal::NotFound)); | 312 | return redirect_back(cx, "/settings?section=links", "revoke", Some(Refusal::NotFound)); |
| 298 | } | 313 | } |
| 299 | match store.revoke_share_link(&input.id).await { | 314 | match store.revoke_share_link(&input.id).await { |
| 300 | - Ok(()) => redirect_back(cx, "/settings?section=links", "revoke", None), | 315 | + Ok(()) => { |
| 316 | + // The sealed address dies with the link: deleting the row is | ||
| 317 | + // part of revoking, not cleanup after it, so a failed delete | ||
| 318 | + // reports the revoke as refused. A retry finishes the job — | ||
| 319 | + // revoking twice is not an error. | ||
| 320 | + match store | ||
| 321 | + .delete_setting(&format!("share_token:{}", input.id)) | ||
| 322 | + .await | ||
| 323 | + { | ||
| 324 | + 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 | + } | ||
| 328 | + } | ||
| 329 | + } | ||
| 301 | Err(error) => redirect_back(cx, "/settings?section=links", "revoke", Some(refusal_of(error))), | 330 | Err(error) => redirect_back(cx, "/settings?section=links", "revoke", Some(refusal_of(error))), |
| 302 | } | 331 | } |
| 303 | } | 332 | } |
| @@ -1504,6 +1533,10 @@ pub(crate) async fn share_modal( | |||
| 1504 | </form> | 1533 | </form> |
| 1505 | } | 1534 | } |
| 1506 | for link in live.iter().take(1) { | 1535 | for link in live.iter().take(1) { |
| 1536 | + // The full address, re-derived from the token the creation sealed | ||
| 1537 | + // away. A link from before the sealing — or one whose key is gone — | ||
| 1538 | + // keeps the masked value and carries the carry-forward note. | ||
| 1539 | + let url = share_link_url(cx, *link).await; | ||
| 1507 | <div class="member-row"> | 1540 | <div class="member-row"> |
| 1508 | <span class="member-name">(t(language, Key::AnyoneWithLink))</span> | 1541 | <span class="member-name">(t(language, Key::AnyoneWithLink))</span> |
| 1509 | <div class="spacer"></div> | 1542 | <div class="spacer"></div> |
| @@ -1514,7 +1547,13 @@ pub(crate) async fn share_modal( | |||
| 1514 | <span class="field-note">(access_chip(language, link.can_download))</span> | 1547 | <span class="field-note">(access_chip(language, link.can_download))</span> |
| 1515 | </div> | 1548 | </div> |
| 1516 | <div class="share-link-row"> | 1549 | <div class="share-link-row"> |
| 1517 | - <input class="field-input share-link-url" readonly="" value=(format!("{origin}/s/…")) aria-label=(t(language, Key::ShareLink))> | 1550 | + if let Some(url) = url { |
| 1551 | + <input class="field-input share-link-url" readonly="" value=(url) aria-label=(t(language, Key::ShareLink))> | ||
| 1552 | + <button class="quiet share-copy" type="button" data-copied-label=(t(language, Key::Copied))>(t(language, Key::CopyLink))</button> | ||
| 1553 | + } else { | ||
| 1554 | + <input class="field-input share-link-url" readonly="" value=(format!("{origin}/s/…")) aria-label=(t(language, Key::ShareLink))> | ||
| 1555 | + <p class="field-note">(t(language, Key::LegacyLinkNote))</p> | ||
| 1556 | + } | ||
| 1518 | <form class="pop-row-form" method="post" action="/api/share/link/revoke"> | 1557 | <form class="pop-row-form" method="post" action="/api/share/link/revoke"> |
| 1519 | <input type="hidden" name="id" value=(link.id.clone())> | 1558 | <input type="hidden" name="id" value=(link.id.clone())> |
| 1520 | <button class="quiet quiet-danger" type="submit">(t(language, Key::RevokeLink))</button> | 1559 | <button class="quiet quiet-danger" type="submit">(t(language, Key::RevokeLink))</button> |
| @@ -1529,7 +1568,7 @@ pub(crate) async fn share_modal( | |||
| 1529 | 1568 | ||
| 1530 | /// The copy button's client half: one delegated listener, idempotent across | 1569 | /// The copy button's client half: one delegated listener, idempotent across |
| 1531 | /// the modal's re-renders (the `share-modal-copy` class marks a wired row). | 1570 | /// the modal's re-renders (the `share-modal-copy` class marks a wired row). |
| 1532 | -async fn share_copy_script(cx: &Cx) -> Result { | 1571 | +pub(crate) async fn share_copy_script(cx: &Cx) -> Result { |
| 1533 | use topcoat::view::Unescaped; | 1572 | use topcoat::view::Unescaped; |
| 1534 | const JS: &str = "\ | 1573 | const JS: &str = "\ |
| 1535 | (function () { \ | 1574 | (function () { \ |
crates/in-web/tests/http.rsmodified+231 -5
| @@ -374,8 +374,10 @@ impl TestApp { | |||
| 374 | store: store.clone(), | 374 | store: store.clone(), |
| 375 | config: config.clone(), | 375 | config: config.clone(), |
| 376 | shutdown: in_web::live::Shutdown(stopping), | 376 | shutdown: in_web::live::Shutdown(stopping), |
| 377 | + // Deliberately not the cookie key: the sealing helpers must | ||
| 378 | + // reach for `link_key`, not for whatever key sits nearest. | ||
| 379 | + link_key: [11u8; 32], | ||
| 377 | }) | 380 | }) |
| 378 | - .app_context(in_web::live::LiveWindow(std::time::Duration::from_secs(10))) | ||
| 379 | .build(); | 381 | .build(); |
| 380 | Self { | 382 | Self { |
| 381 | dir, | 383 | dir, |
| @@ -2001,6 +2003,229 @@ async fn share_modal_without_a_directory_keeps_the_typed_address() { | |||
| 2001 | ); | 2003 | ); |
| 2002 | } | 2004 | } |
| 2003 | 2005 | ||
| 2006 | +/// The link a person just minted stays visible: creation seals the token | ||
| 2007 | +/// onto its setting row, and the modal's live row and the settings panel's | ||
| 2008 | +/// row both re-derive the full address from it — copy buttons included, | ||
| 2009 | +/// masked value nowhere. | ||
| 2010 | +#[tokio::test] | ||
| 2011 | +async fn created_link_is_revisible_and_copyable_everywhere() { | ||
| 2012 | + let app = TestApp::build().await; | ||
| 2013 | + let ada = app.sign_in("sub-admin", "ada@in.test", "Ada").await; | ||
| 2014 | + let owner = owner_of(&app, "sub-admin").await; | ||
| 2015 | + let file = file_id(&app, &owner, "visible.txt", b"visible").await; | ||
| 2016 | + | ||
| 2017 | + let answer = app | ||
| 2018 | + .post( | ||
| 2019 | + "/api/share/link/create", | ||
| 2020 | + Some(&ada), | ||
| 2021 | + &[("kind", "file"), ("target_id", &file), ("can_download", "1")], | ||
| 2022 | + ) | ||
| 2023 | + .await; | ||
| 2024 | + assert!(answer.accepted(), "create refused: {:?}", answer.location); | ||
| 2025 | + let token = created_token(answer.location.as_deref().unwrap()); | ||
| 2026 | + let url = format!("http://127.0.0.1:7655/s/{token}"); | ||
| 2027 | + | ||
| 2028 | + // The mint stored the sealed token — ciphertext, not the plaintext — | ||
| 2029 | + // and the app's link key is what opens it. | ||
| 2030 | + let link = &app.store.share_links(&owner).await.unwrap()[0]; | ||
| 2031 | + let sealed = app | ||
| 2032 | + .store | ||
| 2033 | + .get_setting(&format!("share_token:{}", link.id)) | ||
| 2034 | + .await | ||
| 2035 | + .unwrap() | ||
| 2036 | + .expect("no sealed token row after mint"); | ||
| 2037 | + assert_ne!(sealed, token); | ||
| 2038 | + assert_eq!( | ||
| 2039 | + in_core::store::secret::open(&[11u8; 32], &sealed).as_deref(), | ||
| 2040 | + Some(token.as_str()) | ||
| 2041 | + ); | ||
| 2042 | + | ||
| 2043 | + // The modal's live row carries the full address with its copy button. | ||
| 2044 | + let page = app | ||
| 2045 | + .get( | ||
| 2046 | + &format!("/drive?share=file:{file}&created={token}"), | ||
| 2047 | + Some(&ada), | ||
| 2048 | + ) | ||
| 2049 | + .await; | ||
| 2050 | + assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | ||
| 2051 | + let text = page.text(); | ||
| 2052 | + assert!( | ||
| 2053 | + text.contains(&format!("value=\"{url}\"")), | ||
| 2054 | + "no full url in the modal: {text}" | ||
| 2055 | + ); | ||
| 2056 | + assert!( | ||
| 2057 | + text.contains("class=\"quiet share-copy\""), | ||
| 2058 | + "no copy button in the modal: {text}" | ||
| 2059 | + ); | ||
| 2060 | + assert!( | ||
| 2061 | + !text.contains("/s/…"), | ||
| 2062 | + "masked value on a re-visible link: {text}" | ||
| 2063 | + ); | ||
| 2064 | + | ||
| 2065 | + // The settings panel's row carries the same. | ||
| 2066 | + let page = app.get("/settings?section=links", Some(&ada)).await; | ||
| 2067 | + assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | ||
| 2068 | + let text = page.text(); | ||
| 2069 | + assert!( | ||
| 2070 | + text.contains(&format!("value=\"{url}\"")), | ||
| 2071 | + "no full url in settings: {text}" | ||
| 2072 | + ); | ||
| 2073 | + assert!( | ||
| 2074 | + text.contains("class=\"quiet share-copy\""), | ||
| 2075 | + "no copy button in settings: {text}" | ||
| 2076 | + ); | ||
| 2077 | + assert!( | ||
| 2078 | + text.contains("__inShareCopy"), | ||
| 2079 | + "no copy script on the links panel: {text}" | ||
| 2080 | + ); | ||
| 2081 | +} | ||
| 2082 | + | ||
| 2083 | +/// Revoking deletes the sealed row too — it is part of the revoke, so a | ||
| 2084 | +/// mint-and-revoke round trip leaves no orphan setting behind. | ||
| 2085 | +#[tokio::test] | ||
| 2086 | +async fn revoke_deletes_the_sealed_token_row() { | ||
| 2087 | + let app = TestApp::build().await; | ||
| 2088 | + let ada = app.sign_in("sub-admin", "ada@in.test", "Ada").await; | ||
| 2089 | + let owner = owner_of(&app, "sub-admin").await; | ||
| 2090 | + let file = file_id(&app, &owner, "sealed.txt", b"sealed").await; | ||
| 2091 | + | ||
| 2092 | + for round in 0..2 { | ||
| 2093 | + let answer = app | ||
| 2094 | + .post( | ||
| 2095 | + "/api/share/link/create", | ||
| 2096 | + Some(&ada), | ||
| 2097 | + &[("kind", "file"), ("target_id", &file)], | ||
| 2098 | + ) | ||
| 2099 | + .await; | ||
| 2100 | + assert!(answer.accepted(), "create refused: {:?}", answer.location); | ||
| 2101 | + let id = app.store.share_links(&owner).await.unwrap()[0].id.clone(); | ||
| 2102 | + let key = format!("share_token:{id}"); | ||
| 2103 | + assert!( | ||
| 2104 | + app.store.get_setting(&key).await.unwrap().is_some(), | ||
| 2105 | + "no sealed row after mint {round}" | ||
| 2106 | + ); | ||
| 2107 | + | ||
| 2108 | + let answer = app | ||
| 2109 | + .post("/api/share/link/revoke", Some(&ada), &[("id", &id)]) | ||
| 2110 | + .await; | ||
| 2111 | + assert!(answer.accepted(), "revoke refused: {:?}", answer.location); | ||
| 2112 | + assert!( | ||
| 2113 | + app.store.get_setting(&key).await.unwrap().is_none(), | ||
| 2114 | + "sealed row survived the revoke {round}" | ||
| 2115 | + ); | ||
| 2116 | + } | ||
| 2117 | +} | ||
| 2118 | + | ||
| 2119 | +/// A link minted before the sealing has no row to open: the modal and the | ||
| 2120 | +/// settings panel keep the masked value and carry the carry-forward note | ||
| 2121 | +/// instead of a copy button. | ||
| 2122 | +#[tokio::test] | ||
| 2123 | +async fn legacy_link_stays_masked_with_the_carry_forward_note() { | ||
| 2124 | + let app = TestApp::build().await; | ||
| 2125 | + let ada = app.sign_in("sub-admin", "ada@in.test", "Ada").await; | ||
| 2126 | + let owner = owner_of(&app, "sub-admin").await; | ||
| 2127 | + let file = file_id(&app, &owner, "legacy.txt", b"legacy").await; | ||
| 2128 | + // Minted through the store alone, as the pre-sealing code did it: no | ||
| 2129 | + // setting row ever comes to be. | ||
| 2130 | + app.store | ||
| 2131 | + .create_share_link(&owner, ShareKind::File, &file, false, None, None) | ||
| 2132 | + .await | ||
| 2133 | + .unwrap(); | ||
| 2134 | + | ||
| 2135 | + let page = app | ||
| 2136 | + .get(&format!("/drive?share=file:{file}"), Some(&ada)) | ||
| 2137 | + .await; | ||
| 2138 | + assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | ||
| 2139 | + let text = page.text(); | ||
| 2140 | + assert!(text.contains("/s/…"), "no masked value: {text}"); | ||
| 2141 | + assert!( | ||
| 2142 | + text.contains("predates re-viewable addresses"), | ||
| 2143 | + "no carry-forward note: {text}" | ||
| 2144 | + ); | ||
| 2145 | + assert!( | ||
| 2146 | + !text.contains("class=\"quiet share-copy\""), | ||
| 2147 | + "copy button on a link with no re-derivable address: {text}" | ||
| 2148 | + ); | ||
| 2149 | + | ||
| 2150 | + let page = app.get("/settings?section=links", Some(&ada)).await; | ||
| 2151 | + assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | ||
| 2152 | + let text = page.text(); | ||
| 2153 | + assert!(text.contains("/s/…"), "no masked value: {text}"); | ||
| 2154 | + assert!( | ||
| 2155 | + text.contains("predates re-viewable addresses"), | ||
| 2156 | + "no carry-forward note: {text}" | ||
| 2157 | + ); | ||
| 2158 | + assert!( | ||
| 2159 | + !text.contains("class=\"quiet share-copy\""), | ||
| 2160 | + "copy button on a link with no re-derivable address: {text}" | ||
| 2161 | + ); | ||
| 2162 | +} | ||
| 2163 | + | ||
| 2164 | +/// Live public links and grants to other people mark their drive rows with | ||
| 2165 | +/// the Shared chip; unmarked siblings carry nothing, and no row carries two. | ||
| 2166 | +#[tokio::test] | ||
| 2167 | +async fn drive_marks_shared_rows() { | ||
| 2168 | + let app = TestApp::build().await; | ||
| 2169 | + let ada = app.sign_in("sub-admin", "ada@in.test", "Ada").await; | ||
| 2170 | + app.sign_in("sub-ember", "ember@in.test", "Ember").await; | ||
| 2171 | + let owner = owner_of(&app, "sub-admin").await; | ||
| 2172 | + let linked = file_id(&app, &owner, "linked.txt", b"linked").await; | ||
| 2173 | + let plain = file_id(&app, &owner, "plain.txt", b"plain").await; | ||
| 2174 | + let granted = file_id(&app, &owner, "granted.txt", b"granted").await; | ||
| 2175 | + let answer = app | ||
| 2176 | + .post( | ||
| 2177 | + "/api/folder/create", | ||
| 2178 | + Some(&ada), | ||
| 2179 | + &[("parent_id", ""), ("name", "Dossier")], | ||
| 2180 | + ) | ||
| 2181 | + .await; | ||
| 2182 | + assert!(answer.accepted(), "folder create refused: {:?}", answer.location); | ||
| 2183 | + let folder = folder_id(&app, &owner, None, "Dossier").await; | ||
| 2184 | + | ||
| 2185 | + // A live public link onto the file, another onto the folder. | ||
| 2186 | + for (kind, target) in [("file", linked.as_str()), ("folder", folder.as_str())] { | ||
| 2187 | + let answer = app | ||
| 2188 | + .post( | ||
| 2189 | + "/api/share/link/create", | ||
| 2190 | + Some(&ada), | ||
| 2191 | + &[("kind", kind), ("target_id", target)], | ||
| 2192 | + ) | ||
| 2193 | + .await; | ||
| 2194 | + assert!(answer.accepted(), "create refused: {:?}", answer.location); | ||
| 2195 | + } | ||
| 2196 | + // A grant onto the third file. | ||
| 2197 | + let ember = app | ||
| 2198 | + .store | ||
| 2199 | + .user_by_email("ember@in.test") | ||
| 2200 | + .await | ||
| 2201 | + .unwrap() | ||
| 2202 | + .unwrap(); | ||
| 2203 | + app.store | ||
| 2204 | + .add_share_user(&owner, ShareKind::File, &granted, &ember.id, true) | ||
| 2205 | + .await | ||
| 2206 | + .unwrap(); | ||
| 2207 | + | ||
| 2208 | + let page = app.get("/drive", Some(&ada)).await; | ||
| 2209 | + assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | ||
| 2210 | + let text = page.text(); | ||
| 2211 | + let chips = text.matches("chip chip-shared").count(); | ||
| 2212 | + assert_eq!(chips, 3, "expected three marked rows: {text}"); | ||
| 2213 | + assert!( | ||
| 2214 | + text.contains("<span class=\"chip chip-shared\">Shared</span>"), | ||
| 2215 | + "chip markup changed: {text}" | ||
| 2216 | + ); | ||
| 2217 | + // The unshared sibling is on the page, but its row carries no mark. | ||
| 2218 | + assert!(text.contains("plain.txt"), "sibling missing: {text}"); | ||
| 2219 | + let plain_row = text | ||
| 2220 | + .split("<div class=\"drive-row\">") | ||
| 2221 | + .find(|row| row.contains("plain.txt")) | ||
| 2222 | + .expect("no drive row for the unshared sibling"); | ||
| 2223 | + assert!( | ||
| 2224 | + !plain_row.contains("chip-shared"), | ||
| 2225 | + "unshared sibling marked: {plain_row}" | ||
| 2226 | + ); | ||
| 2227 | +} | ||
| 2228 | + | ||
| 2004 | /// View only means preview, no download: the reader sees the media inline | 2229 | /// View only means preview, no download: the reader sees the media inline |
| 2005 | /// on the viewer page and reads the inline bytes, while `?dl=1` stays dead | 2230 | /// on the viewer page and reads the inline bytes, while `?dl=1` stays dead |
| 2006 | /// and the page never offers the Download link. | 2231 | /// and the page never offers the Download link. |
| @@ -2518,8 +2743,8 @@ async fn share_links_carry_the_configured_base_url() { | |||
| 2518 | page.text() | 2743 | page.text() |
| 2519 | ); | 2744 | ); |
| 2520 | 2745 | ||
| 2521 | - // The modal says the same: the minted row and the live-link | 2746 | + // The modal says the same — and a sealed link now carries the full |
| 2522 | - // placeholder alike. | 2747 | + // address, leaving no masked placeholder behind. |
| 2523 | let page = app | 2748 | let page = app |
| 2524 | .get( | 2749 | .get( |
| 2525 | &format!("/drive?share=file:{file}&created={token}"), | 2750 | &format!("/drive?share=file:{file}&created={token}"), |
| @@ -2534,8 +2759,8 @@ async fn share_links_carry_the_configured_base_url() { | |||
| 2534 | page.text() | 2759 | page.text() |
| 2535 | ); | 2760 | ); |
| 2536 | assert!( | 2761 | assert!( |
| 2537 | - page.text().contains("https://files.example.com/s/…"), | 2762 | + !page.text().contains("/s/…"), |
| 2538 | - "modal placeholder showed no domain: {}", | 2763 | + "modal kept a masked placeholder on a sealed link: {}", |
| 2539 | page.text() | 2764 | page.text() |
| 2540 | ); | 2765 | ); |
| 2541 | } | 2766 | } |
| @@ -4474,3 +4699,4 @@ async fn an_empty_folder_says_how_to_fill_it() { | |||
| 4474 | assert!(body.contains("id=\"upload-form\""), "{body}"); | 4699 | assert!(body.contains("id=\"upload-form\""), "{body}"); |
| 4475 | assert!(body.contains("__inDrop"), "{body}"); | 4700 | assert!(body.contains("__inDrop"), "{body}"); |
| 4476 | } | 4701 | } |
| 4702 | + | ||
style/main.scssmodified+15 -1
| @@ -788,13 +788,15 @@ a { | |||
| 788 | 788 | ||
| 789 | &-role, | 789 | &-role, |
| 790 | &-admin, | 790 | &-admin, |
| 791 | + &-shared, | ||
| 791 | &-connected, | 792 | &-connected, |
| 792 | &-off { | 793 | &-off { |
| 793 | text-transform: capitalize; | 794 | text-transform: capitalize; |
| 794 | } | 795 | } |
| 795 | 796 | ||
| 796 | &-role { background: var(--surface-sunken); border: 1px solid var(--border-strong); color: var(--ink-soft); } | 797 | &-role { background: var(--surface-sunken); border: 1px solid var(--border-strong); color: var(--ink-soft); } |
| 797 | - &-admin { background: var(--panel-sunken); border: 1px solid var(--border-strong); color: var(--muted); } | 798 | + &-admin, |
| 799 | + &-shared { background: var(--panel-sunken); border: 1px solid var(--border-strong); color: var(--muted); } | ||
| 798 | &-connected { background: var(--positive-tint); color: var(--positive-ink); } | 800 | &-connected { background: var(--positive-tint); color: var(--positive-ink); } |
| 799 | &-off { background: var(--warn-tint); color: var(--warn-ink); } | 801 | &-off { background: var(--warn-tint); color: var(--warn-ink); } |
| 800 | } | 802 | } |
| @@ -5184,6 +5186,18 @@ div.member-row + div.member-row { | |||
| 5184 | &:hover .dep-title { text-decoration: underline; } | 5186 | &:hover .dep-title { text-decoration: underline; } |
| 5185 | } | 5187 | } |
| 5186 | 5188 | ||
| 5189 | +// The name column of a drive row: the title keeps its ellipsis and the | ||
| 5190 | +// Shared mark rides beside it inside the one grid cell, so the mark never | ||
| 5191 | +// becomes a column of its own on the row's grid. | ||
| 5192 | +.dep-name-cell { | ||
| 5193 | + display: flex; | ||
| 5194 | + align-items: center; | ||
| 5195 | + gap: 8px; | ||
| 5196 | + min-width: 0; | ||
| 5197 | +} | ||
| 5198 | + | ||
| 5199 | +.dep-name-cell .dep-title { min-width: 0; } | ||
| 5200 | + | ||
| 5187 | .drive-meta { | 5201 | .drive-meta { |
| 5188 | min-width: 0; | 5202 | min-width: 0; |
| 5189 | overflow: hidden; | 5203 | overflow: hidden; |