From 1db37bf3d06543c890612ff88193813035763034 Mon Sep 17 00:00:00 2001 From: Olivier Martin Date: Mon, 12 Apr 2021 21:54:57 -0400 Subject: [PATCH] make error toast display detailed message replace invite accept error message with the one from upstream check if config mail is enabled --- src/api/core/organizations.rs | 14 +++++++------- src/api/core/two_factor/mod.rs | 8 +++++--- src/error.rs | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/api/core/organizations.rs b/src/api/core/organizations.rs index e750841c..fbb27840 100644 --- a/src/api/core/organizations.rs +++ b/src/api/core/organizations.rs @@ -656,10 +656,8 @@ fn accept_invite(_org_id: String, _org_user_id: String, data: JsonUpcase, _headers: A if user_twofactor_disabled && user_org.atype < UserOrgType::Admin { - let org = Organization::find_by_uuid(&user_org.org_uuid, &conn).unwrap(); - let user = User::find_by_uuid(&user_org.user_uuid, &conn).unwrap(); + if CONFIG.mail_enabled() { + let org = Organization::find_by_uuid(&user_org.org_uuid, &conn).unwrap(); + let user = User::find_by_uuid(&user_org.user_uuid, &conn).unwrap(); - mail::send_2fa_removed_from_org(&user.email, &org.name)?; + mail::send_2fa_removed_from_org(&user.email, &org.name)?; + } user_org.delete(&conn)?; } } diff --git a/src/api/core/two_factor/mod.rs b/src/api/core/two_factor/mod.rs index c0764761..d1d9e2b4 100644 --- a/src/api/core/two_factor/mod.rs +++ b/src/api/core/two_factor/mod.rs @@ -11,7 +11,7 @@ use crate::{ models::*, DbConn, }, - mail, + mail, CONFIG, }; pub mod authenticator; @@ -144,9 +144,11 @@ fn disable_twofactor(data: JsonUpcase, headers: Headers, c for user_org in org_list.into_iter() { if user_org.atype < UserOrgType::Admin { - let org = Organization::find_by_uuid(&user_org.org_uuid, &conn).unwrap(); - mail::send_2fa_removed_from_org(&user.email, &org.name)?; + if CONFIG.mail_enabled() { + let org = Organization::find_by_uuid(&user_org.org_uuid, &conn).unwrap(); + mail::send_2fa_removed_from_org(&user.email, &org.name)?; + } user_org.delete(&conn)?; } } diff --git a/src/error.rs b/src/error.rs index a0b28a4b..25c18e10 100644 --- a/src/error.rs +++ b/src/error.rs @@ -166,7 +166,7 @@ fn _serialize(e: &impl serde::Serialize, _msg: &str) -> String { fn _api_error(_: &impl std::any::Any, msg: &str) -> String { let json = json!({ - "Message": "", + "Message": msg, "error": "", "error_description": "", "ValidationErrors": {"": [ msg ]},