fix: prevent auto add duplicate user (#3395)

This commit is contained in:
HugoCasa
2024-03-12 13:31:53 +01:00
committed by GitHub
parent a501d45e70
commit 9a1d10fed6
2 changed files with 6 additions and 4 deletions
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
"query": "SELECT workspace_id, auto_invite_operator, auto_add FROM workspace_settings WHERE auto_invite_domain = $1 OR auto_invite_domain = '*'",
"query": "SELECT workspace_id, auto_invite_operator, auto_add FROM workspace_settings ws WHERE (auto_invite_domain = $1 OR auto_invite_domain = '*') AND NOT EXISTS (SELECT 1 FROM usr WHERE workspace_id = ws.workspace_id AND email = $2)",
"describe": {
"columns": [
{
@@ -21,6 +21,7 @@
],
"parameters": {
"Left": [
"Text",
"Text"
]
},
@@ -30,5 +31,5 @@
true
]
},
"hash": "3bea19482b516841561702a73fe64f411342ed0c169164eadf2f4c3f6c2e3ba1"
"hash": "fc8fa909ef7a15c7ad30dd938be3c13864e855219c7f366c86f0605ec25d1538"
}
+3 -2
View File
@@ -1690,8 +1690,9 @@ pub async fn invite_user_to_all_auto_invite_worspaces(db: &DB, email: &str) -> R
let mut tx = db.begin().await?;
let domain = email.split('@').last().unwrap();
let workspaces = sqlx::query!(
"SELECT workspace_id, auto_invite_operator, auto_add FROM workspace_settings WHERE auto_invite_domain = $1 OR auto_invite_domain = '*'",
domain
"SELECT workspace_id, auto_invite_operator, auto_add FROM workspace_settings ws WHERE (auto_invite_domain = $1 OR auto_invite_domain = '*') AND NOT EXISTS (SELECT 1 FROM usr WHERE workspace_id = ws.workspace_id AND email = $2)",
domain,
email
)
.fetch_all(&mut *tx)
.await?;