Spiegel von
https://github.com/dani-garcia/vaultwarden.git
synchronisiert 2024-11-23 05:20:28 +01:00
admin: Make invite_user error codes more specific
- Return 409 Conflict for when a user with that email already exists - Return 500 InternalServerError for everything else
Dieser Commit ist enthalten in:
Ursprung
68e5d95d25
Commit
e60bdc7efe
1 geänderte Dateien mit 13 neuen und 8 gelöschten Zeilen
|
@ -292,19 +292,24 @@ fn invite_user(data: Json<InviteData>, _token: AdminToken, conn: DbConn) -> Json
|
||||||
let data: InviteData = data.into_inner();
|
let data: InviteData = data.into_inner();
|
||||||
let email = data.email.clone();
|
let email = data.email.clone();
|
||||||
if User::find_by_mail(&data.email, &conn).is_some() {
|
if User::find_by_mail(&data.email, &conn).is_some() {
|
||||||
err!("User already exists")
|
err_code!("User already exists", Status::Conflict.code)
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut user = User::new(email);
|
let mut user = User::new(email);
|
||||||
|
|
||||||
if CONFIG.mail_enabled() {
|
// TODO: After try_blocks is stabilized, this can be made more readable
|
||||||
mail::send_invite(&user.email, &user.uuid, None, None, &CONFIG.invitation_org_name(), None)?;
|
// See: https://github.com/rust-lang/rust/issues/31436
|
||||||
} else {
|
(|| {
|
||||||
let invitation = Invitation::new(data.email);
|
if CONFIG.mail_enabled() {
|
||||||
invitation.save(&conn)?;
|
mail::send_invite(&user.email, &user.uuid, None, None, &CONFIG.invitation_org_name(), None)?;
|
||||||
}
|
} else {
|
||||||
|
let invitation = Invitation::new(data.email);
|
||||||
|
invitation.save(&conn)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
user.save(&conn)
|
||||||
|
})().map_err(|e| e.with_code(Status::InternalServerError.code))?;
|
||||||
|
|
||||||
user.save(&conn)?;
|
|
||||||
Ok(Json(user.to_json(&conn)))
|
Ok(Json(user.to_json(&conn)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Laden …
In neuem Issue referenzieren