Revert unnecessary logic for fetching invites' platform_unknown flag

This commit is contained in:
Max Brunsfeld 2022-10-14 16:13:38 -07:00
parent 3a4e802093
commit b541ac313c
3 changed files with 19 additions and 45 deletions

View file

@ -1,6 +1,6 @@
use crate::{ use crate::{
auth, auth,
db::{Invite, NewUserParams, ProjectId, Signup, UnsentInvite, User, UserId, WaitlistSummary}, db::{Invite, NewUserParams, ProjectId, Signup, User, UserId, WaitlistSummary},
rpc::{self, ResultExt}, rpc::{self, ResultExt},
AppState, Error, Result, AppState, Error, Result,
}; };
@ -471,7 +471,7 @@ pub struct GetUnsentInvitesParams {
async fn get_unsent_invites( async fn get_unsent_invites(
Query(params): Query<GetUnsentInvitesParams>, Query(params): Query<GetUnsentInvitesParams>,
Extension(app): Extension<Arc<AppState>>, Extension(app): Extension<Arc<AppState>>,
) -> Result<Json<Vec<UnsentInvite>>> { ) -> Result<Json<Vec<Invite>>> {
Ok(Json(app.db.get_unsent_invites(params.count).await?)) Ok(Json(app.db.get_unsent_invites(params.count).await?))
} }

View file

@ -45,7 +45,7 @@ pub trait Db: Send + Sync {
async fn create_signup(&self, signup: Signup) -> Result<()>; async fn create_signup(&self, signup: Signup) -> Result<()>;
async fn get_waitlist_summary(&self) -> Result<WaitlistSummary>; async fn get_waitlist_summary(&self) -> Result<WaitlistSummary>;
async fn get_unsent_invites(&self, count: usize) -> Result<Vec<UnsentInvite>>; async fn get_unsent_invites(&self, count: usize) -> Result<Vec<Invite>>;
async fn record_sent_invites(&self, invites: &[Invite]) -> Result<()>; async fn record_sent_invites(&self, invites: &[Invite]) -> Result<()>;
async fn create_user_from_invite( async fn create_user_from_invite(
&self, &self,
@ -442,11 +442,11 @@ impl Db for PostgresDb {
.await?) .await?)
} }
async fn get_unsent_invites(&self, count: usize) -> Result<Vec<UnsentInvite>> { async fn get_unsent_invites(&self, count: usize) -> Result<Vec<Invite>> {
let rows: Vec<(String, String, bool)> = sqlx::query_as( Ok(sqlx::query_as(
" "
SELECT SELECT
email_address, email_confirmation_code, platform_unknown email_address, email_confirmation_code
FROM signups FROM signups
WHERE WHERE
NOT email_confirmation_sent AND NOT email_confirmation_sent AND
@ -456,19 +456,7 @@ impl Db for PostgresDb {
) )
.bind(count as i32) .bind(count as i32)
.fetch_all(&self.pool) .fetch_all(&self.pool)
.await?; .await?)
Ok(rows
.into_iter()
.map(
|(email_address, email_confirmation_code, platform_unknown)| UnsentInvite {
invite: Invite {
email_address,
email_confirmation_code,
},
platform_unknown,
},
)
.collect())
} }
async fn record_sent_invites(&self, invites: &[Invite]) -> Result<()> { async fn record_sent_invites(&self, invites: &[Invite]) -> Result<()> {
@ -1737,19 +1725,12 @@ pub struct WaitlistSummary {
pub unknown_count: i64, pub unknown_count: i64,
} }
#[derive(Clone, FromRow, PartialEq, Debug, Serialize, Deserialize)] #[derive(FromRow, PartialEq, Debug, Serialize, Deserialize)]
pub struct Invite { pub struct Invite {
pub email_address: String, pub email_address: String,
pub email_confirmation_code: String, pub email_confirmation_code: String,
} }
#[derive(Serialize, Debug, PartialEq)]
pub struct UnsentInvite {
#[serde(flatten)]
pub invite: Invite,
pub platform_unknown: bool,
}
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct NewUserParams { pub struct NewUserParams {
pub github_login: String, pub github_login: String,
@ -1965,7 +1946,7 @@ mod test {
unimplemented!() unimplemented!()
} }
async fn get_unsent_invites(&self, _count: usize) -> Result<Vec<UnsentInvite>> { async fn get_unsent_invites(&self, _count: usize) -> Result<Vec<Invite>> {
unimplemented!() unimplemented!()
} }

View file

@ -1030,7 +1030,7 @@ async fn test_signups() {
let signups_batch1 = db.get_unsent_invites(3).await.unwrap(); let signups_batch1 = db.get_unsent_invites(3).await.unwrap();
let addresses = signups_batch1 let addresses = signups_batch1
.iter() .iter()
.map(|s| &s.invite.email_address) .map(|s| &s.email_address)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
assert_eq!( assert_eq!(
addresses, addresses,
@ -1041,8 +1041,8 @@ async fn test_signups() {
] ]
); );
assert_ne!( assert_ne!(
signups_batch1[0].invite.email_confirmation_code, signups_batch1[0].email_confirmation_code,
signups_batch1[1].invite.email_confirmation_code signups_batch1[1].email_confirmation_code
); );
// the waitlist isn't updated until we record that the emails // the waitlist isn't updated until we record that the emails
@ -1052,18 +1052,11 @@ async fn test_signups() {
// once the emails go out, we can retrieve the next batch // once the emails go out, we can retrieve the next batch
// of signups. // of signups.
db.record_sent_invites( db.record_sent_invites(&signups_batch1).await.unwrap();
&signups_batch1
.iter()
.map(|i| i.invite.clone())
.collect::<Vec<_>>(),
)
.await
.unwrap();
let signups_batch2 = db.get_unsent_invites(3).await.unwrap(); let signups_batch2 = db.get_unsent_invites(3).await.unwrap();
let addresses = signups_batch2 let addresses = signups_batch2
.iter() .iter()
.map(|s| &s.invite.email_address) .map(|s| &s.email_address)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
assert_eq!( assert_eq!(
addresses, addresses,
@ -1096,8 +1089,8 @@ async fn test_signups() {
} = db } = db
.create_user_from_invite( .create_user_from_invite(
&Invite { &Invite {
email_address: signups_batch1[0].invite.email_address.clone(), email_address: signups_batch1[0].email_address.clone(),
email_confirmation_code: signups_batch1[0].invite.email_confirmation_code.clone(), email_confirmation_code: signups_batch1[0].email_confirmation_code.clone(),
}, },
NewUserParams { NewUserParams {
github_login: "person-0".into(), github_login: "person-0".into(),
@ -1117,8 +1110,8 @@ async fn test_signups() {
// cannot redeem the same signup again. // cannot redeem the same signup again.
db.create_user_from_invite( db.create_user_from_invite(
&Invite { &Invite {
email_address: signups_batch1[0].invite.email_address.clone(), email_address: signups_batch1[0].email_address.clone(),
email_confirmation_code: signups_batch1[0].invite.email_confirmation_code.clone(), email_confirmation_code: signups_batch1[0].email_confirmation_code.clone(),
}, },
NewUserParams { NewUserParams {
github_login: "some-other-github_account".into(), github_login: "some-other-github_account".into(),
@ -1132,7 +1125,7 @@ async fn test_signups() {
// cannot redeem a signup with the wrong confirmation code. // cannot redeem a signup with the wrong confirmation code.
db.create_user_from_invite( db.create_user_from_invite(
&Invite { &Invite {
email_address: signups_batch1[1].invite.email_address.clone(), email_address: signups_batch1[1].email_address.clone(),
email_confirmation_code: "the-wrong-code".to_string(), email_confirmation_code: "the-wrong-code".to_string(),
}, },
NewUserParams { NewUserParams {