the face is the directory's fact: im's photo_version rides the roster onto the user row (migration 0006, reconcile map, born-linked inserts), a /directory/live stream task in iz-web applies each Profile event through the same sync_member the 300s watchdog beat keeps as healer, im-client (pinned, OIDC half off) supplies the shared DirectoryClient the avatar route and the mirror both use, and the avatar proxy drops its own-id gate — any member's face serves to any signed-in member, ETagged p{row version}, a matching ?v= cached immutable for a year while every other spelling revalidates — and every avatar URL now carries the stamp, so an im-side upload lands as a members announce, a morph, and a new src on open boards with no reload
Browse files at this commit506e5257c027340471613f4c1cf355a4ff423e0cParent: 2f7e95919 changed files +442 -213
- Cargo.lock +22 -0
- Cargo.toml +1 -0
- crates/iz-client/src/lib.rs +0 -62
- crates/iz-core/migrations/0006_photo_version.sql +7 -0
- crates/iz-core/src/board.rs +4 -4
- crates/iz-core/src/store/mod.rs +13 -6
- crates/iz-core/src/store/reconcile.rs +15 -1
- crates/iz-core/src/store/schema.rs +1 -0
- crates/iz-core/src/store/turso_store.rs +36 -21
- crates/iz-core/tests/store.rs +57 -15
- crates/iz-web/Cargo.toml +1 -0
- crates/iz-web/src/avatar.rs +53 -40
- crates/iz-web/src/board.rs +1 -1
- crates/iz-web/src/detail.rs +7 -4
- crates/iz-web/src/layout.rs +16 -8
- crates/iz-web/src/main.rs +103 -25
- crates/iz-web/src/people.rs +1 -1
- crates/iz-web/src/settings.rs +5 -2
- crates/iz-web/tests/http.rs +99 -23
Cargo.lockmodified+22 -0
| @@ -1768,6 +1768,27 @@ dependencies = [ | |||
| 1768 | "icu_properties", | 1768 | "icu_properties", |
| 1769 | ] | 1769 | ] |
| 1770 | 1770 | ||
| 1771 | +[[package]] | ||
| 1772 | +name = "im-client" | ||
| 1773 | +version = "0.1.0" | ||
| 1774 | +source = "git+https://github.com/DizeyLab/im?rev=f7b2081#f7b208171820ca309b10043c6e86de12b81f3826" | ||
| 1775 | +dependencies = [ | ||
| 1776 | + "base64 0.22.1", | ||
| 1777 | + "chacha20poly1305", | ||
| 1778 | + "rand 0.10.2", | ||
| 1779 | + "reqwest", | ||
| 1780 | + "rsa", | ||
| 1781 | + "serde", | ||
| 1782 | + "serde_json", | ||
| 1783 | + "sha2 0.10.9", | ||
| 1784 | + "sha2 0.11.0", | ||
| 1785 | + "subtle", | ||
| 1786 | + "thiserror", | ||
| 1787 | + "time", | ||
| 1788 | + "tokio", | ||
| 1789 | + "topcoat", | ||
| 1790 | +] | ||
| 1791 | + | ||
| 1771 | [[package]] | 1792 | [[package]] |
| 1772 | name = "indexmap" | 1793 | name = "indexmap" |
| 1773 | version = "2.14.0" | 1794 | version = "2.14.0" |
| @@ -1904,6 +1925,7 @@ dependencies = [ | |||
| 1904 | "grass", | 1925 | "grass", |
| 1905 | "http", | 1926 | "http", |
| 1906 | "http-body-util", | 1927 | "http-body-util", |
| 1928 | + "im-client", | ||
| 1907 | "iz-client", | 1929 | "iz-client", |
| 1908 | "iz-core", | 1930 | "iz-core", |
| 1909 | "lettre", | 1931 | "lettre", |
Cargo.tomlmodified+1 -0
| @@ -11,6 +11,7 @@ repository = "https://github.com/DizeyLab/iz" | |||
| 11 | [workspace.dependencies] | 11 | [workspace.dependencies] |
| 12 | iz-core = { path = "crates/iz-core", default-features = false } | 12 | iz-core = { path = "crates/iz-core", default-features = false } |
| 13 | iz-client = { path = "crates/iz-client" } | 13 | iz-client = { path = "crates/iz-client" } |
| 14 | +im-client = { git = "https://github.com/DizeyLab/im", rev = "f7b2081", default-features = false } | ||
| 14 | serde = { version = "1.0.229", features = ["derive"] } | 15 | serde = { version = "1.0.229", features = ["derive"] } |
| 15 | serde_json = "1.0.145" | 16 | serde_json = "1.0.145" |
| 16 | thiserror = "2.0.20" | 17 | thiserror = "2.0.20" |
crates/iz-client/src/lib.rsmodified+0 -62
| @@ -150,48 +150,6 @@ pub async fn current_user(cx: &Cx) -> Option<User> { | |||
| 150 | } | 150 | } |
| 151 | } | 151 | } |
| 152 | 152 | ||
| 153 | -/// The person's profile photo from im, if im has one. `None` on 404 and on | ||
| 154 | -/// anything else that is not the bytes — a dropped connection, a body that | ||
| 155 | -/// will not read, a reply without a mime — because a missing face must never | ||
| 156 | -/// fail the page around it: the caller renders its initials instead. | ||
| 157 | -/// | ||
| 158 | -/// Authenticated as the app, not the browser: `Authorization: Basic | ||
| 159 | -/// base64(client_id ":" client_secret)` against im's `/photo/{user_id}`, | ||
| 160 | -/// the same credentials the introspection round-trip posts with. | ||
| 161 | -pub async fn photo_for(cx: &Cx, user_id: &str) -> Option<(Vec<u8>, String)> { | ||
| 162 | - let state = client(cx); | ||
| 163 | - let reply = state | ||
| 164 | - .http | ||
| 165 | - .get(format!("{}/photo/{user_id}", state.config.issuer)) | ||
| 166 | - .basic_auth(&state.config.client_id, Some(&state.config.client_secret)) | ||
| 167 | - .send() | ||
| 168 | - .await | ||
| 169 | - .ok()?; | ||
| 170 | - if !reply.status().is_success() { | ||
| 171 | - return None; | ||
| 172 | - } | ||
| 173 | - let mime = reply | ||
| 174 | - .headers() | ||
| 175 | - .get(reqwest::header::CONTENT_TYPE)? | ||
| 176 | - .to_str() | ||
| 177 | - .ok()? | ||
| 178 | - .to_string(); | ||
| 179 | - let bytes = reply.bytes().await.ok()?.to_vec(); | ||
| 180 | - Some((bytes, mime)) | ||
| 181 | -} | ||
| 182 | - | ||
| 183 | -/// One entry of im's directory: the stable subject, the address, the | ||
| 184 | -/// display name, and whether im calls the person an admin — exactly what | ||
| 185 | -/// mirroring the directory into local member rows needs. | ||
| 186 | -#[derive(Debug, Clone, serde::Deserialize)] | ||
| 187 | -pub struct DirectoryMember { | ||
| 188 | - pub sub: String, | ||
| 189 | - pub email: String, | ||
| 190 | - pub name: String, | ||
| 191 | - #[serde(default)] | ||
| 192 | - pub admin: bool, | ||
| 193 | -} | ||
| 194 | - | ||
| 195 | /// One entry of im's family list: the wordmark key, the human name, and | 153 | /// One entry of im's family list: the wordmark key, the human name, and |
| 196 | /// where the app lives — exactly what the topbar switcher renders. | 154 | /// where the app lives — exactly what the topbar switcher renders. |
| 197 | /// `Serialize` because the app that fetched it mirrors it into its own | 155 | /// `Serialize` because the app that fetched it mirrors it into its own |
| @@ -204,26 +162,6 @@ pub struct FamilyService { | |||
| 204 | } | 162 | } |
| 205 | 163 | ||
| 206 | impl IzClient { | 164 | impl IzClient { |
| 207 | - /// The family phonebook: every non-disabled user im knows, fetched as | ||
| 208 | - /// the app (`Authorization: Basic` with the client pair, the same | ||
| 209 | - /// credentials the photo route takes). `None` on anything that is not a | ||
| 210 | - /// readable list — a refused pair, a dropped connection, a body that is | ||
| 211 | - /// not the array — because a missed beat must never look like an empty | ||
| 212 | - /// directory: the caller keeps the rows it has and asks again next beat. | ||
| 213 | - pub async fn directory(&self) -> Option<Vec<DirectoryMember>> { | ||
| 214 | - let reply = self | ||
| 215 | - .http | ||
| 216 | - .get(format!("{}/directory", self.config.issuer)) | ||
| 217 | - .basic_auth(&self.config.client_id, Some(&self.config.client_secret)) | ||
| 218 | - .send() | ||
| 219 | - .await | ||
| 220 | - .ok()?; | ||
| 221 | - if !reply.status().is_success() { | ||
| 222 | - return None; | ||
| 223 | - } | ||
| 224 | - reply.json().await.ok() | ||
| 225 | - } | ||
| 226 | - | ||
| 227 | /// The family list: every app im's admin panel serves, fetched as the | 165 | /// The family list: every app im's admin panel serves, fetched as the |
| 228 | /// app (`Authorization: Basic` with the client pair, the same | 166 | /// app (`Authorization: Basic` with the client pair, the same |
| 229 | /// credentials the directory takes). `None` on anything that is not a | 167 | /// credentials the directory takes). `None` on anything that is not a |
crates/iz-core/migrations/0006_photo_version.sqladded+7 -0
| @@ -0,0 +1,7 @@ | |||
| 1 | +-- The face wears a version now. im counts every change to a member's photo, | ||
| 2 | +-- and the count rides the directory: a sync that sees a new number knows the | ||
| 3 | +-- face changed without fetching it, and an avatar URL stamped with the number | ||
| 4 | +-- a page rendered can be cached hard — the browser only refetches when the | ||
| 5 | +-- stamp it holds is no longer the stamp the row carries. Rows from before | ||
| 6 | +-- this column start at zero, the count of a member im has never photographed. | ||
| 7 | +ALTER TABLE user ADD COLUMN photo_version INTEGER NOT NULL DEFAULT 0; | ||
crates/iz-core/src/board.rsmodified+4 -4
| @@ -95,10 +95,10 @@ pub enum Moved { | |||
| 95 | pub struct Person { | 95 | pub struct Person { |
| 96 | pub id: String, | 96 | pub id: String, |
| 97 | pub display_name: String, | 97 | pub display_name: String, |
| 98 | - /// Whether a local photo exists — always false since SSO: avatars come | 98 | + /// How many times the provider has re-photographed this person: the |
| 99 | - /// from the provider, and the board keeps the field so the shape the | 99 | + /// `?v=` an avatar URL carries, so a browser may cache the bytes hard |
| 100 | - /// pages read does not churn under them. | 100 | + /// and still refetch the day the face changes. Zero: no photo there. |
| 101 | - pub has_photo: bool, | 101 | + pub photo_version: u64, |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | impl Person { | 104 | impl Person { |
crates/iz-core/src/store/mod.rsmodified+13 -6
| @@ -200,6 +200,11 @@ pub struct User { | |||
| 200 | pub language: String, | 200 | pub language: String, |
| 201 | /// Display-only, as [`Self::timezone`]. | 201 | /// Display-only, as [`Self::timezone`]. |
| 202 | pub ui: String, | 202 | pub ui: String, |
| 203 | + /// How many times the person's photo has changed at the provider: the | ||
| 204 | + /// `?v=` stamp an avatar URL carries, so a page can be served for months | ||
| 205 | + /// and the browser still refetches the day the face changes. Zero: no | ||
| 206 | + /// photo, or a provider too old to count. | ||
| 207 | + pub photo_version: u64, | ||
| 203 | } | 208 | } |
| 204 | 209 | ||
| 205 | /// The profile page's totals for one person: what is on their plate, what | 210 | /// The profile page's totals for one person: what is on their plate, what |
| @@ -784,18 +789,20 @@ pub trait Store: BoardReads + DetailReads + 'static { | |||
| 784 | /// gets a row born linked — assignable, mailable and avatar-able before | 789 | /// gets a row born linked — assignable, mailable and avatar-able before |
| 785 | /// their first visit. An unclaimed row with a matching address is | 790 | /// their first visit. An unclaimed row with a matching address is |
| 786 | /// claimed (sub stamped, id/role/preferences/history kept), a known row | 791 | /// claimed (sub stamped, id/role/preferences/history kept), a known row |
| 787 | - /// follows the provider's address, name and admin flag, and a row that | 792 | + /// follows the provider's address, name, admin flag and photo version, |
| 788 | - /// already agrees is left alone. Unlike [`Store::provision_user`] this | 793 | + /// and a row that already agrees is left alone. Unlike |
| 789 | - /// is not a sign-in: `last_signed_in_at` is never stamped, and an empty | 794 | + /// [`Store::provision_user`] this is not a sign-in: `last_signed_in_at` |
| 790 | - /// database grows no workspace (the first sign-in builds it; the next | 795 | + /// is never stamped, and an empty database grows no workspace (the first |
| 791 | - /// beat mirrors everyone). The admin flag claims an unclaimed owner the | 796 | + /// sign-in builds it; the next beat mirrors everyone). The admin flag |
| 792 | - /// same way provision does. Says what happened through [`MemberSync`]. | 797 | + /// claims an unclaimed owner the same way provision does. Says what |
| 798 | + /// happened through [`MemberSync`]. | ||
| 793 | async fn sync_member( | 799 | async fn sync_member( |
| 794 | &self, | 800 | &self, |
| 795 | sub: &str, | 801 | sub: &str, |
| 796 | email: &str, | 802 | email: &str, |
| 797 | display_name: &str, | 803 | display_name: &str, |
| 798 | im_admin: bool, | 804 | im_admin: bool, |
| 805 | + photo_version: u64, | ||
| 799 | ) -> Result<MemberSync>; | 806 | ) -> Result<MemberSync>; |
| 800 | 807 | ||
| 801 | async fn user(&self, id: &str) -> Result<Option<User>>; | 808 | async fn user(&self, id: &str) -> Result<Option<User>>; |
crates/iz-core/src/store/reconcile.rsmodified+15 -1
| @@ -270,6 +270,7 @@ fn build_maps( | |||
| 270 | old_has_clock: bool, | 270 | old_has_clock: bool, |
| 271 | old_has_reminder: bool, | 271 | old_has_reminder: bool, |
| 272 | old_has_tag: bool, | 272 | old_has_tag: bool, |
| 273 | + old_has_photo_version: bool, | ||
| 273 | ) -> Vec<TableMap> { | 274 | ) -> Vec<TableMap> { |
| 274 | let mut maps = Vec::new(); | 275 | let mut maps = Vec::new(); |
| 275 | 276 | ||
| @@ -363,6 +364,17 @@ fn build_maps( | |||
| 363 | ("language", "old.language".into()), | 364 | ("language", "old.language".into()), |
| 364 | ("ui", "old.ui".into()), | 365 | ("ui", "old.ui".into()), |
| 365 | ("created_at", "old.created_at".into()), | 366 | ("created_at", "old.created_at".into()), |
| 367 | + ( | ||
| 368 | + // A database from before faces wore versions starts every | ||
| 369 | + // member at zero — im's count of "never photographed" — and | ||
| 370 | + // the next directory pass stamps the real one. | ||
| 371 | + "photo_version", | ||
| 372 | + if old_has_photo_version { | ||
| 373 | + "old.photo_version".into() | ||
| 374 | + } else { | ||
| 375 | + "0".to_string() | ||
| 376 | + }, | ||
| 377 | + ), | ||
| 366 | ("last_signed_in_at", "old.last_signed_in_at".into()), | 378 | ("last_signed_in_at", "old.last_signed_in_at".into()), |
| 367 | ], | 379 | ], |
| 368 | }); | 380 | }); |
| @@ -747,12 +759,14 @@ async fn copy_data(old_conn: &Connection, new_conn: &Connection, path: &str) -> | |||
| 747 | let has_reminder = old_has_column(old_conn, "workspace", "reminder_minutes").await?; | 759 | let has_reminder = old_has_column(old_conn, "workspace", "reminder_minutes").await?; |
| 748 | let has_tag = old_has_column(old_conn, "tag", "id").await?; | 760 | let has_tag = old_has_column(old_conn, "tag", "id").await?; |
| 749 | let has_setting = old_has_column(old_conn, "setting", "key").await?; | 761 | let has_setting = old_has_column(old_conn, "setting", "key").await?; |
| 762 | + let has_photo_version = old_has_column(old_conn, "user", "photo_version").await?; | ||
| 750 | let maps = build_maps( | 763 | let maps = build_maps( |
| 751 | has_smtp_check, | 764 | has_smtp_check, |
| 752 | has_batch_window, | 765 | has_batch_window, |
| 753 | has_clock, | 766 | has_clock, |
| 754 | has_reminder, | 767 | has_reminder, |
| 755 | has_tag, | 768 | has_tag, |
| 769 | + has_photo_version, | ||
| 756 | ); | 770 | ); |
| 757 | validate_maps(new_conn, &maps).await?; | 771 | validate_maps(new_conn, &maps).await?; |
| 758 | 772 | ||
| @@ -1059,7 +1073,7 @@ mod tests { | |||
| 1059 | let conn = db.connect().unwrap(); | 1073 | let conn = db.connect().unwrap(); |
| 1060 | conn.execute_batch(&schema_sql()).await.unwrap(); | 1074 | conn.execute_batch(&schema_sql()).await.unwrap(); |
| 1061 | 1075 | ||
| 1062 | - let maps = build_maps(false, false, false, false, false); | 1076 | + let maps = build_maps(false, false, false, false, false, false); |
| 1063 | validate_maps(&conn, &maps) | 1077 | validate_maps(&conn, &maps) |
| 1064 | .await | 1078 | .await |
| 1065 | .expect("the full map set was refused against the declared schema"); | 1079 | .expect("the full map set was refused against the declared schema"); |
crates/iz-core/src/store/schema.rsmodified+1 -0
| @@ -19,6 +19,7 @@ pub(crate) const MIGRATIONS: &[&str] = &[ | |||
| 19 | include_str!("../../migrations/0003_sso.sql"), | 19 | include_str!("../../migrations/0003_sso.sql"), |
| 20 | include_str!("../../migrations/0004_no_photo_limit.sql"), | 20 | include_str!("../../migrations/0004_no_photo_limit.sql"), |
| 21 | include_str!("../../migrations/0005_settings.sql"), | 21 | include_str!("../../migrations/0005_settings.sql"), |
| 22 | + include_str!("../../migrations/0006_photo_version.sql"), | ||
| 22 | ]; | 23 | ]; |
| 23 | 24 | ||
| 24 | /// The whole declared schema — every migration applied in order — as one | 25 | /// The whole declared schema — every migration applied in order — as one |
crates/iz-core/src/store/turso_store.rsmodified+36 -21
| @@ -1232,11 +1232,12 @@ fn user_from(row: &Row) -> Result<User> { | |||
| 1232 | theme: text(row, 10)?, | 1232 | theme: text(row, 10)?, |
| 1233 | language: text(row, 11)?, | 1233 | language: text(row, 11)?, |
| 1234 | ui: text(row, 12)?, | 1234 | ui: text(row, 12)?, |
| 1235 | + photo_version: row.get::<i64>(13).map_err(backend)?.max(0) as u64, | ||
| 1235 | }) | 1236 | }) |
| 1236 | } | 1237 | } |
| 1237 | 1238 | ||
| 1238 | const USER_COLUMNS: &str = "id, workspace_id, oidc_sub, email, display_name, role, disabled, \ | 1239 | const USER_COLUMNS: &str = "id, workspace_id, oidc_sub, email, display_name, role, disabled, \ |
| 1239 | - created_at, last_signed_in_at, timezone, theme, language, ui"; | 1240 | + created_at, last_signed_in_at, timezone, theme, language, ui, photo_version"; |
| 1240 | 1241 | ||
| 1241 | /// Addresses are matched case-insensitively; the display form is kept as typed. | 1242 | /// Addresses are matched case-insensitively; the display form is kept as typed. |
| 1242 | fn fold_email(email: &str) -> String { | 1243 | fn fold_email(email: &str) -> String { |
| @@ -1463,6 +1464,7 @@ impl Store for TursoStore { | |||
| 1463 | email: &str, | 1464 | email: &str, |
| 1464 | display_name: &str, | 1465 | display_name: &str, |
| 1465 | im_admin: bool, | 1466 | im_admin: bool, |
| 1467 | + photo_version: u64, | ||
| 1466 | ) -> Result<MemberSync> { | 1468 | ) -> Result<MemberSync> { |
| 1467 | let email = fold_email(email); | 1469 | let email = fold_email(email); |
| 1468 | // IMMEDIATE like provision_user: a beat racing a first sign-in over | 1470 | // IMMEDIATE like provision_user: a beat racing a first sign-in over |
| @@ -1485,12 +1487,23 @@ impl Store for TursoStore { | |||
| 1485 | let role = synced_role(user.role, im_admin); | 1487 | let role = synced_role(user.role, im_admin); |
| 1486 | // A sync is not a sign-in: last_signed_in_at is the person's own | 1488 | // A sync is not a sign-in: last_signed_in_at is the person's own |
| 1487 | // fact, and the directory says nothing about it. | 1489 | // fact, and the directory says nothing about it. |
| 1488 | - if user.email == email && user.display_name == display_name && role == user.role { | 1490 | + if user.email == email |
| 1491 | + && user.display_name == display_name | ||
| 1492 | + && role == user.role | ||
| 1493 | + && user.photo_version == photo_version | ||
| 1494 | + { | ||
| 1489 | Some((user.id, MemberSync::Untouched)) | 1495 | Some((user.id, MemberSync::Untouched)) |
| 1490 | } else { | 1496 | } else { |
| 1491 | tx.execute( | 1497 | tx.execute( |
| 1492 | - "UPDATE user SET email = ?1, display_name = ?2, role = ?3 WHERE id = ?4", | 1498 | + "UPDATE user SET email = ?1, display_name = ?2, role = ?3, \ |
| 1493 | - params![email.clone(), display_name, role.as_str(), user.id.clone()], | 1499 | + photo_version = ?4 WHERE id = ?5", |
| 1500 | + params![ | ||
| 1501 | + email.clone(), | ||
| 1502 | + display_name, | ||
| 1503 | + role.as_str(), | ||
| 1504 | + photo_version as i64, | ||
| 1505 | + user.id.clone() | ||
| 1506 | + ], | ||
| 1494 | ) | 1507 | ) |
| 1495 | .await | 1508 | .await |
| 1496 | .map_err(backend)?; | 1509 | .map_err(backend)?; |
| @@ -1511,13 +1524,14 @@ impl Store for TursoStore { | |||
| 1511 | if let Some(user) = seen { | 1524 | if let Some(user) = seen { |
| 1512 | let role = synced_role(user.role, im_admin); | 1525 | let role = synced_role(user.role, im_admin); |
| 1513 | tx.execute( | 1526 | tx.execute( |
| 1514 | - "UPDATE user SET oidc_sub = ?1, email = ?2, display_name = ?3, role = ?4 \ | 1527 | + "UPDATE user SET oidc_sub = ?1, email = ?2, display_name = ?3, role = ?4, \ |
| 1515 | - WHERE id = ?5", | 1528 | + photo_version = ?5 WHERE id = ?6", |
| 1516 | params![ | 1529 | params![ |
| 1517 | sub, | 1530 | sub, |
| 1518 | email.clone(), | 1531 | email.clone(), |
| 1519 | display_name, | 1532 | display_name, |
| 1520 | role.as_str(), | 1533 | role.as_str(), |
| 1534 | + photo_version as i64, | ||
| 1521 | user.id.clone() | 1535 | user.id.clone() |
| 1522 | ], | 1536 | ], |
| 1523 | ) | 1537 | ) |
| @@ -1547,8 +1561,8 @@ impl Store for TursoStore { | |||
| 1547 | let role = if im_admin { Role::Admin } else { Role::Member }; | 1561 | let role = if im_admin { Role::Admin } else { Role::Member }; |
| 1548 | tx.execute( | 1562 | tx.execute( |
| 1549 | "INSERT INTO user (id, workspace_id, oidc_sub, email, display_name, \ | 1563 | "INSERT INTO user (id, workspace_id, oidc_sub, email, display_name, \ |
| 1550 | - role, disabled, created_at, last_signed_in_at) \ | 1564 | + role, disabled, created_at, last_signed_in_at, photo_version) \ |
| 1551 | - VALUES (?1, ?2, ?3, ?4, ?5, ?6, 0, ?7, NULL)", | 1565 | + VALUES (?1, ?2, ?3, ?4, ?5, ?6, 0, ?7, NULL, ?8)", |
| 1552 | params![ | 1566 | params![ |
| 1553 | id.clone(), | 1567 | id.clone(), |
| 1554 | workspace_id, | 1568 | workspace_id, |
| @@ -1556,7 +1570,8 @@ impl Store for TursoStore { | |||
| 1556 | email.clone(), | 1570 | email.clone(), |
| 1557 | display_name, | 1571 | display_name, |
| 1558 | role.as_str(), | 1572 | role.as_str(), |
| 1559 | - now.clone() | 1573 | + now.clone(), |
| 1574 | + photo_version as i64 | ||
| 1560 | ], | 1575 | ], |
| 1561 | ) | 1576 | ) |
| 1562 | .await | 1577 | .await |
| @@ -4807,7 +4822,7 @@ impl DetailReads for TursoStore { | |||
| 4807 | let conn = self.conn.lock().await; | 4822 | let conn = self.conn.lock().await; |
| 4808 | let mut rows = conn | 4823 | let mut rows = conn |
| 4809 | .query( | 4824 | .query( |
| 4810 | - "SELECT u.id, u.display_name, 0 FROM task_assignee a \ | 4825 | + "SELECT u.id, u.display_name, u.photo_version FROM task_assignee a \ |
| 4811 | JOIN user u ON u.id = a.user_id \ | 4826 | JOIN user u ON u.id = a.user_id \ |
| 4812 | WHERE a.task_id = ?1 ORDER BY u.display_name", | 4827 | WHERE a.task_id = ?1 ORDER BY u.display_name", |
| 4813 | params![task_id], | 4828 | params![task_id], |
| @@ -4819,7 +4834,7 @@ impl DetailReads for TursoStore { | |||
| 4819 | out.push(Person { | 4834 | out.push(Person { |
| 4820 | id: text(&row, 0)?, | 4835 | id: text(&row, 0)?, |
| 4821 | display_name: text(&row, 1)?, | 4836 | display_name: text(&row, 1)?, |
| 4822 | - has_photo: row.get::<i64>(2).map_err(backend)? != 0, | 4837 | + photo_version: row.get::<i64>(2).map_err(backend)?.max(0) as u64, |
| 4823 | }); | 4838 | }); |
| 4824 | } | 4839 | } |
| 4825 | Ok(out) | 4840 | Ok(out) |
| @@ -4831,7 +4846,7 @@ impl DetailReads for TursoStore { | |||
| 4831 | // so neither leaves the server for this screen. | 4846 | // so neither leaves the server for this screen. |
| 4832 | let mut rows = conn | 4847 | let mut rows = conn |
| 4833 | .query( | 4848 | .query( |
| 4834 | - "SELECT id, display_name, 0 FROM user \ | 4849 | + "SELECT id, display_name, photo_version FROM user \ |
| 4835 | WHERE workspace_id = ?1 AND role <> ?2 ORDER BY display_name", | 4850 | WHERE workspace_id = ?1 AND role <> ?2 ORDER BY display_name", |
| 4836 | params![workspace_id, Role::Viewer.as_str()], | 4851 | params![workspace_id, Role::Viewer.as_str()], |
| 4837 | ) | 4852 | ) |
| @@ -4842,7 +4857,7 @@ impl DetailReads for TursoStore { | |||
| 4842 | out.push(Person { | 4857 | out.push(Person { |
| 4843 | id: text(&row, 0)?, | 4858 | id: text(&row, 0)?, |
| 4844 | display_name: text(&row, 1)?, | 4859 | display_name: text(&row, 1)?, |
| 4845 | - has_photo: row.get::<i64>(2).map_err(backend)? != 0, | 4860 | + photo_version: row.get::<i64>(2).map_err(backend)?.max(0) as u64, |
| 4846 | }); | 4861 | }); |
| 4847 | } | 4862 | } |
| 4848 | Ok(out) | 4863 | Ok(out) |
| @@ -4890,7 +4905,7 @@ impl DetailReads for TursoStore { | |||
| 4890 | let conn = self.conn.lock().await; | 4905 | let conn = self.conn.lock().await; |
| 4891 | let mut rows = conn | 4906 | let mut rows = conn |
| 4892 | .query( | 4907 | .query( |
| 4893 | - "SELECT c.id, c.body, c.created_at, u.id, u.display_name, 0 \ | 4908 | + "SELECT c.id, c.body, c.created_at, u.id, u.display_name, u.photo_version \ |
| 4894 | FROM comment c JOIN user u ON u.id = c.author_id \ | 4909 | FROM comment c JOIN user u ON u.id = c.author_id \ |
| 4895 | WHERE c.task_id = ?1 ORDER BY c.created_at, c.rowid", | 4910 | WHERE c.task_id = ?1 ORDER BY c.created_at, c.rowid", |
| 4896 | params![task_id], | 4911 | params![task_id], |
| @@ -4906,7 +4921,7 @@ impl DetailReads for TursoStore { | |||
| 4906 | author: Person { | 4921 | author: Person { |
| 4907 | id: text(&row, 3)?, | 4922 | id: text(&row, 3)?, |
| 4908 | display_name: text(&row, 4)?, | 4923 | display_name: text(&row, 4)?, |
| 4909 | - has_photo: row.get::<i64>(5).map_err(backend)? != 0, | 4924 | + photo_version: row.get::<i64>(5).map_err(backend)?.max(0) as u64, |
| 4910 | }, | 4925 | }, |
| 4911 | }); | 4926 | }); |
| 4912 | } | 4927 | } |
| @@ -4946,7 +4961,7 @@ impl DetailReads for TursoStore { | |||
| 4946 | let mut rows = conn | 4961 | let mut rows = conn |
| 4947 | .query( | 4962 | .query( |
| 4948 | "SELECT a.id, a.kind, a.detail, a.created_at, u.id, u.display_name, \ | 4963 | "SELECT a.id, a.kind, a.detail, a.created_at, u.id, u.display_name, \ |
| 4949 | - 0 \ | 4964 | + u.photo_version \ |
| 4950 | FROM activity a LEFT JOIN user u ON u.id = a.actor_id \ | 4965 | FROM activity a LEFT JOIN user u ON u.id = a.actor_id \ |
| 4951 | WHERE a.task_id = ?1 ORDER BY a.created_at DESC, a.rowid DESC", | 4966 | WHERE a.task_id = ?1 ORDER BY a.created_at DESC, a.rowid DESC", |
| 4952 | params![task_id], | 4967 | params![task_id], |
| @@ -4959,7 +4974,7 @@ impl DetailReads for TursoStore { | |||
| 4959 | Some(id) => Some(Person { | 4974 | Some(id) => Some(Person { |
| 4960 | id, | 4975 | id, |
| 4961 | display_name: text(&row, 5)?, | 4976 | display_name: text(&row, 5)?, |
| 4962 | - has_photo: row.get::<i64>(6).map_err(backend)? != 0, | 4977 | + photo_version: row.get::<i64>(6).map_err(backend)?.max(0) as u64, |
| 4963 | }), | 4978 | }), |
| 4964 | None => None, | 4979 | None => None, |
| 4965 | }; | 4980 | }; |
| @@ -4983,7 +4998,7 @@ impl DetailReads for TursoStore { | |||
| 4983 | let mut rows = conn | 4998 | let mut rows = conn |
| 4984 | .query( | 4999 | .query( |
| 4985 | "SELECT t.id, t.task_key, t.title, t.column_id, t.done_at, t.parent_id, \ | 5000 | "SELECT t.id, t.task_key, t.title, t.column_id, t.done_at, t.parent_id, \ |
| 4986 | - u.id, u.display_name, 0 \ | 5001 | + u.id, u.display_name, u.photo_version \ |
| 4987 | FROM task t \ | 5002 | FROM task t \ |
| 4988 | LEFT JOIN task_assignee a ON a.task_id = t.id \ | 5003 | LEFT JOIN task_assignee a ON a.task_id = t.id \ |
| 4989 | LEFT JOIN user u ON u.id = a.user_id \ | 5004 | LEFT JOIN user u ON u.id = a.user_id \ |
| @@ -5007,7 +5022,7 @@ impl DetailReads for TursoStore { | |||
| 5007 | Some(user_id) => Some(Person { | 5022 | Some(user_id) => Some(Person { |
| 5008 | id: user_id, | 5023 | id: user_id, |
| 5009 | display_name: text(&row, 7)?, | 5024 | display_name: text(&row, 7)?, |
| 5010 | - has_photo: row.get::<i64>(8).map_err(backend)? != 0, | 5025 | + photo_version: row.get::<i64>(8).map_err(backend)?.max(0) as u64, |
| 5011 | }), | 5026 | }), |
| 5012 | None => None, | 5027 | None => None, |
| 5013 | }; | 5028 | }; |
| @@ -5116,7 +5131,7 @@ impl BoardReads for TursoStore { | |||
| 5116 | let conn = self.conn.lock().await; | 5131 | let conn = self.conn.lock().await; |
| 5117 | let mut rows = conn | 5132 | let mut rows = conn |
| 5118 | .query( | 5133 | .query( |
| 5119 | - "SELECT a.task_id, u.id, u.display_name, 0 \ | 5134 | + "SELECT a.task_id, u.id, u.display_name, u.photo_version \ |
| 5120 | FROM task_assignee a \ | 5135 | FROM task_assignee a \ |
| 5121 | JOIN task t ON t.id = a.task_id \ | 5136 | JOIN task t ON t.id = a.task_id \ |
| 5122 | JOIN user u ON u.id = a.user_id \ | 5137 | JOIN user u ON u.id = a.user_id \ |
| @@ -5133,7 +5148,7 @@ impl BoardReads for TursoStore { | |||
| 5133 | Person { | 5148 | Person { |
| 5134 | id: text(&row, 1)?, | 5149 | id: text(&row, 1)?, |
| 5135 | display_name: text(&row, 2)?, | 5150 | display_name: text(&row, 2)?, |
| 5136 | - has_photo: row.get::<i64>(3).map_err(backend)? != 0, | 5151 | + photo_version: row.get::<i64>(3).map_err(backend)?.max(0) as u64, |
| 5137 | }, | 5152 | }, |
| 5138 | )); | 5153 | )); |
| 5139 | } | 5154 | } |
crates/iz-core/tests/store.rsmodified+57 -15
| @@ -1803,7 +1803,7 @@ fn initials_fall_back_to_two_letters() { | |||
| 1803 | let person = |name: &str| Person { | 1803 | let person = |name: &str| Person { |
| 1804 | id: "u".into(), | 1804 | id: "u".into(), |
| 1805 | display_name: name.into(), | 1805 | display_name: name.into(), |
| 1806 | - has_photo: false, | 1806 | + photo_version: 0, |
| 1807 | }; | 1807 | }; |
| 1808 | assert_eq!(person("Mel Duarte").initials(), "MD"); | 1808 | assert_eq!(person("Mel Duarte").initials(), "MD"); |
| 1809 | assert_eq!(person("Ada").initials(), "A"); | 1809 | assert_eq!(person("Ada").initials(), "A"); |
| @@ -8407,8 +8407,7 @@ async fn set_user_disabled_round_trips() { | |||
| 8407 | async fn a_synced_member_is_born_linked_and_never_signed_in() { | 8407 | async fn a_synced_member_is_born_linked_and_never_signed_in() { |
| 8408 | let (scratch, workspace, _admin) = workspace_with_admin().await; | 8408 | let (scratch, workspace, _admin) = workspace_with_admin().await; |
| 8409 | let sync = scratch | 8409 | let sync = scratch |
| 8410 | - .store | 8410 | + .store.sync_member("sub-mert", "mert@iz.sh", "Mert", false, 0) |
| 8411 | - .sync_member("sub-mert", "mert@iz.sh", "Mert", false) | ||
| 8412 | .await | 8411 | .await |
| 8413 | .unwrap(); | 8412 | .unwrap(); |
| 8414 | assert_eq!(sync, iz_core::store::MemberSync::Inserted); | 8413 | assert_eq!(sync, iz_core::store::MemberSync::Inserted); |
| @@ -8423,8 +8422,7 @@ async fn a_synced_member_is_born_linked_and_never_signed_in() { | |||
| 8423 | assert!(row.last_signed_in_at.is_none()); | 8422 | assert!(row.last_signed_in_at.is_none()); |
| 8424 | // An im admin the workspace has never met is Admin from the first beat. | 8423 | // An im admin the workspace has never met is Admin from the first beat. |
| 8425 | scratch | 8424 | scratch |
| 8426 | - .store | 8425 | + .store.sync_member("sub-boss", "boss@iz.sh", "Boss", true, 0) |
| 8427 | - .sync_member("sub-boss", "boss@iz.sh", "Boss", true) | ||
| 8428 | .await | 8426 | .await |
| 8429 | .unwrap(); | 8427 | .unwrap(); |
| 8430 | let boss = scratch | 8428 | let boss = scratch |
| @@ -8445,8 +8443,7 @@ async fn a_sync_claims_an_unclaimed_row_without_touching_its_sign_in_fact() { | |||
| 8445 | .await | 8443 | .await |
| 8446 | .unwrap(); | 8444 | .unwrap(); |
| 8447 | let sync = scratch | 8445 | let sync = scratch |
| 8448 | - .store | 8446 | + .store.sync_member("sub-mert", "MERT@iz.sh", "Mert Yılmaz", false, 0) |
| 8449 | - .sync_member("sub-mert", "MERT@iz.sh", "Mert Yılmaz", false) | ||
| 8450 | .await | 8447 | .await |
| 8451 | .unwrap(); | 8448 | .unwrap(); |
| 8452 | assert_eq!(sync, iz_core::store::MemberSync::Claimed); | 8449 | assert_eq!(sync, iz_core::store::MemberSync::Claimed); |
| @@ -8467,8 +8464,7 @@ async fn a_sync_follows_provider_drift_but_not_the_sign_in_fact() { | |||
| 8467 | let before = scratch.store.user(&admin_id).await.unwrap().unwrap(); | 8464 | let before = scratch.store.user(&admin_id).await.unwrap().unwrap(); |
| 8468 | let seen = before.last_signed_in_at.clone(); | 8465 | let seen = before.last_signed_in_at.clone(); |
| 8469 | let sync = scratch | 8466 | let sync = scratch |
| 8470 | - .store | 8467 | + .store.sync_member("sub-ada", "ada@iz.sh", "Ada Lovelace", true, 0) |
| 8471 | - .sync_member("sub-ada", "ada@iz.sh", "Ada Lovelace", true) | ||
| 8472 | .await | 8468 | .await |
| 8473 | .unwrap(); | 8469 | .unwrap(); |
| 8474 | assert_eq!(sync, iz_core::store::MemberSync::Refreshed); | 8470 | assert_eq!(sync, iz_core::store::MemberSync::Refreshed); |
| @@ -8477,8 +8473,7 @@ async fn a_sync_follows_provider_drift_but_not_the_sign_in_fact() { | |||
| 8477 | assert_eq!(after.last_signed_in_at, seen); | 8473 | assert_eq!(after.last_signed_in_at, seen); |
| 8478 | // Losing the flag in the directory drops an Admin to Member. | 8474 | // Losing the flag in the directory drops an Admin to Member. |
| 8479 | scratch | 8475 | scratch |
| 8480 | - .store | 8476 | + .store.sync_member("sub-ada", "ada@iz.sh", "Ada Lovelace", false, 0) |
| 8481 | - .sync_member("sub-ada", "ada@iz.sh", "Ada Lovelace", false) | ||
| 8482 | .await | 8477 | .await |
| 8483 | .unwrap(); | 8478 | .unwrap(); |
| 8484 | let demoted = scratch.store.user(&admin_id).await.unwrap().unwrap(); | 8479 | let demoted = scratch.store.user(&admin_id).await.unwrap().unwrap(); |
| @@ -8490,8 +8485,7 @@ async fn an_agreeing_sync_is_untouched_and_silent() { | |||
| 8490 | let (scratch, _, _) = workspace_with_admin().await; | 8485 | let (scratch, _, _) = workspace_with_admin().await; |
| 8491 | let mut rx = scratch.store.subscribe(); | 8486 | let mut rx = scratch.store.subscribe(); |
| 8492 | let sync = scratch | 8487 | let sync = scratch |
| 8493 | - .store | 8488 | + .store.sync_member("sub-ada", "ada@iz.sh", "Ada", true, 0) |
| 8494 | - .sync_member("sub-ada", "ada@iz.sh", "Ada", true) | ||
| 8495 | .await | 8489 | .await |
| 8496 | .unwrap(); | 8490 | .unwrap(); |
| 8497 | assert_eq!(sync, iz_core::store::MemberSync::Untouched); | 8491 | assert_eq!(sync, iz_core::store::MemberSync::Untouched); |
| @@ -8502,14 +8496,62 @@ async fn an_agreeing_sync_is_untouched_and_silent() { | |||
| 8502 | async fn a_sync_without_a_workspace_skips_and_writes_nothing() { | 8496 | async fn a_sync_without_a_workspace_skips_and_writes_nothing() { |
| 8503 | let scratch = Scratch::open().await; | 8497 | let scratch = Scratch::open().await; |
| 8504 | let sync = scratch | 8498 | let sync = scratch |
| 8505 | - .store | 8499 | + .store.sync_member("sub-mert", "mert@iz.sh", "Mert", false, 0) |
| 8506 | - .sync_member("sub-mert", "mert@iz.sh", "Mert", false) | ||
| 8507 | .await | 8500 | .await |
| 8508 | .unwrap(); | 8501 | .unwrap(); |
| 8509 | assert_eq!(sync, iz_core::store::MemberSync::Skipped); | 8502 | assert_eq!(sync, iz_core::store::MemberSync::Skipped); |
| 8510 | assert!(scratch.store.workspace().await.unwrap().is_none()); | 8503 | assert!(scratch.store.workspace().await.unwrap().is_none()); |
| 8511 | } | 8504 | } |
| 8512 | 8505 | ||
| 8506 | +/// The face's version is the row's fact like the name: a sync that hears of | ||
| 8507 | +/// a new photo stamps it and says Refreshed (so the live channel hears), | ||
| 8508 | +/// one that already agrees says Untouched, and a row born from the | ||
| 8509 | +/// directory carries the version it was told before the first visit. | ||
| 8510 | +#[tokio::test] | ||
| 8511 | +async fn a_photo_version_bump_refreshes_and_announces() { | ||
| 8512 | + let (scratch, workspace, _admin) = workspace_with_admin().await; | ||
| 8513 | + let mut rx = scratch.store.subscribe(); | ||
| 8514 | + let sync = scratch | ||
| 8515 | + .store | ||
| 8516 | + .sync_member("sub-mert", "mert@iz.sh", "Mert", false, 2) | ||
| 8517 | + .await | ||
| 8518 | + .unwrap(); | ||
| 8519 | + assert_eq!(sync, iz_core::store::MemberSync::Inserted); | ||
| 8520 | + let row = scratch | ||
| 8521 | + .store | ||
| 8522 | + .user_by_email(&workspace, "mert@iz.sh") | ||
| 8523 | + .await | ||
| 8524 | + .unwrap() | ||
| 8525 | + .unwrap(); | ||
| 8526 | + assert_eq!(row.photo_version, 2); | ||
| 8527 | + assert_eq!(announced(&mut rx), vec!["members".to_string()]); | ||
| 8528 | + | ||
| 8529 | + // The same version again: the row agrees, and silence is the answer. | ||
| 8530 | + let again = scratch | ||
| 8531 | + .store | ||
| 8532 | + .sync_member("sub-mert", "mert@iz.sh", "Mert", false, 2) | ||
| 8533 | + .await | ||
| 8534 | + .unwrap(); | ||
| 8535 | + assert_eq!(again, iz_core::store::MemberSync::Untouched); | ||
| 8536 | + assert!(announced(&mut rx).is_empty()); | ||
| 8537 | + | ||
| 8538 | + // im counted another upload: the stamp moves and the move is news. | ||
| 8539 | + let bumped = scratch | ||
| 8540 | + .store | ||
| 8541 | + .sync_member("sub-mert", "mert@iz.sh", "Mert", false, 3) | ||
| 8542 | + .await | ||
| 8543 | + .unwrap(); | ||
| 8544 | + assert_eq!(bumped, iz_core::store::MemberSync::Refreshed); | ||
| 8545 | + let moved = scratch | ||
| 8546 | + .store | ||
| 8547 | + .user_by_email(&workspace, "mert@iz.sh") | ||
| 8548 | + .await | ||
| 8549 | + .unwrap() | ||
| 8550 | + .unwrap(); | ||
| 8551 | + assert_eq!(moved.photo_version, 3); | ||
| 8552 | + assert_eq!(announced(&mut rx), vec!["members".to_string()]); | ||
| 8553 | +} | ||
| 8554 | + | ||
| 8513 | /// The app-level setting drawer: a key never set reads as absent, one set | 8555 | /// The app-level setting drawer: a key never set reads as absent, one set |
| 8514 | /// reads back, and setting it again replaces rather than duplicates — the | 8556 | /// reads back, and setting it again replaces rather than duplicates — the |
| 8515 | /// family mirror rewrites its key every beat, and two rows for one key | 8557 | /// family mirror rewrites its key every beat, and two rows for one key |
crates/iz-web/Cargo.tomlmodified+1 -0
| @@ -20,6 +20,7 @@ topcoat = { version = "0.6.2", default-features = false, features = [ | |||
| 20 | "sse", | 20 | "sse", |
| 21 | ] } | 21 | ] } |
| 22 | iz-client = { workspace = true } | 22 | iz-client = { workspace = true } |
| 23 | +im-client = { workspace = true } | ||
| 23 | iz-core = { workspace = true, features = ["server"] } | 24 | iz-core = { workspace = true, features = ["server"] } |
| 24 | serde.workspace = true | 25 | serde.workspace = true |
| 25 | serde_json.workspace = true | 26 | serde_json.workspace = true |
crates/iz-web/src/avatar.rsmodified+53 -40
| @@ -1,16 +1,21 @@ | |||
| 1 | -//! The signed-in person's face, proxied from im. | 1 | +//! Every workspace member's face, proxied from im. |
| 2 | //! | 2 | //! |
| 3 | -//! `GET /avatar/{user_id}` answers with im's photo bytes for the caller's own | 3 | +//! `GET /avatar/{user_id}` answers with im's photo bytes for any member of |
| 4 | -//! id — anything else (another id, no photo, im unreachable) is the same 404, | 4 | +//! this workspace — not just the caller, whose own face is the common case. |
| 5 | -//! and a browser without a session is refused outright. Served with the same | 5 | +//! The URL carries the member's `photo_version` as `?v=`, so a page may be |
| 6 | -//! fnv1a ETag + immutable cache as im's own photo route, so the topbar's | 6 | +//! cached for months and the browser still refetches the day the face |
| 7 | -//! `<img>` revalidates rather than refetches. | 7 | +//! changes: a matching `?v` is served `private, max-age=31536000, immutable`, |
| 8 | +//! any other spelling revalidates, and the `ETag` names the row's version so | ||
| 9 | +//! a revalidation ends in a bodyless 304. A browser without a session is | ||
| 10 | +//! refused outright; an id outside the workspace, or im unreachable, is the | ||
| 11 | +//! same 404 — the `<img>` hides itself and the initials beneath stand in. | ||
| 8 | 12 | ||
| 9 | -use topcoat::context::Cx; | 13 | +use im_client::directory::DirectoryClient; |
| 14 | +use topcoat::context::{Cx, try_app_context}; | ||
| 10 | use topcoat::router::request::headers as request_headers; | 15 | use topcoat::router::request::headers as request_headers; |
| 11 | use topcoat::router::{HeaderMap, HeaderValue, StatusCode, header, path_param, route}; | 16 | use topcoat::router::{HeaderMap, HeaderValue, StatusCode, header, path_param, route}; |
| 12 | 17 | ||
| 13 | -use crate::server::require_user; | 18 | +use crate::server::{require_user, store}; |
| 14 | 19 | ||
| 15 | path_param!(user_id); | 20 | path_param!(user_id); |
| 16 | 21 | ||
| @@ -18,45 +23,64 @@ fn not_found() -> (StatusCode, HeaderMap, Vec<u8>) { | |||
| 18 | (StatusCode::NOT_FOUND, HeaderMap::new(), Vec::new()) | 23 | (StatusCode::NOT_FOUND, HeaderMap::new(), Vec::new()) |
| 19 | } | 24 | } |
| 20 | 25 | ||
| 21 | -/// `GET /avatar/{user_id}`: im's photo for the caller, or the same not-found | 26 | +/// The shared directory client `main.rs` registers on the router from the |
| 22 | -/// a stranger would see — never a `403`, which would confirm the id belongs | 27 | +/// `[oidc]` config: one HTTP pool, the app's Basic pair on every call. |
| 23 | -/// to somebody else's account. | 28 | +pub fn directory(cx: &Cx) -> &DirectoryClient { |
| 29 | + try_app_context::<DirectoryClient>(cx) | ||
| 30 | + .expect("the directory client was registered on the router") | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +fn stamped_version(cx: &Cx) -> Option<u64> { | ||
| 34 | + let query = topcoat::router::request::uri(cx).query().unwrap_or(""); | ||
| 35 | + query | ||
| 36 | + .split('&') | ||
| 37 | + .filter_map(|pair| pair.split_once('=')) | ||
| 38 | + .find(|(key, _)| *key == "v") | ||
| 39 | + .and_then(|(_, value)| value.parse::<u64>().ok()) | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +/// `GET /avatar/{user_id}`: im's photo for the named member, or the same | ||
| 43 | +/// not-found an unknown id would see — never a `403`, which would confirm | ||
| 44 | +/// the id belongs to somebody. | ||
| 24 | #[route(GET "/avatar/{user_id}")] | 45 | #[route(GET "/avatar/{user_id}")] |
| 25 | async fn avatar(cx: &Cx) -> topcoat::Result<(StatusCode, HeaderMap, Vec<u8>)> { | 46 | async fn avatar(cx: &Cx) -> topcoat::Result<(StatusCode, HeaderMap, Vec<u8>)> { |
| 26 | let target: &str = path_param::<UserId>(cx); | 47 | let target: &str = path_param::<UserId>(cx); |
| 27 | 48 | ||
| 28 | - let user = match require_user(cx).await { | 49 | + let _viewer = match require_user(cx).await { |
| 29 | Ok(user) => user, | 50 | Ok(user) => user, |
| 30 | // An `<img>` has no page to carry a refusal on; 401 names the fix | 51 | // An `<img>` has no page to carry a refusal on; 401 names the fix |
| 31 | // the way the live channel's does. | 52 | // the way the live channel's does. |
| 32 | Err(_) => return Ok((StatusCode::UNAUTHORIZED, HeaderMap::new(), Vec::new())), | 53 | Err(_) => return Ok((StatusCode::UNAUTHORIZED, HeaderMap::new(), Vec::new())), |
| 33 | }; | 54 | }; |
| 34 | - // One's own face only — anyone else's id reads exactly like no | 55 | + let row = store(cx).user(target).await?; |
| 35 | - // photo, so one account's face can never be probed through another's. | 56 | + let Some(row) = row else { |
| 36 | - if target != user.id { | ||
| 37 | return Ok(not_found()); | 57 | return Ok(not_found()); |
| 38 | - } | 58 | + }; |
| 39 | - let Some(sub) = user.oidc_sub.clone() else { | 59 | + let Some(sub) = row.oidc_sub.clone() else { |
| 40 | return Ok(not_found()); | 60 | return Ok(not_found()); |
| 41 | }; | 61 | }; |
| 42 | - let Some((bytes, mime)) = iz_client::photo_for(cx, &sub).await else { | 62 | + let Ok((bytes, mime)) = directory(cx).photo(&sub).await else { |
| 43 | return Ok(not_found()); | 63 | return Ok(not_found()); |
| 44 | }; | 64 | }; |
| 45 | 65 | ||
| 46 | - let etag = format!("\"{:x}\"", fnv1a(&bytes)); | 66 | + // The row's version IS the version this URL names: the directory keeps |
| 67 | + // it current (live stream, and the beat behind it), so a stale face | ||
| 68 | + // means a stale row, never a lie about freshness. | ||
| 69 | + let etag = format!("\"p{}\"", row.photo_version); | ||
| 47 | let mut headers = HeaderMap::new(); | 70 | let mut headers = HeaderMap::new(); |
| 48 | - headers.insert( | 71 | + headers.insert(header::ETAG, HeaderValue::from_str(&etag).unwrap()); |
| 49 | - header::ETAG, | 72 | + // A `?v` that agrees with the row means this exact face is pinned to a |
| 50 | - HeaderValue::from_str(&etag).unwrap_or(HeaderValue::from_static("\"0\"")), | 73 | + // URL that changes the day the face does, so the browser may keep it |
| 51 | - ); | 74 | + // for a year. Every other spelling — including no stamp at all — |
| 52 | - // The bytes are im's to version and this URL carries no stamp of its | 75 | + // revalidates. `private` because the route is gated and a shared proxy |
| 53 | - // own, so a changed photo may take up to a year to show — the price of | 76 | + // must not answer a stranger from another account's entry. |
| 54 | - // proxying without a stamp channel. `private` because the route is | ||
| 55 | - // gated and a shared proxy must not answer a stranger from another | ||
| 56 | - // account's entry. | ||
| 57 | headers.insert( | 77 | headers.insert( |
| 58 | header::CACHE_CONTROL, | 78 | header::CACHE_CONTROL, |
| 59 | - HeaderValue::from_static("private, max-age=31536000, immutable"), | 79 | + HeaderValue::from_static(if stamped_version(cx) == Some(row.photo_version) { |
| 80 | + "private, max-age=31536000, immutable" | ||
| 81 | + } else { | ||
| 82 | + "private, no-cache" | ||
| 83 | + }), | ||
| 60 | ); | 84 | ); |
| 61 | headers.insert( | 85 | headers.insert( |
| 62 | header::CONTENT_TYPE, | 86 | header::CONTENT_TYPE, |
| @@ -71,14 +95,3 @@ async fn avatar(cx: &Cx) -> topcoat::Result<(StatusCode, HeaderMap, Vec<u8>)> { | |||
| 71 | } | 95 | } |
| 72 | Ok((StatusCode::OK, headers, bytes)) | 96 | Ok((StatusCode::OK, headers, bytes)) |
| 73 | } | 97 | } |
| 74 | - | ||
| 75 | -/// A cheap, non-cryptographic hash — good enough for an `ETag` on bytes only | ||
| 76 | -/// im ever writes. | ||
| 77 | -fn fnv1a(bytes: &[u8]) -> u64 { | ||
| 78 | - let mut hash: u64 = 0xcbf29ce484222325; | ||
| 79 | - for &b in bytes { | ||
| 80 | - hash ^= b as u64; | ||
| 81 | - hash = hash.wrapping_mul(0x100000001b3); | ||
| 82 | - } | ||
| 83 | - hash | ||
| 84 | -} | ||
crates/iz-web/src/board.rsmodified+1 -1
| @@ -422,7 +422,7 @@ async fn render_card( | |||
| 422 | let subtasks_open = card.holds_on_subtasks(); | 422 | let subtasks_open = card.holds_on_subtasks(); |
| 423 | let mut assignees = Vec::new(); | 423 | let mut assignees = Vec::new(); |
| 424 | for person in card.assignees.iter() { | 424 | for person in card.assignees.iter() { |
| 425 | - assignees.push(crate::layout::avatar(cx, &person.id, &person.display_name, "").await?); | 425 | + assignees.push(crate::layout::avatar(cx, &person.id, &person.display_name, person.photo_version, "").await?); |
| 426 | } | 426 | } |
| 427 | let has_assignees = !card.assignees.is_empty(); | 427 | let has_assignees = !card.assignees.is_empty(); |
| 428 | let task_id = card.id.clone(); | 428 | let task_id = card.id.clone(); |
crates/iz-web/src/detail.rsmodified+7 -4
| @@ -51,6 +51,8 @@ pub struct Me { | |||
| 51 | pub email: String, | 51 | pub email: String, |
| 52 | pub role: iz_core::Role, | 52 | pub role: iz_core::Role, |
| 53 | pub language: String, | 53 | pub language: String, |
| 54 | + /// The face's version, for the topbar avatar's `?v=` stamp. | ||
| 55 | + pub photo_version: u64, | ||
| 54 | } | 56 | } |
| 55 | 57 | ||
| 56 | impl From<&User> for Me { | 58 | impl From<&User> for Me { |
| @@ -61,6 +63,7 @@ impl From<&User> for Me { | |||
| 61 | email: user.email.clone(), | 63 | email: user.email.clone(), |
| 62 | role: user.role, | 64 | role: user.role, |
| 63 | language: user.language.clone(), | 65 | language: user.language.clone(), |
| 66 | + photo_version: user.photo_version, | ||
| 64 | } | 67 | } |
| 65 | } | 68 | } |
| 66 | } | 69 | } |
| @@ -1556,7 +1559,7 @@ async fn assignee_chip( | |||
| 1556 | cx => | 1559 | cx => |
| 1557 | <span class="assignee-chip"> | 1560 | <span class="assignee-chip"> |
| 1558 | <a class="person-link" href=(format!("/people/{}", person.id))> | 1561 | <a class="person-link" href=(format!("/people/{}", person.id))> |
| 1559 | - (crate::layout::avatar(cx, &person.id, &person.display_name, "avatar-sm").await?) | 1562 | + (crate::layout::avatar(cx, &person.id, &person.display_name, person.photo_version, "avatar-sm").await?) |
| 1560 | <span class="assignee-name">(person.display_name.clone())</span> | 1563 | <span class="assignee-name">(person.display_name.clone())</span> |
| 1561 | </a> | 1564 | </a> |
| 1562 | if may_write { | 1565 | if may_write { |
| @@ -1588,7 +1591,7 @@ async fn assignee_picker(cx: &Cx, task_id: &str, people: &[Person], lang: Lang) | |||
| 1588 | <input type="hidden" name="task_id" value=(task_id.to_string())> | 1591 | <input type="hidden" name="task_id" value=(task_id.to_string())> |
| 1589 | <input type="hidden" name="user_id" value=(person.id.clone())> | 1592 | <input type="hidden" name="user_id" value=(person.id.clone())> |
| 1590 | <button class="pop-row" type="submit"> | 1593 | <button class="pop-row" type="submit"> |
| 1591 | - (crate::layout::avatar(cx, &person.id, &person.display_name, "avatar-sm").await?) | 1594 | + (crate::layout::avatar(cx, &person.id, &person.display_name, person.photo_version, "avatar-sm").await?) |
| 1592 | <span class="pop-row-name">(person.display_name.clone())</span> | 1595 | <span class="pop-row-name">(person.display_name.clone())</span> |
| 1593 | </button> | 1596 | </button> |
| 1594 | </form> | 1597 | </form> |
| @@ -1668,7 +1671,7 @@ async fn subtask_row( | |||
| 1668 | let release_title = t(lang, Key::ReleaseThisPart); | 1671 | let release_title = t(lang, Key::ReleaseThisPart); |
| 1669 | let mut faces = Vec::new(); | 1672 | let mut faces = Vec::new(); |
| 1670 | for person in &part.assignees { | 1673 | for person in &part.assignees { |
| 1671 | - faces.push(crate::layout::avatar(cx, &person.id, &person.display_name, "").await?); | 1674 | + faces.push(crate::layout::avatar(cx, &person.id, &person.display_name, person.photo_version, "").await?); |
| 1672 | } | 1675 | } |
| 1673 | view! { | 1676 | view! { |
| 1674 | cx => | 1677 | cx => |
| @@ -1844,7 +1847,7 @@ async fn comment_row(cx: &Cx, comment: &Comment, zone: UtcOffset) -> Result { | |||
| 1844 | cx => | 1847 | cx => |
| 1845 | <div class="comment"> | 1848 | <div class="comment"> |
| 1846 | <a class="person-link" href=(format!("/people/{}", comment.author.id))> | 1849 | <a class="person-link" href=(format!("/people/{}", comment.author.id))> |
| 1847 | - (crate::layout::avatar(cx, &comment.author.id, &comment.author.display_name, "avatar-lg").await?) | 1850 | + (crate::layout::avatar(cx, &comment.author.id, &comment.author.display_name, comment.author.photo_version, "avatar-lg").await?) |
| 1848 | </a> | 1851 | </a> |
| 1849 | <div class="comment-said"> | 1852 | <div class="comment-said"> |
| 1850 | <div class="comment-head"> | 1853 | <div class="comment-head"> |
crates/iz-web/src/layout.rsmodified+16 -8
| @@ -69,19 +69,27 @@ pub(crate) async fn wordmark(cx: &Cx) -> Result { | |||
| 69 | 69 | ||
| 70 | /// A person as a circle (or, on the Instrument skin, a square): the initials, | 70 | /// A person as a circle (or, on the Instrument skin, a square): the initials, |
| 71 | /// toned by the id so every account has its own colour, with the im photo | 71 | /// toned by the id so every account has its own colour, with the im photo |
| 72 | -/// over it when im has one. Whether im has one is not known cheaply — the | 72 | +/// over it when im has one. The URL carries the row's `photo_version` as |
| 73 | -/// photo is the app's credentialed fetch, not the browser's — so the `<img>` | 73 | +/// `?v=`, so a changed face is a changed URL: a browser may cache the old |
| 74 | -/// always renders and hides itself on error (see `avatar_script`), leaving | 74 | +/// answer for a year and still see the new one the day the row moves — the |
| 75 | -/// the initials beneath as the fallback. Shared by the board, the modal and | 75 | +/// live refresh morphs the attribute and the img follows. The `<img>` always |
| 76 | +/// renders and hides itself on error (see `avatar_script`), leaving the | ||
| 77 | +/// initials beneath as the fallback. Shared by the board, the modal and | ||
| 76 | /// every topbar user menu. | 78 | /// every topbar user menu. |
| 77 | -pub(crate) async fn avatar(cx: &Cx, id: &str, display_name: &str, extra: &str) -> Result { | 79 | +pub(crate) async fn avatar( |
| 80 | + cx: &Cx, | ||
| 81 | + id: &str, | ||
| 82 | + display_name: &str, | ||
| 83 | + photo_version: u64, | ||
| 84 | + extra: &str, | ||
| 85 | +) -> Result { | ||
| 78 | let tone = id | 86 | let tone = id |
| 79 | .bytes() | 87 | .bytes() |
| 80 | .fold(0u32, |acc, b| acc.wrapping_mul(31).wrapping_add(b as u32)) | 88 | .fold(0u32, |acc, b| acc.wrapping_mul(31).wrapping_add(b as u32)) |
| 81 | % 5; | 89 | % 5; |
| 82 | let class = format!("avatar avatar-tone-{tone} {extra}"); | 90 | let class = format!("avatar avatar-tone-{tone} {extra}"); |
| 83 | let initials = initials_of(display_name); | 91 | let initials = initials_of(display_name); |
| 84 | - let src = format!("/avatar/{id}"); | 92 | + let src = format!("/avatar/{id}?v={photo_version}"); |
| 85 | view! { | 93 | view! { |
| 86 | cx => | 94 | cx => |
| 87 | <span class="avatar-stack"> | 95 | <span class="avatar-stack"> |
| @@ -149,7 +157,7 @@ pub async fn user_menu(cx: &Cx, me: &crate::detail::Me, lang: Lang) -> Result { | |||
| 149 | cx => | 157 | cx => |
| 150 | <div class="user-menu"> | 158 | <div class="user-menu"> |
| 151 | <button type="button" class="user-menu-trigger"> | 159 | <button type="button" class="user-menu-trigger"> |
| 152 | - (avatar(cx, &me.id, &me.display_name, "").await?) | 160 | + (avatar(cx, &me.id, &me.display_name, me.photo_version, "").await?) |
| 153 | <span class="user-menu-trigger-name">(me.display_name.clone())</span> | 161 | <span class="user-menu-trigger-name">(me.display_name.clone())</span> |
| 154 | </button> | 162 | </button> |
| 155 | <div class="user-menu-panel"> | 163 | <div class="user-menu-panel"> |
| @@ -158,7 +166,6 @@ pub async fn user_menu(cx: &Cx, me: &crate::detail::Me, lang: Lang) -> Result { | |||
| 158 | <div class="user-menu-role">(t(lang, role_key))</div> | 166 | <div class="user-menu-role">(t(lang, role_key))</div> |
| 159 | <a class="user-menu-item" href=(format!("{}/", crate::server::config(cx).oidc.issuer)) data-hard="">(t(lang, Key::Profile))</a> | 167 | <a class="user-menu-item" href=(format!("{}/", crate::server::config(cx).oidc.issuer)) data-hard="">(t(lang, Key::Profile))</a> |
| 160 | <a class="user-menu-item" href="/settings">(t(lang, Key::NavSettings))</a> | 168 | <a class="user-menu-item" href="/settings">(t(lang, Key::NavSettings))</a> |
| 161 | - <a class="user-menu-item" href="/auth/logout" data-hard="">(t(lang, Key::SignOut))</a> | ||
| 162 | </div> | 169 | </div> |
| 163 | </div> | 170 | </div> |
| 164 | (avatar_script(cx).await?) | 171 | (avatar_script(cx).await?) |
| @@ -869,6 +876,7 @@ pub async fn live_script(cx: &Cx) -> Result { | |||
| 869 | if (path === '/tags') { return topic === 'tags' || topic === 'members'; } \ | 876 | if (path === '/tags') { return topic === 'tags' || topic === 'members'; } \ |
| 870 | if (path === '/settings') { return topic === 'settings' || topic === 'members'; } \ | 877 | if (path === '/settings') { return topic === 'settings' || topic === 'members'; } \ |
| 871 | if (path === '/people/') { return topic === 'members'; } \ | 878 | if (path === '/people/') { return topic === 'members'; } \ |
| 879 | + return topic === 'members'; \ | ||
| 872 | } \ | 880 | } \ |
| 873 | try { \ | 881 | try { \ |
| 874 | var src = new EventSource('/api/live'); \ | 882 | var src = new EventSource('/api/live'); \ |
crates/iz-web/src/main.rsmodified+103 -25
| @@ -131,6 +131,15 @@ async fn main() { | |||
| 131 | cookie_name: "iz_session".to_string(), | 131 | cookie_name: "iz_session".to_string(), |
| 132 | cookie_key, | 132 | cookie_key, |
| 133 | }; | 133 | }; |
| 134 | + // The shared identity directory: the same issuer and Basic pair the OIDC | ||
| 135 | + // side holds, pointed at im's roster. One HTTP pool inside, cheap to | ||
| 136 | + // clone — the avatar route reaches it through the router context below, | ||
| 137 | + // and the two mirror tasks carry their own handles. | ||
| 138 | + let directory = im_client::directory::DirectoryClient::new( | ||
| 139 | + config.oidc.issuer.clone(), | ||
| 140 | + config.oidc.client_id.clone(), | ||
| 141 | + config.oidc.client_secret.clone(), | ||
| 142 | + ); | ||
| 134 | // The engine is always built, because a sender can appear at any moment: | 143 | // The engine is always built, because a sender can appear at any moment: |
| 135 | // an admin fills the panel in and the next sweep sends what was held. It | 144 | // an admin fills the panel in and the next sweep sends what was held. It |
| 136 | // holds one connection pool, rebuilt only when the settings behind it | 145 | // holds one connection pool, rebuilt only when the settings behind it |
| @@ -142,19 +151,24 @@ async fn main() { | |||
| 142 | )); | 151 | )); |
| 143 | tokio::spawn(sweep(engine.clone(), store.clone())); | 152 | tokio::spawn(sweep(engine.clone(), store.clone())); |
| 144 | 153 | ||
| 145 | - // The member list mirrors im's directory: people are assignable and | 154 | + // The member list mirrors im's directory two ways. The live stream is |
| 146 | - // mailable before their first visit, and the provider's renames and | 155 | + // the fast path — a photo uploaded, a rename, a disable in im lands |
| 147 | - // admin flips follow on their own. Runs beside the sweep, first pass | 156 | + // within a moment and announces, so every open board swaps the face |
| 148 | - // right away so a fresh deploy sees everyone at boot. | 157 | + // without a reload. The beat stays as the watchdog: one full pass |
| 158 | + // every five minutes heals whatever a dead stream hid, and keeps the | ||
| 159 | + // family list fresh, which the stream does not carry. First passes | ||
| 160 | + // run right away, so a fresh deploy sees everyone at boot. | ||
| 149 | // The address the app files itself under is `base_url` alone: a bound | 161 | // The address the app files itself under is `base_url` alone: a bound |
| 150 | // address is no fallback here — a loopback bind is nothing anyone else | 162 | // address is no fallback here — a loopback bind is nothing anyone else |
| 151 | // can reach, and filing it would overwrite the real one in every | 163 | // can reach, and filing it would overwrite the real one in every |
| 152 | // switcher. | 164 | // switcher. |
| 153 | tokio::spawn(directory_sync( | 165 | tokio::spawn(directory_sync( |
| 154 | store.clone(), | 166 | store.clone(), |
| 167 | + directory.clone(), | ||
| 155 | iz_client::IzClient::new(oidc.clone()), | 168 | iz_client::IzClient::new(oidc.clone()), |
| 156 | config.base_url.clone(), | 169 | config.base_url.clone(), |
| 157 | )); | 170 | )); |
| 171 | + tokio::spawn(directory_stream(store.clone(), directory.clone())); | ||
| 158 | // Told when the process is stopping, so the live streams end instead of | 172 | // Told when the process is stopping, so the live streams end instead of |
| 159 | // being waited out. See `iz_web::live::Shutdown`. | 173 | // being waited out. See `iz_web::live::Shutdown`. |
| 160 | let (stop, stopping) = tokio::sync::watch::channel(false); | 174 | let (stop, stopping) = tokio::sync::watch::channel(false); |
| @@ -171,6 +185,7 @@ async fn main() { | |||
| 171 | oidc, | 185 | oidc, |
| 172 | ) | 186 | ) |
| 173 | .app_context(store.clone()) | 187 | .app_context(store.clone()) |
| 188 | + .app_context(directory) | ||
| 174 | .app_context(iz_client::LogoutBack(Arc::new(iz_web::server::logout_back))) | 189 | .app_context(iz_client::LogoutBack(Arc::new(iz_web::server::logout_back))) |
| 175 | .app_context(config.clone()) | 190 | .app_context(config.clone()) |
| 176 | .app_context(iz_web::live::LiveWindow(std::time::Duration::from_secs( | 191 | .app_context(iz_web::live::LiveWindow(std::time::Duration::from_secs( |
| @@ -321,13 +336,15 @@ async fn sweep(engine: std::sync::Arc<iz_core::MailEngine>, store: Arc<dyn iz_co | |||
| 321 | const DIRECTORY_SECONDS: u64 = 300; | 336 | const DIRECTORY_SECONDS: u64 = 300; |
| 322 | 337 | ||
| 323 | /// Keeps the member list a mirror of im's directory, and the switcher's | 338 | /// Keeps the member list a mirror of im's directory, and the switcher's |
| 324 | -/// family list a mirror of im's admin panel, first pass at boot and then | 339 | +/// family list a mirror of im's admin panel, on the beat. The live stream |
| 325 | -/// on the beat. Every pass is a full read of a short list, so the store | 340 | +/// (see [`directory_stream`]) is the fast path; this loop is the watchdog — |
| 326 | -/// hears one entry at a time and announces only what changed. An im that | 341 | +/// every pass is a full read of a short list, so whatever a dead stream |
| 327 | -/// does not answer — down, restarting, mid-deploy — costs one log line | 342 | +/// quietly missed is healed within five minutes. An im that does not |
| 328 | -/// and nothing else: the rows stay, and the next beat asks again. | 343 | +/// answer — down, restarting, mid-deploy — costs one log line and nothing |
| 344 | +/// else: the rows stay, and the next beat asks again. | ||
| 329 | async fn directory_sync( | 345 | async fn directory_sync( |
| 330 | store: Arc<dyn iz_core::store::Store>, | 346 | store: Arc<dyn iz_core::store::Store>, |
| 347 | + directory: im_client::directory::DirectoryClient, | ||
| 331 | client: iz_client::IzClient, | 348 | client: iz_client::IzClient, |
| 332 | configured_url: String, | 349 | configured_url: String, |
| 333 | ) { | 350 | ) { |
| @@ -336,19 +353,7 @@ async fn directory_sync( | |||
| 336 | // said once and the mirror goes on without it. | 353 | // said once and the mirror goes on without it. |
| 337 | let mut said_no_address = false; | 354 | let mut said_no_address = false; |
| 338 | loop { | 355 | loop { |
| 339 | - match client.directory().await { | 356 | + mirror_directory(&store, &directory).await; |
| 340 | - Some(members) => { | ||
| 341 | - for member in members { | ||
| 342 | - if let Err(problem) = store | ||
| 343 | - .sync_member(&member.sub, &member.email, &member.name, member.admin) | ||
| 344 | - .await | ||
| 345 | - { | ||
| 346 | - eprintln!("directory sync: {}: {problem}", member.email); | ||
| 347 | - } | ||
| 348 | - } | ||
| 349 | - } | ||
| 350 | - None => eprintln!("directory sync: im did not answer; keeping the rows there are"), | ||
| 351 | - } | ||
| 352 | // Before asking for the family, this app files itself in it, so a | 357 | // Before asking for the family, this app files itself in it, so a |
| 353 | // deployment appears in everyone's switcher without an admin | 358 | // deployment appears in everyone's switcher without an admin |
| 354 | // typing its address. Resolved per beat in the order a sign-out | 359 | // typing its address. Resolved per beat in the order a sign-out |
| @@ -393,6 +398,80 @@ async fn directory_sync( | |||
| 393 | } | 398 | } |
| 394 | } | 399 | } |
| 395 | 400 | ||
| 401 | +/// One full pass of im's roster through the member rows: every entry | ||
| 402 | +/// through [`iz_core::store::Store::sync_member`], which announces only | ||
| 403 | +/// the rows that actually changed. | ||
| 404 | +async fn mirror_directory( | ||
| 405 | + store: &Arc<dyn iz_core::store::Store>, | ||
| 406 | + directory: &im_client::directory::DirectoryClient, | ||
| 407 | +) { | ||
| 408 | + match directory.directory().await { | ||
| 409 | + Ok(members) => { | ||
| 410 | + for member in members { | ||
| 411 | + apply_member(store, &member).await; | ||
| 412 | + } | ||
| 413 | + } | ||
| 414 | + Err(problem) => { | ||
| 415 | + eprintln!("directory sync: im did not answer ({problem}); keeping the rows there are") | ||
| 416 | + } | ||
| 417 | + } | ||
| 418 | +} | ||
| 419 | + | ||
| 420 | +async fn apply_member( | ||
| 421 | + store: &Arc<dyn iz_core::store::Store>, | ||
| 422 | + member: &im_client::directory::DirectoryMember, | ||
| 423 | +) { | ||
| 424 | + if let Err(problem) = store | ||
| 425 | + .sync_member( | ||
| 426 | + &member.sub, | ||
| 427 | + &member.email, | ||
| 428 | + &member.name, | ||
| 429 | + member.admin, | ||
| 430 | + member.photo_version, | ||
| 431 | + ) | ||
| 432 | + .await | ||
| 433 | + { | ||
| 434 | + eprintln!("directory sync: {}: {problem}", member.email); | ||
| 435 | + } | ||
| 436 | +} | ||
| 437 | + | ||
| 438 | +/// The live half of the mirror: im's `/directory/live`, one event per | ||
| 439 | +/// changed member. Forever, in this shape: a full pass, then the stream; | ||
| 440 | +/// whenever the stream ends — im restarting, or its fifty-minute window | ||
| 441 | +/// closing — wait out a backoff that doubles from one second to thirty, | ||
| 442 | +/// replay a full pass (the resync that heals whatever the dead stream | ||
| 443 | +/// carried or dropped), and redial. A stream error inside the body is the | ||
| 444 | +/// same exit as a clean close: the pass below is what converges. | ||
| 445 | +async fn directory_stream( | ||
| 446 | + store: Arc<dyn iz_core::store::Store>, | ||
| 447 | + directory: im_client::directory::DirectoryClient, | ||
| 448 | +) { | ||
| 449 | + let mut backoff = std::time::Duration::from_secs(1); | ||
| 450 | + loop { | ||
| 451 | + mirror_directory(&store, &directory).await; | ||
| 452 | + match directory.open_stream().await { | ||
| 453 | + Ok(mut stream) => { | ||
| 454 | + backoff = std::time::Duration::from_secs(1); | ||
| 455 | + while let Some(event) = stream.next().await { | ||
| 456 | + match event { | ||
| 457 | + Ok(im_client::directory::DirectoryEvent::Profile(member)) => { | ||
| 458 | + apply_member(&store, &member).await; | ||
| 459 | + } | ||
| 460 | + Err(problem) => { | ||
| 461 | + eprintln!("directory stream: {problem}; re-listing"); | ||
| 462 | + break; | ||
| 463 | + } | ||
| 464 | + } | ||
| 465 | + } | ||
| 466 | + } | ||
| 467 | + Err(problem) => { | ||
| 468 | + eprintln!("directory stream: im did not answer ({problem})"); | ||
| 469 | + } | ||
| 470 | + } | ||
| 471 | + tokio::time::sleep(backoff).await; | ||
| 472 | + backoff = (backoff * 2).min(std::time::Duration::from_secs(30)); | ||
| 473 | + } | ||
| 474 | +} | ||
| 396 | /// Waits for something to happen to the mail queue specifically. | 475 | /// Waits for something to happen to the mail queue specifically. |
| 397 | /// | 476 | /// |
| 398 | /// The channel carries every topic, and the sweep cares about one. Filtering | 477 | /// The channel carries every topic, and the sweep cares about one. Filtering |
| @@ -403,7 +482,6 @@ async fn directory_sync( | |||
| 403 | /// | 482 | /// |
| 404 | /// Lagging means announcements were dropped — a reason to look, not to stop. | 483 | /// Lagging means announcements were dropped — a reason to look, not to stop. |
| 405 | async fn queue_touched(rx: &mut tokio::sync::broadcast::Receiver<iz_core::Change>) -> bool { | 484 | async fn queue_touched(rx: &mut tokio::sync::broadcast::Receiver<iz_core::Change>) -> bool { |
| 406 | - use tokio::sync::broadcast::error::RecvError; | ||
| 407 | loop { | 485 | loop { |
| 408 | match rx.recv().await { | 486 | match rx.recv().await { |
| 409 | Ok(change) => { | 487 | Ok(change) => { |
| @@ -411,8 +489,8 @@ async fn queue_touched(rx: &mut tokio::sync::broadcast::Receiver<iz_core::Change | |||
| 411 | return true; | 489 | return true; |
| 412 | } | 490 | } |
| 413 | } | 491 | } |
| 414 | - Err(RecvError::Lagged(_)) => return true, | 492 | + Err(tokio::sync::broadcast::error::RecvError::Lagged(_)) => return true, |
| 415 | - Err(RecvError::Closed) => return false, | 493 | + Err(tokio::sync::broadcast::error::RecvError::Closed) => return false, |
| 416 | } | 494 | } |
| 417 | } | 495 | } |
| 418 | } | 496 | } |
crates/iz-web/src/people.rsmodified+1 -1
| @@ -117,7 +117,7 @@ async fn people_page(cx: &Cx) -> Result { | |||
| 117 | <main class="people-shell"> | 117 | <main class="people-shell"> |
| 118 | <section class="panel person-card"> | 118 | <section class="panel person-card"> |
| 119 | <div class="person-head"> | 119 | <div class="person-head"> |
| 120 | - (crate::layout::avatar(cx, &person.id, &person.display_name, "avatar-xl").await?) | 120 | + (crate::layout::avatar(cx, &person.id, &person.display_name, person.photo_version, "avatar-xl").await?) |
| 121 | <div class="person-heading"> | 121 | <div class="person-heading"> |
| 122 | <h2 class="person-name">(person.display_name.clone())</h2> | 122 | <h2 class="person-name">(person.display_name.clone())</h2> |
| 123 | <div class="person-marks"> | 123 | <div class="person-marks"> |
crates/iz-web/src/settings.rsmodified+5 -2
| @@ -938,6 +938,8 @@ struct Member { | |||
| 938 | email: String, | 938 | email: String, |
| 939 | role: iz_core::Role, | 939 | role: iz_core::Role, |
| 940 | disabled: bool, | 940 | disabled: bool, |
| 941 | + /// The face's version, for the row's avatar `?v=` stamp. | ||
| 942 | + photo_version: u64, | ||
| 941 | /// The day they last signed in, as the list writes it, or nothing. | 943 | /// The day they last signed in, as the list writes it, or nothing. |
| 942 | last_signed_in: Option<String>, | 944 | last_signed_in: Option<String>, |
| 943 | is_you: bool, | 945 | is_you: bool, |
| @@ -955,6 +957,7 @@ async fn members_now(cx: &Cx, asking: &User) -> Result<Vec<Member>> { | |||
| 955 | .into_iter() | 957 | .into_iter() |
| 956 | .map(|user| Member { | 958 | .map(|user| Member { |
| 957 | disabled: user.disabled, | 959 | disabled: user.disabled, |
| 960 | + photo_version: user.photo_version, | ||
| 958 | last_signed_in: user | 961 | last_signed_in: user |
| 959 | .last_signed_in_at | 962 | .last_signed_in_at |
| 960 | .map(|at| iz_core::board::day_label(at.to_offset(zone).date())), | 963 | .map(|at| iz_core::board::day_label(at.to_offset(zone).date())), |
| @@ -1272,7 +1275,7 @@ async fn settings_page(cx: &Cx) -> Result { | |||
| 1272 | </div> | 1275 | </div> |
| 1273 | <div class="panel-body"> | 1276 | <div class="panel-body"> |
| 1274 | <div class="identity-row"> | 1277 | <div class="identity-row"> |
| 1275 | - (crate::layout::avatar(cx, &user.id, &user.display_name, "avatar-lg").await?) | 1278 | + (crate::layout::avatar(cx, &user.id, &user.display_name, user.photo_version, "avatar-lg").await?) |
| 1276 | <div class="identity-who"> | 1279 | <div class="identity-who"> |
| 1277 | <div class="identity-name">(user.display_name.clone())</div> | 1280 | <div class="identity-name">(user.display_name.clone())</div> |
| 1278 | <div class="identity-address">(user.email.clone())</div> | 1281 | <div class="identity-address">(user.email.clone())</div> |
| @@ -1604,7 +1607,7 @@ async fn settings_page(cx: &Cx) -> Result { | |||
| 1604 | <tr class="member-row"> | 1607 | <tr class="member-row"> |
| 1605 | <td class="member-col-name member-name"> | 1608 | <td class="member-col-name member-name"> |
| 1606 | <span class="member-name-row"> | 1609 | <span class="member-name-row"> |
| 1607 | - (crate::layout::avatar(cx, &member.id, &member.display_name, "avatar-sm").await?) | 1610 | + (crate::layout::avatar(cx, &member.id, &member.display_name, member.photo_version, "avatar-sm").await?) |
| 1608 | <a href=(format!("/people/{}", member.id))>(member.display_name.clone())</a> | 1611 | <a href=(format!("/people/{}", member.id))>(member.display_name.clone())</a> |
| 1609 | if member.is_you { | 1612 | if member.is_you { |
| 1610 | <span class="member-you">(t(lang, Key::You))</span> | 1613 | <span class="member-you">(t(lang, Key::You))</span> |
crates/iz-web/tests/http.rsmodified+99 -23
| @@ -349,6 +349,11 @@ impl App { | |||
| 349 | client.clone(), | 349 | client.clone(), |
| 350 | ) | 350 | ) |
| 351 | .app_context(store.clone()) | 351 | .app_context(store.clone()) |
| 352 | + .app_context(im_client::directory::DirectoryClient::new( | ||
| 353 | + fake.url(), | ||
| 354 | + "iz-test", | ||
| 355 | + "s3cr3t", | ||
| 356 | + )) | ||
| 352 | .app_context(iz_client::LogoutBack(Arc::new( | 357 | .app_context(iz_client::LogoutBack(Arc::new( |
| 353 | iz_web::server::logout_back, | 358 | iz_web::server::logout_back, |
| 354 | ))) | 359 | ))) |
| @@ -432,6 +437,11 @@ impl App { | |||
| 432 | client.clone(), | 437 | client.clone(), |
| 433 | ) | 438 | ) |
| 434 | .app_context(store.clone()) | 439 | .app_context(store.clone()) |
| 440 | + .app_context(im_client::directory::DirectoryClient::new( | ||
| 441 | + fake.url(), | ||
| 442 | + "iz-test", | ||
| 443 | + "s3cr3t", | ||
| 444 | + )) | ||
| 435 | .app_context(iz_client::LogoutBack(Arc::new( | 445 | .app_context(iz_client::LogoutBack(Arc::new( |
| 436 | iz_web::server::logout_back, | 446 | iz_web::server::logout_back, |
| 437 | ))) | 447 | ))) |
| @@ -708,6 +718,11 @@ impl App { | |||
| 708 | .get(header::ETAG) | 718 | .get(header::ETAG) |
| 709 | .and_then(|value| value.to_str().ok()) | 719 | .and_then(|value| value.to_str().ok()) |
| 710 | .map(str::to_string); | 720 | .map(str::to_string); |
| 721 | + let cache_control = response | ||
| 722 | + .headers() | ||
| 723 | + .get(header::CACHE_CONTROL) | ||
| 724 | + .and_then(|value| value.to_str().ok()) | ||
| 725 | + .map(str::to_string); | ||
| 711 | let location = response | 726 | let location = response |
| 712 | .headers() | 727 | .headers() |
| 713 | .get(header::LOCATION) | 728 | .get(header::LOCATION) |
| @@ -724,6 +739,7 @@ impl App { | |||
| 724 | content_range, | 739 | content_range, |
| 725 | accept_ranges, | 740 | accept_ranges, |
| 726 | etag, | 741 | etag, |
| 742 | + cache_control, | ||
| 727 | location, | 743 | location, |
| 728 | bytes, | 744 | bytes, |
| 729 | } | 745 | } |
| @@ -745,6 +761,7 @@ struct Raw { | |||
| 745 | content_range: Option<String>, | 761 | content_range: Option<String>, |
| 746 | accept_ranges: Option<String>, | 762 | accept_ranges: Option<String>, |
| 747 | etag: Option<String>, | 763 | etag: Option<String>, |
| 764 | + cache_control: Option<String>, | ||
| 748 | /// Where a 303 sends the browser — the sign-out handoff's whole point. | 765 | /// Where a 303 sends the browser — the sign-out handoff's whole point. |
| 749 | location: Option<String>, | 766 | location: Option<String>, |
| 750 | bytes: Vec<u8>, | 767 | bytes: Vec<u8>, |
| @@ -4945,8 +4962,7 @@ async fn a_synced_member_is_listed_and_assignable_before_their_first_sign_in() { | |||
| 4945 | .unwrap(); | 4962 | .unwrap(); |
| 4946 | 4963 | ||
| 4947 | let sync = app | 4964 | let sync = app |
| 4948 | - .store | 4965 | + .store.sync_member("sub-mert", "mert@iz.sh", "Mert", false, 0) |
| 4949 | - .sync_member("sub-mert", "mert@iz.sh", "Mert", false) | ||
| 4950 | .await | 4966 | .await |
| 4951 | .unwrap(); | 4967 | .unwrap(); |
| 4952 | assert_eq!(sync, iz_core::store::MemberSync::Inserted); | 4968 | assert_eq!(sync, iz_core::store::MemberSync::Inserted); |
| @@ -5164,10 +5180,12 @@ async fn the_sign_in_card_links_the_login_and_names_a_failed_round_trip() { | |||
| 5164 | // Avatar: the signed-in person's face, proxied from im | 5180 | // Avatar: the signed-in person's face, proxied from im |
| 5165 | // --------------------------------------------------------------------------- | 5181 | // --------------------------------------------------------------------------- |
| 5166 | 5182 | ||
| 5167 | -/// One's own avatar proxies im's photo bytes with the app's credential. | 5183 | +/// A member's avatar proxies im's photo bytes with the app's credential. |
| 5168 | -/// Catches a proxy that drops the auth or mangles the bytes. | 5184 | +/// Catches a proxy that drops the auth or mangles the bytes, and pins the |
| 5185 | +/// versioned caching: the row's `photo_version` is the ETag and the `?v=` | ||
| 5186 | +/// stamp a page renders. | ||
| 5169 | #[tokio::test] | 5187 | #[tokio::test] |
| 5170 | -async fn ones_own_avatar_proxies_the_im_photo() { | 5188 | +async fn a_members_avatar_proxies_the_im_photo() { |
| 5171 | let app = App::open().await; | 5189 | let app = App::open().await; |
| 5172 | let admin = admin(&app).await; | 5190 | let admin = admin(&app).await; |
| 5173 | let admin_id = user_id(&app, "ada@iz.sh").await; | 5191 | let admin_id = user_id(&app, "ada@iz.sh").await; |
| @@ -5177,46 +5195,99 @@ async fn ones_own_avatar_proxies_the_im_photo() { | |||
| 5177 | assert_eq!(photo.status, StatusCode::OK); | 5195 | assert_eq!(photo.status, StatusCode::OK); |
| 5178 | assert_eq!(photo.content_type.as_deref(), Some("image/png")); | 5196 | assert_eq!(photo.content_type.as_deref(), Some("image/png")); |
| 5179 | assert_eq!(photo.bytes, PNG); | 5197 | assert_eq!(photo.bytes, PNG); |
| 5198 | + // The row has met no photo yet: version zero, and the ETag says so. | ||
| 5199 | + assert_eq!(photo.etag.as_deref(), Some("\"p0\"")); | ||
| 5200 | + // No stamp on the URL: revalidate, never cache hard — the URL a page | ||
| 5201 | + // renders always carries the stamp, so this is only the stray fetch. | ||
| 5202 | + assert_eq!(photo.cache_control.as_deref(), Some("private, no-cache")); | ||
| 5180 | 5203 | ||
| 5181 | - let etag = photo.etag.clone().expect("no ETag on the served avatar"); | ||
| 5182 | let cached = app | 5204 | let cached = app |
| 5183 | - .get_with_if_none_match(&format!("/avatar/{admin_id}"), Some(&admin), &etag) | 5205 | + .get_with_if_none_match(&format!("/avatar/{admin_id}"), Some(&admin), "\"p0\"") |
| 5184 | .await; | 5206 | .await; |
| 5185 | assert_eq!(cached.status, StatusCode::NOT_MODIFIED); | 5207 | assert_eq!(cached.status, StatusCode::NOT_MODIFIED); |
| 5186 | assert!(cached.bytes.is_empty()); | 5208 | assert!(cached.bytes.is_empty()); |
| 5187 | } | 5209 | } |
| 5188 | 5210 | ||
| 5189 | -/// Another account's id reads exactly like no photo — never a glimpse across | 5211 | +/// The stamp the row carries pins the face: `?v=` agreeing with the row is |
| 5190 | -/// the fence. Catches a proxy that serves any id to any session. | 5212 | +/// cacheable for a year because the URL itself changes when the face does, |
| 5213 | +/// any other spelling revalidates, and a sync that hears of a new photo | ||
| 5214 | +/// moves both the stamp and the ETag together. | ||
| 5191 | #[tokio::test] | 5215 | #[tokio::test] |
| 5192 | -async fn another_accounts_avatar_is_not_found() { | 5216 | +async fn a_matching_version_stamp_is_immutable_and_a_new_one_moves_it() { |
| 5193 | let app = App::open().await; | 5217 | let app = App::open().await; |
| 5194 | let admin_cookie = admin(&app).await; | 5218 | let admin_cookie = admin(&app).await; |
| 5195 | - let admin_id = user_id(&app, "ada@iz.sh").await; | ||
| 5196 | let member = invited(&app, &admin_cookie, "emre@iz.sh", "Emre", Role::Member).await; | 5219 | let member = invited(&app, &admin_cookie, "emre@iz.sh", "Emre", Role::Member).await; |
| 5197 | - app.fake.set_photo("im-ada", PNG.to_vec(), "image/png"); | 5220 | + let member_id = user_id(&app, "emre@iz.sh").await; |
| 5221 | + // The directory pass finds the row by its sub — the same subject the | ||
| 5222 | + // sign-in provisions — and reports the face's third revision. | ||
| 5223 | + app.store | ||
| 5224 | + .sync_member("im-emre@iz.sh", "emre@iz.sh", "Emre", false, 3) | ||
| 5225 | + .await | ||
| 5226 | + .unwrap(); | ||
| 5227 | + app.fake.set_photo("im-emre@iz.sh", PNG.to_vec(), "image/png"); | ||
| 5198 | 5228 | ||
| 5199 | - let photo = app.get(&format!("/avatar/{admin_id}"), Some(&member)).await; | 5229 | + let stamped = app |
| 5200 | - assert_eq!(photo.status, StatusCode::NOT_FOUND); | 5230 | + .get(&format!("/avatar/{member_id}?v=3"), Some(&member)) |
| 5231 | + .await; | ||
| 5232 | + assert_eq!(stamped.status, StatusCode::OK); | ||
| 5233 | + assert_eq!( | ||
| 5234 | + stamped.cache_control.as_deref(), | ||
| 5235 | + Some("private, max-age=31536000, immutable") | ||
| 5236 | + ); | ||
| 5237 | + assert_eq!(stamped.etag.as_deref(), Some("\"p3\"")); | ||
| 5238 | + | ||
| 5239 | + // Any other spelling — a stale stamp, junk, none — may not be pinned. | ||
| 5240 | + for query in ["?v=2", "?v=junk", ""] { | ||
| 5241 | + let stray = app | ||
| 5242 | + .get(&format!("/avatar/{member_id}{query}"), Some(&member)) | ||
| 5243 | + .await; | ||
| 5244 | + assert_eq!(stray.cache_control.as_deref(), Some("private, no-cache")); | ||
| 5245 | + } | ||
| 5246 | + | ||
| 5247 | + // im's count moves; the next sync (the stream's event, or the beat) | ||
| 5248 | + // carries it onto the row, and the old stamp stops being true. | ||
| 5249 | + app.store | ||
| 5250 | + .sync_member("sub-emre", "emre@iz.sh", "Emre", false, 4) | ||
| 5251 | + .await | ||
| 5252 | + .unwrap(); | ||
| 5253 | + let moved = app | ||
| 5254 | + .get(&format!("/avatar/{member_id}?v=4"), Some(&member)) | ||
| 5255 | + .await; | ||
| 5256 | + assert_eq!(moved.etag.as_deref(), Some("\"p4\"")); | ||
| 5257 | + assert_eq!( | ||
| 5258 | + moved.cache_control.as_deref(), | ||
| 5259 | + Some("private, max-age=31536000, immutable") | ||
| 5260 | + ); | ||
| 5261 | + let stale = app | ||
| 5262 | + .get(&format!("/avatar/{member_id}?v=3"), Some(&member)) | ||
| 5263 | + .await; | ||
| 5264 | + assert_eq!(stale.cache_control.as_deref(), Some("private, no-cache")); | ||
| 5201 | } | 5265 | } |
| 5202 | 5266 | ||
| 5203 | -/// Without a session the avatar names the fix: 401, the way the live channel | 5267 | +/// Any member's face serves to any signed-in member — the board shows |
| 5204 | -/// refuses. Catches a proxy that 404s strangers into probing ids. | 5268 | +/// assignees' faces, so the bytes must be reachable — while a browser |
| 5269 | +/// without a session is refused outright, the way the live channel is. | ||
| 5205 | #[tokio::test] | 5270 | #[tokio::test] |
| 5206 | -async fn the_avatar_refuses_a_signed_out_browser() { | 5271 | +async fn another_members_avatar_serves_but_a_signed_out_browser_does_not() { |
| 5207 | let app = App::open().await; | 5272 | let app = App::open().await; |
| 5208 | - let _ = admin(&app).await; | 5273 | + let admin_cookie = admin(&app).await; |
| 5209 | let admin_id = user_id(&app, "ada@iz.sh").await; | 5274 | let admin_id = user_id(&app, "ada@iz.sh").await; |
| 5275 | + let member = invited(&app, &admin_cookie, "emre@iz.sh", "Emre", Role::Member).await; | ||
| 5210 | app.fake.set_photo("im-ada", PNG.to_vec(), "image/png"); | 5276 | app.fake.set_photo("im-ada", PNG.to_vec(), "image/png"); |
| 5211 | 5277 | ||
| 5212 | - let photo = app.get(&format!("/avatar/{admin_id}"), None).await; | 5278 | + let photo = app.get(&format!("/avatar/{admin_id}"), Some(&member)).await; |
| 5213 | - assert_eq!(photo.status, StatusCode::UNAUTHORIZED); | 5279 | + assert_eq!(photo.status, StatusCode::OK); |
| 5280 | + assert_eq!(photo.bytes, PNG); | ||
| 5281 | + | ||
| 5282 | + let refused = app.get(&format!("/avatar/{admin_id}"), None).await; | ||
| 5283 | + assert_eq!(refused.status, StatusCode::UNAUTHORIZED); | ||
| 5214 | } | 5284 | } |
| 5215 | 5285 | ||
| 5216 | -/// im has no photo for this account: 404, and the page falls back to | 5286 | +/// A row that has not met the provider — invited, never signed in, never |
| 5217 | -/// initials. Catches a proxy that fails the page around a missing face. | 5287 | +/// synced — has no face to fetch, and an id nobody holds reads the same. |
| 5288 | +/// Catches a proxy that fails the page around a missing face. | ||
| 5218 | #[tokio::test] | 5289 | #[tokio::test] |
| 5219 | -async fn the_avatar_is_not_found_without_an_im_photo() { | 5290 | +async fn the_avatar_is_not_found_without_a_linked_row() { |
| 5220 | let app = App::open().await; | 5291 | let app = App::open().await; |
| 5221 | let admin_cookie = admin(&app).await; | 5292 | let admin_cookie = admin(&app).await; |
| 5222 | let member = invited(&app, &admin_cookie, "emre@iz.sh", "Emre", Role::Member).await; | 5293 | let member = invited(&app, &admin_cookie, "emre@iz.sh", "Emre", Role::Member).await; |
| @@ -5226,6 +5297,11 @@ async fn the_avatar_is_not_found_without_an_im_photo() { | |||
| 5226 | .get(&format!("/avatar/{member_id}"), Some(&member)) | 5297 | .get(&format!("/avatar/{member_id}"), Some(&member)) |
| 5227 | .await; | 5298 | .await; |
| 5228 | assert_eq!(photo.status, StatusCode::NOT_FOUND); | 5299 | assert_eq!(photo.status, StatusCode::NOT_FOUND); |
| 5300 | + | ||
| 5301 | + let stranger = app | ||
| 5302 | + .get(&format!("/avatar/{}", Ulid::new()), Some(&member)) | ||
| 5303 | + .await; | ||
| 5304 | + assert_eq!(stranger.status, StatusCode::NOT_FOUND); | ||
| 5229 | } | 5305 | } |
| 5230 | 5306 | ||
| 5231 | /// Every page with avatars carries the fallback script: the board's topbar | 5307 | /// Every page with avatars carries the fallback script: the board's topbar |