From 626c7ebc85aa7603c31130f52ae02b917aec84a0 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Wed, 4 Oct 2023 15:20:22 +0200 Subject: [PATCH] Handle empty reason for registration application denial (fixes #3485) (#4008) * Handle empty reason for registration application denial (fixes #3485) * clippy * clippy --- crates/api/src/local_user/login.rs | 12 ++++-------- crates/utils/src/error.rs | 8 ++++---- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/crates/api/src/local_user/login.rs b/crates/api/src/local_user/login.rs index 11a5c6b01..46f547671 100644 --- a/crates/api/src/local_user/login.rs +++ b/crates/api/src/local_user/login.rs @@ -4,7 +4,6 @@ use bcrypt::verify; use lemmy_api_common::{ context::LemmyContext, person::{Login, LoginResponse}, - utils, utils::check_user_valid, }; use lemmy_db_schema::{ @@ -89,15 +88,12 @@ async fn check_registration_application( && !local_user_view.local_user.accepted_application && !local_user_view.local_user.admin { - // Fetch the registration, see if its denied + // Fetch the registration application. If no admin id is present its still pending. Otherwise it + // was processed (either accepted or denied). let local_user_id = local_user_view.local_user.id; let registration = RegistrationApplication::find_by_local_user_id(pool, local_user_id).await?; - if let Some(deny_reason) = registration.deny_reason { - let lang = utils::get_interface_language(local_user_view); - let registration_denied_message = format!("{}: {}", lang.registration_denied(), deny_reason); - Err(LemmyErrorType::RegistrationDenied( - registration_denied_message, - ))? + if registration.admin_id.is_some() { + Err(LemmyErrorType::RegistrationDenied(registration.deny_reason))? } else { Err(LemmyErrorType::RegistrationApplicationIsPending)? } diff --git a/crates/utils/src/error.rs b/crates/utils/src/error.rs index 079d0fc94..c37bdac0a 100644 --- a/crates/utils/src/error.rs +++ b/crates/utils/src/error.rs @@ -196,7 +196,7 @@ pub enum LemmyErrorType { EmailSendFailed, Slurs, CouldntFindObject, - RegistrationDenied(String), + RegistrationDenied(Option), FederationDisabled, DomainBlocked(String), DomainNotInAllowList(String), @@ -276,12 +276,12 @@ mod tests { #[test] fn deserializes_with_message() { - let reg_denied = LemmyErrorType::RegistrationDenied(String::from("reason")); - let err = LemmyError::from(reg_denied).error_response(); + let reg_banned = LemmyErrorType::PersonIsBannedFromSite(String::from("reason")); + let err = LemmyError::from(reg_banned).error_response(); let json = String::from_utf8(err.into_body().try_into_bytes().unwrap().to_vec()).unwrap(); assert_eq!( &json, - "{\"error\":\"registration_denied\",\"message\":\"reason\"}" + "{\"error\":\"person_is_banned_from_site\",\"message\":\"reason\"}" ) }