From b7cbe5fdfdb10aa525ac20f501866ee28ec1e1f3 Mon Sep 17 00:00:00 2001 From: Nam Rodriguez Date: Tue, 3 Nov 2026 14:48:40 -0500 Subject: [PATCH] Hybrid: every Other apps tool uses CoderHelm's app by default Jira, Notion, Confluence and Google Drive now default to CoderHelm's app on a hybrid install, on a new install and on one that registered before. An explicit choice of the install's own app is kept: choices are stored per tool, a record from before reads its explicit picks once, and a tool for which the install has its own app set up keeps it until someone picks CoderHelm's. The install guide's choices arrive as apps on the setup settings call and are applied when the install registers. Only which app a sign-in goes through changes; nothing connects or syncs until someone connects the tool. --- docs/self-host/hybrid.md | 13 +- docs/self-host/setup-checks.md | 2 +- services/common/src/hybrid/integrations.rs | 11 + services/gateway/src/routes/hybrid_install.rs | 350 ++++++++++++++++-- 4 files changed, 337 insertions(+), 39 deletions(-) diff --git a/docs/self-host/hybrid.md b/docs/self-host/hybrid.md index e433d7c9f..857cc90af 100644 --- a/docs/self-host/hybrid.md +++ b/docs/self-host/hybrid.md @@ -13,7 +13,9 @@ A **hybrid** install runs entirely in your AWS account, like any self-hosted Cod | **CoderHelm's Jira app**, through the event relay | setting up your own Jira app | link your Jira site once; its events arrive at your install, without the app's secret | | **CoderHelm's integration apps** (Notion, Confluence, Google Drive) | registering an app with each provider | sign in with one click, as on coderhelm.com | -Each part is a separate choice, at install time (the [install guide](/self-host/install/)) or later in **Settings, System, Hybrid**. **Fully private** (your own domain or the AWS address, your own GitHub App and apps) stays the default and sends nothing to CoderHelm. +Each part is a separate choice, at install time (the [install guide](/self-host/install/)) or later in **Settings, System, Hybrid**. **Fully private** (your own domain or the AWS address, your own GitHub App and apps) sends nothing to CoderHelm and needs no registration. + +On a hybrid install, every tool under **Other apps** (Jira, Notion, Confluence, Google Drive) uses CoderHelm's app unless you choose **Use my own app (fully private)** for it ([Other apps](#other-apps)). That only decides which app a sign-in goes through: nothing reaches your install or CoderHelm until someone connects the tool. ## Trust model @@ -124,6 +126,15 @@ The **Jira app relay** above is the other way round: a Jira site whose own Jira The Setup checks show the link as `hybrid_jira` (in Settings, Setup and the install guide's `/api/setup/status`): `no_link` (todo) until it is linked, `syncing` (wait) while your install fetches the proxy settings, `ok` once linked. Linking needs an install admin, so `/api/setup/status` keeps reporting this one check (its code only) after someone has signed up, while Link through CoderHelm is on. +## Other apps + +**Settings, System, Hybrid, Other apps** lists each tool with **Use Coderhelm's app (easiest)** or **Use my own app (fully private)**, and one line on what passes through CoderHelm for it. The install guide offers the same choices under **What CoderHelm sets up for you**, all on, and applies them when the install registers. + +- **CoderHelm's app is the default** for each tool nobody chose, on a new install and on an install that registered before these choices existed. A tool for which your install already has its own app set up (its own Notion, Atlassian or Google client in its secret) keeps using that until you pick CoderHelm's. +- **A choice is kept.** Picking **Use my own app** for a tool, in Settings or the guide, stays until you change it. An install whose admin had already turned some tools on under Other apps keeps the others on its own app. +- **Nothing starts by itself.** With CoderHelm's app chosen, **Connect** on that tool signs in through CoderHelm's app; until someone connects, no sign-in exists, no event is relayed and nothing is synced. Jira events come through only once CoderHelm's Jira app is installed on your site with your install id, or a site is linked. +- **A tool CoderHelm can't offer yet** (its app for that provider isn't set up on the hosted side) shows **Coderhelm's app isn't set up yet** and uses your own app until it is. + ## Integrations | Integration | Through CoderHelm's app | Notes | diff --git a/docs/self-host/setup-checks.md b/docs/self-host/setup-checks.md index e02936360..af1fe8062 100644 --- a/docs/self-host/setup-checks.md +++ b/docs/self-host/setup-checks.md @@ -25,7 +25,7 @@ The guide's checks come from the install's public `GET /api/setup/status`, the s - `domain`: when you chose your own domain, the guide shows a Domain step between AWS and GitHub, checks until the code is `ok`, then follows the install to the domain (so the GitHub App gets the domain's URLs). The records to add are in Settings, then System. You can skip it and add the domain later there. - `github_manifest_ready`: one click when true; the terminal command (`pull`, then `github-app`) when false. - `setup_open: false` (someone has signed up): the install is shown as ready. A hybrid install with **Link through CoderHelm** on still reports `hybrid_jira` then, because linking a Jira site needs an install admin: the guide's Jira step follows it until `ok`. -- `POST /api/setup/hybrid/settings` (with the setup key, while nobody has signed up) takes `github_mode`, `sharing` and `jira_link`; the guide sends `jira_link: true` when **Use CoderHelm's Jira app** is on, so the install reports `hybrid_jira` from then on. +- `POST /api/setup/hybrid/settings` (with the setup key, while nobody has signed up) takes `github_mode`, `sharing`, `jira_link` and `apps` (per tool, `{"jira": "coderhelm" | "own", "notion": …, "confluence": …, "google_drive": …}`); the guide sends `jira_link: true` when **Use CoderHelm's Jira app** is on, so the install reports `hybrid_jira` from then on, and `apps` with each **Other apps** choice (all `coderhelm` unless turned off). The answer carries no ids or URLs, so the guide makes its own links: the Bedrock console for the region it launched in, the models a new install calls (the release's defaults with the region's inference profile prefix), the SES console for that region, and `https://github.com/apps//installations/new` from the slug the manifest landing hands back. diff --git a/services/common/src/hybrid/integrations.rs b/services/common/src/hybrid/integrations.rs index 3305537a0..3c58b337c 100644 --- a/services/common/src/hybrid/integrations.rs +++ b/services/common/src/hybrid/integrations.rs @@ -124,6 +124,13 @@ pub fn hosted_ids() -> impl Iterator { .map(|e| e.id) } +/// The tools an install picks an app for, one by one (Settings, System, +/// Hybrid, Other apps, and the install guide): every hosted one but GitHub, +/// which has its own choice. +pub fn app_choice_ids() -> impl Iterator { + hosted_ids().filter(|id| *id != "github") +} + #[cfg(test)] mod tests { use super::*; @@ -153,6 +160,10 @@ mod tests { ids, vec!["github", "jira", "notion", "confluence", "google_drive"] ); + assert_eq!( + app_choice_ids().collect::>(), + vec!["jira", "notion", "confluence", "google_drive"] + ); assert!(entry("github").is_some() && entry("nope").is_none()); let j = serde_json::to_value(entry("slack_commands").unwrap()).unwrap(); assert_eq!(j["mode"], "unavailable"); diff --git a/services/gateway/src/routes/hybrid_install.rs b/services/gateway/src/routes/hybrid_install.rs index 5ad2afa0a..b6eab18d9 100644 --- a/services/gateway/src/routes/hybrid_install.rs +++ b/services/gateway/src/routes/hybrid_install.rs @@ -16,6 +16,7 @@ //! The registration (id, secret, relay key) lives in the install's own //! secret; everything else here is the `SYSTEM`/`HYBRID` settings item. +use std::collections::BTreeMap; use std::sync::{Arc, Mutex, RwLock}; use std::time::{Duration, Instant}; @@ -73,9 +74,25 @@ pub struct Local { /// `own` (the install's GitHub App) or `hosted` (CoderHelm's, relayed). #[serde(default)] pub github_mode: String, - /// Integrations using CoderHelm's apps (common::hybrid::integrations). + /// Integrations using CoderHelm's apps (common::hybrid::integrations), as + /// CoderHelm last accepted them. Worked out from `github_mode` and + /// `apps` ([`wanted_integrations`]), never set by hand. #[serde(default)] pub integrations: Vec, + /// Other apps, per tool (`integrations::app_choice_ids`): `coderhelm` or + /// `own`, as someone chose it in Settings or the install guide. A tool + /// with no entry was never chosen and uses CoderHelm's app, unless this + /// install has its own app for it set up. + #[serde(default)] + pub apps: BTreeMap, + /// 1 once `apps` holds the choices. A record from before (0) kept them + /// only in `integrations`; [`migrate_apps`] reads them from there once. + #[serde(default)] + pub apps_v: u8, + /// The `integrations` last asked of CoderHelm (it may accept fewer: + /// only what it offers), so the same list isn't sent again. + #[serde(default)] + pub apps_sent: Vec, #[serde(default)] pub sharing: bool, #[serde(default)] @@ -361,6 +378,9 @@ pub(crate) async fn do_register(state: &AppState) -> Result, + /// Other apps, per tool: `{ "notion": "coderhelm" | "own", ... }`. Only + /// the tools named change. + #[serde(default)] + pub apps: Option>, } #[derive(Deserialize, Default, Clone)] @@ -597,17 +621,34 @@ pub fn apply_settings(l: &mut Local, b: &SettingsBody) -> Result<(), &'static st } } if let Some(list) = &b.integrations { + // The whole list (from a dashboard before `apps`): only the tools it + // switches on or off become a choice. let allowed: Vec<&str> = integrations::hosted_ids().collect(); - if let Some(bad) = list.iter().find(|i| !allowed.contains(&i.as_str())) { - let _ = bad; + if list.iter().any(|i| !allowed.contains(&i.as_str())) { return Err("an integration that can't use CoderHelm's app"); } - l.integrations = list.clone(); + for id in integrations::app_choice_ids() { + let listed = list.iter().any(|i| i == id); + let on = l.integrations.iter().any(|i| i == id); + if listed && !on { + l.apps.insert(id.into(), "coderhelm".into()); + } else if !listed && on { + l.apps.insert(id.into(), "own".into()); + } + } } - // GitHub through CoderHelm's app is the "github" integration. - l.integrations.retain(|i| i != "github"); - if l.github_mode == "hosted" { - l.integrations.insert(0, "github".into()); + if let Some(apps) = &b.apps { + for (id, v) in apps { + if !integrations::app_choice_ids().any(|x| x == id) { + return Err("an integration that can't use CoderHelm's app"); + } + if v != "coderhelm" && v != "own" { + return Err("each app is coderhelm or own"); + } + } + for (id, v) in apps { + l.apps.insert(id.clone(), v.clone()); + } } if let Some(s) = &b.sharing { l.sharing = s.enabled; @@ -625,6 +666,7 @@ async fn do_settings( ) -> Result)> { let mut l = local(state).await; let was_linking = l.jira_link; + migrate_apps(&mut l, None); apply_settings(&mut l, b).map_err(|m| fail(StatusCode::BAD_REQUEST, "bad_settings", m))?; if l.jira_link && creds_now().await.is_none() { return Err(not_registered()); @@ -634,22 +676,147 @@ async fn do_settings( jira_unlink_now(state, &mut l).await?; } if let Some(c) = creds_now().await { - client::call( + let want = wanted_integrations(&l, |id| own_app_set(state, id)); + let v = client::call( &state.http, &c, "PUT", "/hybrid/settings", - Some(&json!({ "integrations": l.integrations, "sharing": { "enabled": l.sharing, "payloads": l.share_payloads } })), + Some(&json!({ "integrations": want, "sharing": { "enabled": l.sharing, "payloads": l.share_payloads } })), ) .await .map_err(from_call)?; - } else if !l.integrations.is_empty() || l.sharing { + l.integrations = strings(&v["integrations"]).unwrap_or_else(|| want.clone()); + l.apps_sent = want; + } else if l.github_mode == "hosted" || l.sharing { return Err(not_registered()); } save_local(state, &l).await?; Ok(l) } +/// A JSON array of strings, if it is one. +fn strings(v: &Value) -> Option> { + v.as_array().map(|a| { + a.iter() + .filter_map(Value::as_str) + .map(str::to_string) + .collect() + }) +} + +/// Does this install have its own app set up for a tool (its own Notion, +/// Atlassian or Google client in its secret)? Then a tool nobody chose for +/// keeps using it. +fn own_app_set(state: &AppState, id: &str) -> bool { + common::knowledge::sources::Kind::parse(id) + .is_some_and(|k| super::knowledge_sources::app(state, k).is_set()) +} + +/// Does `id` use CoderHelm's app: as chosen, or by default (CoderHelm's, +/// unless the install has its own app for it set up). Pure; tested. +pub fn uses_coderhelm(l: &Local, id: &str, own_app_set: impl Fn(&str) -> bool) -> bool { + match l.apps.get(id).map(String::as_str) { + Some("own") => false, + Some(_) => true, + None => !own_app_set(id), + } +} + +/// The integrations to ask CoderHelm for: GitHub when its mode is hosted, +/// then each Other apps tool that uses CoderHelm's app. Pure; tested. +pub fn wanted_integrations(l: &Local, own_app_set: impl Fn(&str) -> bool) -> Vec { + let mut out = vec![]; + if l.github_mode == "hosted" { + out.push("github".to_string()); + } + out.extend( + integrations::app_choice_ids() + .filter(|id| uses_coderhelm(l, id, &own_app_set)) + .map(str::to_string), + ); + out +} + +/// A record from before per-tool choices kept them only as the list. If that +/// list names any Other apps tool, someone chose there: each tool on it is +/// CoderHelm's app, and each one CoderHelm offered but isn't on it is their +/// own. A list with none was never chosen, so every tool takes the default. +/// True when the record changed. Pure; tested. +pub fn migrate_apps(l: &mut Local, offered: Option<&[String]>) -> bool { + if l.apps_v >= 1 { + return false; + } + l.apps_v = 1; + let on = |id: &str| l.integrations.iter().any(|i| i == id); + if integrations::app_choice_ids().any(on) { + let picks: Vec<(String, String)> = integrations::app_choice_ids() + .filter_map(|id| { + if on(id) { + Some((id.into(), "coderhelm".into())) + } else if offered.is_none_or(|o| o.iter().any(|x| x == id)) { + Some((id.into(), "own".into())) + } else { + None + } + }) + .collect(); + l.apps.extend(picks); + } + true +} + +fn same_set(a: &[String], b: &[String]) -> bool { + let mut a = a.to_vec(); + let mut b = b.to_vec(); + a.sort(); + b.sort(); + a == b +} + +/// Should the wanted list be sent to CoderHelm again: it changed since it +/// was last sent, or CoderHelm holds something else than this install +/// thinks. Pure; tested. +pub fn apps_out_of_date(l: &Local, want: &[String], hosted_now: Option<&[String]>) -> bool { + !same_set(want, &l.apps_sent) || hosted_now.is_some_and(|h| !same_set(h, &l.integrations)) +} + +/// Brings the integrations CoderHelm holds in line with the choices (and +/// the defaults for the tools nobody chose). Only which app a sign-in goes +/// through changes: nothing is connected or synced here. +async fn sync_apps(state: &AppState, l: &mut Local, hosted: Option<&Value>) { + let offered = offered_by(hosted); + let mut changed = migrate_apps(l, offered.as_deref()); + let mut want = wanted_integrations(l, |id| own_app_set(state, id)); + if let Some(o) = &offered { + want.retain(|i| o.contains(i)); + } + let hosted_now = hosted.and_then(|h| strings(&h["integrations"])); + if apps_out_of_date(l, &want, hosted_now.as_deref()) { + if let Some(c) = creds_now().await { + match client::call( + &state.http, + &c, + "PUT", + "/hybrid/settings", + Some(&json!({ "integrations": want, "sharing": { "enabled": l.sharing, "payloads": l.share_payloads } })), + ) + .await + { + Ok(v) => { + l.integrations = strings(&v["integrations"]).unwrap_or_else(|| want.clone()); + l.apps_sent = want; + changed = true; + } + Err(e) => warn!(code = %e.code, "hybrid: app choices not sent"), + } + } + } + if changed { + let _ = save_local(state, l).await; + } +} + // ── Status and checks ──────────────────────────────────────────────────── /// One hybrid check: id, status, code, plain title and fix. @@ -780,17 +947,6 @@ pub fn offered_by(hosted: Option<&Value>) -> Option> { }) } -/// Drops chosen integrations the hosted side doesn't offer; true when any -/// were dropped (pure; tested). -pub fn drop_unoffered(l: &mut Local, offered: Option<&[String]>) -> bool { - let Some(o) = offered else { - return false; - }; - let before = l.integrations.len(); - l.integrations.retain(|i| o.iter().any(|x| x == i)); - l.integrations.len() != before -} - async fn status_value(state: &AppState, deep: bool) -> Value { let mut l = local(state).await; let creds = creds_now().await; @@ -853,14 +1009,22 @@ async fn status_value(state: &AppState, deep: bool) -> Value { // app for that provider isn't set up) is dropped, so the add flow never // offers a sign-in the broker would refuse. let offered = offered_by(hosted.as_ref()); - if drop_unoffered(&mut l, offered.as_deref()) { - let _ = save_local(state, &l).await; + if creds.is_some() { + sync_apps(state, &mut l, hosted.as_ref()).await; } let chosen: Vec = integrations::CATALOG .iter() .map(|e| { let mut v = serde_json::to_value(e).unwrap_or_default(); - v["uses_coderhelm"] = json!(l.integrations.iter().any(|i| i == e.id)); + // Registered: what CoderHelm holds. Not yet: what registering applies. + let uses = if creds.is_some() { + l.integrations.iter().any(|i| i == e.id) + } else { + wanted_integrations(&l, |id| own_app_set(state, id)) + .iter() + .any(|i| i == e.id) + }; + v["uses_coderhelm"] = json!(uses); v["offered"] = json!(offered.as_ref().is_none_or(|o| o.iter().any(|i| i == e.id))); v }) @@ -1362,7 +1526,7 @@ async fn ensure_jira_synced(state: &AppState) -> Result<(), (StatusCode, &'stati .map_err(|_| (StatusCode::SERVICE_UNAVAILABLE, "jira_link_unsynced")) } -/// PUT /api/system/hybrid/settings `{github_mode?, integrations?, sharing?}` +/// PUT /api/system/hybrid/settings `{github_mode?, integrations?, sharing?, jira_link?, apps?}` pub async fn put_settings( State(state): State>, Extension(claims): Extension, @@ -1399,6 +1563,9 @@ pub struct GuideBody { /// install admin, after sign-up). #[serde(default)] jira_link: Option, + /// The guide's Other apps choices, per tool (`coderhelm` or `own`). + #[serde(default)] + apps: Option>, } fn guide_body(body: &[u8]) -> GuideBody { @@ -1481,7 +1648,7 @@ pub async fn setup_github_link( guide_reply(r) } -/// POST /api/setup/hybrid/settings `{setup_token, github_mode?, integrations?, sharing?, jira_link?}` +/// POST /api/setup/hybrid/settings `{setup_token, github_mode?, integrations?, sharing?, jira_link?, apps?}` pub async fn setup_settings( State(state): State>, body: Bytes, @@ -1494,6 +1661,7 @@ pub async fn setup_settings( integrations: b.integrations.clone(), sharing: b.sharing.clone(), jira_link: b.jira_link, + apps: b.apps.clone(), }; do_settings(&state, &s).await?; Ok(Json(status_value(&state, false).await)) @@ -2034,21 +2202,122 @@ pub async fn github_hosted(state: &AppState) -> bool { #[cfg(test)] mod tests { + fn no_own_apps(_: &str) -> bool { + false + } + #[test] - fn a_choice_the_hosted_side_no_longer_offers_is_dropped() { + fn every_other_app_uses_coderhelms_unless_someone_chose_their_own() { + // A new install: nobody chose, so every tool is CoderHelm's app. + let mut l = Local::default(); + assert!(migrate_apps(&mut l, None) && l.apps.is_empty()); + assert_eq!( + wanted_integrations(&l, no_own_apps), + vec!["jira", "notion", "confluence", "google_drive"] + ); + // An explicit "my own app" is kept; the rest stay on the default. + l.apps.insert("notion".into(), "own".into()); + assert!(!uses_coderhelm(&l, "notion", no_own_apps)); + assert!(uses_coderhelm(&l, "confluence", no_own_apps)); + // A tool nobody chose, with the install's own app set up, keeps it. + let own_drive = |id: &str| id == "google_drive"; + assert!(!uses_coderhelm(&l, "google_drive", own_drive)); + // Chosen CoderHelm's app explicitly: wins over an own app set up. + l.apps.insert("google_drive".into(), "coderhelm".into()); + assert!(uses_coderhelm(&l, "google_drive", own_drive)); + l.github_mode = "hosted".into(); + assert_eq!( + wanted_integrations(&l, no_own_apps), + vec!["github", "jira", "confluence", "google_drive"] + ); + // Unrecorded: the serde default of a record from before is unset. + let old: Local = serde_json::from_str(r#"{"integrations":["github"]}"#).unwrap(); + assert!(old.apps.is_empty() && old.apps_v == 0); + } + + #[test] + fn a_record_from_before_keeps_its_explicit_own_choices() { + // Never chose anything in Other apps (only GitHub's app): defaults. let mut l = Local { - integrations: vec!["github".into(), "notion".into(), "google_drive".into()], + github_mode: "hosted".into(), + integrations: vec!["github".into()], ..Default::default() }; - assert!(!drop_unoffered(&mut l, None)); - assert_eq!(l.integrations.len(), 3); - let hosted = serde_json::json!({ "offered": ["github", "jira", "notion"] }); - let o = offered_by(Some(&hosted)); - assert!(drop_unoffered(&mut l, o.as_deref())); - assert_eq!(l.integrations, vec!["github", "notion"]); + assert!(migrate_apps(&mut l, None)); + assert!(l.apps.is_empty()); + assert_eq!( + wanted_integrations(&l, no_own_apps), + vec!["github", "jira", "notion", "confluence", "google_drive"] + ); + assert!(!migrate_apps(&mut l, None), "only once"); + // Chose Notion only, while Google Drive wasn't offered: Jira and + // Confluence were left on their own app on purpose, Drive wasn't. + let mut l = Local { + integrations: vec!["notion".into()], + ..Default::default() + }; + let offered: Vec = ["github", "jira", "notion", "confluence"] + .map(String::from) + .to_vec(); + assert!(migrate_apps(&mut l, Some(&offered))); + assert_eq!(l.apps.get("notion").map(String::as_str), Some("coderhelm")); + assert_eq!(l.apps.get("jira").map(String::as_str), Some("own")); + assert_eq!(l.apps.get("confluence").map(String::as_str), Some("own")); + assert!(!l.apps.contains_key("google_drive")); + assert_eq!( + wanted_integrations(&l, no_own_apps), + vec!["notion", "google_drive"] + ); assert!(offered_by(Some(&serde_json::json!({}))).is_none()); } + #[test] + fn the_list_is_sent_again_only_when_it_changed() { + let mut l = Local::default(); + let want = wanted_integrations(&l, no_own_apps); + assert!(apps_out_of_date(&l, &want, None), "never sent"); + l.apps_sent = want.clone(); + // CoderHelm took fewer (it doesn't offer Drive): no resend loop. + l.integrations = vec!["jira".into(), "notion".into(), "confluence".into()]; + assert!(!apps_out_of_date(&l, &want, Some(&l.integrations.clone()))); + // CoderHelm holds something else: send again. + assert!(apps_out_of_date(&l, &want, Some(&["jira".to_string()]))); + l.apps.insert("jira".into(), "own".into()); + let want = wanted_integrations(&l, no_own_apps); + assert!(apps_out_of_date(&l, &want, None)); + } + + #[test] + fn the_guide_and_settings_record_each_tool_they_name() { + let mut l = Local::default(); + let b = SettingsBody { + apps: Some( + [("notion", "own"), ("jira", "coderhelm")] + .map(|(a, b)| (a.to_string(), b.to_string())) + .into(), + ), + ..Default::default() + }; + apply_settings(&mut l, &b).unwrap(); + assert_eq!( + wanted_integrations(&l, no_own_apps), + vec!["jira", "confluence", "google_drive"] + ); + let bad = |id: &str, v: &str| SettingsBody { + apps: Some([(id.to_string(), v.to_string())].into()), + ..Default::default() + }; + assert!(apply_settings(&mut l, &bad("github", "own")).is_err()); + assert!(apply_settings(&mut l, &bad("slack_commands", "coderhelm")).is_err()); + assert!(apply_settings(&mut l, &bad("notion", "both")).is_err()); + // The guide's body takes the same field. + let g = guide_body(br#"{"setup_token":"t","apps":{"confluence":"own"}}"#); + assert_eq!( + g.apps.unwrap().get("confluence").map(String::as_str), + Some("own") + ); + } + #[test] fn the_intake_never_takes_a_copy_it_couldnt_record() { use common::claim::Claim; @@ -2329,16 +2598,23 @@ mod tests { payloads: true, }), jira_link: None, + apps: None, }; apply_settings(&mut l, &b).unwrap(); - assert_eq!(l.integrations, vec!["github", "notion"]); + // The whole list from an older dashboard: Notion switched on. + assert_eq!(l.apps.get("notion").map(String::as_str), Some("coderhelm")); + assert_eq!(wanted_integrations(&l, no_own_apps)[0], "github"); assert!(!l.share_payloads, "payloads only with sharing on"); + // Switched off in that list: an explicit own choice. + l.integrations = vec!["github".into(), "notion".into()]; let b = SettingsBody { github_mode: Some("own".into()), + integrations: Some(vec![]), ..Default::default() }; apply_settings(&mut l, &b).unwrap(); - assert_eq!(l.integrations, vec!["notion"]); + assert_eq!(l.apps.get("notion").map(String::as_str), Some("own")); + assert!(!wanted_integrations(&l, no_own_apps).contains(&"github".to_string())); let bad = SettingsBody { integrations: Some(vec!["slack_commands".into()]), ..Default::default()