use actix_web::web::Data;
use lemmy_api_common::context::LemmyContext;
+use lemmy_db_schema::source::local_site::LocalSite;
use lemmy_utils::{error::LemmyError, ConnectionId};
mod comment;
websocket_id: Option<ConnectionId>,
) -> Result<Self::Response, LemmyError>;
}
+
+/// Make sure if applications are required, that there is an application questionnaire
+pub fn check_application_question(
+ application_question: &Option<Option<String>>,
+ local_site: &LocalSite,
+ require_application: &Option<bool>,
+) -> Result<(), LemmyError> {
+ if require_application.unwrap_or(false)
+ && (application_question == &Some(None)
+ || (application_question.is_none() && local_site.application_question.is_none()))
+ {
+ return Err(LemmyError::from_message("application_question_required"));
+ }
+ Ok(())
+}
&local_recipient,
&lang.notification_private_message_subject(&local_recipient.person.name),
&lang.notification_private_message_body(
- &inbox_link,
+ inbox_link,
&content_slurs_removed,
&local_recipient.person.name,
),
-use crate::PerformCrud;
+use crate::{check_application_question, PerformCrud};
use activitypub_federation::core::signatures::generate_actor_keypair;
use actix_web::web::Data;
use lemmy_api_common::{
use lemmy_db_views::structs::SiteView;
use lemmy_utils::{
error::LemmyError,
- utils::{check_application_question, check_slurs, check_slurs_opt},
+ utils::{check_slurs, check_slurs_opt},
ConnectionId,
};
use url::Url;
}
let application_question = diesel_option_overwrite(&data.application_question);
- check_application_question(&application_question, &data.require_application)?;
+ check_application_question(
+ &application_question,
+ &local_site,
+ &data.require_application,
+ )?;
let actor_id: DbUrl = Url::parse(&context.settings().get_protocol_and_hostname())?.into();
let inbox_url = Some(generate_site_inbox_url(&actor_id)?);
-use crate::PerformCrud;
+use crate::{check_application_question, PerformCrud};
use actix_web::web::Data;
use lemmy_api_common::{
context::LemmyContext,
ListingType,
};
use lemmy_db_views::structs::SiteView;
-use lemmy_utils::{
- error::LemmyError,
- utils::{check_application_question, check_slurs_opt},
- ConnectionId,
-};
+use lemmy_utils::{error::LemmyError, utils::check_slurs_opt, ConnectionId};
use std::str::FromStr;
#[async_trait::async_trait(?Send)]
}
let application_question = diesel_option_overwrite(&data.application_question);
- check_application_question(&application_question, &data.require_application)?;
+ check_application_question(
+ &application_question,
+ &local_site,
+ &data.require_application,
+ )?;
if let Some(default_post_listing_type) = &data.default_post_listing_type {
// only allow all or local as default listing types
[start, combined].concat()
}
-/// Make sure if applications are required, that there is an application questionnaire
-pub fn check_application_question(
- application_question: &Option<Option<String>>,
- require_application: &Option<bool>,
-) -> Result<(), LemmyError> {
- if require_application.unwrap_or(false)
- && application_question.as_ref().unwrap_or(&None).is_none()
- {
- Err(LemmyError::from_message("application_question_required"))
- } else {
- Ok(())
- }
-}
-
pub fn generate_random_string() -> String {
thread_rng()
.sample_iter(&Alphanumeric)