Pinned repositories and paginated tabs
Browse files at this commit590ac380e9002ab01a9af45118512c238a9d602fParent: 8758f0c- feat
- pinned repositories and paginated tabs
12 changed files +1445 -93
- crates/forge-core/migrations/0037_profile_pins.sql +10 -0
- crates/forge-core/src/store/migrate.rs +1 -0
- crates/forge-core/src/store/mod.rs +2 -0
- crates/forge-core/src/store/profile_pins.rs +213 -0
- crates/forge-core/src/store/user_delete.rs +1 -0
- crates/forge-web/src/i18n/orgs.rs +44 -4
- crates/forge-web/src/pages/mod.rs +1 -0
- crates/forge-web/src/pages/profile.rs +561 -84
- crates/forge-web/src/pages/profile_pins.rs +471 -0
- crates/forge-web/src/views/mod.rs +0 -1
- crates/forge-web/tests/stars_e2e.rs +4 -4
- style/main.scss +137 -0
crates/forge-core/migrations/0037_profile_pins.sqladded+10 -0
| @@ -0,0 +1,10 @@ | |||
| 1 | +-- Repos pinned on a user or organization profile, shown first on the profile page. At most six | ||
| 2 | +-- per owner (enforced by store/profile_pins.rs). position orders the cards. A row goes with the | ||
| 3 | +-- profile owner or with the repo. | ||
| 4 | + | ||
| 5 | +CREATE TABLE profile_pins ( | ||
| 6 | + user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE, | ||
| 7 | + repo_id TEXT NOT NULL REFERENCES repos(id) ON DELETE CASCADE, | ||
| 8 | + position INTEGER NOT NULL, | ||
| 9 | + PRIMARY KEY (user_id, repo_id) | ||
| 10 | +); | ||
crates/forge-core/src/store/migrate.rsmodified+1 -0
| @@ -55,6 +55,7 @@ pub const MIGRATIONS: &[(u32, &str)] = &[ | |||
| 55 | 36, | 55 | 36, |
| 56 | include_str!("../../migrations/0036_default_light_theme.sql"), | 56 | include_str!("../../migrations/0036_default_light_theme.sql"), |
| 57 | ), | 57 | ), |
| 58 | + (37, include_str!("../../migrations/0037_profile_pins.sql")), | ||
| 58 | ]; | 59 | ]; |
| 59 | 60 | ||
| 60 | /// The highest migration version this binary knows about. | 61 | /// The highest migration version this binary knows about. |
crates/forge-core/src/store/mod.rsmodified+2 -0
| @@ -19,6 +19,7 @@ pub mod notifications; | |||
| 19 | pub mod notifications_extra; | 19 | pub mod notifications_extra; |
| 20 | pub mod orgs; | 20 | pub mod orgs; |
| 21 | pub mod pinned; | 21 | pub mod pinned; |
| 22 | +pub mod profile_pins; | ||
| 22 | pub mod pulls; | 23 | pub mod pulls; |
| 23 | pub mod pulls_list_extra; | 24 | pub mod pulls_list_extra; |
| 24 | pub mod push_recent; | 25 | pub mod push_recent; |
| @@ -1125,6 +1126,7 @@ impl Store { | |||
| 1125 | "DELETE FROM push_events WHERE repo_id = ?1", | 1126 | "DELETE FROM push_events WHERE repo_id = ?1", |
| 1126 | "DELETE FROM branch_protections WHERE repo_id = ?1", | 1127 | "DELETE FROM branch_protections WHERE repo_id = ?1", |
| 1127 | "DELETE FROM stars WHERE repo_id = ?1", | 1128 | "DELETE FROM stars WHERE repo_id = ?1", |
| 1129 | + "DELETE FROM profile_pins WHERE repo_id = ?1", | ||
| 1128 | "DELETE FROM commit_statuses WHERE repo_id = ?1", | 1130 | "DELETE FROM commit_statuses WHERE repo_id = ?1", |
| 1129 | "DELETE FROM lfs_objects WHERE repo_id = ?1", | 1131 | "DELETE FROM lfs_objects WHERE repo_id = ?1", |
| 1130 | "DELETE FROM commit_signatures WHERE repo_id = ?1", | 1132 | "DELETE FROM commit_signatures WHERE repo_id = ?1", |
crates/forge-core/src/store/profile_pins.rsadded+213 -0
| @@ -0,0 +1,213 @@ | |||
| 1 | +//! Profile pins: up to `MAX_PROFILE_PINS` repos of a user or organization shown first on its | ||
| 2 | +//! profile. The stored shape is in migrations/0037_profile_pins.sql. Visibility is not checked | ||
| 3 | +//! here; the profile page filters by what the viewer may read. | ||
| 4 | + | ||
| 5 | +use std::collections::HashSet; | ||
| 6 | + | ||
| 7 | +use super::{REPO_COLS, Store, col_text, db_err, fetch_all, fetch_opt, finish, map_repo}; | ||
| 8 | +use crate::error::{Error, Result}; | ||
| 9 | +use crate::model::Repo; | ||
| 10 | + | ||
| 11 | +/// Most repos one profile may pin. | ||
| 12 | +pub const MAX_PROFILE_PINS: usize = 6; | ||
| 13 | + | ||
| 14 | +impl Store { | ||
| 15 | + /// The repos pinned on a profile, in pin order. Not filtered by visibility. | ||
| 16 | + pub async fn profile_pins(&self, user_id: &str) -> Result<Vec<Repo>> { | ||
| 17 | + let conn = self.read_conn().await; | ||
| 18 | + fetch_all( | ||
| 19 | + &conn, | ||
| 20 | + &format!( | ||
| 21 | + "SELECT {REPO_COLS} FROM profile_pins p JOIN repos r ON r.id = p.repo_id \ | ||
| 22 | + JOIN users u ON u.id = r.owner_id WHERE p.user_id = ?1 ORDER BY p.position" | ||
| 23 | + ), | ||
| 24 | + (user_id.to_string(),), | ||
| 25 | + map_repo, | ||
| 26 | + ) | ||
| 27 | + .await | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + /// Every repo the owner owns, most recently active first (the latest push, or the creation | ||
| 31 | + /// time when it never pushed). Not filtered by visibility. | ||
| 32 | + pub async fn owner_repos_by_activity(&self, owner_id: &str) -> Result<Vec<Repo>> { | ||
| 33 | + let conn = self.read_conn().await; | ||
| 34 | + fetch_all( | ||
| 35 | + &conn, | ||
| 36 | + &format!( | ||
| 37 | + "SELECT {REPO_COLS} FROM repos r JOIN users u ON u.id = r.owner_id \ | ||
| 38 | + WHERE r.owner_id = ?1 \ | ||
| 39 | + ORDER BY COALESCE((SELECT MAX(p.created_at) FROM push_events p \ | ||
| 40 | + WHERE p.repo_id = r.id), r.created_at) DESC, r.name_folded ASC" | ||
| 41 | + ), | ||
| 42 | + (owner_id.to_string(),), | ||
| 43 | + map_repo, | ||
| 44 | + ) | ||
| 45 | + .await | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + /// Replaces the pins of `user_id` with `repo_ids`, kept in the order given. Every repo must be | ||
| 49 | + /// owned by that user (for an organization, by the org). More than `MAX_PROFILE_PINS` repos, | ||
| 50 | + /// a repo listed twice, or a repo the owner does not own is `Invalid`, and then nothing | ||
| 51 | + /// changes. The replacement is one transaction. | ||
| 52 | + pub async fn set_profile_pins(&self, user_id: &str, repo_ids: &[String]) -> Result<()> { | ||
| 53 | + if repo_ids.len() > MAX_PROFILE_PINS { | ||
| 54 | + return Err(Error::Invalid(format!( | ||
| 55 | + "a profile can pin at most {MAX_PROFILE_PINS} repositories" | ||
| 56 | + ))); | ||
| 57 | + } | ||
| 58 | + let distinct: HashSet<&str> = repo_ids.iter().map(String::as_str).collect(); | ||
| 59 | + if distinct.len() != repo_ids.len() { | ||
| 60 | + return Err(Error::Invalid( | ||
| 61 | + "a repository can be pinned only once".into(), | ||
| 62 | + )); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + let conn = self.inner.conn.lock().await; | ||
| 66 | + let tx = conn.unchecked_transaction().await.map_err(db_err)?; | ||
| 67 | + let outcome: Result<()> = async { | ||
| 68 | + for repo_id in repo_ids { | ||
| 69 | + let owner = fetch_opt( | ||
| 70 | + &tx, | ||
| 71 | + "SELECT owner_id FROM repos WHERE id = ?1", | ||
| 72 | + (repo_id.to_string(),), | ||
| 73 | + |row| col_text(row, 0), | ||
| 74 | + ) | ||
| 75 | + .await?; | ||
| 76 | + if owner.as_deref() != Some(user_id) { | ||
| 77 | + return Err(Error::Invalid( | ||
| 78 | + "only repositories owned by this profile can be pinned".into(), | ||
| 79 | + )); | ||
| 80 | + } | ||
| 81 | + } | ||
| 82 | + tx.execute( | ||
| 83 | + "DELETE FROM profile_pins WHERE user_id = ?1", | ||
| 84 | + (user_id.to_string(),), | ||
| 85 | + ) | ||
| 86 | + .await | ||
| 87 | + .map_err(db_err)?; | ||
| 88 | + for (position, repo_id) in repo_ids.iter().enumerate() { | ||
| 89 | + tx.execute( | ||
| 90 | + "INSERT INTO profile_pins (user_id, repo_id, position) VALUES (?1, ?2, ?3)", | ||
| 91 | + ( | ||
| 92 | + user_id.to_string(), | ||
| 93 | + repo_id.to_string(), | ||
| 94 | + i64::try_from(position + 1).unwrap_or(i64::MAX), | ||
| 95 | + ), | ||
| 96 | + ) | ||
| 97 | + .await | ||
| 98 | + .map_err(db_err)?; | ||
| 99 | + } | ||
| 100 | + Ok(()) | ||
| 101 | + } | ||
| 102 | + .await; | ||
| 103 | + finish(tx, outcome).await | ||
| 104 | + } | ||
| 105 | +} | ||
| 106 | + | ||
| 107 | +#[cfg(test)] | ||
| 108 | +mod tests { | ||
| 109 | + use super::*; | ||
| 110 | + use crate::model::Visibility; | ||
| 111 | + | ||
| 112 | + async fn fixture() -> (Store, String, String, tempfile::TempDir) { | ||
| 113 | + let dir = tempfile::tempdir().unwrap(); | ||
| 114 | + let store = Store::open(&dir.path().join("forge.db")).await.unwrap(); | ||
| 115 | + let tahinli = store | ||
| 116 | + .create_user("tahinli", None, "h", false) | ||
| 117 | + .await | ||
| 118 | + .unwrap(); | ||
| 119 | + let carol = store.create_user("carol", None, "h", false).await.unwrap(); | ||
| 120 | + let foreign = store | ||
| 121 | + .create_repo(&carol.id, "carols", "", Visibility::Public, "main") | ||
| 122 | + .await | ||
| 123 | + .unwrap(); | ||
| 124 | + (store, tahinli.id, foreign.id, dir) | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + async fn make_repos(store: &Store, owner: &str, count: usize) -> Vec<String> { | ||
| 128 | + let mut ids = Vec::new(); | ||
| 129 | + for i in 0..count { | ||
| 130 | + let repo = store | ||
| 131 | + .create_repo(owner, &format!("repo-{i}"), "", Visibility::Public, "main") | ||
| 132 | + .await | ||
| 133 | + .unwrap(); | ||
| 134 | + ids.push(repo.id); | ||
| 135 | + } | ||
| 136 | + ids | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + async fn pinned_names(store: &Store, owner: &str) -> Vec<String> { | ||
| 140 | + store | ||
| 141 | + .profile_pins(owner) | ||
| 142 | + .await | ||
| 143 | + .unwrap() | ||
| 144 | + .into_iter() | ||
| 145 | + .map(|r| r.name) | ||
| 146 | + .collect() | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + #[tokio::test] | ||
| 150 | + async fn pins_keep_the_order_given_and_replace_the_old_set() { | ||
| 151 | + let (store, tahinli, _, _dir) = fixture().await; | ||
| 152 | + let ids = make_repos(&store, &tahinli, 3).await; | ||
| 153 | + store | ||
| 154 | + .set_profile_pins(&tahinli, &[ids[2].clone(), ids[0].clone()]) | ||
| 155 | + .await | ||
| 156 | + .unwrap(); | ||
| 157 | + assert_eq!(pinned_names(&store, &tahinli).await, ["repo-2", "repo-0"]); | ||
| 158 | + | ||
| 159 | + store | ||
| 160 | + .set_profile_pins(&tahinli, &[ids[1].clone()]) | ||
| 161 | + .await | ||
| 162 | + .unwrap(); | ||
| 163 | + assert_eq!(pinned_names(&store, &tahinli).await, ["repo-1"]); | ||
| 164 | + | ||
| 165 | + store.set_profile_pins(&tahinli, &[]).await.unwrap(); | ||
| 166 | + assert!(pinned_names(&store, &tahinli).await.is_empty()); | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + #[tokio::test] | ||
| 170 | + async fn more_than_six_pins_is_refused_and_keeps_the_old_pins() { | ||
| 171 | + let (store, tahinli, _, _dir) = fixture().await; | ||
| 172 | + let ids = make_repos(&store, &tahinli, 7).await; | ||
| 173 | + store.set_profile_pins(&tahinli, &ids[..2]).await.unwrap(); | ||
| 174 | + let too_many = store.set_profile_pins(&tahinli, &ids).await; | ||
| 175 | + assert!(matches!(too_many, Err(Error::Invalid(_)))); | ||
| 176 | + assert_eq!(pinned_names(&store, &tahinli).await, ["repo-0", "repo-1"]); | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + #[tokio::test] | ||
| 180 | + async fn foreign_and_repeated_repos_are_refused_atomically() { | ||
| 181 | + let (store, tahinli, foreign, _dir) = fixture().await; | ||
| 182 | + let ids = make_repos(&store, &tahinli, 1).await; | ||
| 183 | + store.set_profile_pins(&tahinli, &ids[..1]).await.unwrap(); | ||
| 184 | + | ||
| 185 | + let stolen = store | ||
| 186 | + .set_profile_pins(&tahinli, &[ids[0].clone(), foreign]) | ||
| 187 | + .await; | ||
| 188 | + assert!(matches!(stolen, Err(Error::Invalid(_)))); | ||
| 189 | + let repeated = store | ||
| 190 | + .set_profile_pins(&tahinli, &[ids[0].clone(), ids[0].clone()]) | ||
| 191 | + .await; | ||
| 192 | + assert!(matches!(repeated, Err(Error::Invalid(_)))); | ||
| 193 | + assert_eq!(pinned_names(&store, &tahinli).await, ["repo-0"]); | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + #[tokio::test] | ||
| 197 | + async fn deleting_a_pinned_repo_removes_its_pin() { | ||
| 198 | + let (store, tahinli, _, _dir) = fixture().await; | ||
| 199 | + let ids = make_repos(&store, &tahinli, 2).await; | ||
| 200 | + store.set_profile_pins(&tahinli, &ids).await.unwrap(); | ||
| 201 | + store.delete_repo(&ids[0]).await.unwrap(); | ||
| 202 | + assert_eq!(pinned_names(&store, &tahinli).await, ["repo-1"]); | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + #[tokio::test] | ||
| 206 | + async fn owner_repos_by_activity_lists_every_owned_repo() { | ||
| 207 | + let (store, tahinli, foreign, _dir) = fixture().await; | ||
| 208 | + make_repos(&store, &tahinli, 2).await; | ||
| 209 | + let listed = store.owner_repos_by_activity(&tahinli).await.unwrap(); | ||
| 210 | + assert_eq!(listed.len(), 2); | ||
| 211 | + assert!(listed.iter().all(|r| r.id != foreign)); | ||
| 212 | + } | ||
| 213 | +} | ||
crates/forge-core/src/store/user_delete.rsmodified+1 -0
| @@ -110,6 +110,7 @@ const REMOVED: &[(&str, &str, &str)] = &[ | |||
| 110 | ("access tokens", "access_tokens", "user_id"), | 110 | ("access tokens", "access_tokens", "user_id"), |
| 111 | ("collaborations", "collaborators", "user_id"), | 111 | ("collaborations", "collaborators", "user_id"), |
| 112 | ("stars", "stars", "user_id"), | 112 | ("stars", "stars", "user_id"), |
| 113 | + ("profile pins", "profile_pins", "user_id"), | ||
| 113 | ("issue assignments", "issue_assignees", "user_id"), | 114 | ("issue assignments", "issue_assignees", "user_id"), |
| 114 | ("recovery codes", "recovery_codes", "user_id"), | 115 | ("recovery codes", "recovery_codes", "user_id"), |
| 115 | ("avatar", "avatars", "user_id"), | 116 | ("avatar", "avatars", "user_id"), |
crates/forge-web/src/i18n/orgs.rsmodified+44 -4
| @@ -109,8 +109,18 @@ pub enum K { | |||
| 109 | AllMembers, | 109 | AllMembers, |
| 110 | NoMembers, | 110 | NoMembers, |
| 111 | NoVisibleRepos, | 111 | NoVisibleRepos, |
| 112 | - Starred, | ||
| 113 | NoVisibleStarred, | 112 | NoVisibleStarred, |
| 113 | + Pinned, | ||
| 114 | + PopularRepos, | ||
| 115 | + CustomizePins, | ||
| 116 | + PinsIntro, | ||
| 117 | + SavePins, | ||
| 118 | + PinsTooMany, | ||
| 119 | + NoPinnableRepos, | ||
| 120 | + TabOverview, | ||
| 121 | + TabStars, | ||
| 122 | + FilterRepos, | ||
| 123 | + NoReposMatch, | ||
| 114 | // Dashboard and landing. | 124 | // Dashboard and landing. |
| 115 | Dashboard, | 125 | Dashboard, |
| 116 | Home, | 126 | Home, |
| @@ -335,10 +345,30 @@ pub fn t(lang: Lang, key: K) -> &'static str { | |||
| 335 | (NoMembers, Tr) => "Üye yok.", | 345 | (NoMembers, Tr) => "Üye yok.", |
| 336 | (NoVisibleRepos, En) => "No visible repositories.", | 346 | (NoVisibleRepos, En) => "No visible repositories.", |
| 337 | (NoVisibleRepos, Tr) => "Görünür depo yok.", | 347 | (NoVisibleRepos, Tr) => "Görünür depo yok.", |
| 338 | - (Starred, En) => "Starred", | ||
| 339 | - (Starred, Tr) => "Yıldızlılar", | ||
| 340 | (NoVisibleStarred, En) => "No visible starred repositories.", | 348 | (NoVisibleStarred, En) => "No visible starred repositories.", |
| 341 | (NoVisibleStarred, Tr) => "Görünür yıldızlı depo yok.", | 349 | (NoVisibleStarred, Tr) => "Görünür yıldızlı depo yok.", |
| 350 | + (Pinned, En) => "Pinned", | ||
| 351 | + (Pinned, Tr) => "Sabitlenenler", | ||
| 352 | + (PopularRepos, En) => "Popular repositories", | ||
| 353 | + (PopularRepos, Tr) => "Popüler depolar", | ||
| 354 | + (CustomizePins, En) => "Customize pins", | ||
| 355 | + (CustomizePins, Tr) => "Sabitlemeleri düzenle", | ||
| 356 | + (PinsIntro, En) => "Pick up to six repositories to show first on this profile.", | ||
| 357 | + (PinsIntro, Tr) => "Bu profilde önce gösterilecek en fazla altı depoyu seç.", | ||
| 358 | + (SavePins, En) => "Save pins", | ||
| 359 | + (SavePins, Tr) => "Sabitlemeleri kaydet", | ||
| 360 | + (PinsTooMany, En) => "You can pin at most six repositories.", | ||
| 361 | + (PinsTooMany, Tr) => "En fazla altı depo sabitleyebilirsin.", | ||
| 362 | + (NoPinnableRepos, En) => "No repositories to pin yet.", | ||
| 363 | + (NoPinnableRepos, Tr) => "Henüz sabitlenecek depo yok.", | ||
| 364 | + (TabOverview, En) => "Overview", | ||
| 365 | + (TabOverview, Tr) => "Genel bakış", | ||
| 366 | + (TabStars, En) => "Stars", | ||
| 367 | + (TabStars, Tr) => "Yıldızlar", | ||
| 368 | + (FilterRepos, En) => "Find a repository", | ||
| 369 | + (FilterRepos, Tr) => "Depo ara", | ||
| 370 | + (NoReposMatch, En) => "No repositories match.", | ||
| 371 | + (NoReposMatch, Tr) => "Aramayla eşleşen depo yok.", | ||
| 342 | (Dashboard, En) => "Dashboard", | 372 | (Dashboard, En) => "Dashboard", |
| 343 | (Dashboard, Tr) => "Pano", | 373 | (Dashboard, Tr) => "Pano", |
| 344 | (Home, En) => "Home", | 374 | (Home, En) => "Home", |
| @@ -551,8 +581,18 @@ mod tests { | |||
| 551 | K::AllMembers, | 581 | K::AllMembers, |
| 552 | K::NoMembers, | 582 | K::NoMembers, |
| 553 | K::NoVisibleRepos, | 583 | K::NoVisibleRepos, |
| 554 | - K::Starred, | ||
| 555 | K::NoVisibleStarred, | 584 | K::NoVisibleStarred, |
| 585 | + K::Pinned, | ||
| 586 | + K::PopularRepos, | ||
| 587 | + K::CustomizePins, | ||
| 588 | + K::PinsIntro, | ||
| 589 | + K::SavePins, | ||
| 590 | + K::PinsTooMany, | ||
| 591 | + K::NoPinnableRepos, | ||
| 592 | + K::TabOverview, | ||
| 593 | + K::TabStars, | ||
| 594 | + K::FilterRepos, | ||
| 595 | + K::NoReposMatch, | ||
| 556 | K::Dashboard, | 596 | K::Dashboard, |
| 557 | K::Home, | 597 | K::Home, |
| 558 | K::LandingTagline, | 598 | K::LandingTagline, |
crates/forge-web/src/pages/mod.rsmodified+1 -0
| @@ -51,6 +51,7 @@ pub mod org_new; | |||
| 51 | pub mod org_settings; | 51 | pub mod org_settings; |
| 52 | pub mod org_teams; | 52 | pub mod org_teams; |
| 53 | pub mod profile; | 53 | pub mod profile; |
| 54 | +pub mod profile_pins; | ||
| 54 | pub mod pull_branch; | 55 | pub mod pull_branch; |
| 55 | pub mod pull_files; | 56 | pub mod pull_files; |
| 56 | pub mod pull_reviews; | 57 | pub mod pull_reviews; |
crates/forge-web/src/pages/profile.rsmodified+561 -84
| @@ -1,31 +1,51 @@ | |||
| 1 | -//! Page: public profile at `/{username}`. Avatar, about (rendered markdown), local time and the | 1 | +//! Page: public profile at `/{username}`. Avatar, about (rendered markdown) and local time, then |
| 2 | -//! repositories the viewer is allowed to read. Fixed single-segment routes are registered | 2 | +//! three tabs: `overview` (pinned repos, or the most recently active ones when nothing is pinned, |
| 3 | -//! statically, so they win over this parameter route. | 3 | +//! plus an organization's members and teams), `repositories` and `stars`. The repo tabs list what |
| 4 | +//! the viewer is allowed to read, 30 per page, with a name filter. Fixed single-segment routes are | ||
| 5 | +//! registered statically, so they win over this parameter route. | ||
| 4 | 6 | ||
| 5 | use forge_core::authz::{Action, authorize}; | 7 | use forge_core::authz::{Action, authorize}; |
| 8 | +use forge_core::store::orgs::OrgMemberRole; | ||
| 9 | +use forge_core::store::profile_pins::MAX_PROFILE_PINS; | ||
| 6 | use forge_core::tz::local_time_now; | 10 | use forge_core::tz::local_time_now; |
| 7 | -use forge_core::{Repo, User}; | 11 | +use forge_core::{Repo, User, Visibility}; |
| 8 | use topcoat::Result; | 12 | use topcoat::Result; |
| 9 | use topcoat::context::{Cx, app_context}; | 13 | use topcoat::context::{Cx, app_context}; |
| 10 | use topcoat::router::error::not_found; | 14 | use topcoat::router::error::not_found; |
| 11 | -use topcoat::router::{page, path_param}; | 15 | +use topcoat::router::{page, path_param, query_params}; |
| 12 | use topcoat::view::{Unescaped, View, component, view}; | 16 | use topcoat::view::{Unescaped, View, component, view}; |
| 13 | 17 | ||
| 14 | use crate::auth::current_user; | 18 | use crate::auth::current_user; |
| 19 | +use crate::i18n::misc::{self as mi, K as MK}; | ||
| 15 | use crate::i18n::orgs::{self as g, K}; | 20 | use crate::i18n::orgs::{self as g, K}; |
| 16 | use crate::i18n::{self, Lang}; | 21 | use crate::i18n::{self, Lang}; |
| 17 | use crate::pages::dashboard::badge_class; | 22 | use crate::pages::dashboard::badge_class; |
| 18 | use crate::render::markdown::render_markdown; | 23 | use crate::render::markdown::render_markdown; |
| 19 | use crate::state::AppState; | 24 | use crate::state::AppState; |
| 20 | -use crate::views::{avatar_url, now_unix, repo_href, shell}; | 25 | +use crate::views::{avatar_url, enc, now_unix, repo_href, shell}; |
| 21 | 26 | ||
| 22 | path_param!(username); | 27 | path_param!(username); |
| 23 | 28 | ||
| 29 | +/// Repos per page on the repositories and stars tabs. | ||
| 30 | +const PER_PAGE: usize = 30; | ||
| 31 | +/// Repos the overview shows when the owner has no visible pins. | ||
| 32 | +const POPULAR_COUNT: usize = 6; | ||
| 33 | +/// Longest name filter kept, in characters. | ||
| 34 | +const MAX_QUERY_CHARS: usize = 100; | ||
| 35 | + | ||
| 36 | +#[query_params(error = bad_request)] | ||
| 37 | +struct ProfileQuery { | ||
| 38 | + tab: Option<String>, | ||
| 39 | + q: Option<String>, | ||
| 40 | + page: Option<String>, | ||
| 41 | +} | ||
| 42 | + | ||
| 24 | #[page("/{username}")] | 43 | #[page("/{username}")] |
| 25 | async fn profile_page(cx: &Cx) -> Result<impl View> { | 44 | async fn profile_page(cx: &Cx) -> Result<impl View> { |
| 26 | let name = path_param::<Username>(cx); | 45 | let name = path_param::<Username>(cx); |
| 27 | let state = app_context::<AppState>(cx); | 46 | let state = app_context::<AppState>(cx); |
| 28 | let viewer = current_user(cx).await?; | 47 | let viewer = current_user(cx).await?; |
| 48 | + let query = query_params::<ProfileQuery>(cx)?; | ||
| 29 | 49 | ||
| 30 | let Some(user) = state.store.user_by_username(name).await? else { | 50 | let Some(user) = state.store.user_by_username(name).await? else { |
| 31 | return Err(not_found().into()); | 51 | return Err(not_found().into()); |
| @@ -40,40 +60,108 @@ async fn profile_page(cx: &Cx) -> Result<impl View> { | |||
| 40 | let local_time = local_time_now(&user.timezone, now_unix()); | 60 | let local_time = local_time_now(&user.timezone, now_unix()); |
| 41 | 61 | ||
| 42 | let actor = viewer.as_ref().map(|(u, _)| u); | 62 | let actor = viewer.as_ref().map(|(u, _)| u); |
| 43 | - let mut repos = Vec::new(); | 63 | + let lang = i18n::lang(cx, actor); |
| 44 | - for repo in state.store.list_repos_by_owner(&user.id).await? { | 64 | + let tab = tab_key(query.tab.as_deref()); |
| 45 | - let (role, org_role) = match actor { | 65 | + let q: String = query |
| 46 | - Some(u) => ( | 66 | + .q |
| 47 | - state.store.collaborator_role(&repo.id, &u.id).await?, | 67 | + .as_deref() |
| 48 | - state | 68 | + .unwrap_or("") |
| 49 | - .store | 69 | + .trim() |
| 50 | - .org_repo_role(&repo.owner_id, &u.id, &repo.id) | 70 | + .chars() |
| 51 | - .await?, | 71 | + .take(MAX_QUERY_CHARS) |
| 52 | - ), | 72 | + .collect(); |
| 53 | - None => (None, None), | 73 | + let page = page_number(query.page.as_deref()); |
| 54 | - }; | 74 | + |
| 55 | - if authorize(actor, &repo, role, org_role, Action::Read).is_ok() { | 75 | + // Both lists are read once and filtered by visibility; the tab labels count what is readable. |
| 56 | - repos.push(repo); | 76 | + let repos = readable( |
| 77 | + state, | ||
| 78 | + actor, | ||
| 79 | + state.store.list_repos_by_owner(&user.id).await?, | ||
| 80 | + usize::MAX, | ||
| 81 | + ) | ||
| 82 | + .await?; | ||
| 83 | + let starred = readable( | ||
| 84 | + state, | ||
| 85 | + actor, | ||
| 86 | + state.store.starred_repos(&user.id).await?, | ||
| 87 | + usize::MAX, | ||
| 88 | + ) | ||
| 89 | + .await?; | ||
| 90 | + let repo_total = repos.len(); | ||
| 91 | + let star_total = starred.len(); | ||
| 92 | + | ||
| 93 | + // The overview shows the owner's pins that the viewer may read. With none visible, it shows | ||
| 94 | + // the most recently active repos instead. | ||
| 95 | + let mut cards = Vec::new(); | ||
| 96 | + let mut from_pins = true; | ||
| 97 | + if tab == "overview" { | ||
| 98 | + let mut shown = readable( | ||
| 99 | + state, | ||
| 100 | + actor, | ||
| 101 | + state.store.profile_pins(&user.id).await?, | ||
| 102 | + MAX_PROFILE_PINS, | ||
| 103 | + ) | ||
| 104 | + .await?; | ||
| 105 | + if shown.is_empty() { | ||
| 106 | + from_pins = false; | ||
| 107 | + shown = readable( | ||
| 108 | + state, | ||
| 109 | + actor, | ||
| 110 | + state.store.owner_repos_by_activity(&user.id).await?, | ||
| 111 | + POPULAR_COUNT, | ||
| 112 | + ) | ||
| 113 | + .await?; | ||
| 114 | + } | ||
| 115 | + for repo in shown { | ||
| 116 | + let stars = state.store.star_count(&repo.id).await?; | ||
| 117 | + cards.push(PinCard { repo, stars }); | ||
| 57 | } | 118 | } |
| 58 | } | 119 | } |
| 59 | 120 | ||
| 60 | - // Starred repos are the user's bookmarks; only the ones the viewer may read are shown. | 121 | + // An organization's pins are edited by its owners, a user's by the user. |
| 61 | - let mut starred = Vec::new(); | 122 | + let can_edit_pins = match actor { |
| 62 | - for repo in state.store.starred_repos(&user.id).await? { | 123 | + Some(u) if user.is_org() => { |
| 63 | - let (role, org_role) = match actor { | 124 | + state.store.org_member_role(&user.id, &u.id).await? == Some(OrgMemberRole::Owner) |
| 64 | - Some(u) => ( | ||
| 65 | - state.store.collaborator_role(&repo.id, &u.id).await?, | ||
| 66 | - state | ||
| 67 | - .store | ||
| 68 | - .org_repo_role(&repo.owner_id, &u.id, &repo.id) | ||
| 69 | - .await?, | ||
| 70 | - ), | ||
| 71 | - None => (None, None), | ||
| 72 | - }; | ||
| 73 | - if authorize(actor, &repo, role, org_role, Action::Read).is_ok() { | ||
| 74 | - starred.push(repo); | ||
| 75 | } | 125 | } |
| 76 | - } | 126 | + Some(u) => u.id == user.id, |
| 127 | + None => false, | ||
| 128 | + }; | ||
| 129 | + let pins_edit_href = can_edit_pins.then(|| { | ||
| 130 | + if user.is_org() { | ||
| 131 | + format!("/org/{}/settings/pins", user.username) | ||
| 132 | + } else { | ||
| 133 | + "/settings/pins".to_owned() | ||
| 134 | + } | ||
| 135 | + }); | ||
| 136 | + let edit_profile = !user.is_org() && actor.is_some_and(|u| u.id == user.id); | ||
| 137 | + | ||
| 138 | + let listing = match tab { | ||
| 139 | + "repositories" => paginate( | ||
| 140 | + repos, | ||
| 141 | + &user.username, | ||
| 142 | + tab, | ||
| 143 | + &q, | ||
| 144 | + page, | ||
| 145 | + if q.is_empty() { | ||
| 146 | + g::t(lang, K::NoVisibleRepos) | ||
| 147 | + } else { | ||
| 148 | + g::t(lang, K::NoReposMatch) | ||
| 149 | + }, | ||
| 150 | + ), | ||
| 151 | + "stars" => paginate( | ||
| 152 | + starred, | ||
| 153 | + &user.username, | ||
| 154 | + tab, | ||
| 155 | + &q, | ||
| 156 | + page, | ||
| 157 | + if q.is_empty() { | ||
| 158 | + g::t(lang, K::NoVisibleStarred) | ||
| 159 | + } else { | ||
| 160 | + g::t(lang, K::NoReposMatch) | ||
| 161 | + }, | ||
| 162 | + ), | ||
| 163 | + _ => Listing::default(), | ||
| 164 | + }; | ||
| 77 | 165 | ||
| 78 | // An organization shows its members and how many teams it has. Its `about` is its description. | 166 | // An organization shows its members and how many teams it has. Its `about` is its description. |
| 79 | let org = if user.is_org() { | 167 | let org = if user.is_org() { |
| @@ -91,10 +179,12 @@ async fn profile_page(cx: &Cx) -> Result<impl View> { | |||
| 91 | }; | 179 | }; |
| 92 | 180 | ||
| 93 | let title = user.username.clone(); | 181 | let title = user.username.clone(); |
| 94 | - let lang = i18n::lang(cx, viewer.as_ref().map(|(u, _)| u)); | ||
| 95 | Ok(view! { cx => | 182 | Ok(view! { cx => |
| 96 | shell(title: title.as_str(), viewer: viewer.as_ref(), | 183 | shell(title: title.as_str(), viewer: viewer.as_ref(), |
| 97 | - profile_card(user: user, avatar: avatar, about_html: about_html, local_time: local_time, repos: repos, starred: starred, org: org, lang: lang)) | 184 | + profile_card(user: user, avatar: avatar, about_html: about_html, local_time: local_time, |
| 185 | + org: org, lang: lang, tab: tab.to_owned(), q: q, repo_total: repo_total, | ||
| 186 | + star_total: star_total, cards: cards, from_pins: from_pins, | ||
| 187 | + pins_edit_href: pins_edit_href, edit_profile: edit_profile, listing: listing)) | ||
| 98 | }) | 188 | }) |
| 99 | } | 189 | } |
| 100 | 190 | ||
| @@ -104,24 +194,183 @@ struct OrgSummary { | |||
| 104 | teams: usize, | 194 | teams: usize, |
| 105 | } | 195 | } |
| 106 | 196 | ||
| 197 | +/// A repo card on the overview: the repo and its star count. | ||
| 198 | +struct PinCard { | ||
| 199 | + repo: Repo, | ||
| 200 | + stars: u64, | ||
| 201 | +} | ||
| 202 | + | ||
| 203 | +/// One page of a repo tab: the rows, the match count, the pager links and the empty-list text. | ||
| 204 | +#[derive(Default)] | ||
| 205 | +struct Listing { | ||
| 206 | + rows: Vec<Repo>, | ||
| 207 | + total: usize, | ||
| 208 | + page: usize, | ||
| 209 | + pages: usize, | ||
| 210 | + prev: Option<String>, | ||
| 211 | + next: Option<String>, | ||
| 212 | + empty: &'static str, | ||
| 213 | +} | ||
| 214 | + | ||
| 215 | +/// The profile tabs, by their `?tab=` key. Anything unknown is the overview. | ||
| 216 | +fn tab_key(raw: Option<&str>) -> &'static str { | ||
| 217 | + match raw { | ||
| 218 | + Some("repositories") => "repositories", | ||
| 219 | + Some("stars") => "stars", | ||
| 220 | + _ => "overview", | ||
| 221 | + } | ||
| 222 | +} | ||
| 223 | + | ||
| 224 | +/// The `?page=` value, 1-based. Anything unreadable is page 1. | ||
| 225 | +fn page_number(raw: Option<&str>) -> usize { | ||
| 226 | + raw.and_then(|p| p.parse::<usize>().ok()) | ||
| 227 | + .unwrap_or(1) | ||
| 228 | + .max(1) | ||
| 229 | +} | ||
| 230 | + | ||
| 231 | +/// The profile URL for a tab, with the name filter and page when they are set. | ||
| 232 | +fn profile_href(name: &str, tab: &str, q: &str, page: usize) -> String { | ||
| 233 | + let mut href = format!("/{}?tab={tab}", enc(name)); | ||
| 234 | + if !q.is_empty() { | ||
| 235 | + href.push_str("&q="); | ||
| 236 | + href.push_str(&enc(q)); | ||
| 237 | + } | ||
| 238 | + if page > 1 { | ||
| 239 | + href.push_str(&format!("&page={page}")); | ||
| 240 | + } | ||
| 241 | + href | ||
| 242 | +} | ||
| 243 | + | ||
| 244 | +fn tab_class(on: bool) -> &'static str { | ||
| 245 | + if on { "tab active" } else { "tab" } | ||
| 246 | +} | ||
| 247 | + | ||
| 248 | +/// Filters `repos` by name (case-insensitive substring) and returns one page of the matches. | ||
| 249 | +/// A page past the end is clamped to the last page. | ||
| 250 | +fn paginate( | ||
| 251 | + repos: Vec<Repo>, | ||
| 252 | + name: &str, | ||
| 253 | + tab: &str, | ||
| 254 | + q: &str, | ||
| 255 | + page: usize, | ||
| 256 | + empty: &'static str, | ||
| 257 | +) -> Listing { | ||
| 258 | + let needle = q.to_lowercase(); | ||
| 259 | + let matched: Vec<Repo> = repos | ||
| 260 | + .into_iter() | ||
| 261 | + .filter(|repo| needle.is_empty() || repo.name.to_lowercase().contains(&needle)) | ||
| 262 | + .collect(); | ||
| 263 | + let total = matched.len(); | ||
| 264 | + let pages = total.div_ceil(PER_PAGE).max(1); | ||
| 265 | + let page = page.min(pages); | ||
| 266 | + let rows = matched | ||
| 267 | + .into_iter() | ||
| 268 | + .skip((page - 1) * PER_PAGE) | ||
| 269 | + .take(PER_PAGE) | ||
| 270 | + .collect(); | ||
| 271 | + Listing { | ||
| 272 | + rows, | ||
| 273 | + total, | ||
| 274 | + page, | ||
| 275 | + pages, | ||
| 276 | + prev: (page > 1).then(|| profile_href(name, tab, q, page - 1)), | ||
| 277 | + next: (page < pages).then(|| profile_href(name, tab, q, page + 1)), | ||
| 278 | + empty, | ||
| 279 | + } | ||
| 280 | +} | ||
| 281 | + | ||
| 282 | +/// Whether the viewer may read `repo`. Public repos, and repos the viewer owns or administers, | ||
| 283 | +/// need no role lookup. Other private repos get their collaborator and org roles, and `authorize` | ||
| 284 | +/// makes the final call either way. | ||
| 285 | +async fn may_read(state: &AppState, actor: Option<&User>, repo: &Repo) -> Result<bool> { | ||
| 286 | + let open = repo.visibility == Visibility::Public | ||
| 287 | + || actor.is_some_and(|u| u.is_admin || u.id == repo.owner_id); | ||
| 288 | + let (role, org_role) = match actor { | ||
| 289 | + Some(u) if !open => ( | ||
| 290 | + state.store.collaborator_role(&repo.id, &u.id).await?, | ||
| 291 | + state | ||
| 292 | + .store | ||
| 293 | + .org_repo_role(&repo.owner_id, &u.id, &repo.id) | ||
| 294 | + .await?, | ||
| 295 | + ), | ||
| 296 | + _ => (None, None), | ||
| 297 | + }; | ||
| 298 | + Ok(authorize(actor, repo, role, org_role, Action::Read).is_ok()) | ||
| 299 | +} | ||
| 300 | + | ||
| 301 | +/// The first `limit` repos of `repos` that the viewer may read, in their order. | ||
| 302 | +async fn readable( | ||
| 303 | + state: &AppState, | ||
| 304 | + actor: Option<&User>, | ||
| 305 | + repos: Vec<Repo>, | ||
| 306 | + limit: usize, | ||
| 307 | +) -> Result<Vec<Repo>> { | ||
| 308 | + let mut out = Vec::new(); | ||
| 309 | + for repo in repos { | ||
| 310 | + if out.len() >= limit { | ||
| 311 | + break; | ||
| 312 | + } | ||
| 313 | + if may_read(state, actor, &repo).await? { | ||
| 314 | + out.push(repo); | ||
| 315 | + } | ||
| 316 | + } | ||
| 317 | + Ok(out) | ||
| 318 | +} | ||
| 319 | + | ||
| 107 | #[component] | 320 | #[component] |
| 108 | async fn profile_card( | 321 | async fn profile_card( |
| 109 | user: User, | 322 | user: User, |
| 110 | avatar: Option<String>, | 323 | avatar: Option<String>, |
| 111 | about_html: String, | 324 | about_html: String, |
| 112 | local_time: String, | 325 | local_time: String, |
| 113 | - repos: Vec<Repo>, | ||
| 114 | - starred: Vec<Repo>, | ||
| 115 | org: Option<OrgSummary>, | 326 | org: Option<OrgSummary>, |
| 116 | lang: Lang, | 327 | lang: Lang, |
| 328 | + tab: String, | ||
| 329 | + q: String, | ||
| 330 | + repo_total: usize, | ||
| 331 | + star_total: usize, | ||
| 332 | + cards: Vec<PinCard>, | ||
| 333 | + from_pins: bool, | ||
| 334 | + pins_edit_href: Option<String>, | ||
| 335 | + edit_profile: bool, | ||
| 336 | + listing: Listing, | ||
| 117 | ) -> Result<impl View> { | 337 | ) -> Result<impl View> { |
| 118 | let src = avatar_url(&user.username, avatar.as_deref()); | 338 | let src = avatar_url(&user.username, avatar.as_deref()); |
| 119 | let has_about = !about_html.is_empty(); | 339 | let has_about = !about_html.is_empty(); |
| 120 | - let no_repos = repos.is_empty(); | ||
| 121 | - let no_starred = starred.is_empty(); | ||
| 122 | let is_org = user.is_org(); | 340 | let is_org = user.is_org(); |
| 123 | let members_href = format!("/org/{}/members", user.username); | 341 | let members_href = format!("/org/{}/members", user.username); |
| 124 | let teams_href = format!("/org/{}/teams", user.username); | 342 | let teams_href = format!("/org/{}/teams", user.username); |
| 343 | + let base = format!("/{}", enc(&user.username)); | ||
| 344 | + let overview_on = tab == "overview"; | ||
| 345 | + let repos_on = tab == "repositories"; | ||
| 346 | + let stars_on = tab == "stars"; | ||
| 347 | + let list_on = repos_on || stars_on; | ||
| 348 | + let overview_href = profile_href(&user.username, "overview", "", 1); | ||
| 349 | + let repositories_href = profile_href(&user.username, "repositories", "", 1); | ||
| 350 | + let stars_href = profile_href(&user.username, "stars", "", 1); | ||
| 351 | + let repo_count_text = repo_total.to_string(); | ||
| 352 | + let star_count_text = star_total.to_string(); | ||
| 353 | + let pinned_heading = if from_pins { | ||
| 354 | + g::t(lang, K::Pinned) | ||
| 355 | + } else { | ||
| 356 | + g::t(lang, K::PopularRepos) | ||
| 357 | + }; | ||
| 358 | + let has_cards = !cards.is_empty(); | ||
| 359 | + let edit_label = mi::t(lang, MK::EditProfile); | ||
| 360 | + let filter_label = g::t(lang, K::FilterRepos); | ||
| 361 | + let Listing { | ||
| 362 | + rows, | ||
| 363 | + total, | ||
| 364 | + page, | ||
| 365 | + pages, | ||
| 366 | + prev, | ||
| 367 | + next, | ||
| 368 | + empty, | ||
| 369 | + } = listing; | ||
| 370 | + let has_rows = !rows.is_empty(); | ||
| 371 | + let has_pager = pages > 1; | ||
| 372 | + let total_text = g::repo_count(lang, total as u64); | ||
| 373 | + let page_label = g::page_of(lang, page as u64, pages as u64); | ||
| 125 | Ok(view! { | 374 | Ok(view! { |
| 126 | <article class="profile-page"> | 375 | <article class="profile-page"> |
| 127 | <header class="profile-head"> | 376 | <header class="profile-head"> |
| @@ -137,54 +386,80 @@ async fn profile_card( | |||
| 137 | if has_about { | 386 | if has_about { |
| 138 | <section class="profile-about markdown-body">(Unescaped::new_unchecked(about_html))</section> | 387 | <section class="profile-about markdown-body">(Unescaped::new_unchecked(about_html))</section> |
| 139 | } | 388 | } |
| 140 | - if let Some(summary) = org { | 389 | + if edit_profile { |
| 141 | - <section class="profile-org"> | 390 | + <a class="button profile-edit" href="/settings/profile">(edit_label)</a> |
| 142 | - <h2>(g::t(lang, K::Members))</h2> | 391 | + } |
| 143 | - <p class="muted small"> | 392 | + <nav class="profile-tabs" aria-label=(user.username.as_str())> |
| 144 | - (g::members_and_teams(lang, summary.members.len(), summary.teams)) | 393 | + <a class=(tab_class(overview_on)) href=(overview_href.as_str())>(g::t(lang, K::TabOverview))</a> |
| 145 | - " \u{b7} " | 394 | + <a class=(tab_class(repos_on)) href=(repositories_href.as_str())> |
| 146 | - <a href=(members_href.as_str())>(g::t(lang, K::AllMembers))</a> | 395 | + (g::t(lang, K::Repositories)) " " <span class="tab-count">(repo_count_text.as_str())</span> |
| 147 | - " \u{b7} " | 396 | + </a> |
| 148 | - <a href=(teams_href.as_str())>(g::t(lang, K::Teams))</a> | 397 | + <a class=(tab_class(stars_on)) href=(stars_href.as_str())> |
| 149 | - </p> | 398 | + (g::t(lang, K::TabStars)) " " <span class="tab-count">(star_count_text.as_str())</span> |
| 150 | - if summary.members.is_empty() { | 399 | + </a> |
| 151 | - <p class="muted">(g::t(lang, K::NoMembers))</p> | 400 | + </nav> |
| 152 | - } else { | 401 | + if overview_on { |
| 153 | - <ul class="item-list"> | 402 | + <section class="profile-pinned"> |
| 154 | - for name in summary.members.iter() { | 403 | + <div class="profile-section-head"> |
| 155 | - <li><a href=(format!("/{}", name.as_str()))>(name.as_str())</a></li> | 404 | + <h2>(pinned_heading)</h2> |
| 405 | + if let Some(href) = pins_edit_href { | ||
| 406 | + <a class="small" href=(href.as_str())>(g::t(lang, K::CustomizePins))</a> | ||
| 407 | + } | ||
| 408 | + </div> | ||
| 409 | + if has_cards { | ||
| 410 | + <ul class="pin-grid"> | ||
| 411 | + for card in cards.into_iter() { | ||
| 412 | + <li class="pin-card"> | ||
| 413 | + <div class="pin-head"> | ||
| 414 | + <a class="repo-name" href=(repo_href(&card.repo.owner_name, &card.repo.name, "", ""))> | ||
| 415 | + (format!("{}/{}", card.repo.owner_name, card.repo.name)) | ||
| 416 | + </a> | ||
| 417 | + <span class=(badge_class(card.repo.visibility))>(i18n::visibility_label(lang, card.repo.visibility))</span> | ||
| 418 | + </div> | ||
| 419 | + if !card.repo.description.is_empty() { | ||
| 420 | + <p class="muted pin-desc">(card.repo.description.as_str())</p> | ||
| 421 | + } | ||
| 422 | + <p class="muted small">"\u{2605} " (card.stars.to_string())</p> | ||
| 423 | + </li> | ||
| 156 | } | 424 | } |
| 157 | </ul> | 425 | </ul> |
| 426 | + } else { | ||
| 427 | + <p class="muted">(g::t(lang, K::NoVisibleRepos))</p> | ||
| 158 | } | 428 | } |
| 159 | </section> | 429 | </section> |
| 160 | - } | 430 | + if let Some(summary) = org { |
| 161 | - <section class="profile-repos"> | 431 | + <section class="profile-org"> |
| 162 | - <h2>(g::t(lang, K::Repositories))</h2> | 432 | + <h2>(g::t(lang, K::Members))</h2> |
| 163 | - if no_repos { | 433 | + <p class="muted small"> |
| 164 | - <p class="muted">(g::t(lang, K::NoVisibleRepos))</p> | 434 | + (g::members_and_teams(lang, summary.members.len(), summary.teams)) |
| 165 | - } else { | 435 | + " \u{b7} " |
| 166 | - <ul class="repo-list"> | 436 | + <a href=(members_href.as_str())>(g::t(lang, K::AllMembers))</a> |
| 167 | - for repo in repos.into_iter() { | 437 | + " \u{b7} " |
| 168 | - <li class="repo-item"> | 438 | + <a href=(teams_href.as_str())>(g::t(lang, K::Teams))</a> |
| 169 | - <a class="repo-name" href=(repo_href(&repo.owner_name, &repo.name, "", ""))> | 439 | + </p> |
| 170 | - (format!("{}/{}", repo.owner_name, repo.name)) | 440 | + if summary.members.is_empty() { |
| 171 | - </a> | 441 | + <p class="muted">(g::t(lang, K::NoMembers))</p> |
| 172 | - <span class=(badge_class(repo.visibility))>(i18n::visibility_label(lang, repo.visibility))</span> | 442 | + } else { |
| 173 | - if !repo.description.is_empty() { | 443 | + <ul class="item-list"> |
| 174 | - <p class="muted">(repo.description.as_str())</p> | 444 | + for name in summary.members.iter() { |
| 445 | + <li><a href=(format!("/{}", name.as_str()))>(name.as_str())</a></li> | ||
| 175 | } | 446 | } |
| 176 | - </li> | 447 | + </ul> |
| 177 | } | 448 | } |
| 178 | - </ul> | 449 | + </section> |
| 179 | } | 450 | } |
| 180 | - </section> | 451 | + } |
| 181 | - <section class="profile-starred"> | 452 | + if list_on { |
| 182 | - <h2>(g::t(lang, K::Starred))</h2> | 453 | + <form method="get" action=(base.as_str()) class="explore-search" role="search"> |
| 183 | - if no_starred { | 454 | + <input type="hidden" name="tab" value=(tab.as_str())> |
| 184 | - <p class="muted">(g::t(lang, K::NoVisibleStarred))</p> | 455 | + <input type="search" name="q" value=(q.as_str()) |
| 185 | - } else { | 456 | + placeholder=(filter_label) aria-label=(filter_label)> |
| 457 | + <button type="submit">(g::t(lang, K::Search))</button> | ||
| 458 | + </form> | ||
| 459 | + <p class="muted small">(total_text.as_str())</p> | ||
| 460 | + if has_rows { | ||
| 186 | <ul class="repo-list"> | 461 | <ul class="repo-list"> |
| 187 | - for repo in starred.into_iter() { | 462 | + for repo in rows.into_iter() { |
| 188 | <li class="repo-item"> | 463 | <li class="repo-item"> |
| 189 | <a class="repo-name" href=(repo_href(&repo.owner_name, &repo.name, "", ""))> | 464 | <a class="repo-name" href=(repo_href(&repo.owner_name, &repo.name, "", ""))> |
| 190 | (format!("{}/{}", repo.owner_name, repo.name)) | 465 | (format!("{}/{}", repo.owner_name, repo.name)) |
| @@ -196,8 +471,21 @@ async fn profile_card( | |||
| 196 | </li> | 471 | </li> |
| 197 | } | 472 | } |
| 198 | </ul> | 473 | </ul> |
| 474 | + } else { | ||
| 475 | + <p class="muted">(empty)</p> | ||
| 476 | + } | ||
| 477 | + if has_pager { | ||
| 478 | + <nav class="pager" aria-label=(g::t(lang, K::Pages))> | ||
| 479 | + if let Some(href) = prev { | ||
| 480 | + <a href=(href.as_str())>(g::t(lang, K::Previous))</a> | ||
| 481 | + } | ||
| 482 | + <span class="muted small">(page_label.as_str())</span> | ||
| 483 | + if let Some(href) = next { | ||
| 484 | + <a href=(href.as_str())>(g::t(lang, K::Next))</a> | ||
| 485 | + } | ||
| 486 | + </nav> | ||
| 199 | } | 487 | } |
| 200 | - </section> | 488 | + } |
| 201 | </article> | 489 | </article> |
| 202 | }) | 490 | }) |
| 203 | } | 491 | } |
| @@ -326,7 +614,12 @@ mod tests { | |||
| 326 | #[tokio::test] | 614 | #[tokio::test] |
| 327 | async fn owner_sees_private_and_collaborator_sees_their_repo() { | 615 | async fn owner_sees_private_and_collaborator_sees_their_repo() { |
| 328 | let site = seeded().await; | 616 | let site = seeded().await; |
| 329 | - let tahinli = site.store.user_by_username("tahinli").await.unwrap().unwrap(); | 617 | + let tahinli = site |
| 618 | + .store | ||
| 619 | + .user_by_username("tahinli") | ||
| 620 | + .await | ||
| 621 | + .unwrap() | ||
| 622 | + .unwrap(); | ||
| 330 | let cookie = sign_in(&site.store, &tahinli.id, "tahinli-token").await; | 623 | let cookie = sign_in(&site.store, &tahinli.id, "tahinli-token").await; |
| 331 | let (_, body) = get(&site.router, "/tahinli", Some(&cookie)).await; | 624 | let (_, body) = get(&site.router, "/tahinli", Some(&cookie)).await; |
| 332 | assert!(body.contains("tahinli/secret-repo")); | 625 | assert!(body.contains("tahinli/secret-repo")); |
| @@ -379,4 +672,188 @@ mod tests { | |||
| 379 | assert_eq!(status, 404); | 672 | assert_eq!(status, 404); |
| 380 | assert!(!body.contains("<article class=\"profile-page\"")); | 673 | assert!(!body.contains("<article class=\"profile-page\"")); |
| 381 | } | 674 | } |
| 675 | + | ||
| 676 | + fn count(body: &str, needle: &str) -> usize { | ||
| 677 | + body.matches(needle).count() | ||
| 678 | + } | ||
| 679 | + | ||
| 680 | + /// A user with 35 public repos, `bulk-00` to `bulk-34`. | ||
| 681 | + async fn bulk_site() -> Site { | ||
| 682 | + let site = site().await; | ||
| 683 | + let mira = site | ||
| 684 | + .store | ||
| 685 | + .create_user("mira", None, "not-a-real-hash", false) | ||
| 686 | + .await | ||
| 687 | + .unwrap(); | ||
| 688 | + for i in 0..35 { | ||
| 689 | + site.store | ||
| 690 | + .create_repo( | ||
| 691 | + &mira.id, | ||
| 692 | + &format!("bulk-{i:02}"), | ||
| 693 | + "", | ||
| 694 | + Visibility::Public, | ||
| 695 | + "main", | ||
| 696 | + ) | ||
| 697 | + .await | ||
| 698 | + .unwrap(); | ||
| 699 | + } | ||
| 700 | + site | ||
| 701 | + } | ||
| 702 | + | ||
| 703 | + async fn user_id(store: &Store, name: &str) -> String { | ||
| 704 | + store.user_by_username(name).await.unwrap().unwrap().id | ||
| 705 | + } | ||
| 706 | + | ||
| 707 | + #[tokio::test] | ||
| 708 | + async fn repositories_tab_pages_thirty_at_a_time() { | ||
| 709 | + let site = bulk_site().await; | ||
| 710 | + let (status, first) = get(&site.router, "/mira?tab=repositories", None).await; | ||
| 711 | + assert_eq!(status, 200); | ||
| 712 | + assert_eq!(count(&first, "class=\"repo-name\""), 30); | ||
| 713 | + assert!(first.contains("page=2"), "next link: {first}"); | ||
| 714 | + | ||
| 715 | + let (_, second) = get(&site.router, "/mira?tab=repositories&page=2", None).await; | ||
| 716 | + assert_eq!(count(&second, "class=\"repo-name\""), 5); | ||
| 717 | + assert!(second.contains("mira/bulk-34")); | ||
| 718 | + assert!(!second.contains("mira/bulk-00")); | ||
| 719 | + } | ||
| 720 | + | ||
| 721 | + #[tokio::test] | ||
| 722 | + async fn name_filter_is_a_case_insensitive_substring() { | ||
| 723 | + let site = bulk_site().await; | ||
| 724 | + let (_, body) = get(&site.router, "/mira?tab=repositories&q=BULK-1", None).await; | ||
| 725 | + assert_eq!(count(&body, "class=\"repo-name\""), 10); | ||
| 726 | + assert!(body.contains("mira/bulk-12")); | ||
| 727 | + assert!(!body.contains("mira/bulk-22")); | ||
| 728 | + } | ||
| 729 | + | ||
| 730 | + #[tokio::test] | ||
| 731 | + async fn stars_tab_lists_only_starred_repos_the_viewer_may_read() { | ||
| 732 | + let site = seeded().await; | ||
| 733 | + let mira = site | ||
| 734 | + .store | ||
| 735 | + .create_user("mira", None, "not-a-real-hash", false) | ||
| 736 | + .await | ||
| 737 | + .unwrap(); | ||
| 738 | + let open = site | ||
| 739 | + .store | ||
| 740 | + .list_repos_by_owner(&user_id(&site.store, "tahinli").await) | ||
| 741 | + .await | ||
| 742 | + .unwrap(); | ||
| 743 | + for repo in &open { | ||
| 744 | + if repo.name == "open-repo" || repo.name == "secret-repo" { | ||
| 745 | + site.store.star(&mira.id, &repo.id).await.unwrap(); | ||
| 746 | + } | ||
| 747 | + } | ||
| 748 | + let (_, anon) = get(&site.router, "/mira?tab=stars", None).await; | ||
| 749 | + assert!(anon.contains("tahinli/open-repo")); | ||
| 750 | + assert!(!anon.contains("tahinli/secret-repo")); | ||
| 751 | + } | ||
| 752 | + | ||
| 753 | + #[tokio::test] | ||
| 754 | + async fn pins_show_on_the_overview_and_private_ones_only_to_the_owner() { | ||
| 755 | + let site = seeded().await; | ||
| 756 | + let tahinli = user_id(&site.store, "tahinli").await; | ||
| 757 | + let repos = site.store.list_repos_by_owner(&tahinli).await.unwrap(); | ||
| 758 | + let open = repos | ||
| 759 | + .iter() | ||
| 760 | + .find(|r| r.name == "open-repo") | ||
| 761 | + .unwrap() | ||
| 762 | + .id | ||
| 763 | + .clone(); | ||
| 764 | + let secret = repos | ||
| 765 | + .iter() | ||
| 766 | + .find(|r| r.name == "secret-repo") | ||
| 767 | + .unwrap() | ||
| 768 | + .id | ||
| 769 | + .clone(); | ||
| 770 | + site.store | ||
| 771 | + .set_profile_pins(&tahinli, &[open, secret]) | ||
| 772 | + .await | ||
| 773 | + .unwrap(); | ||
| 774 | + | ||
| 775 | + let (_, anon) = get(&site.router, "/tahinli", None).await; | ||
| 776 | + assert!(anon.contains("<h2>Pinned</h2>")); | ||
| 777 | + assert_eq!(count(&anon, "class=\"pin-card\""), 1); | ||
| 778 | + assert!(anon.contains("tahinli/open-repo")); | ||
| 779 | + assert!(!anon.contains("tahinli/secret-repo")); | ||
| 780 | + assert!(!anon.contains("Customize pins")); | ||
| 781 | + | ||
| 782 | + let cookie = sign_in(&site.store, &tahinli, "tahinli-token").await; | ||
| 783 | + let (_, owner) = get(&site.router, "/tahinli", Some(&cookie)).await; | ||
| 784 | + assert_eq!(count(&owner, "class=\"pin-card\""), 2); | ||
| 785 | + assert!(owner.contains("tahinli/secret-repo")); | ||
| 786 | + assert!(owner.contains("Customize pins")); | ||
| 787 | + assert!(owner.contains("href=\"/settings/pins\"")); | ||
| 788 | + } | ||
| 789 | + | ||
| 790 | + #[tokio::test] | ||
| 791 | + async fn overview_falls_back_to_popular_repos_when_no_pin_is_visible() { | ||
| 792 | + let site = seeded().await; | ||
| 793 | + let tahinli = user_id(&site.store, "tahinli").await; | ||
| 794 | + let secret = site | ||
| 795 | + .store | ||
| 796 | + .list_repos_by_owner(&tahinli) | ||
| 797 | + .await | ||
| 798 | + .unwrap() | ||
| 799 | + .into_iter() | ||
| 800 | + .find(|r| r.name == "secret-repo") | ||
| 801 | + .unwrap() | ||
| 802 | + .id; | ||
| 803 | + site.store | ||
| 804 | + .set_profile_pins(&tahinli, &[secret]) | ||
| 805 | + .await | ||
| 806 | + .unwrap(); | ||
| 807 | + | ||
| 808 | + let (_, anon) = get(&site.router, "/tahinli", None).await; | ||
| 809 | + assert!(anon.contains("Popular repositories")); | ||
| 810 | + assert!(anon.contains("tahinli/open-repo")); | ||
| 811 | + assert!(!anon.contains("tahinli/secret-repo")); | ||
| 812 | + } | ||
| 813 | + | ||
| 814 | + #[tokio::test] | ||
| 815 | + async fn only_the_owner_sees_the_edit_profile_button() { | ||
| 816 | + let site = seeded().await; | ||
| 817 | + let tahinli = user_id(&site.store, "tahinli").await; | ||
| 818 | + let cookie = sign_in(&site.store, &tahinli, "tahinli-token").await; | ||
| 819 | + let (_, owner) = get(&site.router, "/tahinli", Some(&cookie)).await; | ||
| 820 | + assert!(owner.contains("class=\"button profile-edit\" href=\"/settings/profile\"")); | ||
| 821 | + | ||
| 822 | + let (_, anon) = get(&site.router, "/tahinli", None).await; | ||
| 823 | + assert!(!anon.contains("profile-edit")); | ||
| 824 | + | ||
| 825 | + let bob = site | ||
| 826 | + .store | ||
| 827 | + .create_user("bob", None, "not-a-real-hash", false) | ||
| 828 | + .await | ||
| 829 | + .unwrap(); | ||
| 830 | + let cookie = sign_in(&site.store, &bob.id, "bob-token").await; | ||
| 831 | + let (_, other) = get(&site.router, "/tahinli", Some(&cookie)).await; | ||
| 832 | + assert!(!other.contains("profile-edit")); | ||
| 833 | + } | ||
| 834 | + | ||
| 835 | + #[tokio::test] | ||
| 836 | + async fn org_pins_show_on_the_org_profile_with_an_edit_link_for_owners() { | ||
| 837 | + let site = seeded().await; | ||
| 838 | + let tahinli = user_id(&site.store, "tahinli").await; | ||
| 839 | + let acme = site.store.create_org("acme", &tahinli).await.unwrap(); | ||
| 840 | + let lib = site | ||
| 841 | + .store | ||
| 842 | + .create_repo(&acme.id, "lib", "", Visibility::Public, "main") | ||
| 843 | + .await | ||
| 844 | + .unwrap(); | ||
| 845 | + site.store | ||
| 846 | + .set_profile_pins(&acme.id, &[lib.id]) | ||
| 847 | + .await | ||
| 848 | + .unwrap(); | ||
| 849 | + | ||
| 850 | + let cookie = sign_in(&site.store, &tahinli, "tahinli-token").await; | ||
| 851 | + let (_, owner) = get(&site.router, "/acme", Some(&cookie)).await; | ||
| 852 | + assert!(owner.contains("acme/lib")); | ||
| 853 | + assert!(owner.contains("href=\"/org/acme/settings/pins\"")); | ||
| 854 | + | ||
| 855 | + let (_, anon) = get(&site.router, "/acme", None).await; | ||
| 856 | + assert!(anon.contains("acme/lib")); | ||
| 857 | + assert!(!anon.contains("Customize pins")); | ||
| 858 | + } | ||
| 382 | } | 859 | } |
crates/forge-web/src/pages/profile_pins.rsadded+471 -0
| @@ -0,0 +1,471 @@ | |||
| 1 | +//! Pages: where a profile's owner picks the repos pinned on it, at most six. `/settings/pins` is for | ||
| 2 | +//! the signed-in user. `/org/{org}/settings/pins` is for an organization, and only its owners may | ||
| 3 | +//! use it. Both show a form of checkboxes, one per repo the owner has, and redirect to the profile | ||
| 4 | +//! after a save. | ||
| 5 | + | ||
| 6 | +use forge_core::store::profile_pins::MAX_PROFILE_PINS; | ||
| 7 | +use forge_core::{Repo, Session, User}; | ||
| 8 | +use topcoat::Result; | ||
| 9 | +use topcoat::context::{Cx, app_context}; | ||
| 10 | +use topcoat::router::content::RawForm; | ||
| 11 | +use topcoat::router::error::see_other; | ||
| 12 | +use topcoat::router::{page, path_param}; | ||
| 13 | +use topcoat::view::{View, component, view}; | ||
| 14 | + | ||
| 15 | +use crate::auth::{require_csrf, require_user}; | ||
| 16 | +use crate::i18n::orgs::{self as g, K}; | ||
| 17 | +use crate::i18n::{self, Lang}; | ||
| 18 | +use crate::pages::issue_meta::{form_all, form_field, form_pairs}; | ||
| 19 | +use crate::pages::org_ctx::{load_org, require_form_csrf, require_owner}; | ||
| 20 | +use crate::state::AppState; | ||
| 21 | +use crate::views::shell; | ||
| 22 | + | ||
| 23 | +path_param!(org); | ||
| 24 | + | ||
| 25 | +/// A repo the owner may pin, and whether it is pinned now. | ||
| 26 | +struct PinOption { | ||
| 27 | + repo: Repo, | ||
| 28 | + checked: bool, | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +/// The repo ids pinned, in order. | ||
| 32 | +fn ids(repos: Vec<Repo>) -> Vec<String> { | ||
| 33 | + repos.into_iter().map(|repo| repo.id).collect() | ||
| 34 | +} | ||
| 35 | + | ||
| 36 | +/// The repo ids a form chose: blanks and repeats are dropped, the order is kept. | ||
| 37 | +fn selection(raw: Vec<String>) -> Vec<String> { | ||
| 38 | + let mut out: Vec<String> = Vec::new(); | ||
| 39 | + for id in raw { | ||
| 40 | + if !id.is_empty() && !out.contains(&id) { | ||
| 41 | + out.push(id); | ||
| 42 | + } | ||
| 43 | + } | ||
| 44 | + out | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +/// The pin form for `owner`, with the `chosen` repos ticked. `error` is shown above the form. | ||
| 48 | +/// The values are owned so the returned view borrows nothing from the caller. | ||
| 49 | +async fn pins_form( | ||
| 50 | + cx: &Cx, | ||
| 51 | + viewer: (User, Session), | ||
| 52 | + owner: User, | ||
| 53 | + action: String, | ||
| 54 | + chosen: Vec<String>, | ||
| 55 | + error: Option<&'static str>, | ||
| 56 | +) -> Result<impl View> { | ||
| 57 | + let state = app_context::<AppState>(cx); | ||
| 58 | + let lang = i18n::lang(cx, Some(&viewer.0)); | ||
| 59 | + let options: Vec<PinOption> = state | ||
| 60 | + .store | ||
| 61 | + .list_repos_by_owner(&owner.id) | ||
| 62 | + .await? | ||
| 63 | + .into_iter() | ||
| 64 | + .map(|repo| { | ||
| 65 | + let checked = chosen.contains(&repo.id); | ||
| 66 | + PinOption { repo, checked } | ||
| 67 | + }) | ||
| 68 | + .collect(); | ||
| 69 | + let csrf = viewer.1.csrf_token.clone(); | ||
| 70 | + let title = g::t(lang, K::CustomizePins); | ||
| 71 | + let error = error.map(str::to_owned); | ||
| 72 | + Ok(view! { cx => | ||
| 73 | + shell(title: title, viewer: Some(&viewer), | ||
| 74 | + pins_body(lang: lang, action: action, csrf: csrf, options: options, error: error)) | ||
| 75 | + }) | ||
| 76 | +} | ||
| 77 | + | ||
| 78 | +#[component] | ||
| 79 | +async fn pins_body( | ||
| 80 | + lang: Lang, | ||
| 81 | + action: String, | ||
| 82 | + csrf: String, | ||
| 83 | + options: Vec<PinOption>, | ||
| 84 | + error: Option<String>, | ||
| 85 | +) -> Result<impl View> { | ||
| 86 | + let has_options = !options.is_empty(); | ||
| 87 | + let intro = g::t(lang, K::PinsIntro); | ||
| 88 | + let empty = g::t(lang, K::NoPinnableRepos); | ||
| 89 | + let save = g::t(lang, K::SavePins); | ||
| 90 | + Ok(view! { | ||
| 91 | + <section class="profile-pins-edit"> | ||
| 92 | + <h1>(g::t(lang, K::CustomizePins))</h1> | ||
| 93 | + <p class="muted">(intro)</p> | ||
| 94 | + if let Some(message) = error { | ||
| 95 | + <p class="alert" role="alert">(message.as_str())</p> | ||
| 96 | + } | ||
| 97 | + if has_options { | ||
| 98 | + <form method="post" action=(action.as_str()) class="stack"> | ||
| 99 | + <input type="hidden" name="csrf" value=(csrf.as_str())> | ||
| 100 | + <ul class="pin-options"> | ||
| 101 | + for option in options.into_iter() { | ||
| 102 | + <li> | ||
| 103 | + <label> | ||
| 104 | + <input type="checkbox" name="repo" value=(option.repo.id.as_str()) checked=(option.checked)> | ||
| 105 | + (format!("{}/{}", option.repo.owner_name, option.repo.name)) | ||
| 106 | + </label> | ||
| 107 | + </li> | ||
| 108 | + } | ||
| 109 | + </ul> | ||
| 110 | + <div> | ||
| 111 | + <button type="submit" class="primary">(save)</button> | ||
| 112 | + </div> | ||
| 113 | + </form> | ||
| 114 | + } else { | ||
| 115 | + <p class="muted">(empty)</p> | ||
| 116 | + } | ||
| 117 | + </section> | ||
| 118 | + }) | ||
| 119 | +} | ||
| 120 | + | ||
| 121 | +/// Stores the chosen pins for `owner` and redirects to `back`. More than the limit re-shows the | ||
| 122 | +/// form with the error and changes nothing. | ||
| 123 | +async fn save_pins( | ||
| 124 | + cx: &Cx, | ||
| 125 | + viewer: (User, Session), | ||
| 126 | + owner: User, | ||
| 127 | + action: String, | ||
| 128 | + chosen: Vec<String>, | ||
| 129 | + back: String, | ||
| 130 | +) -> Result<impl View> { | ||
| 131 | + if chosen.len() > MAX_PROFILE_PINS { | ||
| 132 | + let lang = i18n::lang(cx, Some(&viewer.0)); | ||
| 133 | + let error = g::t(lang, K::PinsTooMany); | ||
| 134 | + return pins_form(cx, viewer, owner, action, chosen, Some(error)).await; | ||
| 135 | + } | ||
| 136 | + app_context::<AppState>(cx) | ||
| 137 | + .store | ||
| 138 | + .set_profile_pins(&owner.id, &chosen) | ||
| 139 | + .await?; | ||
| 140 | + Err(see_other(back).into()) | ||
| 141 | +} | ||
| 142 | + | ||
| 143 | +/// Gets the pin form for the signed-in user's own profile. | ||
| 144 | +#[page("/settings/pins")] | ||
| 145 | +async fn pins_page(cx: &Cx) -> Result<impl View> { | ||
| 146 | + let viewer = require_user(cx).await?; | ||
| 147 | + let store = &app_context::<AppState>(cx).store; | ||
| 148 | + let chosen = ids(store.profile_pins(&viewer.0.id).await?); | ||
| 149 | + let owner = viewer.0.clone(); | ||
| 150 | + pins_form(cx, viewer, owner, "/settings/pins".to_owned(), chosen, None).await | ||
| 151 | +} | ||
| 152 | + | ||
| 153 | +/// Saves the signed-in user's pins, then back to the profile. | ||
| 154 | +#[page(POST "/settings/pins")] | ||
| 155 | +async fn pins_save(cx: &Cx, RawForm(raw): RawForm) -> Result<impl View> { | ||
| 156 | + let pairs = form_pairs(&raw[..]); | ||
| 157 | + let viewer = require_csrf(cx, &form_field(&pairs, "csrf")).await?; | ||
| 158 | + let chosen = selection(form_all(&pairs, "repo")); | ||
| 159 | + let back = format!("/{}", viewer.0.username); | ||
| 160 | + let owner = viewer.0.clone(); | ||
| 161 | + save_pins(cx, viewer, owner, "/settings/pins".to_owned(), chosen, back).await | ||
| 162 | +} | ||
| 163 | + | ||
| 164 | +/// Gets the pin form for an organization. Owners only. | ||
| 165 | +#[page("/org/{org}/settings/pins")] | ||
| 166 | +async fn org_pins_page(cx: &Cx) -> Result<impl View> { | ||
| 167 | + let ctx = load_org(cx, path_param::<Org>(cx)).await?; | ||
| 168 | + require_owner(&ctx)?; | ||
| 169 | + let store = &app_context::<AppState>(cx).store; | ||
| 170 | + let chosen = ids(store.profile_pins(&ctx.org.id).await?); | ||
| 171 | + let action = ctx.href("/settings/pins"); | ||
| 172 | + pins_form(cx, ctx.viewer, ctx.org, action, chosen, None).await | ||
| 173 | +} | ||
| 174 | + | ||
| 175 | +/// Saves an organization's pins, then back to the org profile. Owners only. | ||
| 176 | +#[page(POST "/org/{org}/settings/pins")] | ||
| 177 | +async fn org_pins_save(cx: &Cx, RawForm(raw): RawForm) -> Result<impl View> { | ||
| 178 | + let ctx = load_org(cx, path_param::<Org>(cx)).await?; | ||
| 179 | + let pairs = form_pairs(&raw[..]); | ||
| 180 | + require_form_csrf(&ctx, &form_field(&pairs, "csrf"))?; | ||
| 181 | + require_owner(&ctx)?; | ||
| 182 | + let chosen = selection(form_all(&pairs, "repo")); | ||
| 183 | + let action = ctx.href("/settings/pins"); | ||
| 184 | + let back = format!("/{}", ctx.org.username); | ||
| 185 | + save_pins(cx, ctx.viewer, ctx.org, action, chosen, back).await | ||
| 186 | +} | ||
| 187 | + | ||
| 188 | +#[cfg(test)] | ||
| 189 | +mod tests { | ||
| 190 | + use forge_core::{Store, Visibility}; | ||
| 191 | + use topcoat::router::request::Request; | ||
| 192 | + use topcoat::router::{Body, Router, to_bytes}; | ||
| 193 | + | ||
| 194 | + use crate::auth::SESSION_COOKIE; | ||
| 195 | + | ||
| 196 | + const CSRF: &str = "pins-test-csrf"; | ||
| 197 | + | ||
| 198 | + struct Site { | ||
| 199 | + router: Router, | ||
| 200 | + store: Store, | ||
| 201 | + _dir: tempfile::TempDir, | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + struct Reply { | ||
| 205 | + status: u16, | ||
| 206 | + location: Option<String>, | ||
| 207 | + body: String, | ||
| 208 | + } | ||
| 209 | + | ||
| 210 | + async fn site() -> Site { | ||
| 211 | + let dir = tempfile::tempdir().expect("tempdir"); | ||
| 212 | + let state = crate::test_support::test_state(dir.path()).await; | ||
| 213 | + let store = state.store.clone(); | ||
| 214 | + let router = crate::test_support::app_router(state); | ||
| 215 | + Site { | ||
| 216 | + router, | ||
| 217 | + store, | ||
| 218 | + _dir: dir, | ||
| 219 | + } | ||
| 220 | + } | ||
| 221 | + | ||
| 222 | + async fn sign_in(store: &Store, user_id: &str, token: &str) -> String { | ||
| 223 | + crate::test_support::create_session(store, user_id, token, CSRF).await; | ||
| 224 | + format!("__Host-{SESSION_COOKIE}={token}") | ||
| 225 | + } | ||
| 226 | + | ||
| 227 | + async fn send( | ||
| 228 | + site: &Site, | ||
| 229 | + method: &str, | ||
| 230 | + uri: &str, | ||
| 231 | + cookie: Option<&str>, | ||
| 232 | + fields: &[(&str, &str)], | ||
| 233 | + ) -> Reply { | ||
| 234 | + let mut builder = Request::builder().method(method).uri(uri); | ||
| 235 | + if let Some(cookie) = cookie { | ||
| 236 | + builder = builder.header("cookie", cookie); | ||
| 237 | + } | ||
| 238 | + let body = form_urlencoded::Serializer::new(String::new()) | ||
| 239 | + .extend_pairs(fields) | ||
| 240 | + .finish(); | ||
| 241 | + builder = builder.header("content-type", "application/x-www-form-urlencoded"); | ||
| 242 | + let res = site | ||
| 243 | + .router | ||
| 244 | + .handle(builder.body(Body::from(body)).expect("request")) | ||
| 245 | + .await; | ||
| 246 | + let status = res.status().as_u16(); | ||
| 247 | + let location = res | ||
| 248 | + .headers() | ||
| 249 | + .get("location") | ||
| 250 | + .and_then(|v| v.to_str().ok()) | ||
| 251 | + .map(str::to_owned); | ||
| 252 | + let bytes = to_bytes(res.into_body(), usize::MAX).await.expect("body"); | ||
| 253 | + Reply { | ||
| 254 | + status, | ||
| 255 | + location, | ||
| 256 | + body: String::from_utf8_lossy(&bytes).into_owned(), | ||
| 257 | + } | ||
| 258 | + } | ||
| 259 | + | ||
| 260 | + /// `tahinli` owns `open-repo`, `secret-repo` and five more; `carol` owns `carols-repo`. | ||
| 261 | + struct Seed { | ||
| 262 | + site: Site, | ||
| 263 | + tahinli: String, | ||
| 264 | + open: String, | ||
| 265 | + secret: String, | ||
| 266 | + carols: String, | ||
| 267 | + } | ||
| 268 | + | ||
| 269 | + async fn seeded() -> Seed { | ||
| 270 | + let site = site().await; | ||
| 271 | + let tahinli = site | ||
| 272 | + .store | ||
| 273 | + .create_user("tahinli", None, "not-a-real-hash", false) | ||
| 274 | + .await | ||
| 275 | + .unwrap(); | ||
| 276 | + let carol = site | ||
| 277 | + .store | ||
| 278 | + .create_user("carol", None, "not-a-real-hash", false) | ||
| 279 | + .await | ||
| 280 | + .unwrap(); | ||
| 281 | + let open = site | ||
| 282 | + .store | ||
| 283 | + .create_repo(&tahinli.id, "open-repo", "", Visibility::Public, "main") | ||
| 284 | + .await | ||
| 285 | + .unwrap(); | ||
| 286 | + let secret = site | ||
| 287 | + .store | ||
| 288 | + .create_repo(&tahinli.id, "secret-repo", "", Visibility::Private, "main") | ||
| 289 | + .await | ||
| 290 | + .unwrap(); | ||
| 291 | + for name in ["one", "two", "three", "four", "five"] { | ||
| 292 | + site.store | ||
| 293 | + .create_repo(&tahinli.id, name, "", Visibility::Public, "main") | ||
| 294 | + .await | ||
| 295 | + .unwrap(); | ||
| 296 | + } | ||
| 297 | + let carols = site | ||
| 298 | + .store | ||
| 299 | + .create_repo(&carol.id, "carols-repo", "", Visibility::Public, "main") | ||
| 300 | + .await | ||
| 301 | + .unwrap(); | ||
| 302 | + Seed { | ||
| 303 | + site, | ||
| 304 | + tahinli: tahinli.id, | ||
| 305 | + open: open.id, | ||
| 306 | + secret: secret.id, | ||
| 307 | + carols: carols.id, | ||
| 308 | + } | ||
| 309 | + } | ||
| 310 | + | ||
| 311 | + async fn pinned_names(store: &Store, owner_id: &str) -> Vec<String> { | ||
| 312 | + store | ||
| 313 | + .profile_pins(owner_id) | ||
| 314 | + .await | ||
| 315 | + .unwrap() | ||
| 316 | + .into_iter() | ||
| 317 | + .map(|r| r.name) | ||
| 318 | + .collect() | ||
| 319 | + } | ||
| 320 | + | ||
| 321 | + #[tokio::test] | ||
| 322 | + async fn owner_saves_pins_and_is_sent_back_to_the_profile() { | ||
| 323 | + let s = seeded().await; | ||
| 324 | + let cookie = sign_in(&s.site.store, &s.tahinli, "tahinli-token").await; | ||
| 325 | + let reply = send( | ||
| 326 | + &s.site, | ||
| 327 | + "POST", | ||
| 328 | + "/settings/pins", | ||
| 329 | + Some(&cookie), | ||
| 330 | + &[("csrf", CSRF), ("repo", &s.secret), ("repo", &s.open)], | ||
| 331 | + ) | ||
| 332 | + .await; | ||
| 333 | + assert_eq!(reply.status, 303); | ||
| 334 | + assert_eq!(reply.location.as_deref(), Some("/tahinli")); | ||
| 335 | + assert_eq!( | ||
| 336 | + pinned_names(&s.site.store, &s.tahinli).await, | ||
| 337 | + ["secret-repo", "open-repo"] | ||
| 338 | + ); | ||
| 339 | + | ||
| 340 | + let form = send(&s.site, "GET", "/settings/pins", Some(&cookie), &[]).await; | ||
| 341 | + assert_eq!(form.status, 200); | ||
| 342 | + assert!(form.body.contains("checked"), "pinned repos are ticked"); | ||
| 343 | + assert!(form.body.contains("tahinli/open-repo")); | ||
| 344 | + } | ||
| 345 | + | ||
| 346 | + #[tokio::test] | ||
| 347 | + async fn more_than_six_pins_shows_the_error_and_keeps_the_old_pins() { | ||
| 348 | + let s = seeded().await; | ||
| 349 | + let cookie = sign_in(&s.site.store, &s.tahinli, "tahinli-token").await; | ||
| 350 | + let repos = s.site.store.list_repos_by_owner(&s.tahinli).await.unwrap(); | ||
| 351 | + assert!(repos.len() >= 7, "seed has enough repos"); | ||
| 352 | + let ids: Vec<String> = repos.iter().map(|r| r.id.clone()).collect(); | ||
| 353 | + let mut fields: Vec<(&str, &str)> = vec![("csrf", CSRF)]; | ||
| 354 | + fields.extend(ids.iter().map(|id| ("repo", id.as_str()))); | ||
| 355 | + | ||
| 356 | + let reply = send(&s.site, "POST", "/settings/pins", Some(&cookie), &fields).await; | ||
| 357 | + assert_eq!(reply.status, 200, "the form is shown again, not redirected"); | ||
| 358 | + assert!( | ||
| 359 | + reply.body.contains("at most six"), | ||
| 360 | + "friendly error: {}", | ||
| 361 | + reply.body | ||
| 362 | + ); | ||
| 363 | + assert!(pinned_names(&s.site.store, &s.tahinli).await.is_empty()); | ||
| 364 | + } | ||
| 365 | + | ||
| 366 | + #[tokio::test] | ||
| 367 | + async fn a_missing_csrf_token_is_refused() { | ||
| 368 | + let s = seeded().await; | ||
| 369 | + let cookie = sign_in(&s.site.store, &s.tahinli, "tahinli-token").await; | ||
| 370 | + let reply = send( | ||
| 371 | + &s.site, | ||
| 372 | + "POST", | ||
| 373 | + "/settings/pins", | ||
| 374 | + Some(&cookie), | ||
| 375 | + &[("csrf", "wrong"), ("repo", &s.open)], | ||
| 376 | + ) | ||
| 377 | + .await; | ||
| 378 | + assert_eq!(reply.status, 403); | ||
| 379 | + assert!(pinned_names(&s.site.store, &s.tahinli).await.is_empty()); | ||
| 380 | + } | ||
| 381 | + | ||
| 382 | + #[tokio::test] | ||
| 383 | + async fn another_users_repo_cannot_be_pinned() { | ||
| 384 | + let s = seeded().await; | ||
| 385 | + let cookie = sign_in(&s.site.store, &s.tahinli, "tahinli-token").await; | ||
| 386 | + let reply = send( | ||
| 387 | + &s.site, | ||
| 388 | + "POST", | ||
| 389 | + "/settings/pins", | ||
| 390 | + Some(&cookie), | ||
| 391 | + &[("csrf", CSRF), ("repo", &s.open), ("repo", &s.carols)], | ||
| 392 | + ) | ||
| 393 | + .await; | ||
| 394 | + assert_ne!(reply.status, 303, "a foreign repo is refused"); | ||
| 395 | + assert!(pinned_names(&s.site.store, &s.tahinli).await.is_empty()); | ||
| 396 | + } | ||
| 397 | + | ||
| 398 | + #[tokio::test] | ||
| 399 | + async fn only_the_signed_in_user_edits_their_own_pins() { | ||
| 400 | + let s = seeded().await; | ||
| 401 | + let carol = s | ||
| 402 | + .site | ||
| 403 | + .store | ||
| 404 | + .user_by_username("carol") | ||
| 405 | + .await | ||
| 406 | + .unwrap() | ||
| 407 | + .unwrap(); | ||
| 408 | + let cookie = sign_in(&s.site.store, &carol.id, "carol-token").await; | ||
| 409 | + // Carol's form lists her own repos; she cannot reach tahinli's pins through it. | ||
| 410 | + let reply = send( | ||
| 411 | + &s.site, | ||
| 412 | + "POST", | ||
| 413 | + "/settings/pins", | ||
| 414 | + Some(&cookie), | ||
| 415 | + &[("csrf", CSRF), ("repo", &s.open)], | ||
| 416 | + ) | ||
| 417 | + .await; | ||
| 418 | + assert_ne!(reply.status, 303); | ||
| 419 | + assert!(pinned_names(&s.site.store, &s.tahinli).await.is_empty()); | ||
| 420 | + let anon = send(&s.site, "POST", "/settings/pins", None, &[("csrf", CSRF)]).await; | ||
| 421 | + assert_eq!(anon.status, 303, "anonymous visitors are sent to log in"); | ||
| 422 | + assert!(anon.location.unwrap_or_default().starts_with("/login")); | ||
| 423 | + } | ||
| 424 | + | ||
| 425 | + #[tokio::test] | ||
| 426 | + async fn org_owner_pins_org_repos_and_others_are_refused() { | ||
| 427 | + let s = seeded().await; | ||
| 428 | + let acme = s.site.store.create_org("acme", &s.tahinli).await.unwrap(); | ||
| 429 | + let lib = s | ||
| 430 | + .site | ||
| 431 | + .store | ||
| 432 | + .create_repo(&acme.id, "lib", "", Visibility::Public, "main") | ||
| 433 | + .await | ||
| 434 | + .unwrap(); | ||
| 435 | + let owner = sign_in(&s.site.store, &s.tahinli, "tahinli-token").await; | ||
| 436 | + let reply = send( | ||
| 437 | + &s.site, | ||
| 438 | + "POST", | ||
| 439 | + "/org/acme/settings/pins", | ||
| 440 | + Some(&owner), | ||
| 441 | + &[("csrf", CSRF), ("repo", &lib.id)], | ||
| 442 | + ) | ||
| 443 | + .await; | ||
| 444 | + assert_eq!(reply.status, 303); | ||
| 445 | + assert_eq!(reply.location.as_deref(), Some("/acme")); | ||
| 446 | + assert_eq!(pinned_names(&s.site.store, &acme.id).await, ["lib"]); | ||
| 447 | + | ||
| 448 | + let carol = s | ||
| 449 | + .site | ||
| 450 | + .store | ||
| 451 | + .user_by_username("carol") | ||
| 452 | + .await | ||
| 453 | + .unwrap() | ||
| 454 | + .unwrap(); | ||
| 455 | + let outsider = sign_in(&s.site.store, &carol.id, "carol-token").await; | ||
| 456 | + let reply = send( | ||
| 457 | + &s.site, | ||
| 458 | + "POST", | ||
| 459 | + "/org/acme/settings/pins", | ||
| 460 | + Some(&outsider), | ||
| 461 | + &[("csrf", CSRF), ("repo", &lib.id)], | ||
| 462 | + ) | ||
| 463 | + .await; | ||
| 464 | + assert!( | ||
| 465 | + reply.status == 403 || reply.status == 404, | ||
| 466 | + "{}", | ||
| 467 | + reply.status | ||
| 468 | + ); | ||
| 469 | + assert_eq!(pinned_names(&s.site.store, &acme.id).await, ["lib"]); | ||
| 470 | + } | ||
| 471 | +} | ||
crates/forge-web/src/views/mod.rsmodified+0 -1
| @@ -263,7 +263,6 @@ pub async fn shell( | |||
| 263 | </summary> | 263 | </summary> |
| 264 | <ul class="menu-list"> | 264 | <ul class="menu-list"> |
| 265 | <li><a href=(user_href(username.as_str()))>(mi::t(lang, MK::YourProfile))</a></li> | 265 | <li><a href=(user_href(username.as_str()))>(mi::t(lang, MK::YourProfile))</a></li> |
| 266 | - <li><a href="/settings/profile">(mi::t(lang, MK::EditProfile))</a></li> | ||
| 267 | <li><a href="/settings/keys">(t(lang, Key::SshKeys))</a></li> | 266 | <li><a href="/settings/keys">(t(lang, Key::SshKeys))</a></li> |
| 268 | <li><a href="/settings/gpg">(t(lang, Key::GpgKeys))</a></li> | 267 | <li><a href="/settings/gpg">(t(lang, Key::GpgKeys))</a></li> |
| 269 | <li><a href="/settings/tokens">(t(lang, Key::AccessTokens))</a></li> | 268 | <li><a href="/settings/tokens">(t(lang, Key::AccessTokens))</a></li> |
crates/forge-web/tests/stars_e2e.rsmodified+4 -4
| @@ -400,7 +400,7 @@ async fn explore_lists_public_repos_and_searches_literally() { | |||
| 400 | } | 400 | } |
| 401 | 401 | ||
| 402 | #[tokio::test] | 402 | #[tokio::test] |
| 403 | -async fn profile_starred_section_hides_repos_the_viewer_cannot_read() { | 403 | +async fn profile_stars_tab_hides_repos_the_viewer_cannot_read() { |
| 404 | let env = start(|dir, store| async move { | 404 | let env = start(|dir, store| async move { |
| 405 | seed_repos(dir, store.clone()).await; | 405 | seed_repos(dir, store.clone()).await; |
| 406 | let tahinli = store | 406 | let tahinli = store |
| @@ -417,11 +417,11 @@ async fn profile_starred_section_hides_repos_the_viewer_cannot_read() { | |||
| 417 | }) | 417 | }) |
| 418 | .await; | 418 | .await; |
| 419 | 419 | ||
| 420 | - let anon = env.http.get("/bob", None).await; | 420 | + let anon = env.http.get("/bob?tab=stars", None).await; |
| 421 | assert_eq!(anon.status, 200); | 421 | assert_eq!(anon.status, 200); |
| 422 | let starred = |body: &str| { | 422 | let starred = |body: &str| { |
| 423 | let doc = scraper::Html::parse_document(body); | 423 | let doc = scraper::Html::parse_document(body); |
| 424 | - let selector = scraper::Selector::parse(".profile-starred .repo-name").expect("selector"); | 424 | + let selector = scraper::Selector::parse(".repo-list .repo-name").expect("selector"); |
| 425 | doc.select(&selector) | 425 | doc.select(&selector) |
| 426 | .map(|el| el.text().collect::<String>().trim().to_owned()) | 426 | .map(|el| el.text().collect::<String>().trim().to_owned()) |
| 427 | .collect::<Vec<_>>() | 427 | .collect::<Vec<_>>() |
| @@ -429,7 +429,7 @@ async fn profile_starred_section_hides_repos_the_viewer_cannot_read() { | |||
| 429 | assert_eq!(starred(&anon.body), vec!["tahinli/pub".to_owned()]); | 429 | assert_eq!(starred(&anon.body), vec!["tahinli/pub".to_owned()]); |
| 430 | 430 | ||
| 431 | let tahinli = login(&env.http, "tahinli").await; | 431 | let tahinli = login(&env.http, "tahinli").await; |
| 432 | - let owner = env.http.get("/bob", Some(&tahinli)).await; | 432 | + let owner = env.http.get("/bob?tab=stars", Some(&tahinli)).await; |
| 433 | let mut names = starred(&owner.body); | 433 | let mut names = starred(&owner.body); |
| 434 | names.sort(); | 434 | names.sort(); |
| 435 | assert_eq!(names, vec!["tahinli/priv".to_owned(), "tahinli/pub".to_owned()]); | 435 | assert_eq!(names, vec!["tahinli/priv".to_owned(), "tahinli/pub".to_owned()]); |
style/main.scssmodified+137 -0
| @@ -1718,6 +1718,143 @@ code { | |||
| 1718 | } | 1718 | } |
| 1719 | } | 1719 | } |
| 1720 | 1720 | ||
| 1721 | +// Profile: the owner's edit button, the pinned repo grid and the section heads. | ||
| 1722 | +.profile-edit { | ||
| 1723 | + display: flex; | ||
| 1724 | + align-items: center; | ||
| 1725 | + justify-content: center; | ||
| 1726 | + width: 100%; | ||
| 1727 | + height: 34px; | ||
| 1728 | + box-sizing: border-box; | ||
| 1729 | + text-align: center; | ||
| 1730 | +} | ||
| 1731 | + | ||
| 1732 | +// Profile tabs: a horizontal underline strip under the header, at every width. Reuses the | ||
| 1733 | +// `.tab` and `.tab-count` looks; the sidebar rules for `.repo-tabs` do not apply here. | ||
| 1734 | +.profile-tabs { | ||
| 1735 | + display: flex; | ||
| 1736 | + gap: 4px; | ||
| 1737 | + border-bottom: 1px solid var(--border); | ||
| 1738 | + margin: 0; | ||
| 1739 | + overflow-x: auto; | ||
| 1740 | + overflow-y: hidden; | ||
| 1741 | + scrollbar-width: none; | ||
| 1742 | + | ||
| 1743 | + &::-webkit-scrollbar { | ||
| 1744 | + display: none; | ||
| 1745 | + } | ||
| 1746 | +} | ||
| 1747 | + | ||
| 1748 | +// Pagers: Previous, "Page X of Y", Next in one row. | ||
| 1749 | +.pager { | ||
| 1750 | + display: flex; | ||
| 1751 | + align-items: center; | ||
| 1752 | + gap: 12px; | ||
| 1753 | + margin-top: 12px; | ||
| 1754 | +} | ||
| 1755 | + | ||
| 1756 | +.pin-head { | ||
| 1757 | + display: flex; | ||
| 1758 | + flex-wrap: wrap; | ||
| 1759 | + align-items: center; | ||
| 1760 | + gap: 8px; | ||
| 1761 | + min-width: 0; | ||
| 1762 | + | ||
| 1763 | + .badge { | ||
| 1764 | + align-self: start; | ||
| 1765 | + justify-self: start; | ||
| 1766 | + width: auto; | ||
| 1767 | + } | ||
| 1768 | +} | ||
| 1769 | + | ||
| 1770 | +.profile-section-head { | ||
| 1771 | + display: flex; | ||
| 1772 | + flex-wrap: wrap; | ||
| 1773 | + align-items: baseline; | ||
| 1774 | + justify-content: space-between; | ||
| 1775 | + gap: 8px; | ||
| 1776 | + margin-bottom: 8px; | ||
| 1777 | + | ||
| 1778 | + h2 { | ||
| 1779 | + font-size: 1.125rem; | ||
| 1780 | + margin: 0; | ||
| 1781 | + } | ||
| 1782 | +} | ||
| 1783 | + | ||
| 1784 | +// Pinned repos: two cards per row on wide screens, one on phones. | ||
| 1785 | +.pin-grid { | ||
| 1786 | + display: grid; | ||
| 1787 | + grid-template-columns: minmax(0, 1fr); | ||
| 1788 | + gap: 16px; | ||
| 1789 | + list-style: none; | ||
| 1790 | + margin: 0; | ||
| 1791 | + padding: 0; | ||
| 1792 | + | ||
| 1793 | + @media (min-width: 720px) { | ||
| 1794 | + grid-template-columns: repeat(2, minmax(0, 1fr)); | ||
| 1795 | + } | ||
| 1796 | +} | ||
| 1797 | + | ||
| 1798 | +.pin-card { | ||
| 1799 | + display: flex; | ||
| 1800 | + flex-direction: column; | ||
| 1801 | + gap: 6px; | ||
| 1802 | + min-width: 0; | ||
| 1803 | + padding: 14px 16px; | ||
| 1804 | + background: var(--surface); | ||
| 1805 | + border: 1px solid var(--border); | ||
| 1806 | + border-radius: var(--radius); | ||
| 1807 | + overflow-wrap: anywhere; | ||
| 1808 | + | ||
| 1809 | + p { | ||
| 1810 | + margin: 0; | ||
| 1811 | + } | ||
| 1812 | +} | ||
| 1813 | + | ||
| 1814 | +.pin-desc { | ||
| 1815 | + display: -webkit-box; | ||
| 1816 | + -webkit-line-clamp: 2; | ||
| 1817 | + -webkit-box-orient: vertical; | ||
| 1818 | + overflow: hidden; | ||
| 1819 | +} | ||
| 1820 | + | ||
| 1821 | +// Pin picker (settings/pins and the org pins page): left-aligned rows, checkbox then name, | ||
| 1822 | +// two columns on wide screens. | ||
| 1823 | +.pin-options { | ||
| 1824 | + display: grid; | ||
| 1825 | + grid-template-columns: minmax(0, 1fr); | ||
| 1826 | + column-gap: 24px; | ||
| 1827 | + list-style: none; | ||
| 1828 | + margin: 0; | ||
| 1829 | + padding: 0; | ||
| 1830 | + text-align: left; | ||
| 1831 | + | ||
| 1832 | + @media (min-width: 40rem) { | ||
| 1833 | + grid-template-columns: repeat(2, minmax(0, 1fr)); | ||
| 1834 | + } | ||
| 1835 | + | ||
| 1836 | + li { | ||
| 1837 | + min-width: 0; | ||
| 1838 | + border-bottom: 1px solid var(--border); | ||
| 1839 | + } | ||
| 1840 | + | ||
| 1841 | + label { | ||
| 1842 | + display: flex; | ||
| 1843 | + flex-direction: row; | ||
| 1844 | + align-items: center; | ||
| 1845 | + gap: 8px; | ||
| 1846 | + width: 100%; | ||
| 1847 | + padding: 8px 0; | ||
| 1848 | + text-align: left; | ||
| 1849 | + cursor: pointer; | ||
| 1850 | + overflow-wrap: anywhere; | ||
| 1851 | + } | ||
| 1852 | + | ||
| 1853 | + input[type="checkbox"] { | ||
| 1854 | + margin: 0; | ||
| 1855 | + } | ||
| 1856 | +} | ||
| 1857 | + | ||
| 1721 | @media (max-width: 600px) { | 1858 | @media (max-width: 600px) { |
| 1722 | .profile-avatar { | 1859 | .profile-avatar { |
| 1723 | width: 112px; | 1860 | width: 112px; |