Add users to mailing list when using an invite link
This commit is contained in:
parent
f61b870db6
commit
c3b102f5a8
3 changed files with 35 additions and 10 deletions
|
@ -353,6 +353,8 @@ pub struct CreateInviteFromCodeParams {
|
||||||
invite_code: String,
|
invite_code: String,
|
||||||
email_address: String,
|
email_address: String,
|
||||||
device_id: Option<String>,
|
device_id: Option<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
added_to_mailing_list: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create_invite_from_code(
|
async fn create_invite_from_code(
|
||||||
|
@ -365,6 +367,7 @@ async fn create_invite_from_code(
|
||||||
¶ms.invite_code,
|
¶ms.invite_code,
|
||||||
¶ms.email_address,
|
¶ms.email_address,
|
||||||
params.device_id.as_deref(),
|
params.device_id.as_deref(),
|
||||||
|
params.added_to_mailing_list,
|
||||||
)
|
)
|
||||||
.await?,
|
.await?,
|
||||||
))
|
))
|
||||||
|
|
|
@ -882,6 +882,7 @@ impl Database {
|
||||||
code: &str,
|
code: &str,
|
||||||
email_address: &str,
|
email_address: &str,
|
||||||
device_id: Option<&str>,
|
device_id: Option<&str>,
|
||||||
|
added_to_mailing_list: bool,
|
||||||
) -> Result<Invite> {
|
) -> Result<Invite> {
|
||||||
self.transaction(|tx| async move {
|
self.transaction(|tx| async move {
|
||||||
let existing_user = user::Entity::find()
|
let existing_user = user::Entity::find()
|
||||||
|
@ -933,6 +934,7 @@ impl Database {
|
||||||
platform_windows: ActiveValue::set(false),
|
platform_windows: ActiveValue::set(false),
|
||||||
platform_unknown: ActiveValue::set(true),
|
platform_unknown: ActiveValue::set(true),
|
||||||
device_id: ActiveValue::set(device_id.map(|device_id| device_id.into())),
|
device_id: ActiveValue::set(device_id.map(|device_id| device_id.into())),
|
||||||
|
added_to_mailing_list: ActiveValue::set(added_to_mailing_list),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.on_conflict(
|
.on_conflict(
|
||||||
|
|
|
@ -567,7 +567,12 @@ async fn test_invite_codes() {
|
||||||
|
|
||||||
// User 2 redeems the invite code and becomes a contact of user 1.
|
// User 2 redeems the invite code and becomes a contact of user 1.
|
||||||
let user2_invite = db
|
let user2_invite = db
|
||||||
.create_invite_from_code(&invite_code, "user2@example.com", Some("user-2-device-id"))
|
.create_invite_from_code(
|
||||||
|
&invite_code,
|
||||||
|
"user2@example.com",
|
||||||
|
Some("user-2-device-id"),
|
||||||
|
true,
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let NewUserResult {
|
let NewUserResult {
|
||||||
|
@ -617,7 +622,7 @@ async fn test_invite_codes() {
|
||||||
|
|
||||||
// User 3 redeems the invite code and becomes a contact of user 1.
|
// User 3 redeems the invite code and becomes a contact of user 1.
|
||||||
let user3_invite = db
|
let user3_invite = db
|
||||||
.create_invite_from_code(&invite_code, "user3@example.com", None)
|
.create_invite_from_code(&invite_code, "user3@example.com", None, true)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let NewUserResult {
|
let NewUserResult {
|
||||||
|
@ -672,7 +677,12 @@ async fn test_invite_codes() {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Trying to reedem the code for the third time results in an error.
|
// Trying to reedem the code for the third time results in an error.
|
||||||
db.create_invite_from_code(&invite_code, "user4@example.com", Some("user-4-device-id"))
|
db.create_invite_from_code(
|
||||||
|
&invite_code,
|
||||||
|
"user4@example.com",
|
||||||
|
Some("user-4-device-id"),
|
||||||
|
true,
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap_err();
|
.unwrap_err();
|
||||||
|
|
||||||
|
@ -684,7 +694,12 @@ async fn test_invite_codes() {
|
||||||
|
|
||||||
// User 4 can now redeem the invite code and becomes a contact of user 1.
|
// User 4 can now redeem the invite code and becomes a contact of user 1.
|
||||||
let user4_invite = db
|
let user4_invite = db
|
||||||
.create_invite_from_code(&invite_code, "user4@example.com", Some("user-4-device-id"))
|
.create_invite_from_code(
|
||||||
|
&invite_code,
|
||||||
|
"user4@example.com",
|
||||||
|
Some("user-4-device-id"),
|
||||||
|
true,
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let user4 = db
|
let user4 = db
|
||||||
|
@ -739,7 +754,12 @@ async fn test_invite_codes() {
|
||||||
);
|
);
|
||||||
|
|
||||||
// An existing user cannot redeem invite codes.
|
// An existing user cannot redeem invite codes.
|
||||||
db.create_invite_from_code(&invite_code, "user2@example.com", Some("user-2-device-id"))
|
db.create_invite_from_code(
|
||||||
|
&invite_code,
|
||||||
|
"user2@example.com",
|
||||||
|
Some("user-2-device-id"),
|
||||||
|
true,
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap_err();
|
.unwrap_err();
|
||||||
let (_, invite_count) = db.get_invite_code_for_user(user1).await.unwrap().unwrap();
|
let (_, invite_count) = db.get_invite_code_for_user(user1).await.unwrap().unwrap();
|
||||||
|
@ -763,7 +783,7 @@ async fn test_invite_codes() {
|
||||||
db.set_invite_count_for_user(user5, 5).await.unwrap();
|
db.set_invite_count_for_user(user5, 5).await.unwrap();
|
||||||
let (user5_invite_code, _) = db.get_invite_code_for_user(user5).await.unwrap().unwrap();
|
let (user5_invite_code, _) = db.get_invite_code_for_user(user5).await.unwrap().unwrap();
|
||||||
let user5_invite_to_user1 = db
|
let user5_invite_to_user1 = db
|
||||||
.create_invite_from_code(&user5_invite_code, "user1@different.com", None)
|
.create_invite_from_code(&user5_invite_code, "user1@different.com", None, true)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let user1_2 = db
|
let user1_2 = db
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue