mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
Allow setting a channel for new users to auto-join (#9291)
Release Notes: - Automatically add new users to the #zed channel
This commit is contained in:
parent
88e33a1dbe
commit
77de5689a3
@ -185,6 +185,8 @@ spec:
|
|||||||
value: "true"
|
value: "true"
|
||||||
- name: ZED_ENVIRONMENT
|
- name: ZED_ENVIRONMENT
|
||||||
value: ${ZED_ENVIRONMENT}
|
value: ${ZED_ENVIRONMENT}
|
||||||
|
- name: AUTO_JOIN_CHANNEL_ID
|
||||||
|
value: ${AUTO_JOIN_CHANNEL_ID}
|
||||||
securityContext:
|
securityContext:
|
||||||
capabilities:
|
capabilities:
|
||||||
# FIXME - Switch to the more restrictive `PERFMON` capability.
|
# FIXME - Switch to the more restrictive `PERFMON` capability.
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
ZED_ENVIRONMENT=production
|
ZED_ENVIRONMENT=production
|
||||||
RUST_LOG=info
|
RUST_LOG=info
|
||||||
INVITE_LINK_PREFIX=https://zed.dev/invites/
|
INVITE_LINK_PREFIX=https://zed.dev/invites/
|
||||||
|
AUTO_JOIN_CHANNEL_ID=283
|
||||||
DATABASE_MAX_CONNECTIONS=85
|
DATABASE_MAX_CONNECTIONS=85
|
||||||
|
@ -2,3 +2,4 @@ ZED_ENVIRONMENT=staging
|
|||||||
RUST_LOG=info
|
RUST_LOG=info
|
||||||
INVITE_LINK_PREFIX=https://staging.zed.dev/invites/
|
INVITE_LINK_PREFIX=https://staging.zed.dev/invites/
|
||||||
DATABASE_MAX_CONNECTIONS=5
|
DATABASE_MAX_CONNECTIONS=5
|
||||||
|
AUTO_JOIN_CHANNEL_ID=8
|
||||||
|
@ -89,12 +89,15 @@ async fn get_authenticated_user(
|
|||||||
Query(params): Query<AuthenticatedUserParams>,
|
Query(params): Query<AuthenticatedUserParams>,
|
||||||
Extension(app): Extension<Arc<AppState>>,
|
Extension(app): Extension<Arc<AppState>>,
|
||||||
) -> Result<Json<AuthenticatedUserResponse>> {
|
) -> Result<Json<AuthenticatedUserResponse>> {
|
||||||
|
let initial_channel_id = app.config.auto_join_channel_id;
|
||||||
|
|
||||||
let user = app
|
let user = app
|
||||||
.db
|
.db
|
||||||
.get_or_create_user_by_github_account(
|
.get_or_create_user_by_github_account(
|
||||||
¶ms.github_login,
|
¶ms.github_login,
|
||||||
params.github_user_id,
|
params.github_user_id,
|
||||||
params.github_email.as_deref(),
|
params.github_email.as_deref(),
|
||||||
|
initial_channel_id,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
let metrics_id = app.db.get_user_metrics_id(user.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<Arc<AppState>>,
|
Extension(app): Extension<Arc<AppState>>,
|
||||||
extract::Json(params): extract::Json<AuthenticatedUserParams>,
|
extract::Json(params): extract::Json<AuthenticatedUserParams>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let initial_channel_id = app.config.auto_join_channel_id;
|
||||||
app.db
|
app.db
|
||||||
.add_contributor(
|
.add_contributor(
|
||||||
¶ms.github_login,
|
¶ms.github_login,
|
||||||
params.github_user_id,
|
params.github_user_id,
|
||||||
params.github_email.as_deref(),
|
params.github_email.as_deref(),
|
||||||
|
initial_channel_id,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,7 @@ async fn main() {
|
|||||||
&github_user.login,
|
&github_user.login,
|
||||||
Some(github_user.id),
|
Some(github_user.id),
|
||||||
github_user.email.as_deref(),
|
github_user.email.as_deref(),
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.expect("failed to insert user");
|
.expect("failed to insert user");
|
||||||
|
@ -65,6 +65,7 @@ impl Database {
|
|||||||
github_login: &str,
|
github_login: &str,
|
||||||
github_user_id: Option<i32>,
|
github_user_id: Option<i32>,
|
||||||
github_email: Option<&str>,
|
github_email: Option<&str>,
|
||||||
|
initial_channel_id: Option<ChannelId>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.transaction(|tx| async move {
|
self.transaction(|tx| async move {
|
||||||
let user = self
|
let user = self
|
||||||
@ -72,6 +73,7 @@ impl Database {
|
|||||||
github_login,
|
github_login,
|
||||||
github_user_id,
|
github_user_id,
|
||||||
github_email,
|
github_email,
|
||||||
|
initial_channel_id,
|
||||||
&tx,
|
&tx,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -74,12 +74,14 @@ impl Database {
|
|||||||
github_login: &str,
|
github_login: &str,
|
||||||
github_user_id: Option<i32>,
|
github_user_id: Option<i32>,
|
||||||
github_email: Option<&str>,
|
github_email: Option<&str>,
|
||||||
|
initial_channel_id: Option<ChannelId>,
|
||||||
) -> Result<User> {
|
) -> Result<User> {
|
||||||
self.transaction(|tx| async move {
|
self.transaction(|tx| async move {
|
||||||
self.get_or_create_user_by_github_account_tx(
|
self.get_or_create_user_by_github_account_tx(
|
||||||
github_login,
|
github_login,
|
||||||
github_user_id,
|
github_user_id,
|
||||||
github_email,
|
github_email,
|
||||||
|
initial_channel_id,
|
||||||
&tx,
|
&tx,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@ -92,6 +94,7 @@ impl Database {
|
|||||||
github_login: &str,
|
github_login: &str,
|
||||||
github_user_id: Option<i32>,
|
github_user_id: Option<i32>,
|
||||||
github_email: Option<&str>,
|
github_email: Option<&str>,
|
||||||
|
initial_channel_id: Option<ChannelId>,
|
||||||
tx: &DatabaseTransaction,
|
tx: &DatabaseTransaction,
|
||||||
) -> Result<User> {
|
) -> Result<User> {
|
||||||
if let Some(github_user_id) = github_user_id {
|
if let Some(github_user_id) = github_user_id {
|
||||||
@ -124,6 +127,17 @@ impl Database {
|
|||||||
})
|
})
|
||||||
.exec_with_returning(tx)
|
.exec_with_returning(tx)
|
||||||
.await?;
|
.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)
|
Ok(user)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -22,13 +22,17 @@ async fn test_contributors(db: &Arc<Database>) {
|
|||||||
|
|
||||||
assert_eq!(db.get_contributors().await.unwrap(), Vec::<String>::new());
|
assert_eq!(db.get_contributors().await.unwrap(), Vec::<String>::new());
|
||||||
|
|
||||||
db.add_contributor("user1", Some(1), None).await.unwrap();
|
db.add_contributor("user1", Some(1), None, None)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
db.get_contributors().await.unwrap(),
|
db.get_contributors().await.unwrap(),
|
||||||
vec!["user1".to_string()]
|
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!(
|
assert_eq!(
|
||||||
db.get_contributors().await.unwrap(),
|
db.get_contributors().await.unwrap(),
|
||||||
vec!["user1".to_string(), "user2".to_string()]
|
vec!["user1".to_string(), "user2".to_string()]
|
||||||
|
@ -102,7 +102,7 @@ async fn test_get_or_create_user_by_github_account(db: &Arc<Database>) {
|
|||||||
.user_id;
|
.user_id;
|
||||||
|
|
||||||
let user = db
|
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
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(user.id, user_id2);
|
assert_eq!(user.id, user_id2);
|
||||||
@ -110,7 +110,7 @@ async fn test_get_or_create_user_by_github_account(db: &Arc<Database>) {
|
|||||||
assert_eq!(user.github_user_id, Some(102));
|
assert_eq!(user.github_user_id, Some(102));
|
||||||
|
|
||||||
let user = db
|
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
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(&user.github_login, "login3");
|
assert_eq!(&user.github_login, "login3");
|
||||||
|
@ -11,7 +11,7 @@ mod tests;
|
|||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use aws_config::{BehaviorVersion, Region};
|
use aws_config::{BehaviorVersion, Region};
|
||||||
use axum::{http::StatusCode, response::IntoResponse};
|
use axum::{http::StatusCode, response::IntoResponse};
|
||||||
use db::Database;
|
use db::{ChannelId, Database};
|
||||||
use executor::Executor;
|
use executor::Executor;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::{path::PathBuf, sync::Arc};
|
use std::{path::PathBuf, sync::Arc};
|
||||||
@ -128,6 +128,7 @@ pub struct Config {
|
|||||||
pub zed_environment: Arc<str>,
|
pub zed_environment: Arc<str>,
|
||||||
pub zed_client_checksum_seed: Option<String>,
|
pub zed_client_checksum_seed: Option<String>,
|
||||||
pub slack_panics_webhook: Option<String>,
|
pub slack_panics_webhook: Option<String>,
|
||||||
|
pub auto_join_channel_id: Option<ChannelId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
|
@ -167,7 +167,7 @@ async fn test_channel_requires_zed_cla(cx_a: &mut TestAppContext, cx_b: &mut Tes
|
|||||||
server
|
server
|
||||||
.app_state
|
.app_state
|
||||||
.db
|
.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
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@ -265,7 +265,7 @@ async fn test_channel_requires_zed_cla(cx_a: &mut TestAppContext, cx_b: &mut Tes
|
|||||||
server
|
server
|
||||||
.app_state
|
.app_state
|
||||||
.db
|
.db
|
||||||
.add_contributor("user_b", Some(100), None)
|
.add_contributor("user_b", Some(100), None, None)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -513,6 +513,7 @@ impl TestServer {
|
|||||||
clickhouse_database: None,
|
clickhouse_database: None,
|
||||||
zed_client_checksum_seed: None,
|
zed_client_checksum_seed: None,
|
||||||
slack_panics_webhook: None,
|
slack_panics_webhook: None,
|
||||||
|
auto_join_channel_id: None,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user