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::{
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)?
}

View file

@ -196,7 +196,7 @@ pub enum LemmyErrorType {
EmailSendFailed,
Slurs,
CouldntFindObject,
RegistrationDenied(String),
RegistrationDenied(Option<String>),
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\"}"
)
}