mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-10-02 00:01:54 +00:00
Merge branch 'main' into diesel_async_1
This commit is contained in:
commit
c78c12ab2d
13 changed files with 48 additions and 25 deletions
|
@ -289,7 +289,7 @@ pub async fn build_federated_instances(
|
|||
|
||||
/// Checks the password length
|
||||
pub fn password_length_check(pass: &str) -> Result<(), LemmyError> {
|
||||
if !(10..=60).contains(&pass.len()) {
|
||||
if !(10..=60).contains(&pass.chars().count()) {
|
||||
Err(LemmyError::from_message("invalid_password"))
|
||||
} else {
|
||||
Ok(())
|
||||
|
@ -721,3 +721,17 @@ pub fn listing_type_with_site_default(
|
|||
&local_site.default_post_listing_type,
|
||||
)?))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::utils::password_length_check;
|
||||
|
||||
#[test]
|
||||
#[rustfmt::skip]
|
||||
fn password_length() {
|
||||
assert!(password_length_check("Õ¼¾°3yË,o¸ãtÌÈú|ÇÁÙAøüÒI©·¤(T]/ð>æºWæ[C¤bªWöaÃÎñ·{=û³&§½K/c").is_ok());
|
||||
assert!(password_length_check("1234567890").is_ok());
|
||||
assert!(password_length_check("short").is_err());
|
||||
assert!(password_length_check("looooooooooooooooooooooooooooooooooooooooooooooooooooooooooong").is_err());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,14 @@ impl PerformCrud for GetPrivateMessages {
|
|||
.list()
|
||||
.await?;
|
||||
|
||||
// Messages sent by ourselves should be marked as read. The `read` column in database is only
|
||||
// for the recipient, and shouldnt be exposed to sender.
|
||||
messages.iter_mut().for_each(|pmv| {
|
||||
if pmv.creator.id == person_id {
|
||||
pmv.private_message.read = true
|
||||
}
|
||||
});
|
||||
|
||||
// Blank out deleted or removed info
|
||||
for pmv in messages
|
||||
.iter_mut()
|
||||
|
|
|
@ -27,7 +27,7 @@ pub(crate) async fn get_apub_comment(
|
|||
return Err(NotFound.into());
|
||||
}
|
||||
|
||||
if !comment.deleted {
|
||||
if !comment.deleted && !comment.removed {
|
||||
Ok(create_apub_response(&comment.into_apub(&**context).await?))
|
||||
} else {
|
||||
Ok(create_apub_tombstone_response(comment.ap_id.clone()))
|
||||
|
|
|
@ -38,7 +38,7 @@ pub(crate) async fn get_apub_community_http(
|
|||
.await?
|
||||
.into();
|
||||
|
||||
if !community.deleted {
|
||||
if !community.deleted && !community.removed {
|
||||
let apub = community.into_apub(&**context).await?;
|
||||
|
||||
Ok(create_apub_response(&apub))
|
||||
|
@ -75,6 +75,9 @@ pub(crate) async fn get_apub_community_outbox(
|
|||
context: web::Data<LemmyContext>,
|
||||
) -> Result<HttpResponse, LemmyError> {
|
||||
let community = Community::read_from_name(context.pool(), &info.community_name, false).await?;
|
||||
if community.deleted || community.removed {
|
||||
return Err(LemmyError::from_message("deleted"));
|
||||
}
|
||||
let id = ObjectId::new(generate_outbox_url(&community.actor_id)?);
|
||||
let outbox_data = CommunityContext(community.into(), context.get_ref().clone());
|
||||
let outbox: ApubCommunityOutbox = id
|
||||
|
@ -92,6 +95,9 @@ pub(crate) async fn get_apub_community_moderators(
|
|||
Community::read_from_name(context.pool(), &info.community_name, false)
|
||||
.await?
|
||||
.into();
|
||||
if community.deleted || community.removed {
|
||||
return Err(LemmyError::from_message("deleted"));
|
||||
}
|
||||
let id = ObjectId::new(generate_outbox_url(&community.actor_id)?);
|
||||
let outbox_data = CommunityContext(community, context.get_ref().clone());
|
||||
let moderators: ApubCommunityModerators = id
|
||||
|
|
|
@ -27,7 +27,7 @@ pub(crate) async fn get_apub_post(
|
|||
return Err(NotFound.into());
|
||||
}
|
||||
|
||||
if !post.deleted {
|
||||
if !post.deleted && !post.removed {
|
||||
Ok(create_apub_response(&post.into_apub(&context).await?))
|
||||
} else {
|
||||
Ok(create_apub_tombstone_response(post.ap_id.clone()))
|
||||
|
|
|
@ -190,7 +190,7 @@ impl ApubObject for ApubComment {
|
|||
removed: None,
|
||||
published: note.published.map(|u| u.naive_local()),
|
||||
updated: note.updated.map(|u| u.naive_local()),
|
||||
deleted: None,
|
||||
deleted: Some(false),
|
||||
ap_id: Some(note.id.into()),
|
||||
distinguished: note.distinguished,
|
||||
local: Some(false),
|
||||
|
|
|
@ -152,7 +152,7 @@ impl ApubObject for ApubPerson {
|
|||
display_name: person.name,
|
||||
banned: None,
|
||||
ban_expires: None,
|
||||
deleted: None,
|
||||
deleted: Some(false),
|
||||
avatar: person.icon.map(|i| i.url.into()),
|
||||
banner: person.image.map(|i| i.url.into()),
|
||||
published: person.published.map(|u| u.naive_local()),
|
||||
|
|
|
@ -206,7 +206,7 @@ impl ApubObject for ApubPost {
|
|||
locked: page.comments_enabled.map(|e| !e),
|
||||
published: page.published.map(|u| u.naive_local()),
|
||||
updated: page.updated.map(|u| u.naive_local()),
|
||||
deleted: None,
|
||||
deleted: Some(false),
|
||||
nsfw: page.sensitive,
|
||||
stickied: page.stickied,
|
||||
embed_title,
|
||||
|
|
|
@ -146,7 +146,7 @@ impl ApubObject for ApubPrivateMessage {
|
|||
content: read_from_string_or_source(¬e.content, &None, ¬e.source),
|
||||
published: note.published.map(|u| u.naive_local()),
|
||||
updated: note.updated.map(|u| u.naive_local()),
|
||||
deleted: None,
|
||||
deleted: Some(false),
|
||||
read: None,
|
||||
ap_id: Some(note.id.into()),
|
||||
local: Some(false),
|
||||
|
|
|
@ -102,7 +102,7 @@ impl Group {
|
|||
removed: None,
|
||||
published: self.published.map(|u| u.naive_local()),
|
||||
updated: self.updated.map(|u| u.naive_local()),
|
||||
deleted: None,
|
||||
deleted: Some(false),
|
||||
nsfw: Some(self.sensitive.unwrap_or(false)),
|
||||
actor_id: Some(self.id.into()),
|
||||
local: Some(false),
|
||||
|
|
|
@ -131,7 +131,7 @@ pub fn diesel_option_overwrite_to_url_create(
|
|||
}
|
||||
}
|
||||
|
||||
async fn build_db_pool_settings_opt(settings: Option<&Settings>) -> DbPool {
|
||||
async fn build_db_pool_settings_opt(settings: Option<&Settings>) -> Result<DbPool, LemmyError> {
|
||||
let db_url = get_database_url(settings);
|
||||
let pool_size = settings.map(|s| s.database.pool_size).unwrap_or(5);
|
||||
let manager = AsyncDieselConnectionManager::<AsyncPgConnection>::new(&db_url);
|
||||
|
@ -139,15 +139,14 @@ async fn build_db_pool_settings_opt(settings: Option<&Settings>) -> DbPool {
|
|||
.max_size(pool_size)
|
||||
.min_idle(Some(1))
|
||||
.build(manager)
|
||||
.await
|
||||
.unwrap_or_else(|_| panic!("Error connecting to {}", db_url));
|
||||
.await?;
|
||||
|
||||
// If there's no settings, that means its a unit test, and migrations need to be run
|
||||
if settings.is_none() {
|
||||
run_migrations(&db_url);
|
||||
}
|
||||
|
||||
pool
|
||||
Ok(pool)
|
||||
}
|
||||
|
||||
pub const MIGRATIONS: EmbeddedMigrations = embed_migrations!();
|
||||
|
@ -161,12 +160,12 @@ pub fn run_migrations(db_url: &str) {
|
|||
.unwrap_or_else(|_| panic!("Couldn't run DB Migrations"));
|
||||
}
|
||||
|
||||
pub async fn build_db_pool(settings: &Settings) -> DbPool {
|
||||
build_db_pool_settings_opt(Some(settings)).await
|
||||
pub async fn build_db_pool(settings: &Settings) -> Result<DbPool, LemmyError> {
|
||||
Ok(build_db_pool_settings_opt(Some(settings)).await?)
|
||||
}
|
||||
|
||||
pub async fn build_db_pool_for_tests() -> DbPool {
|
||||
build_db_pool_settings_opt(None).await
|
||||
build_db_pool_settings_opt(None).await.unwrap()
|
||||
}
|
||||
|
||||
fn get_database_url(settings: Option<&Settings>) -> String {
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
use crate::{utils::get_ip, IpAddr};
|
||||
use actix_web::{
|
||||
dev::{Service, ServiceRequest, ServiceResponse, Transform},
|
||||
HttpResponse,
|
||||
};
|
||||
use crate::{error::LemmyError, utils::get_ip, IpAddr};
|
||||
use actix_web::dev::{Service, ServiceRequest, ServiceResponse, Transform};
|
||||
use futures::future::{ok, Ready};
|
||||
use rate_limiter::{RateLimitType, RateLimiter};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -177,10 +174,9 @@ where
|
|||
service.call(req).await
|
||||
} else {
|
||||
let (http_req, _) = req.into_parts();
|
||||
// if rate limit was hit, respond with http 400
|
||||
Ok(ServiceResponse::new(
|
||||
Ok(ServiceResponse::from_err(
|
||||
LemmyError::from_message("rate_limit_error"),
|
||||
http_req,
|
||||
HttpResponse::BadRequest().finish(),
|
||||
))
|
||||
}
|
||||
})
|
||||
|
|
|
@ -67,7 +67,7 @@ async fn main() -> Result<(), LemmyError> {
|
|||
init_logging(&settings.opentelemetry_url)?;
|
||||
|
||||
// Set up the bb8 connection pool
|
||||
let pool = build_db_pool(&settings).await;
|
||||
let pool = build_db_pool(&settings).await?;
|
||||
|
||||
// Run the migrations from code
|
||||
// let settings_cloned = settings.to_owned();
|
||||
|
|
Loading…
Reference in a new issue