Organization pages update live
Browse files at this commit230dd1d20c62a038d8ac27d11891b299670e2c04Parent: aedd20e- feat
- organization pages update live
12 changed files +1035 -419
- crates/forge-web/src/boot.rs +1 -0
- crates/forge-web/src/live.rs +3 -0
- crates/forge-web/src/pages/mod.rs +1 -0
- crates/forge-web/src/pages/org_ctx.rs +17 -19
- crates/forge-web/src/pages/org_live.rs +247 -0
- crates/forge-web/src/pages/org_members.rs +92 -101
- crates/forge-web/src/pages/org_settings.rs +53 -54
- crates/forge-web/src/pages/org_teams.rs +220 -222
- crates/forge-web/src/test_support.rs +1 -0
- crates/forge-web/tests/orgs_live_e2e.rs +378 -0
- crates/forge-web/tests/orgs_ui_e2e.rs +16 -23
- docs/architecture.md +6 -0
crates/forge-web/src/boot.rsmodified+1 -0
| @@ -170,6 +170,7 @@ pub async fn serve( | |||
| 170 | .layer(crate::pages::repo_ctx::RepoMovedLayer) | 170 | .layer(crate::pages::repo_ctx::RepoMovedLayer) |
| 171 | .layer(crate::pages::pull_live::PullWriteLayer) | 171 | .layer(crate::pages::pull_live::PullWriteLayer) |
| 172 | .layer(crate::pages::discussion_live::DiscussionWriteLayer) | 172 | .layer(crate::pages::discussion_live::DiscussionWriteLayer) |
| 173 | + .layer(crate::pages::org_live::OrgWriteLayer) | ||
| 173 | .layer(crate::pages::not_found_page::NotFoundLayer) | 174 | .layer(crate::pages::not_found_page::NotFoundLayer) |
| 174 | .layer(TowerLayer::new(crate::compression::ResponseCompression)) | 175 | .layer(TowerLayer::new(crate::compression::ResponseCompression)) |
| 175 | .compression(Compression::off()) | 176 | .compression(Compression::off()) |
crates/forge-web/src/live.rsmodified+3 -0
| @@ -78,6 +78,9 @@ pub enum Topic { | |||
| 78 | Snippets, | 78 | Snippets, |
| 79 | /// One snippet: its files, title, visibility and revisions. Keyed by snippet id. | 79 | /// One snippet: its files, title, visibility and revisions. Keyed by snippet id. |
| 80 | Snippet(String), | 80 | Snippet(String), |
| 81 | + /// An organization's pages: its members, teams, team members and linked repos, and settings. | ||
| 82 | + /// Keyed by the org's user id. Bumped by [`crate::pages::org_live`] after a POST under the org. | ||
| 83 | + Org(String), | ||
| 81 | } | 84 | } |
| 82 | 85 | ||
| 83 | /// The open topics, each with the counter its subscribers wait on. | 86 | /// The open topics, each with the counter its subscribers wait on. |
crates/forge-web/src/pages/mod.rsmodified+1 -0
| @@ -70,6 +70,7 @@ pub mod new_repo; | |||
| 70 | pub mod not_found_page; | 70 | pub mod not_found_page; |
| 71 | pub mod notifications; | 71 | pub mod notifications; |
| 72 | pub mod org_ctx; | 72 | pub mod org_ctx; |
| 73 | +pub mod org_live; | ||
| 73 | pub mod org_members; | 74 | pub mod org_members; |
| 74 | pub mod org_new; | 75 | pub mod org_new; |
| 75 | pub mod org_settings; | 76 | pub mod org_settings; |
crates/forge-web/src/pages/org_ctx.rsmodified+17 -19
| @@ -1,6 +1,6 @@ | |||
| 1 | //! Shared pieces of the organization pages (`/org/{name}/...`): loading the org for a request and | 1 | //! Shared pieces of the organization pages (`/org/{name}/...`): loading the org for a request and |
| 2 | -//! the signed-in viewer's role in it, the header tabs, the role words, and the one-shot notices | 2 | +//! the signed-in viewer's role in it, the header tabs, the role words, and the notices shown after |
| 3 | -//! shown after a redirect. | 3 | +//! a write (carried in the redirect's query). |
| 4 | //! | 4 | //! |
| 5 | //! Visibility rules: a non-member gets 404 on every org page below the profile, so a private org's | 5 | //! Visibility rules: a non-member gets 404 on every org page below the profile, so a private org's |
| 6 | //! membership is not revealed. A member who is not an owner gets 403 on the owner-only actions. | 6 | //! membership is not revealed. A member who is not an owner gets 403 on the owner-only actions. |
| @@ -9,8 +9,8 @@ use forge_core::store::orgs::OrgMemberRole; | |||
| 9 | use forge_core::{Role, Session, User}; | 9 | use forge_core::{Role, Session, User}; |
| 10 | use topcoat::Result; | 10 | use topcoat::Result; |
| 11 | use topcoat::context::{Cx, app_context}; | 11 | use topcoat::context::{Cx, app_context}; |
| 12 | -use topcoat::cookie::{Cookie, Cookies, SameSite, cookies}; | ||
| 13 | use topcoat::router::error::{forbidden, not_found}; | 12 | use topcoat::router::error::{forbidden, not_found}; |
| 13 | +use topcoat::router::request::uri; | ||
| 14 | use topcoat::view::{View, component, view}; | 14 | use topcoat::view::{View, component, view}; |
| 15 | 15 | ||
| 16 | use crate::auth::{check_csrf, require_user}; | 16 | use crate::auth::{check_csrf, require_user}; |
| @@ -18,9 +18,10 @@ use crate::i18n::Lang; | |||
| 18 | use crate::i18n::orgs::{self as g, K}; | 18 | use crate::i18n::orgs::{self as g, K}; |
| 19 | use crate::state::AppState; | 19 | use crate::state::AppState; |
| 20 | 20 | ||
| 21 | -/// Cookie that carries a one-shot notice to the next org page. Its value is one of the fixed | 21 | +/// The query key that carries a notice on an org page. Its value is one of the fixed words in |
| 22 | -/// words in `NOTICES`, never user text. | 22 | +/// `NOTICES`, never user text. The notice lives in the URL, not in a cookie: a live refresh of the |
| 23 | -pub const NOTICE_COOKIE: &str = "forge_org_notice"; | 23 | +/// page reads the same URL and shows the notice again, where a cookie would be used up by it. |
| 24 | +pub const NOTICE_PARAM: &str = "notice"; | ||
| 24 | 25 | ||
| 25 | /// Notice words, the text key each one shows, and whether it is an error. | 26 | /// Notice words, the text key each one shows, and whether it is an error. |
| 26 | pub const NOTICES: &[(&str, K, bool)] = &[ | 27 | pub const NOTICES: &[(&str, K, bool)] = &[ |
| @@ -159,22 +160,19 @@ pub fn parse_member_role(word: &str) -> Option<OrgMemberRole> { | |||
| 159 | OrgMemberRole::parse(word).ok() | 160 | OrgMemberRole::parse(word).ok() |
| 160 | } | 161 | } |
| 161 | 162 | ||
| 162 | -/// Sets the notice shown on the next org page view. | 163 | +/// The redirect target `back` with the notice `word` in its query, so the next view of the page |
| 163 | -pub fn set_notice(cx: &Cx, word: &'static str) { | 164 | +/// shows it. `back` is an org path without a query. |
| 164 | - cookies(cx).add( | 165 | +pub fn notice_href(back: &str, word: &'static str) -> String { |
| 165 | - Cookie::build((NOTICE_COOKIE, word)) | 166 | + format!("{back}?{NOTICE_PARAM}={word}") |
| 166 | - .path("/") | ||
| 167 | - .http_only(true) | ||
| 168 | - .same_site(SameSite::Lax) | ||
| 169 | - .build(), | ||
| 170 | - ); | ||
| 171 | } | 167 | } |
| 172 | 168 | ||
| 173 | -/// Reads and clears the notice cookie. Only the fixed words are shown, in the viewer's language. | 169 | +/// The notice in the request's query, if it is one of the fixed words. Only those are shown, in |
| 170 | +/// the viewer's language. Reading it changes nothing, so a reload or a live refresh shows it again. | ||
| 174 | pub fn take_notice(cx: &Cx, lang: Lang) -> Option<(&'static str, bool)> { | 171 | pub fn take_notice(cx: &Cx, lang: Lang) -> Option<(&'static str, bool)> { |
| 175 | - let jar = cookies(cx); | 172 | + let query = uri(cx).query()?; |
| 176 | - let value = jar.get(NOTICE_COOKIE)?.value().to_owned(); | 173 | + let value = query |
| 177 | - jar.remove(Cookie::build((NOTICE_COOKIE, "")).path("/")); | 174 | + .split('&') |
| 175 | + .find_map(|pair| pair.strip_prefix(NOTICE_PARAM)?.strip_prefix('='))?; | ||
| 178 | NOTICES | 176 | NOTICES |
| 179 | .iter() | 177 | .iter() |
| 180 | .find(|(word, _, _)| *word == value) | 178 | .find(|(word, _, _)| *word == value) |
crates/forge-web/src/pages/org_live.rsadded+247 -0
| @@ -0,0 +1,247 @@ | |||
| 1 | +//! Live organization pages. The members, teams, team and settings pages of `/org/{org}/...` follow | ||
| 2 | +//! [`Topic::Org`] of their org. A team page also follows [`Topic::Repo`] of each repo it links, so | ||
| 3 | +//! a repo that is renamed or made private reaches the team page that names it. | ||
| 4 | +//! | ||
| 5 | +//! Every POST under `/org/{org}/{members|teams|settings}` bumps the org's topic through | ||
| 6 | +//! [`OrgWriteLayer`], after the handler ran. A refused write bumps too, as in the pull layer. The | ||
| 7 | +//! streams send `changed` only when their fingerprint moves, so over-bumping is cheap. | ||
| 8 | +//! | ||
| 9 | +//! Auth is the page's own: each stream runs the same `load_org` and role check as its page, so a | ||
| 10 | +//! non-member gets 404 and a member who is not an owner gets 403 on the settings stream. The team | ||
| 11 | +//! stream names only the repos the viewer may read, as the team page does. | ||
| 12 | + | ||
| 13 | +use forge_core::User; | ||
| 14 | +use forge_core::store::Store; | ||
| 15 | +use topcoat::Result; | ||
| 16 | +use topcoat::context::{Cx, app_context}; | ||
| 17 | +use topcoat::router::request::{method, uri}; | ||
| 18 | +use topcoat::router::response::Response; | ||
| 19 | +use topcoat::router::{Body, Layer, LayerFuture, Method, Next, Path, path_param, route}; | ||
| 20 | + | ||
| 21 | +use crate::live::{Topic, stream_changes}; | ||
| 22 | +use crate::pages::org_ctx::{load_org, member_role_word, require_member, require_owner}; | ||
| 23 | +use crate::pages::org_teams::{team_of, visible_team_repos}; | ||
| 24 | +use crate::state::AppState; | ||
| 25 | + | ||
| 26 | +path_param!(org); | ||
| 27 | +path_param!(team); | ||
| 28 | + | ||
| 29 | +/// The org's own line: its name and description, which every org page shows in its header. | ||
| 30 | +async fn org_line(store: &Store, org_id: &str) -> Result<String> { | ||
| 31 | + Ok(match store.user_by_id(org_id).await? { | ||
| 32 | + Some(org) => format!("org {} {}", org.username, org.about), | ||
| 33 | + None => "gone".to_owned(), | ||
| 34 | + }) | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +/// What the members page shows: the org's line and each member's role. | ||
| 38 | +async fn members_fingerprint(store: &Store, org_id: &str) -> Result<String> { | ||
| 39 | + let mut lines = vec![org_line(store, org_id).await?]; | ||
| 40 | + for (user, role) in store.org_members(org_id).await? { | ||
| 41 | + lines.push(format!( | ||
| 42 | + "member {} {} {}", | ||
| 43 | + user.id, | ||
| 44 | + user.username, | ||
| 45 | + member_role_word(role) | ||
| 46 | + )); | ||
| 47 | + } | ||
| 48 | + Ok(lines.join("\n")) | ||
| 49 | +} | ||
| 50 | + | ||
| 51 | +/// What the teams list shows: the org's line and each team's fields. | ||
| 52 | +async fn teams_fingerprint(store: &Store, org_id: &str) -> Result<String> { | ||
| 53 | + let mut lines = vec![org_line(store, org_id).await?]; | ||
| 54 | + for team in store.teams_for_org(org_id).await? { | ||
| 55 | + lines.push(format!( | ||
| 56 | + "team {} {} {} {} {}", | ||
| 57 | + team.id, | ||
| 58 | + team.name, | ||
| 59 | + team.description, | ||
| 60 | + team.role.as_str(), | ||
| 61 | + team.all_repos | ||
| 62 | + )); | ||
| 63 | + } | ||
| 64 | + Ok(lines.join("\n")) | ||
| 65 | +} | ||
| 66 | + | ||
| 67 | +/// What one team page shows for `viewer`: the org's line, the team's fields, its members, the | ||
| 68 | +/// linked repos the viewer may read, and the org's repos the team could still link. | ||
| 69 | +async fn team_fingerprint( | ||
| 70 | + store: &Store, | ||
| 71 | + org_id: &str, | ||
| 72 | + viewer: &User, | ||
| 73 | + team_id: &str, | ||
| 74 | +) -> Result<String> { | ||
| 75 | + let Some(team) = store.team_by_id(team_id).await? else { | ||
| 76 | + return Ok("gone".to_owned()); | ||
| 77 | + }; | ||
| 78 | + if team.org_id != org_id { | ||
| 79 | + return Ok("gone".to_owned()); | ||
| 80 | + } | ||
| 81 | + let mut lines = vec![ | ||
| 82 | + org_line(store, org_id).await?, | ||
| 83 | + format!( | ||
| 84 | + "team {} {} {} {}", | ||
| 85 | + team.name, | ||
| 86 | + team.description, | ||
| 87 | + team.role.as_str(), | ||
| 88 | + team.all_repos | ||
| 89 | + ), | ||
| 90 | + ]; | ||
| 91 | + for user in store.team_members(&team.id).await? { | ||
| 92 | + lines.push(format!("member {} {}", user.id, user.username)); | ||
| 93 | + } | ||
| 94 | + let linked = store.team_repos(&team.id).await?; | ||
| 95 | + for repo in visible_team_repos(store, viewer, &linked).await? { | ||
| 96 | + lines.push(format!("repo {} {}", repo.repo_id, repo.title)); | ||
| 97 | + } | ||
| 98 | + for repo in &linked { | ||
| 99 | + lines.push(format!("linked {}", repo.id)); | ||
| 100 | + } | ||
| 101 | + for repo in store.list_repos_by_owner(org_id).await? { | ||
| 102 | + lines.push(format!( | ||
| 103 | + "owned {} {}/{}", | ||
| 104 | + repo.id, repo.owner_name, repo.name | ||
| 105 | + )); | ||
| 106 | + } | ||
| 107 | + Ok(lines.join("\n")) | ||
| 108 | +} | ||
| 109 | + | ||
| 110 | +/// What the settings page shows: the org's line, the default repo role and the create-repos flag. | ||
| 111 | +async fn settings_fingerprint(store: &Store, org_id: &str) -> Result<String> { | ||
| 112 | + let settings = store.org_settings(org_id).await?; | ||
| 113 | + Ok([ | ||
| 114 | + org_line(store, org_id).await?, | ||
| 115 | + format!( | ||
| 116 | + "settings {} {}", | ||
| 117 | + settings.default_repo_role.as_str(), | ||
| 118 | + settings.members_can_create_repos | ||
| 119 | + ), | ||
| 120 | + ] | ||
| 121 | + .join("\n")) | ||
| 122 | +} | ||
| 123 | + | ||
| 124 | +/// The members page's change stream. Members only, as the page. | ||
| 125 | +#[route(GET "/org/{org}/members/events")] | ||
| 126 | +async fn org_members_events(cx: &Cx) -> Result<Response> { | ||
| 127 | + let ctx = load_org(cx, path_param::<Org>(cx)).await?; | ||
| 128 | + require_member(&ctx)?; | ||
| 129 | + let state = app_context::<AppState>(cx); | ||
| 130 | + let org_id = ctx.org.id.clone(); | ||
| 131 | + let store = state.store.clone(); | ||
| 132 | + stream_changes(cx, &state.live, &[Topic::Org(org_id.clone())], move || { | ||
| 133 | + let store = store.clone(); | ||
| 134 | + let org_id = org_id.clone(); | ||
| 135 | + async move { members_fingerprint(&store, &org_id).await } | ||
| 136 | + }) | ||
| 137 | + .await | ||
| 138 | +} | ||
| 139 | + | ||
| 140 | +/// The teams list's change stream. Members only, as the page. | ||
| 141 | +#[route(GET "/org/{org}/teams/events")] | ||
| 142 | +async fn org_teams_events(cx: &Cx) -> Result<Response> { | ||
| 143 | + let ctx = load_org(cx, path_param::<Org>(cx)).await?; | ||
| 144 | + require_member(&ctx)?; | ||
| 145 | + let state = app_context::<AppState>(cx); | ||
| 146 | + let org_id = ctx.org.id.clone(); | ||
| 147 | + let store = state.store.clone(); | ||
| 148 | + stream_changes(cx, &state.live, &[Topic::Org(org_id.clone())], move || { | ||
| 149 | + let store = store.clone(); | ||
| 150 | + let org_id = org_id.clone(); | ||
| 151 | + async move { teams_fingerprint(&store, &org_id).await } | ||
| 152 | + }) | ||
| 153 | + .await | ||
| 154 | +} | ||
| 155 | + | ||
| 156 | +/// One team page's change stream. Members only, and a team of another org is 404, as the page. | ||
| 157 | +/// It also follows each repo the team links, for a rename or a visibility change. | ||
| 158 | +#[route(GET "/org/{org}/teams/{team}/events")] | ||
| 159 | +async fn org_team_events(cx: &Cx) -> Result<Response> { | ||
| 160 | + let ctx = load_org(cx, path_param::<Org>(cx)).await?; | ||
| 161 | + require_member(&ctx)?; | ||
| 162 | + let state = app_context::<AppState>(cx); | ||
| 163 | + let team = team_of(state, &ctx, path_param::<Team>(cx)).await?; | ||
| 164 | + let linked = state.store.team_repos(&team.id).await?; | ||
| 165 | + let mut topics = vec![Topic::Org(ctx.org.id.clone())]; | ||
| 166 | + topics.extend(linked.iter().map(|repo| Topic::Repo(repo.id.clone()))); | ||
| 167 | + let store = state.store.clone(); | ||
| 168 | + let org_id = ctx.org.id.clone(); | ||
| 169 | + let viewer = ctx.viewer.0.clone(); | ||
| 170 | + let team_id = team.id.clone(); | ||
| 171 | + stream_changes(cx, &state.live, &topics, move || { | ||
| 172 | + let store = store.clone(); | ||
| 173 | + let org_id = org_id.clone(); | ||
| 174 | + let viewer = viewer.clone(); | ||
| 175 | + let team_id = team_id.clone(); | ||
| 176 | + async move { team_fingerprint(&store, &org_id, &viewer, &team_id).await } | ||
| 177 | + }) | ||
| 178 | + .await | ||
| 179 | +} | ||
| 180 | + | ||
| 181 | +/// The settings page's change stream. Owners only, as the page. | ||
| 182 | +#[route(GET "/org/{org}/settings/events")] | ||
| 183 | +async fn org_settings_events(cx: &Cx) -> Result<Response> { | ||
| 184 | + let ctx = load_org(cx, path_param::<Org>(cx)).await?; | ||
| 185 | + require_owner(&ctx)?; | ||
| 186 | + let state = app_context::<AppState>(cx); | ||
| 187 | + let org_id = ctx.org.id.clone(); | ||
| 188 | + let store = state.store.clone(); | ||
| 189 | + stream_changes(cx, &state.live, &[Topic::Org(org_id.clone())], move || { | ||
| 190 | + let store = store.clone(); | ||
| 191 | + let org_id = org_id.clone(); | ||
| 192 | + async move { settings_fingerprint(&store, &org_id).await } | ||
| 193 | + }) | ||
| 194 | + .await | ||
| 195 | +} | ||
| 196 | + | ||
| 197 | +// The write layer | ||
| 198 | + | ||
| 199 | +/// The org a POST under `/org/{org}/{members|teams|settings}` writes to, by its name. | ||
| 200 | +fn written_org(cx: &Cx) -> Option<String> { | ||
| 201 | + if *method(cx) != Method::POST { | ||
| 202 | + return None; | ||
| 203 | + } | ||
| 204 | + let path = uri(cx).path().to_owned(); | ||
| 205 | + let parts: Vec<&str> = path.trim_start_matches('/').split('/').collect(); | ||
| 206 | + let ["org", name, kind, ..] = parts.as_slice() else { | ||
| 207 | + return None; | ||
| 208 | + }; | ||
| 209 | + matches!(*kind, "members" | "teams" | "settings").then(|| (*name).to_owned()) | ||
| 210 | +} | ||
| 211 | + | ||
| 212 | +/// Bumps the org's topic after the handler ran. The org is looked up before the handler, so a | ||
| 213 | +/// write that removes the org (its deletion) still reaches the streams that follow it. The | ||
| 214 | +/// handler's result passes through unchanged. | ||
| 215 | +async fn bump_after_write(cx: &Cx, body: Body, next: Next<'_>) -> topcoat::Result<Response> { | ||
| 216 | + let Some(name) = written_org(cx) else { | ||
| 217 | + return next.run(cx, body).await; | ||
| 218 | + }; | ||
| 219 | + let state = app_context::<AppState>(cx); | ||
| 220 | + let org_id = match state.store.user_by_username(&name).await { | ||
| 221 | + Ok(Some(org)) if org.is_org() => Some(org.id), | ||
| 222 | + Ok(_) => None, | ||
| 223 | + Err(e) => { | ||
| 224 | + tracing::error!(error = %e, name, "live: loading the org to bump failed"); | ||
| 225 | + None | ||
| 226 | + } | ||
| 227 | + }; | ||
| 228 | + let result = next.run(cx, body).await; | ||
| 229 | + if let Some(org_id) = org_id { | ||
| 230 | + state.live.bump(&Topic::Org(org_id)); | ||
| 231 | + } | ||
| 232 | + result | ||
| 233 | +} | ||
| 234 | + | ||
| 235 | +/// Wraps every request. Only a POST under an org's members, teams or settings does anything. | ||
| 236 | +/// Registered on the public router in `boot.rs`, next to the pull write layer. | ||
| 237 | +pub struct OrgWriteLayer; | ||
| 238 | + | ||
| 239 | +impl Layer for OrgWriteLayer { | ||
| 240 | + fn path(&self) -> Option<&Path> { | ||
| 241 | + None | ||
| 242 | + } | ||
| 243 | + | ||
| 244 | + fn handle<'a>(&'a self, cx: &'a Cx, body: Body, next: Next<'a>) -> LayerFuture<'a> { | ||
| 245 | + Box::pin(bump_after_write(cx, body, next)) | ||
| 246 | + } | ||
| 247 | +} | ||
crates/forge-web/src/pages/org_members.rsmodified+92 -101
| @@ -19,8 +19,8 @@ use crate::audit::{self, Actor, Target}; | |||
| 19 | use crate::i18n::orgs::{self as g, K}; | 19 | use crate::i18n::orgs::{self as g, K}; |
| 20 | use crate::i18n::{self, Lang}; | 20 | use crate::i18n::{self, Lang}; |
| 21 | use crate::pages::org_ctx::{ | 21 | use crate::pages::org_ctx::{ |
| 22 | - load_org, member_role_word, org_head, org_notice, parse_member_role, require_form_csrf, | 22 | + load_org, member_role_word, notice_href, org_head, org_notice, parse_member_role, |
| 23 | - require_member, require_owner, set_notice, take_notice, | 23 | + require_form_csrf, require_member, require_owner, take_notice, |
| 24 | }; | 24 | }; |
| 25 | use crate::state::AppState; | 25 | use crate::state::AppState; |
| 26 | use crate::views::{avatar_url, display_name, shell}; | 26 | use crate::views::{avatar_url, display_name, shell}; |
| @@ -77,86 +77,89 @@ async fn members_body( | |||
| 77 | csrf: String, | 77 | csrf: String, |
| 78 | notice: Option<(&'static str, bool)>, | 78 | notice: Option<(&'static str, bool)>, |
| 79 | lang: Lang, | 79 | lang: Lang, |
| 80 | + live: String, | ||
| 80 | ) -> Result<impl View> { | 81 | ) -> Result<impl View> { |
| 81 | let role_action = format!("{base}/members/role"); | 82 | let role_action = format!("{base}/members/role"); |
| 82 | let remove_action = format!("{base}/members/remove"); | 83 | let remove_action = format!("{base}/members/remove"); |
| 83 | let add_action = format!("{base}/members/add"); | 84 | let add_action = format!("{base}/members/add"); |
| 84 | Ok(view! { | 85 | Ok(view! { |
| 85 | - org_head(name: name, description: description) | 86 | + <div data-live=(live.as_str())> |
| 86 | - org_notice(notice: notice) | 87 | + org_head(name: name, description: description) |
| 87 | - <section class="card"> | 88 | + org_notice(notice: notice) |
| 88 | - <h2>(g::t(lang, K::Members))</h2> | 89 | + <section class="card"> |
| 89 | - <div class="table-wrap"> | 90 | + <h2>(g::t(lang, K::Members))</h2> |
| 90 | - <table class="table collaborators"> | 91 | + <div class="table-wrap"> |
| 91 | - <thead> | 92 | + <table class="table collaborators"> |
| 92 | - <tr> | 93 | + <thead> |
| 93 | - <th>(g::t(lang, K::MemberHeader))</th> | ||
| 94 | - <th>(g::t(lang, K::Role))</th> | ||
| 95 | - <th><span class="muted small">(g::t(lang, K::Remove))</span></th> | ||
| 96 | - </tr> | ||
| 97 | - </thead> | ||
| 98 | - <tbody> | ||
| 99 | - for row in rows.iter() { | ||
| 100 | <tr> | 94 | <tr> |
| 101 | - <td> | 95 | + <th>(g::t(lang, K::MemberHeader))</th> |
| 102 | - <a class="user-link" href=(format!("/{}", row.username.as_str()))> | 96 | + <th>(g::t(lang, K::Role))</th> |
| 103 | - <img class="avatar avatar-sm" src=(row.avatar.as_str()) alt="" width="24" height="24"> | 97 | + <th><span class="muted small">(g::t(lang, K::Remove))</span></th> |
| 104 | - <span>(row.label.as_str())</span> | ||
| 105 | - </a> | ||
| 106 | - </td> | ||
| 107 | - <td> | ||
| 108 | - if owner { | ||
| 109 | - <form method="post" action=(role_action.as_str()) class="inline-form"> | ||
| 110 | - <input type="hidden" name="csrf" value=(csrf.as_str())> | ||
| 111 | - <input type="hidden" name="user_id" value=(row.user_id.as_str())> | ||
| 112 | - <select name="role" aria-label=(g::role_for(lang, row.username.as_str()))> | ||
| 113 | - <option value="owner" selected=(row.is_owner)>(g::t(lang, K::RoleOwner))</option> | ||
| 114 | - <option value="member" selected=(!row.is_owner)>(g::t(lang, K::RoleMember))</option> | ||
| 115 | - </select> | ||
| 116 | - <button type="submit">(g::t(lang, K::Save))</button> | ||
| 117 | - </form> | ||
| 118 | - } else { | ||
| 119 | - <span>(if row.is_owner { g::t(lang, K::RoleOwner) } else { g::t(lang, K::RoleMember) })</span> | ||
| 120 | - } | ||
| 121 | - </td> | ||
| 122 | - <td> | ||
| 123 | - if owner || row.is_self { | ||
| 124 | - <form method="post" action=(remove_action.as_str()) class="remove-form"> | ||
| 125 | - <input type="hidden" name="csrf" value=(csrf.as_str())> | ||
| 126 | - <input type="hidden" name="user_id" value=(row.user_id.as_str())> | ||
| 127 | - <button type="submit">(if row.is_self { g::t(lang, K::Leave) } else { g::t(lang, K::Remove) })</button> | ||
| 128 | - </form> | ||
| 129 | - } | ||
| 130 | - </td> | ||
| 131 | </tr> | 98 | </tr> |
| 132 | - } | 99 | + </thead> |
| 133 | - </tbody> | 100 | + <tbody> |
| 134 | - </table> | 101 | + for row in rows.iter() { |
| 135 | - </div> | 102 | + <tr> |
| 136 | - </section> | 103 | + <td> |
| 137 | - if owner { | 104 | + <a class="user-link" href=(format!("/{}", row.username.as_str()))> |
| 138 | - <section class="card"> | 105 | + <img class="avatar avatar-sm" src=(row.avatar.as_str()) alt="" width="24" height="24"> |
| 139 | - <h3>(g::t(lang, K::AddMember))</h3> | 106 | + <span>(row.label.as_str())</span> |
| 140 | - <form method="post" action=(add_action.as_str()) class="stack"> | 107 | + </a> |
| 141 | - <input type="hidden" name="csrf" value=(csrf.as_str())> | 108 | + </td> |
| 142 | - <label> | 109 | + <td> |
| 143 | - <span>(g::t(lang, K::Username))</span> | 110 | + if owner { |
| 144 | - <input type="text" name="username" autocomplete="off" spellcheck="false" required=(true)> | 111 | + <form method="post" action=(role_action.as_str()) class="inline-form"> |
| 145 | - </label> | 112 | + <input type="hidden" name="csrf" value=(csrf.as_str())> |
| 146 | - <label> | 113 | + <input type="hidden" name="user_id" value=(row.user_id.as_str())> |
| 147 | - <span>(g::t(lang, K::Role))</span> | 114 | + <select name="role" aria-label=(g::role_for(lang, row.username.as_str()))> |
| 148 | - <select name="role"> | 115 | + <option value="owner" selected=(row.is_owner)>(g::t(lang, K::RoleOwner))</option> |
| 149 | - <option value="member" selected=(true)>(g::t(lang, K::RoleMember))</option> | 116 | + <option value="member" selected=(!row.is_owner)>(g::t(lang, K::RoleMember))</option> |
| 150 | - <option value="owner">(g::t(lang, K::RoleOwner))</option> | 117 | + </select> |
| 151 | - </select> | 118 | + <button type="submit">(g::t(lang, K::Save))</button> |
| 152 | - </label> | 119 | + </form> |
| 153 | - <p class="muted small">(g::t(lang, K::OwnersHelp))</p> | 120 | + } else { |
| 154 | - <div> | 121 | + <span>(if row.is_owner { g::t(lang, K::RoleOwner) } else { g::t(lang, K::RoleMember) })</span> |
| 155 | - <button type="submit">(g::t(lang, K::AddMemberButton))</button> | 122 | + } |
| 156 | - </div> | 123 | + </td> |
| 157 | - </form> | 124 | + <td> |
| 125 | + if owner || row.is_self { | ||
| 126 | + <form method="post" action=(remove_action.as_str()) class="remove-form"> | ||
| 127 | + <input type="hidden" name="csrf" value=(csrf.as_str())> | ||
| 128 | + <input type="hidden" name="user_id" value=(row.user_id.as_str())> | ||
| 129 | + <button type="submit">(if row.is_self { g::t(lang, K::Leave) } else { g::t(lang, K::Remove) })</button> | ||
| 130 | + </form> | ||
| 131 | + } | ||
| 132 | + </td> | ||
| 133 | + </tr> | ||
| 134 | + } | ||
| 135 | + </tbody> | ||
| 136 | + </table> | ||
| 137 | + </div> | ||
| 158 | </section> | 138 | </section> |
| 159 | - } | 139 | + if owner { |
| 140 | + <section class="card"> | ||
| 141 | + <h3>(g::t(lang, K::AddMember))</h3> | ||
| 142 | + <form method="post" action=(add_action.as_str()) class="stack"> | ||
| 143 | + <input type="hidden" name="csrf" value=(csrf.as_str())> | ||
| 144 | + <label> | ||
| 145 | + <span>(g::t(lang, K::Username))</span> | ||
| 146 | + <input type="text" name="username" autocomplete="off" spellcheck="false" required=(true)> | ||
| 147 | + </label> | ||
| 148 | + <label> | ||
| 149 | + <span>(g::t(lang, K::Role))</span> | ||
| 150 | + <select name="role"> | ||
| 151 | + <option value="member" selected=(true)>(g::t(lang, K::RoleMember))</option> | ||
| 152 | + <option value="owner">(g::t(lang, K::RoleOwner))</option> | ||
| 153 | + </select> | ||
| 154 | + </label> | ||
| 155 | + <p class="muted small">(g::t(lang, K::OwnersHelp))</p> | ||
| 156 | + <div> | ||
| 157 | + <button type="submit">(g::t(lang, K::AddMemberButton))</button> | ||
| 158 | + </div> | ||
| 159 | + </form> | ||
| 160 | + </section> | ||
| 161 | + } | ||
| 162 | + </div> | ||
| 160 | }) | 163 | }) |
| 161 | } | 164 | } |
| 162 | 165 | ||
| @@ -186,10 +189,11 @@ async fn org_members_page(cx: &Cx) -> Result<impl View> { | |||
| 186 | let description = ctx.org.about.clone(); | 189 | let description = ctx.org.about.clone(); |
| 187 | let base = ctx.href(""); | 190 | let base = ctx.href(""); |
| 188 | let csrf = ctx.viewer.1.csrf_token.clone(); | 191 | let csrf = ctx.viewer.1.csrf_token.clone(); |
| 192 | + let live = ctx.href("/members/events"); | ||
| 189 | Ok(view! { cx => | 193 | Ok(view! { cx => |
| 190 | shell(title: title.as_str(), viewer: Some(&ctx.viewer), | 194 | shell(title: title.as_str(), viewer: Some(&ctx.viewer), |
| 191 | members_body(name: name, description: description, base: base, owner: owner, | 195 | members_body(name: name, description: description, base: base, owner: owner, |
| 192 | - rows: rows, csrf: csrf, notice: notice, lang: lang)) | 196 | + rows: rows, csrf: csrf, notice: notice, lang: lang, live: live)) |
| 193 | }) | 197 | }) |
| 194 | } | 198 | } |
| 195 | 199 | ||
| @@ -203,21 +207,17 @@ async fn org_members_add(cx: &Cx, Form(form): Form<AddForm>) -> Result<SeeOther> | |||
| 203 | let back = ctx.href("/members"); | 207 | let back = ctx.href("/members"); |
| 204 | 208 | ||
| 205 | let Some(role) = parse_member_role(form.role.trim()) else { | 209 | let Some(role) = parse_member_role(form.role.trim()) else { |
| 206 | - set_notice(cx, "invalid_role"); | 210 | + return Ok(see_other(notice_href(&back, "invalid_role"))); |
| 207 | - return Ok(see_other(back)); | ||
| 208 | }; | 211 | }; |
| 209 | let username = form.username.trim(); | 212 | let username = form.username.trim(); |
| 210 | if username.is_empty() { | 213 | if username.is_empty() { |
| 211 | - set_notice(cx, "empty_username"); | 214 | + return Ok(see_other(notice_href(&back, "empty_username"))); |
| 212 | - return Ok(see_other(back)); | ||
| 213 | } | 215 | } |
| 214 | let Some(target) = state.store.user_by_username(username).await? else { | 216 | let Some(target) = state.store.user_by_username(username).await? else { |
| 215 | - set_notice(cx, "unknown_user"); | 217 | + return Ok(see_other(notice_href(&back, "unknown_user"))); |
| 216 | - return Ok(see_other(back)); | ||
| 217 | }; | 218 | }; |
| 218 | if target.is_org() { | 219 | if target.is_org() { |
| 219 | - set_notice(cx, "unknown_user"); | 220 | + return Ok(see_other(notice_href(&back, "unknown_user"))); |
| 220 | - return Ok(see_other(back)); | ||
| 221 | } | 221 | } |
| 222 | if state | 222 | if state |
| 223 | .store | 223 | .store |
| @@ -225,8 +225,7 @@ async fn org_members_add(cx: &Cx, Form(form): Form<AddForm>) -> Result<SeeOther> | |||
| 225 | .await? | 225 | .await? |
| 226 | .is_some() | 226 | .is_some() |
| 227 | { | 227 | { |
| 228 | - set_notice(cx, "already_member"); | 228 | + return Ok(see_other(notice_href(&back, "already_member"))); |
| 229 | - return Ok(see_other(back)); | ||
| 230 | } | 229 | } |
| 231 | 230 | ||
| 232 | state | 231 | state |
| @@ -246,8 +245,7 @@ async fn org_members_add(cx: &Cx, Form(form): Form<AddForm>) -> Result<SeeOther> | |||
| 246 | serde_json::json!({ "user": target.username, "role": member_role_word(role) }), | 245 | serde_json::json!({ "user": target.username, "role": member_role_word(role) }), |
| 247 | ) | 246 | ) |
| 248 | .await; | 247 | .await; |
| 249 | - set_notice(cx, "member_added"); | 248 | + Ok(see_other(notice_href(&back, "member_added"))) |
| 250 | - Ok(see_other(back)) | ||
| 251 | } | 249 | } |
| 252 | 250 | ||
| 253 | /// Changes a member's org role. Owners only. Demoting the last owner is refused. | 251 | /// Changes a member's org role. Owners only. Demoting the last owner is refused. |
| @@ -260,8 +258,7 @@ async fn org_members_role(cx: &Cx, Form(form): Form<RoleForm>) -> Result<SeeOthe | |||
| 260 | let back = ctx.href("/members"); | 258 | let back = ctx.href("/members"); |
| 261 | 259 | ||
| 262 | let Some(role) = parse_member_role(form.role.trim()) else { | 260 | let Some(role) = parse_member_role(form.role.trim()) else { |
| 263 | - set_notice(cx, "invalid_role"); | 261 | + return Ok(see_other(notice_href(&back, "invalid_role"))); |
| 264 | - return Ok(see_other(back)); | ||
| 265 | }; | 262 | }; |
| 266 | let user_id = form.user_id.trim(); | 263 | let user_id = form.user_id.trim(); |
| 267 | if state | 264 | if state |
| @@ -270,8 +267,7 @@ async fn org_members_role(cx: &Cx, Form(form): Form<RoleForm>) -> Result<SeeOthe | |||
| 270 | .await? | 267 | .await? |
| 271 | .is_none() | 268 | .is_none() |
| 272 | { | 269 | { |
| 273 | - set_notice(cx, "not_member"); | 270 | + return Ok(see_other(notice_href(&back, "not_member"))); |
| 274 | - return Ok(see_other(back)); | ||
| 275 | } | 271 | } |
| 276 | match state | 272 | match state |
| 277 | .store | 273 | .store |
| @@ -280,8 +276,7 @@ async fn org_members_role(cx: &Cx, Form(form): Form<RoleForm>) -> Result<SeeOthe | |||
| 280 | { | 276 | { |
| 281 | Ok(()) => {} | 277 | Ok(()) => {} |
| 282 | Err(forge_core::Error::Conflict(_)) => { | 278 | Err(forge_core::Error::Conflict(_)) => { |
| 283 | - set_notice(cx, "last_owner"); | 279 | + return Ok(see_other(notice_href(&back, "last_owner"))); |
| 284 | - return Ok(see_other(back)); | ||
| 285 | } | 280 | } |
| 286 | Err(e) => return Err(e.into()), | 281 | Err(e) => return Err(e.into()), |
| 287 | } | 282 | } |
| @@ -298,8 +293,7 @@ async fn org_members_role(cx: &Cx, Form(form): Form<RoleForm>) -> Result<SeeOthe | |||
| 298 | serde_json::json!({ "user": user_id, "role": member_role_word(role) }), | 293 | serde_json::json!({ "user": user_id, "role": member_role_word(role) }), |
| 299 | ) | 294 | ) |
| 300 | .await; | 295 | .await; |
| 301 | - set_notice(cx, "role_updated"); | 296 | + Ok(see_other(notice_href(&back, "role_updated"))) |
| 302 | - Ok(see_other(back)) | ||
| 303 | } | 297 | } |
| 304 | 298 | ||
| 305 | /// Removes a member. Owners may remove anyone; any member may remove themselves (leave). A | 299 | /// Removes a member. Owners may remove anyone; any member may remove themselves (leave). A |
| @@ -323,14 +317,12 @@ async fn org_members_remove(cx: &Cx, Form(form): Form<RemoveForm>) -> Result<See | |||
| 323 | .await? | 317 | .await? |
| 324 | .is_none() | 318 | .is_none() |
| 325 | { | 319 | { |
| 326 | - set_notice(cx, "not_member"); | 320 | + return Ok(see_other(notice_href(&back, "not_member"))); |
| 327 | - return Ok(see_other(back)); | ||
| 328 | } | 321 | } |
| 329 | match state.store.remove_org_member(&ctx.org.id, &user_id).await { | 322 | match state.store.remove_org_member(&ctx.org.id, &user_id).await { |
| 330 | Ok(()) => {} | 323 | Ok(()) => {} |
| 331 | Err(forge_core::Error::Conflict(_)) => { | 324 | Err(forge_core::Error::Conflict(_)) => { |
| 332 | - set_notice(cx, "last_owner"); | 325 | + return Ok(see_other(notice_href(&back, "last_owner"))); |
| 333 | - return Ok(see_other(back)); | ||
| 334 | } | 326 | } |
| 335 | Err(e) => return Err(e.into()), | 327 | Err(e) => return Err(e.into()), |
| 336 | } | 328 | } |
| @@ -350,6 +342,5 @@ async fn org_members_remove(cx: &Cx, Form(form): Form<RemoveForm>) -> Result<See | |||
| 350 | if self_removal { | 342 | if self_removal { |
| 351 | return Ok(see_other(format!("/{}", ctx.org.username))); | 343 | return Ok(see_other(format!("/{}", ctx.org.username))); |
| 352 | } | 344 | } |
| 353 | - set_notice(cx, "member_removed"); | 345 | + Ok(see_other(notice_href(&back, "member_removed"))) |
| 354 | - Ok(see_other(back)) | ||
| 355 | } | 346 | } |
crates/forge-web/src/pages/org_settings.rsmodified+53 -54
| @@ -16,7 +16,7 @@ use crate::audit::{self, Actor, Target}; | |||
| 16 | use crate::i18n::orgs::{self as g, K}; | 16 | use crate::i18n::orgs::{self as g, K}; |
| 17 | use crate::i18n::{self, Lang}; | 17 | use crate::i18n::{self, Lang}; |
| 18 | use crate::pages::org_ctx::{ | 18 | use crate::pages::org_ctx::{ |
| 19 | - DEFAULT_ROLES, load_org, org_head, org_notice, require_form_csrf, require_owner, set_notice, | 19 | + DEFAULT_ROLES, load_org, notice_href, org_head, org_notice, require_form_csrf, require_owner, |
| 20 | take_notice, | 20 | take_notice, |
| 21 | }; | 21 | }; |
| 22 | use crate::state::AppState; | 22 | use crate::state::AppState; |
| @@ -58,53 +58,56 @@ async fn settings_body( | |||
| 58 | members_can_create: bool, | 58 | members_can_create: bool, |
| 59 | notice: Option<(&'static str, bool)>, | 59 | notice: Option<(&'static str, bool)>, |
| 60 | lang: Lang, | 60 | lang: Lang, |
| 61 | + live: String, | ||
| 61 | ) -> Result<impl View> { | 62 | ) -> Result<impl View> { |
| 62 | let save_action = format!("{base}/settings"); | 63 | let save_action = format!("{base}/settings"); |
| 63 | let delete_action = format!("{base}/settings/delete"); | 64 | let delete_action = format!("{base}/settings/delete"); |
| 64 | let confirm_label = g::type_to_confirm(lang, &name); | 65 | let confirm_label = g::type_to_confirm(lang, &name); |
| 65 | Ok(view! { | 66 | Ok(view! { |
| 66 | - org_head(name: name, description: description.clone()) | 67 | + <div data-live=(live.as_str())> |
| 67 | - org_notice(notice: notice) | 68 | + org_head(name: name, description: description.clone()) |
| 68 | - <section class="card"> | 69 | + org_notice(notice: notice) |
| 69 | - <h2>(g::t(lang, K::Settings))</h2> | 70 | + <section class="card"> |
| 70 | - <form method="post" action=(save_action.as_str()) class="stack"> | 71 | + <h2>(g::t(lang, K::Settings))</h2> |
| 71 | - <input type="hidden" name="csrf" value=(csrf.as_str())> | 72 | + <form method="post" action=(save_action.as_str()) class="stack"> |
| 72 | - <label> | 73 | + <input type="hidden" name="csrf" value=(csrf.as_str())> |
| 73 | - <span>(g::t(lang, K::Description))</span> | 74 | + <label> |
| 74 | - <textarea name="description" rows="3" maxlength="2000">(description.as_str())</textarea> | 75 | + <span>(g::t(lang, K::Description))</span> |
| 75 | - </label> | 76 | + <textarea name="description" rows="3" maxlength="2000">(description.as_str())</textarea> |
| 76 | - <label> | 77 | + </label> |
| 77 | - <span>(g::t(lang, K::DefaultRoleLabel))</span> | 78 | + <label> |
| 78 | - <select name="default_repo_role"> | 79 | + <span>(g::t(lang, K::DefaultRoleLabel))</span> |
| 79 | - for choice in DEFAULT_ROLES.iter() { | 80 | + <select name="default_repo_role"> |
| 80 | - <option value=(*choice) selected=(*choice == default_role.as_str())>(g::role_name(lang, choice))</option> | 81 | + for choice in DEFAULT_ROLES.iter() { |
| 81 | - } | 82 | + <option value=(*choice) selected=(*choice == default_role.as_str())>(g::role_name(lang, choice))</option> |
| 82 | - </select> | 83 | + } |
| 83 | - </label> | 84 | + </select> |
| 84 | - <p class="muted small">(g::t(lang, K::DefaultRoleHelp))</p> | 85 | + </label> |
| 85 | - <label class="inline"> | 86 | + <p class="muted small">(g::t(lang, K::DefaultRoleHelp))</p> |
| 86 | - <input type="checkbox" name="members_can_create" value="on" checked=(members_can_create)> | 87 | + <label class="inline"> |
| 87 | - <span>(g::t(lang, K::MembersCanCreate))</span> | 88 | + <input type="checkbox" name="members_can_create" value="on" checked=(members_can_create)> |
| 88 | - </label> | 89 | + <span>(g::t(lang, K::MembersCanCreate))</span> |
| 89 | - <div> | 90 | + </label> |
| 90 | - <button type="submit" class="primary">(g::t(lang, K::SaveSettings))</button> | 91 | + <div> |
| 91 | - </div> | 92 | + <button type="submit" class="primary">(g::t(lang, K::SaveSettings))</button> |
| 92 | - </form> | 93 | + </div> |
| 93 | - </section> | 94 | + </form> |
| 94 | - <section class="card"> | 95 | + </section> |
| 95 | - <h2>(g::t(lang, K::DeleteOrg))</h2> | 96 | + <section class="card"> |
| 96 | - <p class="muted small">(g::t(lang, K::DeleteOrgIntro))</p> | 97 | + <h2>(g::t(lang, K::DeleteOrg))</h2> |
| 97 | - <form method="post" action=(delete_action.as_str()) class="stack"> | 98 | + <p class="muted small">(g::t(lang, K::DeleteOrgIntro))</p> |
| 98 | - <input type="hidden" name="csrf" value=(csrf.as_str())> | 99 | + <form method="post" action=(delete_action.as_str()) class="stack"> |
| 99 | - <label> | 100 | + <input type="hidden" name="csrf" value=(csrf.as_str())> |
| 100 | - <span>(confirm_label.as_str())</span> | 101 | + <label> |
| 101 | - <input type="text" name="confirm" autocomplete="off" spellcheck="false" required=(true)> | 102 | + <span>(confirm_label.as_str())</span> |
| 102 | - </label> | 103 | + <input type="text" name="confirm" autocomplete="off" spellcheck="false" required=(true)> |
| 103 | - <div> | 104 | + </label> |
| 104 | - <button type="submit" class="danger">(g::t(lang, K::DeleteOrg))</button> | 105 | + <div> |
| 105 | - </div> | 106 | + <button type="submit" class="danger">(g::t(lang, K::DeleteOrg))</button> |
| 106 | - </form> | 107 | + </div> |
| 107 | - </section> | 108 | + </form> |
| 109 | + </section> | ||
| 110 | + </div> | ||
| 108 | }) | 111 | }) |
| 109 | } | 112 | } |
| 110 | 113 | ||
| @@ -124,10 +127,11 @@ async fn org_settings_page(cx: &Cx) -> Result<impl View> { | |||
| 124 | let description = ctx.org.about.clone(); | 127 | let description = ctx.org.about.clone(); |
| 125 | let base = ctx.href(""); | 128 | let base = ctx.href(""); |
| 126 | let csrf = ctx.viewer.1.csrf_token.clone(); | 129 | let csrf = ctx.viewer.1.csrf_token.clone(); |
| 130 | + let live = ctx.href("/settings/events"); | ||
| 127 | Ok(view! { cx => | 131 | Ok(view! { cx => |
| 128 | shell(title: title.as_str(), viewer: Some(&ctx.viewer), | 132 | shell(title: title.as_str(), viewer: Some(&ctx.viewer), |
| 129 | settings_body(name: name, description: description, base: base, csrf: csrf, | 133 | settings_body(name: name, description: description, base: base, csrf: csrf, |
| 130 | - default_role: default_role, members_can_create: members_can_create, notice: notice, lang: lang)) | 134 | + default_role: default_role, members_can_create: members_can_create, notice: notice, lang: lang, live: live)) |
| 131 | }) | 135 | }) |
| 132 | } | 136 | } |
| 133 | 137 | ||
| @@ -142,12 +146,10 @@ async fn org_settings_save(cx: &Cx, Form(form): Form<SettingsForm>) -> Result<Se | |||
| 142 | 146 | ||
| 143 | let description = form.description.trim(); | 147 | let description = form.description.trim(); |
| 144 | if description.chars().count() > MAX_DESCRIPTION_CHARS { | 148 | if description.chars().count() > MAX_DESCRIPTION_CHARS { |
| 145 | - set_notice(cx, "description_length"); | 149 | + return Ok(see_other(notice_href(&back, "description_length"))); |
| 146 | - return Ok(see_other(back)); | ||
| 147 | } | 150 | } |
| 148 | let Ok(default_repo_role) = DefaultRepoRole::parse(form.default_repo_role.trim()) else { | 151 | let Ok(default_repo_role) = DefaultRepoRole::parse(form.default_repo_role.trim()) else { |
| 149 | - set_notice(cx, "invalid_role"); | 152 | + return Ok(see_other(notice_href(&back, "invalid_role"))); |
| 150 | - return Ok(see_other(back)); | ||
| 151 | }; | 153 | }; |
| 152 | let members_can_create_repos = !form.members_can_create.is_empty(); | 154 | let members_can_create_repos = !form.members_can_create.is_empty(); |
| 153 | 155 | ||
| @@ -181,8 +183,7 @@ async fn org_settings_save(cx: &Cx, Form(form): Form<SettingsForm>) -> Result<Se | |||
| 181 | }), | 183 | }), |
| 182 | ) | 184 | ) |
| 183 | .await; | 185 | .await; |
| 184 | - set_notice(cx, "settings_saved"); | 186 | + Ok(see_other(notice_href(&back, "settings_saved"))) |
| 185 | - Ok(see_other(back)) | ||
| 186 | } | 187 | } |
| 187 | 188 | ||
| 188 | /// Deletes the org. Owners only, and the name must be typed again. Refused while the org owns | 189 | /// Deletes the org. Owners only, and the name must be typed again. Refused while the org owns |
| @@ -196,14 +197,12 @@ async fn org_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<SeeOther> { | |||
| 196 | let back = ctx.href("/settings"); | 197 | let back = ctx.href("/settings"); |
| 197 | 198 | ||
| 198 | if form.confirm.trim() != ctx.org.username { | 199 | if form.confirm.trim() != ctx.org.username { |
| 199 | - set_notice(cx, "confirm_name"); | 200 | + return Ok(see_other(notice_href(&back, "confirm_name"))); |
| 200 | - return Ok(see_other(back)); | ||
| 201 | } | 201 | } |
| 202 | match state.store.delete_org(&ctx.org.id).await { | 202 | match state.store.delete_org(&ctx.org.id).await { |
| 203 | Ok(()) => {} | 203 | Ok(()) => {} |
| 204 | Err(forge_core::Error::Conflict(_)) => { | 204 | Err(forge_core::Error::Conflict(_)) => { |
| 205 | - set_notice(cx, "has_repos"); | 205 | + return Ok(see_other(notice_href(&back, "has_repos"))); |
| 206 | - return Ok(see_other(back)); | ||
| 207 | } | 206 | } |
| 208 | Err(e) => return Err(e.into()), | 207 | Err(e) => return Err(e.into()), |
| 209 | } | 208 | } |
crates/forge-web/src/pages/org_teams.rsmodified+220 -222
| @@ -19,8 +19,8 @@ use crate::audit::{self, Actor, Target}; | |||
| 19 | use crate::i18n::orgs::{self as g, K}; | 19 | use crate::i18n::orgs::{self as g, K}; |
| 20 | use crate::i18n::{self, Lang}; | 20 | use crate::i18n::{self, Lang}; |
| 21 | use crate::pages::org_ctx::{ | 21 | use crate::pages::org_ctx::{ |
| 22 | - OrgCtx, TEAM_ROLES, load_org, org_head, org_notice, require_form_csrf, require_member, | 22 | + OrgCtx, TEAM_ROLES, load_org, notice_href, org_head, org_notice, require_form_csrf, |
| 23 | - require_owner, set_notice, take_notice, | 23 | + require_member, require_owner, take_notice, |
| 24 | }; | 24 | }; |
| 25 | use crate::state::AppState; | 25 | use crate::state::AppState; |
| 26 | use crate::views::{avatar_url, display_name, repo_href, shell}; | 26 | use crate::views::{avatar_url, display_name, repo_href, shell}; |
| @@ -93,10 +93,10 @@ struct TeamMemberRow { | |||
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | /// A repo linked to the team, shown on the team page. | 95 | /// A repo linked to the team, shown on the team page. |
| 96 | -struct TeamRepoRow { | 96 | +pub(crate) struct TeamRepoRow { |
| 97 | - repo_id: String, | 97 | + pub(crate) repo_id: String, |
| 98 | href: String, | 98 | href: String, |
| 99 | - title: String, | 99 | + pub(crate) title: String, |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | /// A repo the org owns that is not linked to the team yet: the select's options. | 102 | /// A repo the org owns that is not linked to the team yet: the select's options. |
| @@ -110,6 +110,8 @@ struct TeamPage { | |||
| 110 | org_name: String, | 110 | org_name: String, |
| 111 | org_description: String, | 111 | org_description: String, |
| 112 | base: String, | 112 | base: String, |
| 113 | + /// The URL of the team page's change stream. | ||
| 114 | + live: String, | ||
| 113 | owner: bool, | 115 | owner: bool, |
| 114 | csrf: String, | 116 | csrf: String, |
| 115 | team_name: String, | 117 | team_name: String, |
| @@ -140,7 +142,7 @@ fn team_error_notice(err: &forge_core::Error) -> Option<&'static str> { | |||
| 140 | } | 142 | } |
| 141 | 143 | ||
| 142 | /// The team named in the path, if it belongs to this org. Anything else is 404. | 144 | /// The team named in the path, if it belongs to this org. Anything else is 404. |
| 143 | -async fn team_of( | 145 | +pub(crate) async fn team_of( |
| 144 | state: &AppState, | 146 | state: &AppState, |
| 145 | ctx: &OrgCtx, | 147 | ctx: &OrgCtx, |
| 146 | team_id: &str, | 148 | team_id: &str, |
| @@ -151,6 +153,30 @@ async fn team_of( | |||
| 151 | } | 153 | } |
| 152 | } | 154 | } |
| 153 | 155 | ||
| 156 | +/// The linked repos the viewer may read, as the team page names them. A repo the viewer cannot | ||
| 157 | +/// read is left out, so its name stays hidden. The team page and its stream both use this. | ||
| 158 | +pub(crate) async fn visible_team_repos( | ||
| 159 | + store: &forge_core::store::Store, | ||
| 160 | + viewer: &forge_core::User, | ||
| 161 | + linked: &[forge_core::Repo], | ||
| 162 | +) -> Result<Vec<TeamRepoRow>> { | ||
| 163 | + let mut repos = Vec::new(); | ||
| 164 | + for repo in linked { | ||
| 165 | + let role = store.collaborator_role(&repo.id, &viewer.id).await?; | ||
| 166 | + let org_role = store | ||
| 167 | + .org_repo_role(&repo.owner_id, &viewer.id, &repo.id) | ||
| 168 | + .await?; | ||
| 169 | + if authorize(Some(viewer), repo, role, org_role, Action::Read).is_ok() { | ||
| 170 | + repos.push(TeamRepoRow { | ||
| 171 | + repo_id: repo.id.clone(), | ||
| 172 | + href: repo_href(&repo.owner_name, &repo.name, "", ""), | ||
| 173 | + title: format!("{}/{}", repo.owner_name, repo.name), | ||
| 174 | + }); | ||
| 175 | + } | ||
| 176 | + } | ||
| 177 | + Ok(repos) | ||
| 178 | +} | ||
| 179 | + | ||
| 154 | #[component] | 180 | #[component] |
| 155 | async fn teams_body( | 181 | async fn teams_body( |
| 156 | name: String, | 182 | name: String, |
| @@ -161,63 +187,66 @@ async fn teams_body( | |||
| 161 | rows: Vec<TeamRow>, | 187 | rows: Vec<TeamRow>, |
| 162 | notice: Option<(&'static str, bool)>, | 188 | notice: Option<(&'static str, bool)>, |
| 163 | lang: Lang, | 189 | lang: Lang, |
| 190 | + live: String, | ||
| 164 | ) -> Result<impl View> { | 191 | ) -> Result<impl View> { |
| 165 | let create_action = format!("{base}/teams/new"); | 192 | let create_action = format!("{base}/teams/new"); |
| 166 | Ok(view! { | 193 | Ok(view! { |
| 167 | - org_head(name: name, description: description) | 194 | + <div data-live=(live.as_str())> |
| 168 | - org_notice(notice: notice) | 195 | + org_head(name: name, description: description) |
| 169 | - <section class="card"> | 196 | + org_notice(notice: notice) |
| 170 | - <h2>(g::t(lang, K::Teams))</h2> | ||
| 171 | - <p class="muted small">(g::t(lang, K::TeamsIntro))</p> | ||
| 172 | - if rows.is_empty() { | ||
| 173 | - <p class="muted">(g::t(lang, K::NoTeamsYet))</p> | ||
| 174 | - } else { | ||
| 175 | - <ul class="item-list"> | ||
| 176 | - for row in rows.iter() { | ||
| 177 | - <li class="item"> | ||
| 178 | - <div class="item-main"> | ||
| 179 | - <a href=(row.href.as_str())><strong>(row.name.as_str())</strong></a> | ||
| 180 | - <span class="muted small">(g::coverage_text(lang, row.role, row.all_repos))</span> | ||
| 181 | - if !row.description.is_empty() { | ||
| 182 | - <span class="muted small">(row.description.as_str())</span> | ||
| 183 | - } | ||
| 184 | - </div> | ||
| 185 | - </li> | ||
| 186 | - } | ||
| 187 | - </ul> | ||
| 188 | - } | ||
| 189 | - </section> | ||
| 190 | - if owner { | ||
| 191 | <section class="card"> | 197 | <section class="card"> |
| 192 | - <h3>(g::t(lang, K::NewTeam))</h3> | 198 | + <h2>(g::t(lang, K::Teams))</h2> |
| 193 | - <form method="post" action=(create_action.as_str()) class="stack"> | 199 | + <p class="muted small">(g::t(lang, K::TeamsIntro))</p> |
| 194 | - <input type="hidden" name="csrf" value=(csrf.as_str())> | 200 | + if rows.is_empty() { |
| 195 | - <label> | 201 | + <p class="muted">(g::t(lang, K::NoTeamsYet))</p> |
| 196 | - <span>(g::t(lang, K::Name))</span> | 202 | + } else { |
| 197 | - <input type="text" name="name" autocomplete="off" required=(true) maxlength="64"> | 203 | + <ul class="item-list"> |
| 198 | - </label> | 204 | + for row in rows.iter() { |
| 199 | - <label> | 205 | + <li class="item"> |
| 200 | - <span>(g::t(lang, K::DescriptionOptional))</span> | 206 | + <div class="item-main"> |
| 201 | - <textarea name="description" rows="2" maxlength="350"></textarea> | 207 | + <a href=(row.href.as_str())><strong>(row.name.as_str())</strong></a> |
| 202 | - </label> | 208 | + <span class="muted small">(g::coverage_text(lang, row.role, row.all_repos))</span> |
| 203 | - <label> | 209 | + if !row.description.is_empty() { |
| 204 | - <span>(g::t(lang, K::Role))</span> | 210 | + <span class="muted small">(row.description.as_str())</span> |
| 205 | - <select name="role"> | 211 | + } |
| 206 | - for role in TEAM_ROLES.iter() { | 212 | + </div> |
| 207 | - <option value=(role.as_str()) selected=(*role == Role::Read)>(g::role_name(lang, role.as_str()))</option> | 213 | + </li> |
| 208 | - } | 214 | + } |
| 209 | - </select> | 215 | + </ul> |
| 210 | - </label> | 216 | + } |
| 211 | - <label class="inline"> | ||
| 212 | - <input type="checkbox" name="all_repos" value="on"> | ||
| 213 | - <span>(g::t(lang, K::CoversAllRepos))</span> | ||
| 214 | - </label> | ||
| 215 | - <div> | ||
| 216 | - <button type="submit" class="primary">(g::t(lang, K::CreateTeam))</button> | ||
| 217 | - </div> | ||
| 218 | - </form> | ||
| 219 | </section> | 217 | </section> |
| 220 | - } | 218 | + if owner { |
| 219 | + <section class="card"> | ||
| 220 | + <h3>(g::t(lang, K::NewTeam))</h3> | ||
| 221 | + <form method="post" action=(create_action.as_str()) class="stack"> | ||
| 222 | + <input type="hidden" name="csrf" value=(csrf.as_str())> | ||
| 223 | + <label> | ||
| 224 | + <span>(g::t(lang, K::Name))</span> | ||
| 225 | + <input type="text" name="name" autocomplete="off" required=(true) maxlength="64"> | ||
| 226 | + </label> | ||
| 227 | + <label> | ||
| 228 | + <span>(g::t(lang, K::DescriptionOptional))</span> | ||
| 229 | + <textarea name="description" rows="2" maxlength="350"></textarea> | ||
| 230 | + </label> | ||
| 231 | + <label> | ||
| 232 | + <span>(g::t(lang, K::Role))</span> | ||
| 233 | + <select name="role"> | ||
| 234 | + for role in TEAM_ROLES.iter() { | ||
| 235 | + <option value=(role.as_str()) selected=(*role == Role::Read)>(g::role_name(lang, role.as_str()))</option> | ||
| 236 | + } | ||
| 237 | + </select> | ||
| 238 | + </label> | ||
| 239 | + <label class="inline"> | ||
| 240 | + <input type="checkbox" name="all_repos" value="on"> | ||
| 241 | + <span>(g::t(lang, K::CoversAllRepos))</span> | ||
| 242 | + </label> | ||
| 243 | + <div> | ||
| 244 | + <button type="submit" class="primary">(g::t(lang, K::CreateTeam))</button> | ||
| 245 | + </div> | ||
| 246 | + </form> | ||
| 247 | + </section> | ||
| 248 | + } | ||
| 249 | + </div> | ||
| 221 | }) | 250 | }) |
| 222 | } | 251 | } |
| 223 | 252 | ||
| @@ -246,10 +275,11 @@ async fn org_teams_page(cx: &Cx) -> Result<impl View> { | |||
| 246 | let description = ctx.org.about.clone(); | 275 | let description = ctx.org.about.clone(); |
| 247 | let base = ctx.href(""); | 276 | let base = ctx.href(""); |
| 248 | let csrf = ctx.viewer.1.csrf_token.clone(); | 277 | let csrf = ctx.viewer.1.csrf_token.clone(); |
| 278 | + let live = ctx.href("/teams/events"); | ||
| 249 | Ok(view! { cx => | 279 | Ok(view! { cx => |
| 250 | shell(title: title.as_str(), viewer: Some(&ctx.viewer), | 280 | shell(title: title.as_str(), viewer: Some(&ctx.viewer), |
| 251 | teams_body(name: name, description: description, base: base, owner: owner, | 281 | teams_body(name: name, description: description, base: base, owner: owner, |
| 252 | - csrf: csrf, rows: rows, notice: notice, lang: lang)) | 282 | + csrf: csrf, rows: rows, notice: notice, lang: lang, live: live)) |
| 253 | }) | 283 | }) |
| 254 | } | 284 | } |
| 255 | 285 | ||
| @@ -271,114 +301,116 @@ async fn team_body( | |||
| 271 | let has_choices = !data.choices.is_empty(); | 301 | let has_choices = !data.choices.is_empty(); |
| 272 | let has_description = !data.team_description.is_empty(); | 302 | let has_description = !data.team_description.is_empty(); |
| 273 | Ok(view! { | 303 | Ok(view! { |
| 274 | - org_head(name: data.org_name.clone(), description: data.org_description.clone()) | 304 | + <div data-live=(data.live.as_str())> |
| 275 | - org_notice(notice: notice) | 305 | + org_head(name: data.org_name.clone(), description: data.org_description.clone()) |
| 276 | - <section class="card"> | 306 | + org_notice(notice: notice) |
| 277 | - <h2>(data.team_name.as_str())</h2> | 307 | + <section class="card"> |
| 278 | - if has_description { | 308 | + <h2>(data.team_name.as_str())</h2> |
| 279 | - <p class="muted">(data.team_description.as_str())</p> | 309 | + if has_description { |
| 280 | - } | 310 | + <p class="muted">(data.team_description.as_str())</p> |
| 281 | - <p class="muted small">(g::coverage_text(lang, data.team_role, data.team_all_repos))</p> | 311 | + } |
| 282 | - if owner { | 312 | + <p class="muted small">(g::coverage_text(lang, data.team_role, data.team_all_repos))</p> |
| 283 | - <form method="post" action=(update_action.as_str()) class="stack"> | 313 | + if owner { |
| 284 | - <input type="hidden" name="csrf" value=(csrf.as_str())> | 314 | + <form method="post" action=(update_action.as_str()) class="stack"> |
| 285 | - <label> | 315 | + <input type="hidden" name="csrf" value=(csrf.as_str())> |
| 286 | - <span>(g::t(lang, K::Name))</span> | 316 | + <label> |
| 287 | - <input type="text" name="name" value=(data.team_name.as_str()) autocomplete="off" required=(true) maxlength="64"> | 317 | + <span>(g::t(lang, K::Name))</span> |
| 288 | - </label> | 318 | + <input type="text" name="name" value=(data.team_name.as_str()) autocomplete="off" required=(true) maxlength="64"> |
| 289 | - <label> | 319 | + </label> |
| 290 | - <span>(g::t(lang, K::DescriptionOptional))</span> | 320 | + <label> |
| 291 | - <textarea name="description" rows="2" maxlength="350">(data.team_description.as_str())</textarea> | 321 | + <span>(g::t(lang, K::DescriptionOptional))</span> |
| 292 | - </label> | 322 | + <textarea name="description" rows="2" maxlength="350">(data.team_description.as_str())</textarea> |
| 293 | - <label> | 323 | + </label> |
| 294 | - <span>(g::t(lang, K::Role))</span> | 324 | + <label> |
| 295 | - <select name="role"> | 325 | + <span>(g::t(lang, K::Role))</span> |
| 296 | - for role in TEAM_ROLES.iter() { | 326 | + <select name="role"> |
| 297 | - <option value=(role.as_str()) selected=(role.as_str() == data.team_role)>(g::role_name(lang, role.as_str()))</option> | 327 | + for role in TEAM_ROLES.iter() { |
| 328 | + <option value=(role.as_str()) selected=(role.as_str() == data.team_role)>(g::role_name(lang, role.as_str()))</option> | ||
| 329 | + } | ||
| 330 | + </select> | ||
| 331 | + </label> | ||
| 332 | + <label class="inline"> | ||
| 333 | + <input type="checkbox" name="all_repos" value="on" checked=(data.team_all_repos)> | ||
| 334 | + <span>(g::t(lang, K::CoversAllRepos))</span> | ||
| 335 | + </label> | ||
| 336 | + <div> | ||
| 337 | + <button type="submit" class="primary">(g::t(lang, K::SaveTeam))</button> | ||
| 338 | + </div> | ||
| 339 | + </form> | ||
| 340 | + <form method="post" action=(delete_action.as_str()) class="team-form"> | ||
| 341 | + <input type="hidden" name="csrf" value=(csrf.as_str())> | ||
| 342 | + <button type="submit" class="danger">(g::t(lang, K::DeleteTeam))</button> | ||
| 343 | + </form> | ||
| 344 | + } | ||
| 345 | + </section> | ||
| 346 | + <section class="card"> | ||
| 347 | + <h3>(g::t(lang, K::Members))</h3> | ||
| 348 | + if data.members.is_empty() { | ||
| 349 | + <p class="muted">(g::t(lang, K::NoTeamMembers))</p> | ||
| 350 | + } else { | ||
| 351 | + <ul class="item-list"> | ||
| 352 | + for member in data.members.iter() { | ||
| 353 | + <li class="item"> | ||
| 354 | + <div class="item-main"> | ||
| 355 | + <a class="user-link" href=(format!("/{}", member.username.as_str()))> | ||
| 356 | + <img class="avatar avatar-sm" src=(member.avatar.as_str()) alt="" width="24" height="24"> | ||
| 357 | + <span>(member.label.as_str())</span> | ||
| 358 | + </a> | ||
| 359 | + </div> | ||
| 360 | + if owner { | ||
| 361 | + <form method="post" action=(remove_member_action.as_str()) class="remove-form"> | ||
| 362 | + <input type="hidden" name="csrf" value=(csrf.as_str())> | ||
| 363 | + <input type="hidden" name="user_id" value=(member.user_id.as_str())> | ||
| 364 | + <button type="submit">(g::t(lang, K::Remove))</button> | ||
| 365 | + </form> | ||
| 366 | + } | ||
| 367 | + </li> | ||
| 368 | + } | ||
| 369 | + </ul> | ||
| 370 | + } | ||
| 371 | + if owner { | ||
| 372 | + <form method="post" action=(add_member_action.as_str()) class="team-form"> | ||
| 373 | + <input type="hidden" name="csrf" value=(csrf.as_str())> | ||
| 374 | + <input type="text" name="username" placeholder=(g::t(lang, K::Username)) aria-label=(g::t(lang, K::Username)) autocomplete="off" spellcheck="false" required=(true)> | ||
| 375 | + <button type="submit">(g::t(lang, K::AddToTeam))</button> | ||
| 376 | + </form> | ||
| 377 | + } | ||
| 378 | + </section> | ||
| 379 | + <section class="card"> | ||
| 380 | + <h3>(g::t(lang, K::Repositories))</h3> | ||
| 381 | + if data.repos.is_empty() { | ||
| 382 | + <p class="muted">(g::t(lang, K::NoTeamRepos))</p> | ||
| 383 | + } else { | ||
| 384 | + <ul class="item-list"> | ||
| 385 | + for repo in data.repos.iter() { | ||
| 386 | + <li class="item"> | ||
| 387 | + <div class="item-main"> | ||
| 388 | + <a href=(repo.href.as_str())>(repo.title.as_str())</a> | ||
| 389 | + </div> | ||
| 390 | + if owner { | ||
| 391 | + <form method="post" action=(remove_repo_action.as_str()) class="remove-form"> | ||
| 392 | + <input type="hidden" name="csrf" value=(csrf.as_str())> | ||
| 393 | + <input type="hidden" name="repo_id" value=(repo.repo_id.as_str())> | ||
| 394 | + <button type="submit">(g::t(lang, K::Unlink))</button> | ||
| 395 | + </form> | ||
| 396 | + } | ||
| 397 | + </li> | ||
| 398 | + } | ||
| 399 | + </ul> | ||
| 400 | + } | ||
| 401 | + if owner && has_choices { | ||
| 402 | + <form method="post" action=(add_repo_action.as_str()) class="team-form"> | ||
| 403 | + <input type="hidden" name="csrf" value=(csrf.as_str())> | ||
| 404 | + <select name="repo_id" aria-label=(g::t(lang, K::Repository))> | ||
| 405 | + for choice in data.choices.iter() { | ||
| 406 | + <option value=(choice.id.as_str())>(choice.title.as_str())</option> | ||
| 298 | } | 407 | } |
| 299 | </select> | 408 | </select> |
| 300 | - </label> | 409 | + <button type="submit">(g::t(lang, K::LinkRepository))</button> |
| 301 | - <label class="inline"> | 410 | + </form> |
| 302 | - <input type="checkbox" name="all_repos" value="on" checked=(data.team_all_repos)> | 411 | + } |
| 303 | - <span>(g::t(lang, K::CoversAllRepos))</span> | 412 | + </section> |
| 304 | - </label> | 413 | + </div> |
| 305 | - <div> | ||
| 306 | - <button type="submit" class="primary">(g::t(lang, K::SaveTeam))</button> | ||
| 307 | - </div> | ||
| 308 | - </form> | ||
| 309 | - <form method="post" action=(delete_action.as_str()) class="team-form"> | ||
| 310 | - <input type="hidden" name="csrf" value=(csrf.as_str())> | ||
| 311 | - <button type="submit" class="danger">(g::t(lang, K::DeleteTeam))</button> | ||
| 312 | - </form> | ||
| 313 | - } | ||
| 314 | - </section> | ||
| 315 | - <section class="card"> | ||
| 316 | - <h3>(g::t(lang, K::Members))</h3> | ||
| 317 | - if data.members.is_empty() { | ||
| 318 | - <p class="muted">(g::t(lang, K::NoTeamMembers))</p> | ||
| 319 | - } else { | ||
| 320 | - <ul class="item-list"> | ||
| 321 | - for member in data.members.iter() { | ||
| 322 | - <li class="item"> | ||
| 323 | - <div class="item-main"> | ||
| 324 | - <a class="user-link" href=(format!("/{}", member.username.as_str()))> | ||
| 325 | - <img class="avatar avatar-sm" src=(member.avatar.as_str()) alt="" width="24" height="24"> | ||
| 326 | - <span>(member.label.as_str())</span> | ||
| 327 | - </a> | ||
| 328 | - </div> | ||
| 329 | - if owner { | ||
| 330 | - <form method="post" action=(remove_member_action.as_str()) class="remove-form"> | ||
| 331 | - <input type="hidden" name="csrf" value=(csrf.as_str())> | ||
| 332 | - <input type="hidden" name="user_id" value=(member.user_id.as_str())> | ||
| 333 | - <button type="submit">(g::t(lang, K::Remove))</button> | ||
| 334 | - </form> | ||
| 335 | - } | ||
| 336 | - </li> | ||
| 337 | - } | ||
| 338 | - </ul> | ||
| 339 | - } | ||
| 340 | - if owner { | ||
| 341 | - <form method="post" action=(add_member_action.as_str()) class="team-form"> | ||
| 342 | - <input type="hidden" name="csrf" value=(csrf.as_str())> | ||
| 343 | - <input type="text" name="username" placeholder=(g::t(lang, K::Username)) aria-label=(g::t(lang, K::Username)) autocomplete="off" spellcheck="false" required=(true)> | ||
| 344 | - <button type="submit">(g::t(lang, K::AddToTeam))</button> | ||
| 345 | - </form> | ||
| 346 | - } | ||
| 347 | - </section> | ||
| 348 | - <section class="card"> | ||
| 349 | - <h3>(g::t(lang, K::Repositories))</h3> | ||
| 350 | - if data.repos.is_empty() { | ||
| 351 | - <p class="muted">(g::t(lang, K::NoTeamRepos))</p> | ||
| 352 | - } else { | ||
| 353 | - <ul class="item-list"> | ||
| 354 | - for repo in data.repos.iter() { | ||
| 355 | - <li class="item"> | ||
| 356 | - <div class="item-main"> | ||
| 357 | - <a href=(repo.href.as_str())>(repo.title.as_str())</a> | ||
| 358 | - </div> | ||
| 359 | - if owner { | ||
| 360 | - <form method="post" action=(remove_repo_action.as_str()) class="remove-form"> | ||
| 361 | - <input type="hidden" name="csrf" value=(csrf.as_str())> | ||
| 362 | - <input type="hidden" name="repo_id" value=(repo.repo_id.as_str())> | ||
| 363 | - <button type="submit">(g::t(lang, K::Unlink))</button> | ||
| 364 | - </form> | ||
| 365 | - } | ||
| 366 | - </li> | ||
| 367 | - } | ||
| 368 | - </ul> | ||
| 369 | - } | ||
| 370 | - if owner && has_choices { | ||
| 371 | - <form method="post" action=(add_repo_action.as_str()) class="team-form"> | ||
| 372 | - <input type="hidden" name="csrf" value=(csrf.as_str())> | ||
| 373 | - <select name="repo_id" aria-label=(g::t(lang, K::Repository))> | ||
| 374 | - for choice in data.choices.iter() { | ||
| 375 | - <option value=(choice.id.as_str())>(choice.title.as_str())</option> | ||
| 376 | - } | ||
| 377 | - </select> | ||
| 378 | - <button type="submit">(g::t(lang, K::LinkRepository))</button> | ||
| 379 | - </form> | ||
| 380 | - } | ||
| 381 | - </section> | ||
| 382 | }) | 414 | }) |
| 383 | } | 415 | } |
| 384 | 416 | ||
| @@ -402,26 +434,8 @@ async fn org_team_page(cx: &Cx) -> Result<impl View> { | |||
| 402 | username: user.username, | 434 | username: user.username, |
| 403 | }) | 435 | }) |
| 404 | .collect(); | 436 | .collect(); |
| 405 | - // Only the linked repos the viewer may read are named, so a private repo's name stays hidden. | ||
| 406 | let linked = state.store.team_repos(&team.id).await?; | 437 | let linked = state.store.team_repos(&team.id).await?; |
| 407 | - let mut repos: Vec<TeamRepoRow> = Vec::new(); | 438 | + let repos = visible_team_repos(&state.store, &ctx.viewer.0, &linked).await?; |
| 408 | - for repo in linked.iter() { | ||
| 409 | - let role = state | ||
| 410 | - .store | ||
| 411 | - .collaborator_role(&repo.id, &ctx.viewer.0.id) | ||
| 412 | - .await?; | ||
| 413 | - let org_role = state | ||
| 414 | - .store | ||
| 415 | - .org_repo_role(&repo.owner_id, &ctx.viewer.0.id, &repo.id) | ||
| 416 | - .await?; | ||
| 417 | - if authorize(Some(&ctx.viewer.0), repo, role, org_role, Action::Read).is_ok() { | ||
| 418 | - repos.push(TeamRepoRow { | ||
| 419 | - repo_id: repo.id.clone(), | ||
| 420 | - href: repo_href(&repo.owner_name, &repo.name, "", ""), | ||
| 421 | - title: format!("{}/{}", repo.owner_name, repo.name), | ||
| 422 | - }); | ||
| 423 | - } | ||
| 424 | - } | ||
| 425 | let choices: Vec<RepoChoice> = state | 439 | let choices: Vec<RepoChoice> = state |
| 426 | .store | 440 | .store |
| 427 | .list_repos_by_owner(&ctx.org.id) | 441 | .list_repos_by_owner(&ctx.org.id) |
| @@ -438,6 +452,7 @@ async fn org_team_page(cx: &Cx) -> Result<impl View> { | |||
| 438 | org_name: ctx.org.username.clone(), | 452 | org_name: ctx.org.username.clone(), |
| 439 | org_description: ctx.org.about.clone(), | 453 | org_description: ctx.org.about.clone(), |
| 440 | base: ctx.href(&format!("/teams/{}", team.id)), | 454 | base: ctx.href(&format!("/teams/{}", team.id)), |
| 455 | + live: ctx.href(&format!("/teams/{}/events", team.id)), | ||
| 441 | owner: ctx.is_owner(), | 456 | owner: ctx.is_owner(), |
| 442 | csrf: ctx.viewer.1.csrf_token.clone(), | 457 | csrf: ctx.viewer.1.csrf_token.clone(), |
| 443 | team_name: team.name.clone(), | 458 | team_name: team.name.clone(), |
| @@ -465,13 +480,11 @@ async fn org_team_create(cx: &Cx, Form(form): Form<TeamForm>) -> Result<SeeOther | |||
| 465 | let back = ctx.href("/teams"); | 480 | let back = ctx.href("/teams"); |
| 466 | 481 | ||
| 467 | let Some(role) = parse_team_role(&form.role) else { | 482 | let Some(role) = parse_team_role(&form.role) else { |
| 468 | - set_notice(cx, "invalid_role"); | 483 | + return Ok(see_other(notice_href(&back, "invalid_role"))); |
| 469 | - return Ok(see_other(back)); | ||
| 470 | }; | 484 | }; |
| 471 | let description = form.description.trim(); | 485 | let description = form.description.trim(); |
| 472 | if description.chars().count() > MAX_TEAM_DESCRIPTION_CHARS { | 486 | if description.chars().count() > MAX_TEAM_DESCRIPTION_CHARS { |
| 473 | - set_notice(cx, "team_description_length"); | 487 | + return Ok(see_other(notice_href(&back, "team_description_length"))); |
| 474 | - return Ok(see_other(back)); | ||
| 475 | } | 488 | } |
| 476 | let all_repos = !form.all_repos.is_empty(); | 489 | let all_repos = !form.all_repos.is_empty(); |
| 477 | let team = match state | 490 | let team = match state |
| @@ -482,8 +495,7 @@ async fn org_team_create(cx: &Cx, Form(form): Form<TeamForm>) -> Result<SeeOther | |||
| 482 | Ok(team) => team, | 495 | Ok(team) => team, |
| 483 | Err(e) => match team_error_notice(&e) { | 496 | Err(e) => match team_error_notice(&e) { |
| 484 | Some(word) => { | 497 | Some(word) => { |
| 485 | - set_notice(cx, word); | 498 | + return Ok(see_other(notice_href(&back, word))); |
| 486 | - return Ok(see_other(back)); | ||
| 487 | } | 499 | } |
| 488 | None => return Err(e.into()), | 500 | None => return Err(e.into()), |
| 489 | }, | 501 | }, |
| @@ -505,8 +517,8 @@ async fn org_team_create(cx: &Cx, Form(form): Form<TeamForm>) -> Result<SeeOther | |||
| 505 | }), | 517 | }), |
| 506 | ) | 518 | ) |
| 507 | .await; | 519 | .await; |
| 508 | - set_notice(cx, "team_created"); | 520 | + let team_href = ctx.href(&format!("/teams/{}", team.id)); |
| 509 | - Ok(see_other(ctx.href(&format!("/teams/{}", team.id)))) | 521 | + Ok(see_other(notice_href(&team_href, "team_created"))) |
| 510 | } | 522 | } |
| 511 | 523 | ||
| 512 | /// Renames a team and changes its description, role and coverage. Owners only. | 524 | /// Renames a team and changes its description, role and coverage. Owners only. |
| @@ -520,13 +532,11 @@ async fn org_team_update(cx: &Cx, Form(form): Form<TeamForm>) -> Result<SeeOther | |||
| 520 | let back = ctx.href(&format!("/teams/{}", team.id)); | 532 | let back = ctx.href(&format!("/teams/{}", team.id)); |
| 521 | 533 | ||
| 522 | let Some(role) = parse_team_role(&form.role) else { | 534 | let Some(role) = parse_team_role(&form.role) else { |
| 523 | - set_notice(cx, "invalid_role"); | 535 | + return Ok(see_other(notice_href(&back, "invalid_role"))); |
| 524 | - return Ok(see_other(back)); | ||
| 525 | }; | 536 | }; |
| 526 | let description = form.description.trim(); | 537 | let description = form.description.trim(); |
| 527 | if description.chars().count() > MAX_TEAM_DESCRIPTION_CHARS { | 538 | if description.chars().count() > MAX_TEAM_DESCRIPTION_CHARS { |
| 528 | - set_notice(cx, "team_description_length"); | 539 | + return Ok(see_other(notice_href(&back, "team_description_length"))); |
| 529 | - return Ok(see_other(back)); | ||
| 530 | } | 540 | } |
| 531 | let all_repos = !form.all_repos.is_empty(); | 541 | let all_repos = !form.all_repos.is_empty(); |
| 532 | match state | 542 | match state |
| @@ -537,8 +547,7 @@ async fn org_team_update(cx: &Cx, Form(form): Form<TeamForm>) -> Result<SeeOther | |||
| 537 | Ok(()) => {} | 547 | Ok(()) => {} |
| 538 | Err(e) => match team_error_notice(&e) { | 548 | Err(e) => match team_error_notice(&e) { |
| 539 | Some(word) => { | 549 | Some(word) => { |
| 540 | - set_notice(cx, word); | 550 | + return Ok(see_other(notice_href(&back, word))); |
| 541 | - return Ok(see_other(back)); | ||
| 542 | } | 551 | } |
| 543 | None => return Err(e.into()), | 552 | None => return Err(e.into()), |
| 544 | }, | 553 | }, |
| @@ -560,8 +569,7 @@ async fn org_team_update(cx: &Cx, Form(form): Form<TeamForm>) -> Result<SeeOther | |||
| 560 | }), | 569 | }), |
| 561 | ) | 570 | ) |
| 562 | .await; | 571 | .await; |
| 563 | - set_notice(cx, "team_updated"); | 572 | + Ok(see_other(notice_href(&back, "team_updated"))) |
| 564 | - Ok(see_other(back)) | ||
| 565 | } | 573 | } |
| 566 | 574 | ||
| 567 | /// Deletes a team. Owners only. | 575 | /// Deletes a team. Owners only. |
| @@ -587,8 +595,7 @@ async fn org_team_delete(cx: &Cx, Form(form): Form<CsrfForm>) -> Result<SeeOther | |||
| 587 | serde_json::Value::Null, | 595 | serde_json::Value::Null, |
| 588 | ) | 596 | ) |
| 589 | .await; | 597 | .await; |
| 590 | - set_notice(cx, "team_deleted"); | 598 | + Ok(see_other(notice_href(&ctx.href("/teams"), "team_deleted"))) |
| 591 | - Ok(see_other(ctx.href("/teams"))) | ||
| 592 | } | 599 | } |
| 593 | 600 | ||
| 594 | /// Adds an organization member to a team. Owners only. | 601 | /// Adds an organization member to a team. Owners only. |
| @@ -603,26 +610,21 @@ async fn org_team_member_add(cx: &Cx, Form(form): Form<TeamMemberForm>) -> Resul | |||
| 603 | 610 | ||
| 604 | let username = form.username.trim(); | 611 | let username = form.username.trim(); |
| 605 | if username.is_empty() { | 612 | if username.is_empty() { |
| 606 | - set_notice(cx, "empty_username"); | 613 | + return Ok(see_other(notice_href(&back, "empty_username"))); |
| 607 | - return Ok(see_other(back)); | ||
| 608 | } | 614 | } |
| 609 | let Some(target) = state.store.user_by_username(username).await? else { | 615 | let Some(target) = state.store.user_by_username(username).await? else { |
| 610 | - set_notice(cx, "unknown_user"); | 616 | + return Ok(see_other(notice_href(&back, "unknown_user"))); |
| 611 | - return Ok(see_other(back)); | ||
| 612 | }; | 617 | }; |
| 613 | if target.is_org() { | 618 | if target.is_org() { |
| 614 | - set_notice(cx, "unknown_user"); | 619 | + return Ok(see_other(notice_href(&back, "unknown_user"))); |
| 615 | - return Ok(see_other(back)); | ||
| 616 | } | 620 | } |
| 617 | match state.store.add_team_member(&team.id, &target.id).await { | 621 | match state.store.add_team_member(&team.id, &target.id).await { |
| 618 | Ok(()) => {} | 622 | Ok(()) => {} |
| 619 | Err(forge_core::Error::Invalid(_)) => { | 623 | Err(forge_core::Error::Invalid(_)) => { |
| 620 | - set_notice(cx, "not_in_org"); | 624 | + return Ok(see_other(notice_href(&back, "not_in_org"))); |
| 621 | - return Ok(see_other(back)); | ||
| 622 | } | 625 | } |
| 623 | Err(forge_core::Error::Conflict(_)) => { | 626 | Err(forge_core::Error::Conflict(_)) => { |
| 624 | - set_notice(cx, "already_in_team"); | 627 | + return Ok(see_other(notice_href(&back, "already_in_team"))); |
| 625 | - return Ok(see_other(back)); | ||
| 626 | } | 628 | } |
| 627 | Err(e) => return Err(e.into()), | 629 | Err(e) => return Err(e.into()), |
| 628 | } | 630 | } |
| @@ -639,8 +641,7 @@ async fn org_team_member_add(cx: &Cx, Form(form): Form<TeamMemberForm>) -> Resul | |||
| 639 | serde_json::json!({ "user": target.username }), | 641 | serde_json::json!({ "user": target.username }), |
| 640 | ) | 642 | ) |
| 641 | .await; | 643 | .await; |
| 642 | - set_notice(cx, "team_member_added"); | 644 | + Ok(see_other(notice_href(&back, "team_member_added"))) |
| 643 | - Ok(see_other(back)) | ||
| 644 | } | 645 | } |
| 645 | 646 | ||
| 646 | /// Removes a person from a team. Owners only. | 647 | /// Removes a person from a team. Owners only. |
| @@ -668,7 +669,7 @@ async fn org_team_member_remove(cx: &Cx, Form(form): Form<TeamUserForm>) -> Resu | |||
| 668 | serde_json::json!({ "user": user_id }), | 669 | serde_json::json!({ "user": user_id }), |
| 669 | ) | 670 | ) |
| 670 | .await; | 671 | .await; |
| 671 | - set_notice(cx, "team_member_removed"); | 672 | + return Ok(see_other(notice_href(&back, "team_member_removed"))); |
| 672 | } | 673 | } |
| 673 | Ok(see_other(back)) | 674 | Ok(see_other(back)) |
| 674 | } | 675 | } |
| @@ -687,12 +688,10 @@ async fn org_team_repo_add(cx: &Cx, Form(form): Form<TeamRepoForm>) -> Result<Se | |||
| 687 | match state.store.add_team_repo(&team.id, repo_id).await { | 688 | match state.store.add_team_repo(&team.id, repo_id).await { |
| 688 | Ok(()) => {} | 689 | Ok(()) => {} |
| 689 | Err(forge_core::Error::Invalid(_)) => { | 690 | Err(forge_core::Error::Invalid(_)) => { |
| 690 | - set_notice(cx, "not_owned"); | 691 | + return Ok(see_other(notice_href(&back, "not_owned"))); |
| 691 | - return Ok(see_other(back)); | ||
| 692 | } | 692 | } |
| 693 | Err(forge_core::Error::Conflict(_)) => { | 693 | Err(forge_core::Error::Conflict(_)) => { |
| 694 | - set_notice(cx, "already_linked"); | 694 | + return Ok(see_other(notice_href(&back, "already_linked"))); |
| 695 | - return Ok(see_other(back)); | ||
| 696 | } | 695 | } |
| 697 | Err(e) => return Err(e.into()), | 696 | Err(e) => return Err(e.into()), |
| 698 | } | 697 | } |
| @@ -709,8 +708,7 @@ async fn org_team_repo_add(cx: &Cx, Form(form): Form<TeamRepoForm>) -> Result<Se | |||
| 709 | serde_json::json!({ "repo_id": repo_id }), | 708 | serde_json::json!({ "repo_id": repo_id }), |
| 710 | ) | 709 | ) |
| 711 | .await; | 710 | .await; |
| 712 | - set_notice(cx, "team_repo_added"); | 711 | + Ok(see_other(notice_href(&back, "team_repo_added"))) |
| 713 | - Ok(see_other(back)) | ||
| 714 | } | 712 | } |
| 715 | 713 | ||
| 716 | /// Unlinks a repo from a team. Owners only. | 714 | /// Unlinks a repo from a team. Owners only. |
| @@ -738,7 +736,7 @@ async fn org_team_repo_remove(cx: &Cx, Form(form): Form<TeamRepoForm>) -> Result | |||
| 738 | serde_json::json!({ "repo_id": repo_id }), | 736 | serde_json::json!({ "repo_id": repo_id }), |
| 739 | ) | 737 | ) |
| 740 | .await; | 738 | .await; |
| 741 | - set_notice(cx, "team_repo_removed"); | 739 | + return Ok(see_other(notice_href(&back, "team_repo_removed"))); |
| 742 | } | 740 | } |
| 743 | Ok(see_other(back)) | 741 | Ok(see_other(back)) |
| 744 | } | 742 | } |
crates/forge-web/src/test_support.rsmodified+1 -0
| @@ -102,6 +102,7 @@ pub fn app_router(state: AppState) -> Router { | |||
| 102 | .layer(RepoMovedLayer) | 102 | .layer(RepoMovedLayer) |
| 103 | .layer(crate::pages::pull_live::PullWriteLayer) | 103 | .layer(crate::pages::pull_live::PullWriteLayer) |
| 104 | .layer(crate::pages::discussion_live::DiscussionWriteLayer) | 104 | .layer(crate::pages::discussion_live::DiscussionWriteLayer) |
| 105 | + .layer(crate::pages::org_live::OrgWriteLayer) | ||
| 105 | .layer(TowerLayer::new(crate::compression::ResponseCompression)) | 106 | .layer(TowerLayer::new(crate::compression::ResponseCompression)) |
| 106 | .compression(Compression::off()) | 107 | .compression(Compression::off()) |
| 107 | .build() | 108 | .build() |
crates/forge-web/tests/orgs_live_e2e.rsadded+378 -0
| @@ -0,0 +1,378 @@ | |||
| 1 | +//! End-to-end: the organization pages follow their change streams. The real `forge` binary runs | ||
| 2 | +//! with a seeded org (owner tahinli, member bob, a team), and the test drives the writes over HTTP | ||
| 3 | +//! and reads each stream. It also checks that each stream refuses the viewers its page refuses. | ||
| 4 | + | ||
| 5 | +mod common; | ||
| 6 | +use common::{BIN, describe, launch, pick_ports, tool_on_path, write_config}; | ||
| 7 | +use std::path::Path; | ||
| 8 | +use std::process::{Command, Output}; | ||
| 9 | +use std::time::Duration; | ||
| 10 | + | ||
| 11 | +use forge_core::Store; | ||
| 12 | +use forge_core::store::orgs::OrgMemberRole; | ||
| 13 | +use reqwest::header::{COOKIE, HeaderMap, LOCATION, SET_COOKIE}; | ||
| 14 | + | ||
| 15 | +/// Each test starts its own server, so the tests run one at a time. | ||
| 16 | +static SERIAL: std::sync::LazyLock<tokio::sync::Mutex<()>> = | ||
| 17 | + std::sync::LazyLock::new(|| tokio::sync::Mutex::new(())); | ||
| 18 | + | ||
| 19 | +const PW: &str = "tahinli-password-123"; | ||
| 20 | + | ||
| 21 | +struct Resp { | ||
| 22 | + status: u16, | ||
| 23 | + headers: HeaderMap, | ||
| 24 | + body: String, | ||
| 25 | +} | ||
| 26 | + | ||
| 27 | +impl Resp { | ||
| 28 | + fn location(&self) -> Option<String> { | ||
| 29 | + self.headers | ||
| 30 | + .get(LOCATION) | ||
| 31 | + .and_then(|v| v.to_str().ok()) | ||
| 32 | + .map(str::to_owned) | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + fn set_cookies(&self) -> Vec<String> { | ||
| 36 | + self.headers | ||
| 37 | + .get_all(SET_COOKIE) | ||
| 38 | + .iter() | ||
| 39 | + .filter_map(|v| v.to_str().ok().map(str::to_owned)) | ||
| 40 | + .collect() | ||
| 41 | + } | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +struct Http { | ||
| 45 | + client: reqwest::Client, | ||
| 46 | + base: String, | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +impl Http { | ||
| 50 | + fn new(port: u16) -> Self { | ||
| 51 | + let client = reqwest::Client::builder() | ||
| 52 | + .redirect(reqwest::redirect::Policy::none()) | ||
| 53 | + .timeout(Duration::from_secs(60)) | ||
| 54 | + .build() | ||
| 55 | + .expect("http client"); | ||
| 56 | + Self { | ||
| 57 | + client, | ||
| 58 | + base: format!("http://127.0.0.1:{port}"), | ||
| 59 | + } | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + async fn get(&self, path: &str, cookie: Option<&str>) -> Resp { | ||
| 63 | + self.send(self.client.get(format!("{}{path}", self.base)), cookie) | ||
| 64 | + .await | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + async fn post_form(&self, path: &str, form: &[(&str, &str)], cookie: Option<&str>) -> Resp { | ||
| 68 | + self.send( | ||
| 69 | + self.client.post(format!("{}{path}", self.base)).form(form), | ||
| 70 | + cookie, | ||
| 71 | + ) | ||
| 72 | + .await | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + async fn send(&self, req: reqwest::RequestBuilder, cookie: Option<&str>) -> Resp { | ||
| 76 | + let req = match cookie { | ||
| 77 | + Some(cookie) => req.header(COOKIE, cookie), | ||
| 78 | + None => req, | ||
| 79 | + }; | ||
| 80 | + let res = req.send().await.expect("http request"); | ||
| 81 | + let status = res.status().as_u16(); | ||
| 82 | + let headers = res.headers().clone(); | ||
| 83 | + let body = res.text().await.expect("read body"); | ||
| 84 | + Resp { | ||
| 85 | + status, | ||
| 86 | + headers, | ||
| 87 | + body, | ||
| 88 | + } | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + /// Opens a live stream as `cookie`, or anonymously. A stream that opens sends its `retry` | ||
| 92 | + /// field first, which is read here, not treated as an event. | ||
| 93 | + async fn stream(&self, path: &str, cookie: Option<&str>) -> reqwest::Response { | ||
| 94 | + let mut req = self.client.get(format!("{}{path}", self.base)); | ||
| 95 | + if let Some(cookie) = cookie { | ||
| 96 | + req = req.header(COOKIE, cookie); | ||
| 97 | + } | ||
| 98 | + let mut res = req.send().await.expect("stream request"); | ||
| 99 | + if res.status().is_success() { | ||
| 100 | + let retry = tokio::time::timeout(Duration::from_secs(5), res.chunk()) | ||
| 101 | + .await | ||
| 102 | + .expect("the retry field") | ||
| 103 | + .expect("stream chunk") | ||
| 104 | + .expect("stream still open"); | ||
| 105 | + assert!(String::from_utf8_lossy(&retry).contains("retry: 1000")); | ||
| 106 | + } | ||
| 107 | + res | ||
| 108 | + } | ||
| 109 | +} | ||
| 110 | + | ||
| 111 | +/// `name=value` for the cookie whose name ends with `suffix`, ignoring cleared cookies. | ||
| 112 | +fn cookie_named(resp: &Resp, suffix: &str) -> Option<String> { | ||
| 113 | + resp.set_cookies().iter().find_map(|set| { | ||
| 114 | + let pair = set.split(';').next()?; | ||
| 115 | + let (name, value) = pair.split_once('=')?; | ||
| 116 | + (name.ends_with(suffix) && !value.is_empty()).then(|| format!("{name}={value}")) | ||
| 117 | + }) | ||
| 118 | +} | ||
| 119 | + | ||
| 120 | +/// The value of the first `<input name="...">` on a page. | ||
| 121 | +fn input_value(body: &str, name: &str) -> String { | ||
| 122 | + let doc = scraper::Html::parse_document(body); | ||
| 123 | + let selector = scraper::Selector::parse(&format!("input[name=\"{name}\"]")).expect("selector"); | ||
| 124 | + doc.select(&selector) | ||
| 125 | + .next() | ||
| 126 | + .and_then(|el| el.value().attr("value")) | ||
| 127 | + .unwrap_or_else(|| panic!("no input named {name} on page")) | ||
| 128 | + .to_owned() | ||
| 129 | +} | ||
| 130 | + | ||
| 131 | +/// The `data-live` value of the first element that names a stream, if any. | ||
| 132 | +fn live_url(body: &str) -> Option<String> { | ||
| 133 | + let doc = scraper::Html::parse_document(body); | ||
| 134 | + let selector = scraper::Selector::parse("[data-live]").expect("selector"); | ||
| 135 | + doc.select(&selector) | ||
| 136 | + .next() | ||
| 137 | + .and_then(|el| el.value().attr("data-live")) | ||
| 138 | + .map(str::to_owned) | ||
| 139 | +} | ||
| 140 | + | ||
| 141 | +/// Runs an admin subcommand with the password in FORGE_PASSWORD and asserts it succeeded. | ||
| 142 | +fn admin(config: &Path, args: &[&str]) -> Output { | ||
| 143 | + let out = Command::new(BIN) | ||
| 144 | + .arg("--config") | ||
| 145 | + .arg(config) | ||
| 146 | + .arg("admin") | ||
| 147 | + .args(args) | ||
| 148 | + .env("FORGE_PASSWORD", PW) | ||
| 149 | + .output() | ||
| 150 | + .expect("run admin command"); | ||
| 151 | + assert!( | ||
| 152 | + out.status.success(), | ||
| 153 | + "admin {args:?} failed:\n{}", | ||
| 154 | + describe(&out) | ||
| 155 | + ); | ||
| 156 | + out | ||
| 157 | +} | ||
| 158 | + | ||
| 159 | +async fn login(http: &Http, username: &str) -> String { | ||
| 160 | + let page = http.get("/login", None).await; | ||
| 161 | + assert_eq!(page.status, 200, "GET /login"); | ||
| 162 | + let precsrf_cookie = cookie_named(&page, "forge_precsrf").expect("precsrf cookie"); | ||
| 163 | + let precsrf = input_value(&page.body, "precsrf"); | ||
| 164 | + let res = http | ||
| 165 | + .post_form( | ||
| 166 | + "/login", | ||
| 167 | + &[ | ||
| 168 | + ("username", username), | ||
| 169 | + ("password", PW), | ||
| 170 | + ("next", "/"), | ||
| 171 | + ("precsrf", &precsrf), | ||
| 172 | + ], | ||
| 173 | + Some(&precsrf_cookie), | ||
| 174 | + ) | ||
| 175 | + .await; | ||
| 176 | + assert_eq!(res.status, 303, "login as {username}: {}", res.body); | ||
| 177 | + cookie_named(&res, "forge_session").expect("session cookie after login") | ||
| 178 | +} | ||
| 179 | + | ||
| 180 | +/// The session's CSRF token, read from a page every signed-in user can open. | ||
| 181 | +async fn csrf_for(http: &Http, session: &str) -> String { | ||
| 182 | + let page = http.get("/settings/tokens", Some(session)).await; | ||
| 183 | + assert_eq!(page.status, 200, "GET /settings/tokens"); | ||
| 184 | + input_value(&page.body, "csrf") | ||
| 185 | +} | ||
| 186 | + | ||
| 187 | +/// Waits for the next event of a stream, which must be `changed`. | ||
| 188 | +async fn next_changed(res: &mut reqwest::Response, what: &str) { | ||
| 189 | + let chunk = tokio::time::timeout(Duration::from_secs(5), res.chunk()) | ||
| 190 | + .await | ||
| 191 | + .unwrap_or_else(|_| panic!("no event after {what}")) | ||
| 192 | + .expect("stream chunk") | ||
| 193 | + .expect("stream still open"); | ||
| 194 | + let text = String::from_utf8_lossy(&chunk); | ||
| 195 | + assert!(text.contains("event: changed"), "{what}: {text}"); | ||
| 196 | +} | ||
| 197 | + | ||
| 198 | +/// Asserts that nothing arrives on a stream for two seconds. | ||
| 199 | +async fn assert_quiet(res: &mut reqwest::Response, what: &str) { | ||
| 200 | + let got = tokio::time::timeout(Duration::from_secs(2), res.chunk()).await; | ||
| 201 | + assert!(got.is_err(), "{what}: the stream sent an event"); | ||
| 202 | +} | ||
| 203 | + | ||
| 204 | +/// A temp dir short enough for the unix socket path limit. | ||
| 205 | +fn short_temp_dir() -> tempfile::TempDir { | ||
| 206 | + tempfile::Builder::new() | ||
| 207 | + .prefix("orgl") | ||
| 208 | + .tempdir_in("/tmp") | ||
| 209 | + .expect("temp dir") | ||
| 210 | +} | ||
| 211 | + | ||
| 212 | +#[tokio::test] | ||
| 213 | +async fn org_pages_follow_writes_live_and_refuse_outsiders() { | ||
| 214 | + let _guard = SERIAL.lock().await; | ||
| 215 | + if !tool_on_path("git") { | ||
| 216 | + eprintln!("SKIP orgs_live_e2e: `git` was not found on PATH"); | ||
| 217 | + return; | ||
| 218 | + } | ||
| 219 | + let root = short_temp_dir(); | ||
| 220 | + let dir = root.path().to_path_buf(); | ||
| 221 | + let ports = pick_ports(); | ||
| 222 | + let config = write_config(&dir, ports); | ||
| 223 | + | ||
| 224 | + admin(&config, &["create-user", "tahinli", "--admin"]); | ||
| 225 | + for name in ["bob", "carol", "dana"] { | ||
| 226 | + admin(&config, &["create-user", name]); | ||
| 227 | + } | ||
| 228 | + | ||
| 229 | + // Acme is tahinli's org with bob as a member. Carol is added and dana never joins. | ||
| 230 | + { | ||
| 231 | + let store = Store::open(&dir.join("forge.db")) | ||
| 232 | + .await | ||
| 233 | + .expect("open store"); | ||
| 234 | + let tahinli = store | ||
| 235 | + .user_by_username("tahinli") | ||
| 236 | + .await | ||
| 237 | + .unwrap() | ||
| 238 | + .expect("tahinli"); | ||
| 239 | + let bob = store.user_by_username("bob").await.unwrap().expect("bob"); | ||
| 240 | + let acme = store.create_org("acme", &tahinli.id).await.expect("acme"); | ||
| 241 | + store | ||
| 242 | + .add_org_member(&acme.id, &bob.id, OrgMemberRole::Member) | ||
| 243 | + .await | ||
| 244 | + .expect("bob joins acme"); | ||
| 245 | + } | ||
| 246 | + | ||
| 247 | + let (_server, ports) = launch(&dir, ports).await; | ||
| 248 | + let http = Http::new(ports.http); | ||
| 249 | + let tahinli = login(&http, "tahinli").await; | ||
| 250 | + let bob = login(&http, "bob").await; | ||
| 251 | + let dana = login(&http, "dana").await; | ||
| 252 | + let csrf = csrf_for(&http, &tahinli).await; | ||
| 253 | + | ||
| 254 | + // Each page names its stream, and the stream is served at that URL. | ||
| 255 | + let members = http.get("/org/acme/members", Some(&tahinli)).await; | ||
| 256 | + assert_eq!(members.status, 200, "GET members"); | ||
| 257 | + assert_eq!( | ||
| 258 | + live_url(&members.body).as_deref(), | ||
| 259 | + Some("/org/acme/members/events"), | ||
| 260 | + "members page follows its stream" | ||
| 261 | + ); | ||
| 262 | + let teams = http.get("/org/acme/teams", Some(&tahinli)).await; | ||
| 263 | + assert_eq!( | ||
| 264 | + live_url(&teams.body).as_deref(), | ||
| 265 | + Some("/org/acme/teams/events"), | ||
| 266 | + "teams page follows its stream" | ||
| 267 | + ); | ||
| 268 | + let settings = http.get("/org/acme/settings", Some(&tahinli)).await; | ||
| 269 | + assert_eq!( | ||
| 270 | + live_url(&settings.body).as_deref(), | ||
| 271 | + Some("/org/acme/settings/events"), | ||
| 272 | + "settings page follows its stream" | ||
| 273 | + ); | ||
| 274 | + | ||
| 275 | + // Owner streams: members, teams and settings all wake on a write to the org. | ||
| 276 | + let mut members_events = http | ||
| 277 | + .stream("/org/acme/members/events", Some(&tahinli)) | ||
| 278 | + .await; | ||
| 279 | + assert_eq!(members_events.status().as_u16(), 200, "members stream"); | ||
| 280 | + let mut teams_events = http.stream("/org/acme/teams/events", Some(&tahinli)).await; | ||
| 281 | + assert_eq!(teams_events.status().as_u16(), 200, "teams stream"); | ||
| 282 | + let mut settings_events = http | ||
| 283 | + .stream("/org/acme/settings/events", Some(&tahinli)) | ||
| 284 | + .await; | ||
| 285 | + assert_eq!(settings_events.status().as_u16(), 200, "settings stream"); | ||
| 286 | + assert_quiet(&mut members_events, "connecting to the members stream").await; | ||
| 287 | + | ||
| 288 | + // Adding carol wakes the members stream, and the redirect carries the notice in its query. | ||
| 289 | + let res = http | ||
| 290 | + .post_form( | ||
| 291 | + "/org/acme/members/add", | ||
| 292 | + &[("csrf", &csrf), ("username", "carol"), ("role", "member")], | ||
| 293 | + Some(&tahinli), | ||
| 294 | + ) | ||
| 295 | + .await; | ||
| 296 | + assert_eq!(res.status, 303, "owner adds carol: {}", res.body); | ||
| 297 | + assert!( | ||
| 298 | + res.location() | ||
| 299 | + .unwrap_or_default() | ||
| 300 | + .ends_with("?notice=member_added"), | ||
| 301 | + "the redirect names the notice" | ||
| 302 | + ); | ||
| 303 | + next_changed(&mut members_events, "adding carol").await; | ||
| 304 | + let shown = http.get("/org/acme/members", Some(&tahinli)).await; | ||
| 305 | + assert!(shown.body.contains("href=\"/carol\""), "carol listed"); | ||
| 306 | + | ||
| 307 | + // Creating a team wakes the teams list. | ||
| 308 | + let res = http | ||
| 309 | + .post_form( | ||
| 310 | + "/org/acme/teams/new", | ||
| 311 | + &[ | ||
| 312 | + ("csrf", &csrf), | ||
| 313 | + ("name", "writers"), | ||
| 314 | + ("description", ""), | ||
| 315 | + ("role", "write"), | ||
| 316 | + ], | ||
| 317 | + Some(&tahinli), | ||
| 318 | + ) | ||
| 319 | + .await; | ||
| 320 | + assert_eq!(res.status, 303, "create team: {}", res.body); | ||
| 321 | + next_changed(&mut teams_events, "creating a team").await; | ||
| 322 | + | ||
| 323 | + // Saving the settings wakes the settings stream. | ||
| 324 | + let res = http | ||
| 325 | + .post_form( | ||
| 326 | + "/org/acme/settings", | ||
| 327 | + &[ | ||
| 328 | + ("csrf", &csrf), | ||
| 329 | + ("description", "Anvils"), | ||
| 330 | + ("default_repo_role", "read"), | ||
| 331 | + ], | ||
| 332 | + Some(&tahinli), | ||
| 333 | + ) | ||
| 334 | + .await; | ||
| 335 | + assert_eq!(res.status, 303, "save settings: {}", res.body); | ||
| 336 | + next_changed(&mut settings_events, "saving the settings").await; | ||
| 337 | + | ||
| 338 | + // The notice is still in the URL after a live refresh reads the same page again, so the | ||
| 339 | + // refreshed page shows it: a read does not use it up. | ||
| 340 | + let location = res.location().expect("settings redirect"); | ||
| 341 | + let first = http.get(&location, Some(&tahinli)).await; | ||
| 342 | + let again = http.get(&location, Some(&tahinli)).await; | ||
| 343 | + assert!( | ||
| 344 | + first.body.contains("Settings saved."), | ||
| 345 | + "notice on first view" | ||
| 346 | + ); | ||
| 347 | + assert!( | ||
| 348 | + again.body.contains("Settings saved."), | ||
| 349 | + "notice survives a re-read" | ||
| 350 | + ); | ||
| 351 | + | ||
| 352 | + // Access: a non-member gets 404 on the members stream, a member who is not an owner gets 403 | ||
| 353 | + // on the settings stream, and an anonymous viewer gets no stream at all. | ||
| 354 | + let outsider = http.stream("/org/acme/members/events", Some(&dana)).await; | ||
| 355 | + assert_eq!(outsider.status().as_u16(), 404, "non-member members stream"); | ||
| 356 | + let outsider = http.stream("/org/acme/teams/events", Some(&dana)).await; | ||
| 357 | + assert_eq!(outsider.status().as_u16(), 404, "non-member teams stream"); | ||
| 358 | + let member = http.stream("/org/acme/settings/events", Some(&bob)).await; | ||
| 359 | + assert_eq!(member.status().as_u16(), 403, "member settings stream"); | ||
| 360 | + let anonymous = http.stream("/org/acme/members/events", None).await; | ||
| 361 | + assert!( | ||
| 362 | + !anonymous.status().is_success(), | ||
| 363 | + "anonymous members stream is refused" | ||
| 364 | + ); | ||
| 365 | + | ||
| 366 | + // Bob is a member, so he follows the members stream and sees writes to it. | ||
| 367 | + let mut bob_members = http.stream("/org/acme/members/events", Some(&bob)).await; | ||
| 368 | + assert_eq!(bob_members.status().as_u16(), 200, "member members stream"); | ||
| 369 | + let res = http | ||
| 370 | + .post_form( | ||
| 371 | + "/org/acme/members/add", | ||
| 372 | + &[("csrf", &csrf), ("username", "dana"), ("role", "member")], | ||
| 373 | + Some(&tahinli), | ||
| 374 | + ) | ||
| 375 | + .await; | ||
| 376 | + assert_eq!(res.status, 303, "owner adds dana: {}", res.body); | ||
| 377 | + next_changed(&mut bob_members, "adding dana").await; | ||
| 378 | +} | ||
crates/forge-web/tests/orgs_ui_e2e.rsmodified+16 -23
| @@ -19,8 +19,6 @@ static SERIAL: std::sync::LazyLock<tokio::sync::Mutex<()>> = | |||
| 19 | std::sync::LazyLock::new(|| tokio::sync::Mutex::new(())); | 19 | std::sync::LazyLock::new(|| tokio::sync::Mutex::new(())); |
| 20 | 20 | ||
| 21 | const PW: &str = "tahinli-password-123"; | 21 | const PW: &str = "tahinli-password-123"; |
| 22 | -/// The one-shot notice cookie of the org pages. | ||
| 23 | -const ORG_NOTICE: &str = "forge_org_notice"; | ||
| 24 | 22 | ||
| 25 | struct Resp { | 23 | struct Resp { |
| 26 | status: u16, | 24 | status: u16, |
| @@ -191,10 +189,10 @@ fn init_bare(data_dir: &Path, repo_id: &str) { | |||
| 191 | assert!(out.status.success(), "git init --bare: {}", describe(&out)); | 189 | assert!(out.status.success(), "git init --bare: {}", describe(&out)); |
| 192 | } | 190 | } |
| 193 | 191 | ||
| 194 | -/// The org notice cookie from a redirect, joined with the session cookie for the next GET. | 192 | +/// The redirect target of a write, which carries the notice in its query: the next GET of it shows the |
| 195 | -fn with_org_notice(session: &str, redirect: &Resp) -> String { | 193 | +/// notice. |
| 196 | - let notice = cookie_named(redirect, ORG_NOTICE).expect("org notice cookie"); | 194 | +fn notice_location(redirect: &Resp) -> String { |
| 197 | - format!("{session}; {notice}") | 195 | + redirect.header(LOCATION).expect("notice redirect") |
| 198 | } | 196 | } |
| 199 | 197 | ||
| 200 | /// A temp dir short enough for the unix socket path limit. | 198 | /// A temp dir short enough for the unix socket path limit. |
| @@ -320,10 +318,11 @@ async fn org_members_teams_and_access_end_to_end() { | |||
| 320 | ) | 318 | ) |
| 321 | .await; | 319 | .await; |
| 322 | assert_eq!(res.status, 303, "owner adds carol: {}", res.body); | 320 | assert_eq!(res.status, 303, "owner adds carol: {}", res.body); |
| 323 | - assert_eq!(res.header(LOCATION).as_deref(), Some(members)); | 321 | + assert!( |
| 324 | - let shown = http | 322 | + notice_location(&res).starts_with(&format!("{members}?notice=member_added")), |
| 325 | - .get(members, Some(&with_org_notice(&tahinli, &res))) | 323 | + "the redirect carries the notice" |
| 326 | - .await; | 324 | + ); |
| 325 | + let shown = http.get(¬ice_location(&res), Some(&tahinli)).await; | ||
| 327 | assert!(shown.body.contains("Member added."), "notice after add"); | 326 | assert!(shown.body.contains("Member added."), "notice after add"); |
| 328 | assert!(shown.body.contains("href=\"/carol\""), "carol listed"); | 327 | assert!(shown.body.contains("href=\"/carol\""), "carol listed"); |
| 329 | assert_eq!( | 328 | assert_eq!( |
| @@ -341,9 +340,7 @@ async fn org_members_teams_and_access_end_to_end() { | |||
| 341 | ) | 340 | ) |
| 342 | .await; | 341 | .await; |
| 343 | assert_eq!(res.status, 303, "leave is answered with a redirect"); | 342 | assert_eq!(res.status, 303, "leave is answered with a redirect"); |
| 344 | - let shown = http | 343 | + let shown = http.get(¬ice_location(&res), Some(&tahinli)).await; |
| 345 | - .get(members, Some(&with_org_notice(&tahinli, &res))) | ||
| 346 | - .await; | ||
| 347 | assert!( | 344 | assert!( |
| 348 | shown | 345 | shown |
| 349 | .body | 346 | .body |
| @@ -398,9 +395,7 @@ async fn org_members_teams_and_access_end_to_end() { | |||
| 398 | ) | 395 | ) |
| 399 | .await; | 396 | .await; |
| 400 | assert_eq!(res.status, 303, "refused add still redirects"); | 397 | assert_eq!(res.status, 303, "refused add still redirects"); |
| 401 | - let shown = http | 398 | + let shown = http.get(¬ice_location(&res), Some(&tahinli)).await; |
| 402 | - .get(&team_page, Some(&with_org_notice(&tahinli, &res))) | ||
| 403 | - .await; | ||
| 404 | assert!( | 399 | assert!( |
| 405 | shown | 400 | shown |
| 406 | .body | 401 | .body |
| @@ -511,9 +506,7 @@ async fn org_settings_delete_and_audit_end_to_end() { | |||
| 511 | ) | 506 | ) |
| 512 | .await; | 507 | .await; |
| 513 | assert_eq!(res.status, 303, "save settings: {}", res.body); | 508 | assert_eq!(res.status, 303, "save settings: {}", res.body); |
| 514 | - let shown = http | 509 | + let shown = http.get(¬ice_location(&res), Some(&tahinli)).await; |
| 515 | - .get(settings, Some(&with_org_notice(&tahinli, &res))) | ||
| 516 | - .await; | ||
| 517 | assert!(shown.body.contains("Settings saved."), "saved notice"); | 510 | assert!(shown.body.contains("Settings saved."), "saved notice"); |
| 518 | assert!(shown.body.contains("Anvils and more"), "description saved"); | 511 | assert!(shown.body.contains("Anvils and more"), "description saved"); |
| 519 | assert_eq!( | 512 | assert_eq!( |
| @@ -531,9 +524,7 @@ async fn org_settings_delete_and_audit_end_to_end() { | |||
| 531 | ) | 524 | ) |
| 532 | .await; | 525 | .await; |
| 533 | assert_eq!(res.status, 303, "refused delete still redirects"); | 526 | assert_eq!(res.status, 303, "refused delete still redirects"); |
| 534 | - let shown = http | 527 | + let shown = http.get(¬ice_location(&res), Some(&tahinli)).await; |
| 535 | - .get(settings, Some(&with_org_notice(&tahinli, &res))) | ||
| 536 | - .await; | ||
| 537 | assert!( | 528 | assert!( |
| 538 | shown.body.contains("Transfer or delete the organization"), | 529 | shown.body.contains("Transfer or delete the organization"), |
| 539 | "repos block the delete" | 530 | "repos block the delete" |
| @@ -802,7 +793,9 @@ async fn org_member_pushes_over_https_through_a_write_team() { | |||
| 802 | ) | 793 | ) |
| 803 | .await; | 794 | .await; |
| 804 | assert_eq!(res.status, 303, "create writers: {}", res.body); | 795 | assert_eq!(res.status, 303, "create writers: {}", res.body); |
| 805 | - let team_url = res.header(LOCATION).expect("team location"); | 796 | + // The redirect carries the notice in its query. The team's own path is what follows. |
| 797 | + let location = res.header(LOCATION).expect("team location"); | ||
| 798 | + let team_url = location.split('?').next().expect("team path").to_owned(); | ||
| 806 | let team = http.get(&team_url, Some(&tahinli)).await; | 799 | let team = http.get(&team_url, Some(&tahinli)).await; |
| 807 | assert_eq!(team.status, 200, "team page"); | 800 | assert_eq!(team.status, 200, "team page"); |
| 808 | let repo_id = first_option(&team.body, "repo_id"); | 801 | let repo_id = first_option(&team.body, "repo_id"); |
docs/architecture.mdmodified+6 -0
| @@ -262,6 +262,12 @@ Pages update without a reload. A write that changes what a page shows calls `Liv | |||
| 262 | | Explore `/explore` | `/explore/events`, with the search, sort and page | the public listing | | 262 | | Explore `/explore` | `/explore/events`, with the search, sort and page | the public listing | |
| 263 | | Wiki `/{owner}/{repo}/wiki`, page list, a page and its history | `/{owner}/{repo}/wiki/-/events` (home and list), `/{owner}/{repo}/wiki/{page}/events` (a page and its history) | the repo's wiki: a web save, or a push to the wiki repo | | 263 | | Wiki `/{owner}/{repo}/wiki`, page list, a page and its history | `/{owner}/{repo}/wiki/-/events` (home and list), `/{owner}/{repo}/wiki/{page}/events` (a page and its history) | the repo's wiki: a web save, or a push to the wiki repo | |
| 264 | | Snippets `/snippets`, a snippet and its revisions | `/snippets/events` (list), `/snippets/{id}/events` (one snippet) | the snippet list and the snippet; a private snippet answers 404 to everyone but its owner | | 264 | | Snippets `/snippets`, a snippet and its revisions | `/snippets/events` (list), `/snippets/{id}/events` (one snippet) | the snippet list and the snippet; a private snippet answers 404 to everyone but its owner | |
| 265 | +| Org members `/org/{org}/members` | `/org/{org}/members/events` | the org (members, roles, description) | | ||
| 266 | +| Org teams `/org/{org}/teams` | `/org/{org}/teams/events` | the org (teams and their coverage) | | ||
| 267 | +| Org team `/org/{org}/teams/{team}` | `/org/{org}/teams/{team}/events` | the org (members, linked repos) and each linked repo (name, visibility) | | ||
| 268 | +| Org settings `/org/{org}/settings` | `/org/{org}/settings/events` | the org (description, default repo role, member repo creation) | | ||
| 269 | + | ||
| 270 | +The org streams follow the same access as their pages: a non-member gets 404, and a member who is not an owner gets 403 on the settings stream. A team page names only the linked repos the viewer may read. Each org write (a POST under `/org/{org}/members`, `teams` or `settings`) wakes the org's streams. The org notices (for example "Member added.") are carried in the redirect's `?notice=` query, not a cookie, so a live refresh of the page shows the same notice again. | ||
| 265 | 271 | ||
| 266 | The user topics are keyed by user id, and their streams take the viewer from the session, so no URL names another user's inbox. Repo streams follow the same visibility as the repo page (a private repo answers 404 to a viewer who cannot read it). Explore lists public repos only. | 272 | The user topics are keyed by user id, and their streams take the viewer from the session, so no URL names another user's inbox. Repo streams follow the same visibility as the repo page (a private repo answers 404 to a viewer who cannot read it). Explore lists public repos only. |
| 267 | 273 | ||