mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-26 11:21:02 +00:00
* Handle empty reason for registration application denial (fixes #3485) * clippy * clippy
This commit is contained in:
parent
50b7322ff3
commit
626c7ebc85
2 changed files with 8 additions and 12 deletions
|
@ -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)?
|
||||
}
|
||||
|
|
|
@ -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\"}"
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue