Remove environment guards (#7741)

Release Notes:

- N/A
This commit is contained in:
Conrad Irwin 2024-02-13 13:20:14 -07:00 committed by GitHub
parent d744aa896f
commit a2144faf9c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 22 additions and 157 deletions

View file

@ -103,7 +103,6 @@ impl Database {
channel_id: ChannelId, channel_id: ChannelId,
user_id: UserId, user_id: UserId,
connection: ConnectionId, connection: ConnectionId,
environment: &str,
) -> Result<(JoinRoom, Option<MembershipUpdated>, ChannelRole)> { ) -> Result<(JoinRoom, Option<MembershipUpdated>, ChannelRole)> {
self.transaction(move |tx| async move { self.transaction(move |tx| async move {
let channel = self.get_channel_internal(channel_id, &*tx).await?; let channel = self.get_channel_internal(channel_id, &*tx).await?;
@ -163,7 +162,7 @@ impl Database {
let live_kit_room = format!("channel-{}", nanoid::nanoid!(30)); let live_kit_room = format!("channel-{}", nanoid::nanoid!(30));
let room_id = self let room_id = self
.get_or_create_channel_room(channel_id, &live_kit_room, environment, &*tx) .get_or_create_channel_room(channel_id, &live_kit_room, &*tx)
.await?; .await?;
self.join_channel_room_internal(room_id, user_id, connection, role, &*tx) self.join_channel_room_internal(room_id, user_id, connection, role, &*tx)
@ -933,7 +932,6 @@ impl Database {
&self, &self,
channel_id: ChannelId, channel_id: ChannelId,
live_kit_room: &str, live_kit_room: &str,
environment: &str,
tx: &DatabaseTransaction, tx: &DatabaseTransaction,
) -> Result<RoomId> { ) -> Result<RoomId> {
let room = room::Entity::find() let room = room::Entity::find()
@ -942,19 +940,11 @@ impl Database {
.await?; .await?;
let room_id = if let Some(room) = room { let room_id = if let Some(room) = room {
if let Some(env) = room.environment {
if &env != environment {
Err(ErrorCode::WrongReleaseChannel
.with_tag("required", &env)
.anyhow())?;
}
}
room.id room.id
} else { } else {
let result = room::Entity::insert(room::ActiveModel { let result = room::Entity::insert(room::ActiveModel {
channel_id: ActiveValue::Set(Some(channel_id)), channel_id: ActiveValue::Set(Some(channel_id)),
live_kit_room: ActiveValue::Set(live_kit_room.to_string()), live_kit_room: ActiveValue::Set(live_kit_room.to_string()),
environment: ActiveValue::Set(Some(environment.to_string())),
..Default::default() ..Default::default()
}) })
.exec(&*tx) .exec(&*tx)

View file

@ -110,12 +110,10 @@ impl Database {
user_id: UserId, user_id: UserId,
connection: ConnectionId, connection: ConnectionId,
live_kit_room: &str, live_kit_room: &str,
release_channel: &str,
) -> Result<proto::Room> { ) -> Result<proto::Room> {
self.transaction(|tx| async move { self.transaction(|tx| async move {
let room = room::ActiveModel { let room = room::ActiveModel {
live_kit_room: ActiveValue::set(live_kit_room.into()), live_kit_room: ActiveValue::set(live_kit_room.into()),
environment: ActiveValue::set(Some(release_channel.to_string())),
..Default::default() ..Default::default()
} }
.insert(&*tx) .insert(&*tx)
@ -302,31 +300,21 @@ impl Database {
room_id: RoomId, room_id: RoomId,
user_id: UserId, user_id: UserId,
connection: ConnectionId, connection: ConnectionId,
environment: &str,
) -> Result<RoomGuard<JoinRoom>> { ) -> Result<RoomGuard<JoinRoom>> {
self.room_transaction(room_id, |tx| async move { self.room_transaction(room_id, |tx| async move {
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] #[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
enum QueryChannelIdAndEnvironment { enum QueryChannelId {
ChannelId, ChannelId,
Environment,
} }
let (channel_id, release_channel): (Option<ChannelId>, Option<String>) = let channel_id: Option<ChannelId> = room::Entity::find()
room::Entity::find() .select_only()
.select_only() .column(room::Column::ChannelId)
.column(room::Column::ChannelId) .filter(room::Column::Id.eq(room_id))
.column(room::Column::Environment) .into_values::<_, QueryChannelId>()
.filter(room::Column::Id.eq(room_id)) .one(&*tx)
.into_values::<_, QueryChannelIdAndEnvironment>() .await?
.one(&*tx) .ok_or_else(|| anyhow!("no such room"))?;
.await?
.ok_or_else(|| anyhow!("no such room"))?;
if let Some(release_channel) = release_channel {
if &release_channel != environment {
Err(anyhow!("must join using the {} release", release_channel))?;
}
}
if channel_id.is_some() { if channel_id.is_some() {
Err(anyhow!("tried to join channel call directly"))? Err(anyhow!("tried to join channel call directly"))?

View file

@ -8,7 +8,6 @@ pub struct Model {
pub id: RoomId, pub id: RoomId,
pub live_kit_room: String, pub live_kit_room: String,
pub channel_id: Option<ChannelId>, pub channel_id: Option<ChannelId>,
pub environment: Option<String>,
} }
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

View file

@ -15,8 +15,6 @@ use std::sync::{
Arc, Arc,
}; };
const TEST_RELEASE_CHANNEL: &'static str = "test";
pub struct TestDb { pub struct TestDb {
pub db: Option<Arc<Database>>, pub db: Option<Arc<Database>>,
pub connection: Option<sqlx::AnyConnection>, pub connection: Option<sqlx::AnyConnection>,

View file

@ -1,6 +1,6 @@
use crate::{ use crate::{
db::{ db::{
tests::{channel_tree, new_test_connection, new_test_user, TEST_RELEASE_CHANNEL}, tests::{channel_tree, new_test_connection, new_test_user},
Channel, ChannelId, ChannelRole, Database, NewUserParams, RoomId, Channel, ChannelId, ChannelRole, Database, NewUserParams, RoomId,
}, },
test_both_dbs, test_both_dbs,
@ -135,12 +135,7 @@ async fn test_joining_channels(db: &Arc<Database>) {
// can join a room with membership to its channel // can join a room with membership to its channel
let (joined_room, _, _) = db let (joined_room, _, _) = db
.join_channel( .join_channel(channel_1, user_1, ConnectionId { owner_id, id: 1 })
channel_1,
user_1,
ConnectionId { owner_id, id: 1 },
TEST_RELEASE_CHANNEL,
)
.await .await
.unwrap(); .unwrap();
assert_eq!(joined_room.room.participants.len(), 1); assert_eq!(joined_room.room.participants.len(), 1);
@ -149,12 +144,7 @@ async fn test_joining_channels(db: &Arc<Database>) {
drop(joined_room); drop(joined_room);
// cannot join a room without membership to its channel // cannot join a room without membership to its channel
assert!(db assert!(db
.join_room( .join_room(room_id, user_2, ConnectionId { owner_id, id: 1 },)
room_id,
user_2,
ConnectionId { owner_id, id: 1 },
TEST_RELEASE_CHANNEL
)
.await .await
.is_err()); .is_err());
} }
@ -732,7 +722,7 @@ async fn test_guest_access(db: &Arc<Database>) {
.await .await
.is_err()); .is_err());
db.join_channel(zed_channel, guest, guest_connection, TEST_RELEASE_CHANNEL) db.join_channel(zed_channel, guest, guest_connection)
.await .await
.unwrap(); .unwrap();

View file

@ -517,7 +517,7 @@ async fn test_project_count(db: &Arc<Database>) {
.unwrap(); .unwrap();
let room_id = RoomId::from_proto( let room_id = RoomId::from_proto(
db.create_room(user1.user_id, ConnectionId { owner_id, id: 0 }, "", "test") db.create_room(user1.user_id, ConnectionId { owner_id, id: 0 }, "")
.await .await
.unwrap() .unwrap()
.id, .id,
@ -531,14 +531,9 @@ async fn test_project_count(db: &Arc<Database>) {
) )
.await .await
.unwrap(); .unwrap();
db.join_room( db.join_room(room_id, user2.user_id, ConnectionId { owner_id, id: 1 })
room_id, .await
user2.user_id, .unwrap();
ConnectionId { owner_id, id: 1 },
"test",
)
.await
.unwrap();
assert_eq!(db.project_count_excluding_admins().await.unwrap(), 0); assert_eq!(db.project_count_excluding_admins().await.unwrap(), 0);
db.share_project(room_id, ConnectionId { owner_id, id: 1 }, &[]) db.share_project(room_id, ConnectionId { owner_id, id: 1 }, &[])
@ -616,80 +611,3 @@ async fn test_fuzzy_search_users(cx: &mut TestAppContext) {
.collect::<Vec<_>>() .collect::<Vec<_>>()
} }
} }
test_both_dbs!(
test_non_matching_release_channels,
test_non_matching_release_channels_postgres,
test_non_matching_release_channels_sqlite
);
async fn test_non_matching_release_channels(db: &Arc<Database>) {
let owner_id = db.create_server("test").await.unwrap().0 as u32;
let user1 = db
.create_user(
&format!("admin@example.com"),
true,
NewUserParams {
github_login: "admin".into(),
github_user_id: 0,
},
)
.await
.unwrap();
let user2 = db
.create_user(
&format!("user@example.com"),
false,
NewUserParams {
github_login: "user".into(),
github_user_id: 1,
},
)
.await
.unwrap();
let room = db
.create_room(
user1.user_id,
ConnectionId { owner_id, id: 0 },
"",
"stable",
)
.await
.unwrap();
db.call(
RoomId::from_proto(room.id),
user1.user_id,
ConnectionId { owner_id, id: 0 },
user2.user_id,
None,
)
.await
.unwrap();
// User attempts to join from preview
let result = db
.join_room(
RoomId::from_proto(room.id),
user2.user_id,
ConnectionId { owner_id, id: 1 },
"preview",
)
.await;
assert!(result.is_err());
// User switches to stable
let result = db
.join_room(
RoomId::from_proto(room.id),
user2.user_id,
ConnectionId { owner_id, id: 1 },
"stable",
)
.await;
assert!(result.is_ok())
}

View file

@ -102,7 +102,6 @@ impl<R: RequestMessage> Response<R> {
#[derive(Clone)] #[derive(Clone)]
struct Session { struct Session {
zed_environment: Arc<str>,
user_id: UserId, user_id: UserId,
connection_id: ConnectionId, connection_id: ConnectionId,
db: Arc<tokio::sync::Mutex<DbHandle>>, db: Arc<tokio::sync::Mutex<DbHandle>>,
@ -617,7 +616,6 @@ impl Server {
user_id, user_id,
connection_id, connection_id,
db: Arc::new(tokio::sync::Mutex::new(DbHandle(this.app_state.db.clone()))), db: Arc::new(tokio::sync::Mutex::new(DbHandle(this.app_state.db.clone()))),
zed_environment: this.app_state.config.zed_environment.clone(),
peer: this.peer.clone(), peer: this.peer.clone(),
connection_pool: this.connection_pool.clone(), connection_pool: this.connection_pool.clone(),
live_kit_client: this.app_state.live_kit_client.clone(), live_kit_client: this.app_state.live_kit_client.clone(),
@ -1009,12 +1007,7 @@ async fn create_room(
let room = session let room = session
.db() .db()
.await .await
.create_room( .create_room(session.user_id, session.connection_id, &live_kit_room)
session.user_id,
session.connection_id,
&live_kit_room,
&session.zed_environment,
)
.await?; .await?;
response.send(proto::CreateRoomResponse { response.send(proto::CreateRoomResponse {
@ -1044,12 +1037,7 @@ async fn join_room(
let room = session let room = session
.db() .db()
.await .await
.join_room( .join_room(room_id, session.user_id, session.connection_id)
room_id,
session.user_id,
session.connection_id,
session.zed_environment.as_ref(),
)
.await?; .await?;
room_updated(&room.room, &session.peer); room_updated(&room.room, &session.peer);
room.into_inner() room.into_inner()
@ -2734,12 +2722,7 @@ async fn join_channel_internal(
let db = session.db().await; let db = session.db().await;
let (joined_room, membership_updated, role) = db let (joined_room, membership_updated, role) = db
.join_channel( .join_channel(channel_id, session.user_id, session.connection_id)
channel_id,
session.user_id,
session.connection_id,
session.zed_environment.as_ref(),
)
.await?; .await?;
let live_kit_connection_info = session.live_kit_client.as_ref().and_then(|live_kit| { let live_kit_connection_info = session.live_kit_client.as_ref().and_then(|live_kit| {

View file

@ -212,13 +212,13 @@ enum ErrorCode {
SignedOut = 3; SignedOut = 3;
UpgradeRequired = 4; UpgradeRequired = 4;
Forbidden = 5; Forbidden = 5;
WrongReleaseChannel = 6;
NeedsCla = 7; NeedsCla = 7;
NotARootChannel = 8; NotARootChannel = 8;
BadPublicNesting = 9; BadPublicNesting = 9;
CircularNesting = 10; CircularNesting = 10;
WrongMoveTarget = 11; WrongMoveTarget = 11;
UnsharedItem = 12; UnsharedItem = 12;
reserved 6;
} }
message Test { message Test {

View file

@ -4201,7 +4201,6 @@ pub fn join_channel(
"This channel is private, and you do not have access. Please ask someone to add you and try again.".into() "This channel is private, and you do not have access. Please ask someone to add you and try again.".into()
}, },
ErrorCode::Disconnected => "Please check your internet connection and try again.".into(), ErrorCode::Disconnected => "Please check your internet connection and try again.".into(),
ErrorCode::WrongReleaseChannel => format!("Others in the channel are using the {} release of Zed. Please switch to join this call.", err.error_tag("required").unwrap_or("other")).into(),
_ => format!("{}\n\nPlease try again.", err).into(), _ => format!("{}\n\nPlease try again.", err).into(),
}; };
cx.prompt( cx.prompt(