Handle empty reason for registration application denial (fixes #3485) (#4008)

* Handle empty reason for registration application denial (fixes #3485)

* clippy

* clippy
This commit is contained in:
Nutomic 2023-10-04 15:20:22 +02:00 committed by GitHub
parent 50b7322ff3
commit 626c7ebc85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 12 deletions

View File

@ -4,7 +4,6 @@ use bcrypt::verify;
use lemmy_api_common::{ use lemmy_api_common::{
context::LemmyContext, context::LemmyContext,
person::{Login, LoginResponse}, person::{Login, LoginResponse},
utils,
utils::check_user_valid, utils::check_user_valid,
}; };
use lemmy_db_schema::{ 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.accepted_application
&& !local_user_view.local_user.admin && !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 local_user_id = local_user_view.local_user.id;
let registration = RegistrationApplication::find_by_local_user_id(pool, local_user_id).await?; let registration = RegistrationApplication::find_by_local_user_id(pool, local_user_id).await?;
if let Some(deny_reason) = registration.deny_reason { if registration.admin_id.is_some() {
let lang = utils::get_interface_language(local_user_view); Err(LemmyErrorType::RegistrationDenied(registration.deny_reason))?
let registration_denied_message = format!("{}: {}", lang.registration_denied(), deny_reason);
Err(LemmyErrorType::RegistrationDenied(
registration_denied_message,
))?
} else { } else {
Err(LemmyErrorType::RegistrationApplicationIsPending)? Err(LemmyErrorType::RegistrationApplicationIsPending)?
} }

View File

@ -196,7 +196,7 @@ pub enum LemmyErrorType {
EmailSendFailed, EmailSendFailed,
Slurs, Slurs,
CouldntFindObject, CouldntFindObject,
RegistrationDenied(String), RegistrationDenied(Option<String>),
FederationDisabled, FederationDisabled,
DomainBlocked(String), DomainBlocked(String),
DomainNotInAllowList(String), DomainNotInAllowList(String),
@ -276,12 +276,12 @@ mod tests {
#[test] #[test]
fn deserializes_with_message() { fn deserializes_with_message() {
let reg_denied = LemmyErrorType::RegistrationDenied(String::from("reason")); let reg_banned = LemmyErrorType::PersonIsBannedFromSite(String::from("reason"));
let err = LemmyError::from(reg_denied).error_response(); let err = LemmyError::from(reg_banned).error_response();
let json = String::from_utf8(err.into_body().try_into_bytes().unwrap().to_vec()).unwrap(); let json = String::from_utf8(err.into_body().try_into_bytes().unwrap().to_vec()).unwrap();
assert_eq!( assert_eq!(
&json, &json,
"{\"error\":\"registration_denied\",\"message\":\"reason\"}" "{\"error\":\"person_is_banned_from_site\",\"message\":\"reason\"}"
) )
} }