diff --git a/crates/collab/k8s/collab.template.yml b/crates/collab/k8s/collab.template.yml index c6862a984dae230cef331867928e761941a1c39c..c5285ba15fdc5364751d3fde4d59daab41a3f8ff 100644 --- a/crates/collab/k8s/collab.template.yml +++ b/crates/collab/k8s/collab.template.yml @@ -185,6 +185,8 @@ spec: value: "true" - name: ZED_ENVIRONMENT value: ${ZED_ENVIRONMENT} + - name: AUTO_JOIN_CHANNEL_ID + value: ${AUTO_JOIN_CHANNEL_ID} securityContext: capabilities: # FIXME - Switch to the more restrictive `PERFMON` capability. diff --git a/crates/collab/k8s/environments/production.sh b/crates/collab/k8s/environments/production.sh index cb1d4b4de712864003c711dd8b46123b31fa5d5f..8b83fd3897109d945a7ab70fc9f4b4603d6fdf34 100644 --- a/crates/collab/k8s/environments/production.sh +++ b/crates/collab/k8s/environments/production.sh @@ -1,4 +1,5 @@ ZED_ENVIRONMENT=production RUST_LOG=info INVITE_LINK_PREFIX=https://zed.dev/invites/ +AUTO_JOIN_CHANNEL_ID=283 DATABASE_MAX_CONNECTIONS=85 diff --git a/crates/collab/k8s/environments/staging.sh b/crates/collab/k8s/environments/staging.sh index b9689ccb19390b412f4a7df9e8fee2e744b0479c..a0d6f5221cf567efd666d9b97c717dd8a2fdea65 100644 --- a/crates/collab/k8s/environments/staging.sh +++ b/crates/collab/k8s/environments/staging.sh @@ -2,3 +2,4 @@ ZED_ENVIRONMENT=staging RUST_LOG=info INVITE_LINK_PREFIX=https://staging.zed.dev/invites/ DATABASE_MAX_CONNECTIONS=5 +AUTO_JOIN_CHANNEL_ID=8 diff --git a/crates/collab/src/api.rs b/crates/collab/src/api.rs index 15c07838ae1f3523ab59e9b2445892a07a03d06f..51cbc5815278631389d307dfd216d67e73025d25 100644 --- a/crates/collab/src/api.rs +++ b/crates/collab/src/api.rs @@ -89,12 +89,15 @@ async fn get_authenticated_user( Query(params): Query, Extension(app): Extension>, ) -> Result> { + let initial_channel_id = app.config.auto_join_channel_id; + let user = app .db .get_or_create_user_by_github_account( ¶ms.github_login, params.github_user_id, params.github_email.as_deref(), + initial_channel_id, ) .await?; let metrics_id = app.db.get_user_metrics_id(user.id).await?; @@ -179,11 +182,13 @@ async fn add_contributor( Extension(app): Extension>, extract::Json(params): extract::Json, ) -> Result<()> { + let initial_channel_id = app.config.auto_join_channel_id; app.db .add_contributor( ¶ms.github_login, params.github_user_id, params.github_email.as_deref(), + initial_channel_id, ) .await } diff --git a/crates/collab/src/bin/seed.rs b/crates/collab/src/bin/seed.rs index 8a998d0bf3ecb0f1204235ee1430522bfd2135e6..66828c75bc089305374f221cd557e239797ecb96 100644 --- a/crates/collab/src/bin/seed.rs +++ b/crates/collab/src/bin/seed.rs @@ -70,6 +70,7 @@ async fn main() { &github_user.login, Some(github_user.id), github_user.email.as_deref(), + None, ) .await .expect("failed to insert user"); diff --git a/crates/collab/src/db/queries/contributors.rs b/crates/collab/src/db/queries/contributors.rs index 49194d6861fc0cf47a2716cddb86e1610070dd0f..703abfb0355fbcf54c02e0d0fa8609dd73597cb9 100644 --- a/crates/collab/src/db/queries/contributors.rs +++ b/crates/collab/src/db/queries/contributors.rs @@ -65,6 +65,7 @@ impl Database { github_login: &str, github_user_id: Option, github_email: Option<&str>, + initial_channel_id: Option, ) -> Result<()> { self.transaction(|tx| async move { let user = self @@ -72,6 +73,7 @@ impl Database { github_login, github_user_id, github_email, + initial_channel_id, &tx, ) .await?; diff --git a/crates/collab/src/db/queries/users.rs b/crates/collab/src/db/queries/users.rs index f17b43bb98b784de7b316289b9eba6599c213103..b884f276de240be32ada482c1e36bb2f0972ffac 100644 --- a/crates/collab/src/db/queries/users.rs +++ b/crates/collab/src/db/queries/users.rs @@ -74,12 +74,14 @@ impl Database { github_login: &str, github_user_id: Option, github_email: Option<&str>, + initial_channel_id: Option, ) -> Result { self.transaction(|tx| async move { self.get_or_create_user_by_github_account_tx( github_login, github_user_id, github_email, + initial_channel_id, &tx, ) .await @@ -92,6 +94,7 @@ impl Database { github_login: &str, github_user_id: Option, github_email: Option<&str>, + initial_channel_id: Option, tx: &DatabaseTransaction, ) -> Result { if let Some(github_user_id) = github_user_id { @@ -124,6 +127,17 @@ impl Database { }) .exec_with_returning(tx) .await?; + if let Some(channel_id) = initial_channel_id { + channel_member::Entity::insert(channel_member::ActiveModel { + id: ActiveValue::NotSet, + channel_id: ActiveValue::Set(channel_id), + user_id: ActiveValue::Set(user.id), + accepted: ActiveValue::Set(true), + role: ActiveValue::Set(ChannelRole::Guest), + }) + .exec(tx) + .await?; + } Ok(user) } } else { diff --git a/crates/collab/src/db/tests/contributor_tests.rs b/crates/collab/src/db/tests/contributor_tests.rs index a51817574a1725e30ac5297eec6a124856b046aa..72fa5f9357e0b82d79f052e8998f6e49bc914499 100644 --- a/crates/collab/src/db/tests/contributor_tests.rs +++ b/crates/collab/src/db/tests/contributor_tests.rs @@ -22,13 +22,17 @@ async fn test_contributors(db: &Arc) { assert_eq!(db.get_contributors().await.unwrap(), Vec::::new()); - db.add_contributor("user1", Some(1), None).await.unwrap(); + db.add_contributor("user1", Some(1), None, None) + .await + .unwrap(); assert_eq!( db.get_contributors().await.unwrap(), vec!["user1".to_string()] ); - db.add_contributor("user2", Some(2), None).await.unwrap(); + db.add_contributor("user2", Some(2), None, None) + .await + .unwrap(); assert_eq!( db.get_contributors().await.unwrap(), vec!["user1".to_string(), "user2".to_string()] diff --git a/crates/collab/src/db/tests/db_tests.rs b/crates/collab/src/db/tests/db_tests.rs index 2edaaa431469710fa847a6deb764d50e6130d60e..96e0898709e6fc12bbe92870f38945111a0b179d 100644 --- a/crates/collab/src/db/tests/db_tests.rs +++ b/crates/collab/src/db/tests/db_tests.rs @@ -102,7 +102,7 @@ async fn test_get_or_create_user_by_github_account(db: &Arc) { .user_id; let user = db - .get_or_create_user_by_github_account("the-new-login2", Some(102), None) + .get_or_create_user_by_github_account("the-new-login2", Some(102), None, None) .await .unwrap(); assert_eq!(user.id, user_id2); @@ -110,7 +110,7 @@ async fn test_get_or_create_user_by_github_account(db: &Arc) { assert_eq!(user.github_user_id, Some(102)); let user = db - .get_or_create_user_by_github_account("login3", Some(103), Some("user3@example.com")) + .get_or_create_user_by_github_account("login3", Some(103), Some("user3@example.com"), None) .await .unwrap(); assert_eq!(&user.github_login, "login3"); diff --git a/crates/collab/src/lib.rs b/crates/collab/src/lib.rs index 616405edadb8af8a122a6294d6499e929cd8b9ce..71ca4788e1fe1a8f62efea5af6c241b67aeb41b4 100644 --- a/crates/collab/src/lib.rs +++ b/crates/collab/src/lib.rs @@ -11,7 +11,7 @@ mod tests; use anyhow::anyhow; use aws_config::{BehaviorVersion, Region}; use axum::{http::StatusCode, response::IntoResponse}; -use db::Database; +use db::{ChannelId, Database}; use executor::Executor; use serde::Deserialize; use std::{path::PathBuf, sync::Arc}; @@ -128,6 +128,7 @@ pub struct Config { pub zed_environment: Arc, pub zed_client_checksum_seed: Option, pub slack_panics_webhook: Option, + pub auto_join_channel_id: Option, } impl Config { diff --git a/crates/collab/src/tests/channel_guest_tests.rs b/crates/collab/src/tests/channel_guest_tests.rs index 24828e42ef3aff0de716dca9fc273bff07cb57c6..1d92691a8afe372a4e17526980481856a9e297da 100644 --- a/crates/collab/src/tests/channel_guest_tests.rs +++ b/crates/collab/src/tests/channel_guest_tests.rs @@ -167,7 +167,7 @@ async fn test_channel_requires_zed_cla(cx_a: &mut TestAppContext, cx_b: &mut Tes server .app_state .db - .get_or_create_user_by_github_account("user_b", Some(100), None) + .get_or_create_user_by_github_account("user_b", Some(100), None, None) .await .unwrap(); @@ -265,7 +265,7 @@ async fn test_channel_requires_zed_cla(cx_a: &mut TestAppContext, cx_b: &mut Tes server .app_state .db - .add_contributor("user_b", Some(100), None) + .add_contributor("user_b", Some(100), None, None) .await .unwrap(); diff --git a/crates/collab/src/tests/test_server.rs b/crates/collab/src/tests/test_server.rs index 1ffb2d281d440bf2ccba82c2936fb05765fc060c..652faa5c53d0378b7aaf2c09561d0d0eefaf1c74 100644 --- a/crates/collab/src/tests/test_server.rs +++ b/crates/collab/src/tests/test_server.rs @@ -513,6 +513,7 @@ impl TestServer { clickhouse_database: None, zed_client_checksum_seed: None, slack_panics_webhook: None, + auto_join_channel_id: None, }, }) }