mirror of https://github.com/LemmyNet/lemmy.git
Attempt to create custom GetConn and RunQueryDsl traits
parent
48e12de921
commit
7aeeec6810
|
@ -95,10 +95,10 @@ mod tests {
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_should_not_validate_user_token_after_password_change() {
|
async fn test_should_not_validate_user_token_after_password_change() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
let secret = Secret::init(&mut *conn).await.unwrap();
|
let secret = Secret::init(conn).await.unwrap();
|
||||||
let settings = &SETTINGS.to_owned();
|
let settings = &SETTINGS.to_owned();
|
||||||
|
|
||||||
let inserted_instance = Instance::read_or_create(&mut *conn, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(conn, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -108,14 +108,14 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_person = Person::create(&mut *conn, &new_person).await.unwrap();
|
let inserted_person = Person::create(conn, &new_person).await.unwrap();
|
||||||
|
|
||||||
let local_user_form = LocalUserInsertForm::builder()
|
let local_user_form = LocalUserInsertForm::builder()
|
||||||
.person_id(inserted_person.id)
|
.person_id(inserted_person.id)
|
||||||
.password_encrypted("123456".to_string())
|
.password_encrypted("123456".to_string())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_local_user = LocalUser::create(&mut *conn, &local_user_form)
|
let inserted_local_user = LocalUser::create(conn, &local_user_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -131,13 +131,13 @@ mod tests {
|
||||||
|
|
||||||
// The check should fail, since the validator time is now newer than the jwt issue time
|
// The check should fail, since the validator time is now newer than the jwt issue time
|
||||||
let updated_local_user =
|
let updated_local_user =
|
||||||
LocalUser::update_password(&mut *conn, inserted_local_user.id, "password111")
|
LocalUser::update_password(conn, inserted_local_user.id, "password111")
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let check_after = check_validator_time(&updated_local_user.validator_time, &claims);
|
let check_after = check_validator_time(&updated_local_user.validator_time, &claims);
|
||||||
assert!(check_after.is_err());
|
assert!(check_after.is_err());
|
||||||
|
|
||||||
let num_deleted = Person::delete(&mut *conn, inserted_person.id)
|
let num_deleted = Person::delete(conn, inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, num_deleted);
|
assert_eq!(1, num_deleted);
|
||||||
|
|
|
@ -24,7 +24,7 @@ use lemmy_db_schema::{
|
||||||
registration_application::RegistrationApplication,
|
registration_application::RegistrationApplication,
|
||||||
},
|
},
|
||||||
traits::{Crud, Readable},
|
traits::{Crud, Readable},
|
||||||
utils::{get_conn, DbConn, DbPool},
|
utils::{get_conn, DbPool, GetConn},
|
||||||
RegistrationMode,
|
RegistrationMode,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::{comment_view::CommentQuery, structs::LocalUserView};
|
use lemmy_db_views::{comment_view::CommentQuery, structs::LocalUserView};
|
||||||
|
@ -50,7 +50,7 @@ use url::{ParseError, Url};
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
pub async fn is_mod_or_admin(
|
pub async fn is_mod_or_admin(
|
||||||
conn: impl DbConn,
|
conn: impl GetConn,
|
||||||
person_id: PersonId,
|
person_id: PersonId,
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
|
@ -63,7 +63,7 @@ pub async fn is_mod_or_admin(
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
pub async fn is_mod_or_admin_opt(
|
pub async fn is_mod_or_admin_opt(
|
||||||
conn: impl DbConn,
|
conn: impl GetConn,
|
||||||
local_user_view: Option<&LocalUserView>,
|
local_user_view: Option<&LocalUserView>,
|
||||||
community_id: Option<CommunityId>,
|
community_id: Option<CommunityId>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
|
@ -101,7 +101,7 @@ pub fn is_top_mod(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
pub async fn get_post(post_id: PostId, conn: impl DbConn) -> Result<Post, LemmyError> {
|
pub async fn get_post(post_id: PostId, conn: impl GetConn) -> Result<Post, LemmyError> {
|
||||||
Post::read(conn, post_id)
|
Post::read(conn, post_id)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_post"))
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_post"))
|
||||||
|
@ -111,7 +111,7 @@ pub async fn get_post(post_id: PostId, conn: impl DbConn) -> Result<Post, LemmyE
|
||||||
pub async fn mark_post_as_read(
|
pub async fn mark_post_as_read(
|
||||||
person_id: PersonId,
|
person_id: PersonId,
|
||||||
post_id: PostId,
|
post_id: PostId,
|
||||||
conn: impl DbConn,
|
conn: impl GetConn,
|
||||||
) -> Result<PostRead, LemmyError> {
|
) -> Result<PostRead, LemmyError> {
|
||||||
let post_read_form = PostReadForm { post_id, person_id };
|
let post_read_form = PostReadForm { post_id, person_id };
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ pub async fn mark_post_as_read(
|
||||||
pub async fn mark_post_as_unread(
|
pub async fn mark_post_as_unread(
|
||||||
person_id: PersonId,
|
person_id: PersonId,
|
||||||
post_id: PostId,
|
post_id: PostId,
|
||||||
conn: impl DbConn,
|
conn: impl GetConn,
|
||||||
) -> Result<usize, LemmyError> {
|
) -> Result<usize, LemmyError> {
|
||||||
let post_read_form = PostReadForm { post_id, person_id };
|
let post_read_form = PostReadForm { post_id, person_id };
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ pub fn check_user_valid(
|
||||||
pub async fn check_community_ban(
|
pub async fn check_community_ban(
|
||||||
person_id: PersonId,
|
person_id: PersonId,
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
conn: impl DbConn,
|
conn: impl GetConn,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let is_banned = CommunityPersonBanView::get(conn, person_id, community_id)
|
let is_banned = CommunityPersonBanView::get(conn, person_id, community_id)
|
||||||
.await
|
.await
|
||||||
|
@ -212,7 +212,7 @@ pub async fn check_community_ban(
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
pub async fn check_community_deleted_or_removed(
|
pub async fn check_community_deleted_or_removed(
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
conn: impl DbConn,
|
conn: impl GetConn,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let community = Community::read(conn, community_id)
|
let community = Community::read(conn, community_id)
|
||||||
.await
|
.await
|
||||||
|
@ -236,7 +236,7 @@ pub fn check_post_deleted_or_removed(post: &Post) -> Result<(), LemmyError> {
|
||||||
pub async fn check_person_block(
|
pub async fn check_person_block(
|
||||||
my_id: PersonId,
|
my_id: PersonId,
|
||||||
potential_blocker_id: PersonId,
|
potential_blocker_id: PersonId,
|
||||||
conn: impl DbConn,
|
conn: impl GetConn,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let is_blocked = PersonBlock::read(conn, potential_blocker_id, my_id)
|
let is_blocked = PersonBlock::read(conn, potential_blocker_id, my_id)
|
||||||
.await
|
.await
|
||||||
|
@ -279,9 +279,9 @@ pub async fn build_federated_instances(
|
||||||
if local_site.federation_enabled {
|
if local_site.federation_enabled {
|
||||||
// TODO I hate that this requires 3 queries
|
// TODO I hate that this requires 3 queries
|
||||||
let (linked, allowed, blocked) = try_join!(
|
let (linked, allowed, blocked) = try_join!(
|
||||||
Instance::linked(&mut *conn_0),
|
Instance::linked(conn_0),
|
||||||
Instance::allowlist(&mut *conn_1),
|
Instance::allowlist(conn_1),
|
||||||
Instance::blocklist(&mut *conn_2)
|
Instance::blocklist(conn_2)
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(Some(FederatedInstances {
|
Ok(Some(FederatedInstances {
|
||||||
|
@ -338,7 +338,7 @@ pub fn send_email_to_user(
|
||||||
|
|
||||||
pub async fn send_password_reset_email(
|
pub async fn send_password_reset_email(
|
||||||
user: &LocalUserView,
|
user: &LocalUserView,
|
||||||
conn: impl DbConn,
|
conn: impl GetConn,
|
||||||
settings: &Settings,
|
settings: &Settings,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
// Generate a random token
|
// Generate a random token
|
||||||
|
@ -362,7 +362,7 @@ pub async fn send_password_reset_email(
|
||||||
pub async fn send_verification_email(
|
pub async fn send_verification_email(
|
||||||
user: &LocalUserView,
|
user: &LocalUserView,
|
||||||
new_email: &str,
|
new_email: &str,
|
||||||
conn: impl DbConn,
|
conn: impl GetConn,
|
||||||
settings: &Settings,
|
settings: &Settings,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let form = EmailVerificationForm {
|
let form = EmailVerificationForm {
|
||||||
|
@ -453,7 +453,7 @@ pub fn send_application_approved_email(
|
||||||
/// Send a new applicant email notification to all admins
|
/// Send a new applicant email notification to all admins
|
||||||
pub async fn send_new_applicant_email_to_admins(
|
pub async fn send_new_applicant_email_to_admins(
|
||||||
applicant_username: &str,
|
applicant_username: &str,
|
||||||
conn: impl DbConn,
|
conn: impl GetConn,
|
||||||
settings: &Settings,
|
settings: &Settings,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
// Collect the admins with emails
|
// Collect the admins with emails
|
||||||
|
@ -478,7 +478,7 @@ pub async fn send_new_applicant_email_to_admins(
|
||||||
pub async fn send_new_report_email_to_admins(
|
pub async fn send_new_report_email_to_admins(
|
||||||
reporter_username: &str,
|
reporter_username: &str,
|
||||||
reported_username: &str,
|
reported_username: &str,
|
||||||
conn: impl DbConn,
|
conn: impl GetConn,
|
||||||
settings: &Settings,
|
settings: &Settings,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
// Collect the admins with emails
|
// Collect the admins with emails
|
||||||
|
@ -499,7 +499,7 @@ pub async fn send_new_report_email_to_admins(
|
||||||
pub async fn check_registration_application(
|
pub async fn check_registration_application(
|
||||||
local_user_view: &LocalUserView,
|
local_user_view: &LocalUserView,
|
||||||
local_site: &LocalSite,
|
local_site: &LocalSite,
|
||||||
conn: impl DbConn,
|
conn: impl GetConn,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
if (local_site.registration_mode == RegistrationMode::RequireApplication
|
if (local_site.registration_mode == RegistrationMode::RequireApplication
|
||||||
|| local_site.registration_mode == RegistrationMode::Closed)
|
|| local_site.registration_mode == RegistrationMode::Closed)
|
||||||
|
|
|
@ -21,7 +21,7 @@ use lemmy_api_common::{
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{community::Community, person::Person, site::Site},
|
source::{community::Community, person::Person, site::Site},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::DbConn,
|
utils::GetConn,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::SiteView;
|
use lemmy_db_views::structs::SiteView;
|
||||||
use lemmy_utils::{error::LemmyError, utils::time::naive_from_unix};
|
use lemmy_utils::{error::LemmyError, utils::time::naive_from_unix};
|
||||||
|
@ -118,7 +118,7 @@ impl SiteOrCommunity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn generate_cc(target: &SiteOrCommunity, conn: impl DbConn) -> Result<Vec<Url>, LemmyError> {
|
async fn generate_cc(target: &SiteOrCommunity, conn: impl GetConn) -> Result<Vec<Url>, LemmyError> {
|
||||||
Ok(match target {
|
Ok(match target {
|
||||||
SiteOrCommunity::Site(_) => Site::read_remote_sites(conn)
|
SiteOrCommunity::Site(_) => Site::read_remote_sites(conn)
|
||||||
.await?
|
.await?
|
||||||
|
|
|
@ -7,7 +7,7 @@ use lemmy_api_common::{
|
||||||
site::{ResolveObject, ResolveObjectResponse},
|
site::{ResolveObject, ResolveObjectResponse},
|
||||||
utils::{check_private_instance, local_user_view_from_jwt},
|
utils::{check_private_instance, local_user_view_from_jwt},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{newtypes::PersonId, source::local_site::LocalSite, utils::DbConn};
|
use lemmy_db_schema::{newtypes::PersonId, source::local_site::LocalSite, utils::GetConn};
|
||||||
use lemmy_db_views::structs::{CommentView, PostView};
|
use lemmy_db_views::structs::{CommentView, PostView};
|
||||||
use lemmy_db_views_actor::structs::{CommunityView, PersonView};
|
use lemmy_db_views_actor::structs::{CommunityView, PersonView};
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
@ -33,7 +33,7 @@ pub async fn resolve_object(
|
||||||
async fn convert_response(
|
async fn convert_response(
|
||||||
object: SearchableObjects,
|
object: SearchableObjects,
|
||||||
user_id: PersonId,
|
user_id: PersonId,
|
||||||
conn: impl DbConn,
|
conn: impl GetConn,
|
||||||
) -> Result<Json<ResolveObjectResponse>, LemmyError> {
|
) -> Result<Json<ResolveObjectResponse>, LemmyError> {
|
||||||
use SearchableObjects::*;
|
use SearchableObjects::*;
|
||||||
let removed_or_deleted;
|
let removed_or_deleted;
|
||||||
|
|
|
@ -25,7 +25,7 @@ use lemmy_db_schema::{
|
||||||
site::{Site, SiteInsertForm},
|
site::{Site, SiteInsertForm},
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::{naive_now, DbConn},
|
utils::{naive_now, GetConn},
|
||||||
};
|
};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
error::LemmyError,
|
error::LemmyError,
|
||||||
|
@ -195,9 +195,11 @@ pub(in crate::objects) async fn fetch_instance_actor_for_object<T: Into<Url> + C
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn remote_instance_inboxes(mut conn: impl DbConn) -> Result<Vec<Url>, LemmyError> {
|
pub(crate) async fn remote_instance_inboxes(
|
||||||
|
mut conn: impl GetConn,
|
||||||
|
) -> Result<Vec<Url>, LemmyError> {
|
||||||
Ok(
|
Ok(
|
||||||
Site::read_remote_sites(&mut *conn)
|
Site::read_remote_sites(conn)
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|s| ApubSite::from(s).shared_inbox_or_inbox())
|
.map(|s| ApubSite::from(s).shared_inbox_or_inbox())
|
||||||
|
|
|
@ -2,7 +2,7 @@ use lemmy_db_schema::{
|
||||||
impls::actor_language::UNDETERMINED_ID,
|
impls::actor_language::UNDETERMINED_ID,
|
||||||
newtypes::LanguageId,
|
newtypes::LanguageId,
|
||||||
source::language::Language,
|
source::language::Language,
|
||||||
utils::DbConn,
|
utils::GetConn,
|
||||||
};
|
};
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -33,9 +33,9 @@ pub(crate) struct LanguageTag {
|
||||||
impl LanguageTag {
|
impl LanguageTag {
|
||||||
pub(crate) async fn new_single(
|
pub(crate) async fn new_single(
|
||||||
lang: LanguageId,
|
lang: LanguageId,
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
) -> Result<Option<LanguageTag>, LemmyError> {
|
) -> Result<Option<LanguageTag>, LemmyError> {
|
||||||
let lang = Language::read_from_id(&mut *conn, lang).await?;
|
let lang = Language::read_from_id(conn, lang).await?;
|
||||||
|
|
||||||
// undetermined
|
// undetermined
|
||||||
if lang.id == UNDETERMINED_ID {
|
if lang.id == UNDETERMINED_ID {
|
||||||
|
@ -50,12 +50,12 @@ impl LanguageTag {
|
||||||
|
|
||||||
pub(crate) async fn new_multiple(
|
pub(crate) async fn new_multiple(
|
||||||
lang_ids: Vec<LanguageId>,
|
lang_ids: Vec<LanguageId>,
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
) -> Result<Vec<LanguageTag>, LemmyError> {
|
) -> Result<Vec<LanguageTag>, LemmyError> {
|
||||||
let mut langs = Vec::<Language>::new();
|
let mut langs = Vec::<Language>::new();
|
||||||
|
|
||||||
for l in lang_ids {
|
for l in lang_ids {
|
||||||
langs.push(Language::read_from_id(&mut *conn, l).await?);
|
langs.push(Language::read_from_id(conn, l).await?);
|
||||||
}
|
}
|
||||||
|
|
||||||
let langs = langs
|
let langs = langs
|
||||||
|
@ -70,23 +70,23 @@ impl LanguageTag {
|
||||||
|
|
||||||
pub(crate) async fn to_language_id_single(
|
pub(crate) async fn to_language_id_single(
|
||||||
lang: Option<Self>,
|
lang: Option<Self>,
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
) -> Result<Option<LanguageId>, LemmyError> {
|
) -> Result<Option<LanguageId>, LemmyError> {
|
||||||
let identifier = lang.map(|l| l.identifier);
|
let identifier = lang.map(|l| l.identifier);
|
||||||
let language = Language::read_id_from_code(&mut *conn, identifier.as_deref()).await?;
|
let language = Language::read_id_from_code(conn, identifier.as_deref()).await?;
|
||||||
|
|
||||||
Ok(language)
|
Ok(language)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn to_language_id_multiple(
|
pub(crate) async fn to_language_id_multiple(
|
||||||
langs: Vec<Self>,
|
langs: Vec<Self>,
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
) -> Result<Vec<LanguageId>, LemmyError> {
|
) -> Result<Vec<LanguageId>, LemmyError> {
|
||||||
let mut language_ids = Vec::new();
|
let mut language_ids = Vec::new();
|
||||||
|
|
||||||
for l in langs {
|
for l in langs {
|
||||||
let id = l.identifier;
|
let id = l.identifier;
|
||||||
language_ids.push(Language::read_id_from_code(&mut *conn, Some(&id)).await?);
|
language_ids.push(Language::read_id_from_code(conn, Some(&id)).await?);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(language_ids.into_iter().flatten().collect())
|
Ok(language_ids.into_iter().flatten().collect())
|
||||||
|
|
|
@ -2,21 +2,21 @@ use crate::{
|
||||||
aggregates::structs::CommentAggregates,
|
aggregates::structs::CommentAggregates,
|
||||||
newtypes::CommentId,
|
newtypes::CommentId,
|
||||||
schema::comment_aggregates,
|
schema::comment_aggregates,
|
||||||
utils::{functions::hot_rank, DbConn},
|
utils::{functions::hot_rank, GetConn},
|
||||||
};
|
};
|
||||||
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
impl CommentAggregates {
|
impl CommentAggregates {
|
||||||
pub async fn read(mut conn: impl DbConn, comment_id: CommentId) -> Result<Self, Error> {
|
pub async fn read(mut conn: impl GetConn, comment_id: CommentId) -> Result<Self, Error> {
|
||||||
comment_aggregates::table
|
comment_aggregates::table
|
||||||
.filter(comment_aggregates::comment_id.eq(comment_id))
|
.filter(comment_aggregates::comment_id.eq(comment_id))
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_hot_rank(
|
pub async fn update_hot_rank(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
comment_id: CommentId,
|
comment_id: CommentId,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
diesel::update(comment_aggregates::table)
|
diesel::update(comment_aggregates::table)
|
||||||
|
@ -25,7 +25,7 @@ impl CommentAggregates {
|
||||||
comment_aggregates::score,
|
comment_aggregates::score,
|
||||||
comment_aggregates::published,
|
comment_aggregates::published,
|
||||||
)))
|
)))
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ mod tests {
|
||||||
async fn test_crud() {
|
async fn test_crud() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
let inserted_instance = Instance::read_or_create(&mut *conn, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(conn, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_person = Person::create(&mut *conn, &new_person).await.unwrap();
|
let inserted_person = Person::create(conn, &new_person).await.unwrap();
|
||||||
|
|
||||||
let another_person = PersonInsertForm::builder()
|
let another_person = PersonInsertForm::builder()
|
||||||
.name("jerry_comment_agg".into())
|
.name("jerry_comment_agg".into())
|
||||||
|
@ -69,7 +69,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let another_inserted_person = Person::create(&mut *conn, &another_person).await.unwrap();
|
let another_inserted_person = Person::create(conn, &another_person).await.unwrap();
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::builder()
|
let new_community = CommunityInsertForm::builder()
|
||||||
.name("TIL_comment_agg".into())
|
.name("TIL_comment_agg".into())
|
||||||
|
@ -78,7 +78,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_community = Community::create(&mut *conn, &new_community).await.unwrap();
|
let inserted_community = Community::create(conn, &new_community).await.unwrap();
|
||||||
|
|
||||||
let new_post = PostInsertForm::builder()
|
let new_post = PostInsertForm::builder()
|
||||||
.name("A test post".into())
|
.name("A test post".into())
|
||||||
|
@ -86,7 +86,7 @@ mod tests {
|
||||||
.community_id(inserted_community.id)
|
.community_id(inserted_community.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_post = Post::create(&mut *conn, &new_post).await.unwrap();
|
let inserted_post = Post::create(conn, &new_post).await.unwrap();
|
||||||
|
|
||||||
let comment_form = CommentInsertForm::builder()
|
let comment_form = CommentInsertForm::builder()
|
||||||
.content("A test comment".into())
|
.content("A test comment".into())
|
||||||
|
@ -94,7 +94,7 @@ mod tests {
|
||||||
.post_id(inserted_post.id)
|
.post_id(inserted_post.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_comment = Comment::create(&mut *conn, &comment_form, None)
|
let inserted_comment = Comment::create(conn, &comment_form, None)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ mod tests {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let _inserted_child_comment = Comment::create(
|
let _inserted_child_comment = Comment::create(
|
||||||
&mut *conn,
|
conn,
|
||||||
&child_comment_form,
|
&child_comment_form,
|
||||||
Some(&inserted_comment.path),
|
Some(&inserted_comment.path),
|
||||||
)
|
)
|
||||||
|
@ -119,9 +119,9 @@ mod tests {
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
CommentLike::like(&mut *conn, &comment_like).await.unwrap();
|
CommentLike::like(conn, &comment_like).await.unwrap();
|
||||||
|
|
||||||
let comment_aggs_before_delete = CommentAggregates::read(&mut *conn, inserted_comment.id)
|
let comment_aggs_before_delete = CommentAggregates::read(conn, inserted_comment.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -137,11 +137,11 @@ mod tests {
|
||||||
score: -1,
|
score: -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
CommentLike::like(&mut *conn, &comment_dislike)
|
CommentLike::like(conn, &comment_dislike)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let comment_aggs_after_dislike = CommentAggregates::read(&mut *conn, inserted_comment.id)
|
let comment_aggs_after_dislike = CommentAggregates::read(conn, inserted_comment.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -150,10 +150,10 @@ mod tests {
|
||||||
assert_eq!(1, comment_aggs_after_dislike.downvotes);
|
assert_eq!(1, comment_aggs_after_dislike.downvotes);
|
||||||
|
|
||||||
// Remove the first comment like
|
// Remove the first comment like
|
||||||
CommentLike::remove(&mut *conn, inserted_person.id, inserted_comment.id)
|
CommentLike::remove(conn, inserted_person.id, inserted_comment.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let after_like_remove = CommentAggregates::read(&mut *conn, inserted_comment.id)
|
let after_like_remove = CommentAggregates::read(conn, inserted_comment.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(-1, after_like_remove.score);
|
assert_eq!(-1, after_like_remove.score);
|
||||||
|
@ -161,28 +161,28 @@ mod tests {
|
||||||
assert_eq!(1, after_like_remove.downvotes);
|
assert_eq!(1, after_like_remove.downvotes);
|
||||||
|
|
||||||
// Remove the parent post
|
// Remove the parent post
|
||||||
Post::delete(&mut *conn, inserted_post.id).await.unwrap();
|
Post::delete(conn, inserted_post.id).await.unwrap();
|
||||||
|
|
||||||
// Should be none found, since the post was deleted
|
// Should be none found, since the post was deleted
|
||||||
let after_delete = CommentAggregates::read(&mut *conn, inserted_comment.id).await;
|
let after_delete = CommentAggregates::read(conn, inserted_comment.id).await;
|
||||||
assert!(after_delete.is_err());
|
assert!(after_delete.is_err());
|
||||||
|
|
||||||
// This should delete all the associated rows, and fire triggers
|
// This should delete all the associated rows, and fire triggers
|
||||||
Person::delete(&mut *conn, another_inserted_person.id)
|
Person::delete(conn, another_inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let person_num_deleted = Person::delete(&mut *conn, inserted_person.id)
|
let person_num_deleted = Person::delete(conn, inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, person_num_deleted);
|
assert_eq!(1, person_num_deleted);
|
||||||
|
|
||||||
// Delete the community
|
// Delete the community
|
||||||
let community_num_deleted = Community::delete(&mut *conn, inserted_community.id)
|
let community_num_deleted = Community::delete(conn, inserted_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, community_num_deleted);
|
assert_eq!(1, community_num_deleted);
|
||||||
|
|
||||||
Instance::delete(&mut *conn, inserted_instance.id)
|
Instance::delete(conn, inserted_instance.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,16 @@ use crate::{
|
||||||
aggregates::structs::CommunityAggregates,
|
aggregates::structs::CommunityAggregates,
|
||||||
newtypes::CommunityId,
|
newtypes::CommunityId,
|
||||||
schema::community_aggregates,
|
schema::community_aggregates,
|
||||||
utils::DbConn,
|
utils::GetConn,
|
||||||
};
|
};
|
||||||
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
impl CommunityAggregates {
|
impl CommunityAggregates {
|
||||||
pub async fn read(mut conn: impl DbConn, community_id: CommunityId) -> Result<Self, Error> {
|
pub async fn read(mut conn: impl GetConn, community_id: CommunityId) -> Result<Self, Error> {
|
||||||
community_aggregates::table
|
community_aggregates::table
|
||||||
.filter(community_aggregates::community_id.eq(community_id))
|
.filter(community_aggregates::community_id.eq(community_id))
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ mod tests {
|
||||||
async fn test_crud() {
|
async fn test_crud() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
let inserted_instance = Instance::read_or_create(&mut *conn, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(conn, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_person = Person::create(&mut *conn, &new_person).await.unwrap();
|
let inserted_person = Person::create(conn, &new_person).await.unwrap();
|
||||||
|
|
||||||
let another_person = PersonInsertForm::builder()
|
let another_person = PersonInsertForm::builder()
|
||||||
.name("jerry_community_agg".into())
|
.name("jerry_community_agg".into())
|
||||||
|
@ -55,7 +55,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let another_inserted_person = Person::create(&mut *conn, &another_person).await.unwrap();
|
let another_inserted_person = Person::create(conn, &another_person).await.unwrap();
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::builder()
|
let new_community = CommunityInsertForm::builder()
|
||||||
.name("TIL_community_agg".into())
|
.name("TIL_community_agg".into())
|
||||||
|
@ -64,7 +64,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_community = Community::create(&mut *conn, &new_community).await.unwrap();
|
let inserted_community = Community::create(conn, &new_community).await.unwrap();
|
||||||
|
|
||||||
let another_community = CommunityInsertForm::builder()
|
let another_community = CommunityInsertForm::builder()
|
||||||
.name("TIL_community_agg_2".into())
|
.name("TIL_community_agg_2".into())
|
||||||
|
@ -73,7 +73,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let another_inserted_community = Community::create(&mut *conn, &another_community)
|
let another_inserted_community = Community::create(conn, &another_community)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ mod tests {
|
||||||
pending: false,
|
pending: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
CommunityFollower::follow(&mut *conn, &first_person_follow)
|
CommunityFollower::follow(conn, &first_person_follow)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ mod tests {
|
||||||
pending: false,
|
pending: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
CommunityFollower::follow(&mut *conn, &second_person_follow)
|
CommunityFollower::follow(conn, &second_person_follow)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ mod tests {
|
||||||
pending: false,
|
pending: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
CommunityFollower::follow(&mut *conn, &another_community_follow)
|
CommunityFollower::follow(conn, &another_community_follow)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ mod tests {
|
||||||
.community_id(inserted_community.id)
|
.community_id(inserted_community.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_post = Post::create(&mut *conn, &new_post).await.unwrap();
|
let inserted_post = Post::create(conn, &new_post).await.unwrap();
|
||||||
|
|
||||||
let comment_form = CommentInsertForm::builder()
|
let comment_form = CommentInsertForm::builder()
|
||||||
.content("A test comment".into())
|
.content("A test comment".into())
|
||||||
|
@ -121,7 +121,7 @@ mod tests {
|
||||||
.post_id(inserted_post.id)
|
.post_id(inserted_post.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_comment = Comment::create(&mut *conn, &comment_form, None)
|
let inserted_comment = Comment::create(conn, &comment_form, None)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ mod tests {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let _inserted_child_comment = Comment::create(
|
let _inserted_child_comment = Comment::create(
|
||||||
&mut *conn,
|
conn,
|
||||||
&child_comment_form,
|
&child_comment_form,
|
||||||
Some(&inserted_comment.path),
|
Some(&inserted_comment.path),
|
||||||
)
|
)
|
||||||
|
@ -140,7 +140,7 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let community_aggregates_before_delete =
|
let community_aggregates_before_delete =
|
||||||
CommunityAggregates::read(&mut *conn, inserted_community.id)
|
CommunityAggregates::read(conn, inserted_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ mod tests {
|
||||||
|
|
||||||
// Test the other community
|
// Test the other community
|
||||||
let another_community_aggs =
|
let another_community_aggs =
|
||||||
CommunityAggregates::read(&mut *conn, another_inserted_community.id)
|
CommunityAggregates::read(conn, another_inserted_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, another_community_aggs.subscribers);
|
assert_eq!(1, another_community_aggs.subscribers);
|
||||||
|
@ -158,60 +158,60 @@ mod tests {
|
||||||
assert_eq!(0, another_community_aggs.comments);
|
assert_eq!(0, another_community_aggs.comments);
|
||||||
|
|
||||||
// Unfollow test
|
// Unfollow test
|
||||||
CommunityFollower::unfollow(&mut *conn, &second_person_follow)
|
CommunityFollower::unfollow(conn, &second_person_follow)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let after_unfollow = CommunityAggregates::read(&mut *conn, inserted_community.id)
|
let after_unfollow = CommunityAggregates::read(conn, inserted_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, after_unfollow.subscribers);
|
assert_eq!(1, after_unfollow.subscribers);
|
||||||
|
|
||||||
// Follow again just for the later tests
|
// Follow again just for the later tests
|
||||||
CommunityFollower::follow(&mut *conn, &second_person_follow)
|
CommunityFollower::follow(conn, &second_person_follow)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let after_follow_again = CommunityAggregates::read(&mut *conn, inserted_community.id)
|
let after_follow_again = CommunityAggregates::read(conn, inserted_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(2, after_follow_again.subscribers);
|
assert_eq!(2, after_follow_again.subscribers);
|
||||||
|
|
||||||
// Remove a parent comment (the comment count should also be 0)
|
// Remove a parent comment (the comment count should also be 0)
|
||||||
Post::delete(&mut *conn, inserted_post.id).await.unwrap();
|
Post::delete(conn, inserted_post.id).await.unwrap();
|
||||||
let after_parent_post_delete = CommunityAggregates::read(&mut *conn, inserted_community.id)
|
let after_parent_post_delete = CommunityAggregates::read(conn, inserted_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(0, after_parent_post_delete.comments);
|
assert_eq!(0, after_parent_post_delete.comments);
|
||||||
assert_eq!(0, after_parent_post_delete.posts);
|
assert_eq!(0, after_parent_post_delete.posts);
|
||||||
|
|
||||||
// Remove the 2nd person
|
// Remove the 2nd person
|
||||||
Person::delete(&mut *conn, another_inserted_person.id)
|
Person::delete(conn, another_inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let after_person_delete = CommunityAggregates::read(&mut *conn, inserted_community.id)
|
let after_person_delete = CommunityAggregates::read(conn, inserted_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, after_person_delete.subscribers);
|
assert_eq!(1, after_person_delete.subscribers);
|
||||||
|
|
||||||
// This should delete all the associated rows, and fire triggers
|
// This should delete all the associated rows, and fire triggers
|
||||||
let person_num_deleted = Person::delete(&mut *conn, inserted_person.id)
|
let person_num_deleted = Person::delete(conn, inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, person_num_deleted);
|
assert_eq!(1, person_num_deleted);
|
||||||
|
|
||||||
// Delete the community
|
// Delete the community
|
||||||
let community_num_deleted = Community::delete(&mut *conn, inserted_community.id)
|
let community_num_deleted = Community::delete(conn, inserted_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, community_num_deleted);
|
assert_eq!(1, community_num_deleted);
|
||||||
|
|
||||||
let another_community_num_deleted =
|
let another_community_num_deleted =
|
||||||
Community::delete(&mut *conn, another_inserted_community.id)
|
Community::delete(conn, another_inserted_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, another_community_num_deleted);
|
assert_eq!(1, another_community_num_deleted);
|
||||||
|
|
||||||
// Should be none found, since the creator was deleted
|
// Should be none found, since the creator was deleted
|
||||||
let after_delete = CommunityAggregates::read(&mut *conn, inserted_community.id).await;
|
let after_delete = CommunityAggregates::read(conn, inserted_community.id).await;
|
||||||
assert!(after_delete.is_err());
|
assert!(after_delete.is_err());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,16 @@ use crate::{
|
||||||
aggregates::structs::PersonAggregates,
|
aggregates::structs::PersonAggregates,
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
schema::person_aggregates,
|
schema::person_aggregates,
|
||||||
utils::DbConn,
|
utils::GetConn,
|
||||||
};
|
};
|
||||||
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
impl PersonAggregates {
|
impl PersonAggregates {
|
||||||
pub async fn read(mut conn: impl DbConn, person_id: PersonId) -> Result<Self, Error> {
|
pub async fn read(mut conn: impl GetConn, person_id: PersonId) -> Result<Self, Error> {
|
||||||
person_aggregates::table
|
person_aggregates::table
|
||||||
.filter(person_aggregates::person_id.eq(person_id))
|
.filter(person_aggregates::person_id.eq(person_id))
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ mod tests {
|
||||||
async fn test_crud() {
|
async fn test_crud() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
let inserted_instance = Instance::read_or_create(&mut *conn, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(conn, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_person = Person::create(&mut *conn, &new_person).await.unwrap();
|
let inserted_person = Person::create(conn, &new_person).await.unwrap();
|
||||||
|
|
||||||
let another_person = PersonInsertForm::builder()
|
let another_person = PersonInsertForm::builder()
|
||||||
.name("jerry_user_agg".into())
|
.name("jerry_user_agg".into())
|
||||||
|
@ -55,7 +55,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let another_inserted_person = Person::create(&mut *conn, &another_person).await.unwrap();
|
let another_inserted_person = Person::create(conn, &another_person).await.unwrap();
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::builder()
|
let new_community = CommunityInsertForm::builder()
|
||||||
.name("TIL_site_agg".into())
|
.name("TIL_site_agg".into())
|
||||||
|
@ -64,7 +64,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_community = Community::create(&mut *conn, &new_community).await.unwrap();
|
let inserted_community = Community::create(conn, &new_community).await.unwrap();
|
||||||
|
|
||||||
let new_post = PostInsertForm::builder()
|
let new_post = PostInsertForm::builder()
|
||||||
.name("A test post".into())
|
.name("A test post".into())
|
||||||
|
@ -72,7 +72,7 @@ mod tests {
|
||||||
.community_id(inserted_community.id)
|
.community_id(inserted_community.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_post = Post::create(&mut *conn, &new_post).await.unwrap();
|
let inserted_post = Post::create(conn, &new_post).await.unwrap();
|
||||||
|
|
||||||
let post_like = PostLikeForm {
|
let post_like = PostLikeForm {
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
|
@ -80,7 +80,7 @@ mod tests {
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
let _inserted_post_like = PostLike::like(&mut *conn, &post_like).await.unwrap();
|
let _inserted_post_like = PostLike::like(conn, &post_like).await.unwrap();
|
||||||
|
|
||||||
let comment_form = CommentInsertForm::builder()
|
let comment_form = CommentInsertForm::builder()
|
||||||
.content("A test comment".into())
|
.content("A test comment".into())
|
||||||
|
@ -88,7 +88,7 @@ mod tests {
|
||||||
.post_id(inserted_post.id)
|
.post_id(inserted_post.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_comment = Comment::create(&mut *conn, &comment_form, None)
|
let inserted_comment = Comment::create(conn, &comment_form, None)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ mod tests {
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
let _inserted_comment_like = CommentLike::like(&mut *conn, &comment_like).await.unwrap();
|
let _inserted_comment_like = CommentLike::like(conn, &comment_like).await.unwrap();
|
||||||
|
|
||||||
let child_comment_form = CommentInsertForm::builder()
|
let child_comment_form = CommentInsertForm::builder()
|
||||||
.content("A test comment".into())
|
.content("A test comment".into())
|
||||||
|
@ -108,7 +108,7 @@ mod tests {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_child_comment = Comment::create(
|
let inserted_child_comment = Comment::create(
|
||||||
&mut *conn,
|
conn,
|
||||||
&child_comment_form,
|
&child_comment_form,
|
||||||
Some(&inserted_comment.path),
|
Some(&inserted_comment.path),
|
||||||
)
|
)
|
||||||
|
@ -122,11 +122,11 @@ mod tests {
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
let _inserted_child_comment_like = CommentLike::like(&mut *conn, &child_comment_like)
|
let _inserted_child_comment_like = CommentLike::like(conn, &child_comment_like)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let person_aggregates_before_delete = PersonAggregates::read(&mut *conn, inserted_person.id)
|
let person_aggregates_before_delete = PersonAggregates::read(conn, inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -136,69 +136,69 @@ mod tests {
|
||||||
assert_eq!(2, person_aggregates_before_delete.comment_score);
|
assert_eq!(2, person_aggregates_before_delete.comment_score);
|
||||||
|
|
||||||
// Remove a post like
|
// Remove a post like
|
||||||
PostLike::remove(&mut *conn, inserted_person.id, inserted_post.id)
|
PostLike::remove(conn, inserted_person.id, inserted_post.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let after_post_like_remove = PersonAggregates::read(&mut *conn, inserted_person.id)
|
let after_post_like_remove = PersonAggregates::read(conn, inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(0, after_post_like_remove.post_score);
|
assert_eq!(0, after_post_like_remove.post_score);
|
||||||
|
|
||||||
Comment::update(
|
Comment::update(
|
||||||
&mut *conn,
|
conn,
|
||||||
inserted_comment.id,
|
inserted_comment.id,
|
||||||
&CommentUpdateForm::builder().removed(Some(true)).build(),
|
&CommentUpdateForm::builder().removed(Some(true)).build(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Comment::update(
|
Comment::update(
|
||||||
&mut *conn,
|
conn,
|
||||||
inserted_child_comment.id,
|
inserted_child_comment.id,
|
||||||
&CommentUpdateForm::builder().removed(Some(true)).build(),
|
&CommentUpdateForm::builder().removed(Some(true)).build(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let after_parent_comment_removed = PersonAggregates::read(&mut *conn, inserted_person.id)
|
let after_parent_comment_removed = PersonAggregates::read(conn, inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(0, after_parent_comment_removed.comment_count);
|
assert_eq!(0, after_parent_comment_removed.comment_count);
|
||||||
assert_eq!(0, after_parent_comment_removed.comment_score);
|
assert_eq!(0, after_parent_comment_removed.comment_score);
|
||||||
|
|
||||||
// Remove a parent comment (the scores should also be removed)
|
// Remove a parent comment (the scores should also be removed)
|
||||||
Comment::delete(&mut *conn, inserted_comment.id)
|
Comment::delete(conn, inserted_comment.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Comment::delete(&mut *conn, inserted_child_comment.id)
|
Comment::delete(conn, inserted_child_comment.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let after_parent_comment_delete = PersonAggregates::read(&mut *conn, inserted_person.id)
|
let after_parent_comment_delete = PersonAggregates::read(conn, inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(0, after_parent_comment_delete.comment_count);
|
assert_eq!(0, after_parent_comment_delete.comment_count);
|
||||||
assert_eq!(0, after_parent_comment_delete.comment_score);
|
assert_eq!(0, after_parent_comment_delete.comment_score);
|
||||||
|
|
||||||
// Add in the two comments again, then delete the post.
|
// Add in the two comments again, then delete the post.
|
||||||
let new_parent_comment = Comment::create(&mut *conn, &comment_form, None)
|
let new_parent_comment = Comment::create(conn, &comment_form, None)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let _new_child_comment = Comment::create(
|
let _new_child_comment = Comment::create(
|
||||||
&mut *conn,
|
conn,
|
||||||
&child_comment_form,
|
&child_comment_form,
|
||||||
Some(&new_parent_comment.path),
|
Some(&new_parent_comment.path),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
comment_like.comment_id = new_parent_comment.id;
|
comment_like.comment_id = new_parent_comment.id;
|
||||||
CommentLike::like(&mut *conn, &comment_like).await.unwrap();
|
CommentLike::like(conn, &comment_like).await.unwrap();
|
||||||
let after_comment_add = PersonAggregates::read(&mut *conn, inserted_person.id)
|
let after_comment_add = PersonAggregates::read(conn, inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(2, after_comment_add.comment_count);
|
assert_eq!(2, after_comment_add.comment_count);
|
||||||
assert_eq!(1, after_comment_add.comment_score);
|
assert_eq!(1, after_comment_add.comment_score);
|
||||||
|
|
||||||
Post::delete(&mut *conn, inserted_post.id).await.unwrap();
|
Post::delete(conn, inserted_post.id).await.unwrap();
|
||||||
let after_post_delete = PersonAggregates::read(&mut *conn, inserted_person.id)
|
let after_post_delete = PersonAggregates::read(conn, inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(0, after_post_delete.comment_score);
|
assert_eq!(0, after_post_delete.comment_score);
|
||||||
|
@ -207,25 +207,25 @@ mod tests {
|
||||||
assert_eq!(0, after_post_delete.post_count);
|
assert_eq!(0, after_post_delete.post_count);
|
||||||
|
|
||||||
// This should delete all the associated rows, and fire triggers
|
// This should delete all the associated rows, and fire triggers
|
||||||
let person_num_deleted = Person::delete(&mut *conn, inserted_person.id)
|
let person_num_deleted = Person::delete(conn, inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, person_num_deleted);
|
assert_eq!(1, person_num_deleted);
|
||||||
Person::delete(&mut *conn, another_inserted_person.id)
|
Person::delete(conn, another_inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Delete the community
|
// Delete the community
|
||||||
let community_num_deleted = Community::delete(&mut *conn, inserted_community.id)
|
let community_num_deleted = Community::delete(conn, inserted_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, community_num_deleted);
|
assert_eq!(1, community_num_deleted);
|
||||||
|
|
||||||
// Should be none found
|
// Should be none found
|
||||||
let after_delete = PersonAggregates::read(&mut *conn, inserted_person.id).await;
|
let after_delete = PersonAggregates::read(conn, inserted_person.id).await;
|
||||||
assert!(after_delete.is_err());
|
assert!(after_delete.is_err());
|
||||||
|
|
||||||
Instance::delete(&mut *conn, inserted_instance.id)
|
Instance::delete(conn, inserted_instance.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,14 @@ use crate::{
|
||||||
diesel::BoolExpressionMethods,
|
diesel::BoolExpressionMethods,
|
||||||
newtypes::{PersonId, PostId},
|
newtypes::{PersonId, PostId},
|
||||||
schema::person_post_aggregates::dsl::{person_id, person_post_aggregates, post_id},
|
schema::person_post_aggregates::dsl::{person_id, person_post_aggregates, post_id},
|
||||||
utils::DbConn,
|
utils::GetConn,
|
||||||
};
|
};
|
||||||
use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
impl PersonPostAggregates {
|
impl PersonPostAggregates {
|
||||||
pub async fn upsert(
|
pub async fn upsert(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
form: &PersonPostAggregatesForm,
|
form: &PersonPostAggregatesForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
insert_into(person_post_aggregates)
|
insert_into(person_post_aggregates)
|
||||||
|
@ -18,17 +18,17 @@ impl PersonPostAggregates {
|
||||||
.on_conflict((person_id, post_id))
|
.on_conflict((person_id, post_id))
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
person_id_: PersonId,
|
person_id_: PersonId,
|
||||||
post_id_: PostId,
|
post_id_: PostId,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
person_post_aggregates
|
person_post_aggregates
|
||||||
.filter(post_id.eq(post_id_).and(person_id.eq(person_id_)))
|
.filter(post_id.eq(post_id_).and(person_id.eq(person_id_)))
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,20 +2,20 @@ use crate::{
|
||||||
aggregates::structs::PostAggregates,
|
aggregates::structs::PostAggregates,
|
||||||
newtypes::PostId,
|
newtypes::PostId,
|
||||||
schema::post_aggregates,
|
schema::post_aggregates,
|
||||||
utils::{functions::hot_rank, DbConn},
|
utils::{functions::hot_rank, GetConn},
|
||||||
};
|
};
|
||||||
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
impl PostAggregates {
|
impl PostAggregates {
|
||||||
pub async fn read(mut conn: impl DbConn, post_id: PostId) -> Result<Self, Error> {
|
pub async fn read(mut conn: impl GetConn, post_id: PostId) -> Result<Self, Error> {
|
||||||
post_aggregates::table
|
post_aggregates::table
|
||||||
.filter(post_aggregates::post_id.eq(post_id))
|
.filter(post_aggregates::post_id.eq(post_id))
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_hot_rank(mut conn: impl DbConn, post_id: PostId) -> Result<Self, Error> {
|
pub async fn update_hot_rank(mut conn: impl GetConn, post_id: PostId) -> Result<Self, Error> {
|
||||||
diesel::update(post_aggregates::table)
|
diesel::update(post_aggregates::table)
|
||||||
.filter(post_aggregates::post_id.eq(post_id))
|
.filter(post_aggregates::post_id.eq(post_id))
|
||||||
.set((
|
.set((
|
||||||
|
@ -25,7 +25,7 @@ impl PostAggregates {
|
||||||
post_aggregates::newest_comment_time_necro,
|
post_aggregates::newest_comment_time_necro,
|
||||||
)),
|
)),
|
||||||
))
|
))
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ mod tests {
|
||||||
async fn test_crud() {
|
async fn test_crud() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
let inserted_instance = Instance::read_or_create(&mut *conn, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(conn, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_person = Person::create(&mut *conn, &new_person).await.unwrap();
|
let inserted_person = Person::create(conn, &new_person).await.unwrap();
|
||||||
|
|
||||||
let another_person = PersonInsertForm::builder()
|
let another_person = PersonInsertForm::builder()
|
||||||
.name("jerry_community_agg".into())
|
.name("jerry_community_agg".into())
|
||||||
|
@ -69,7 +69,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let another_inserted_person = Person::create(&mut *conn, &another_person).await.unwrap();
|
let another_inserted_person = Person::create(conn, &another_person).await.unwrap();
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::builder()
|
let new_community = CommunityInsertForm::builder()
|
||||||
.name("TIL_community_agg".into())
|
.name("TIL_community_agg".into())
|
||||||
|
@ -78,7 +78,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_community = Community::create(&mut *conn, &new_community).await.unwrap();
|
let inserted_community = Community::create(conn, &new_community).await.unwrap();
|
||||||
|
|
||||||
let new_post = PostInsertForm::builder()
|
let new_post = PostInsertForm::builder()
|
||||||
.name("A test post".into())
|
.name("A test post".into())
|
||||||
|
@ -86,7 +86,7 @@ mod tests {
|
||||||
.community_id(inserted_community.id)
|
.community_id(inserted_community.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_post = Post::create(&mut *conn, &new_post).await.unwrap();
|
let inserted_post = Post::create(conn, &new_post).await.unwrap();
|
||||||
|
|
||||||
let comment_form = CommentInsertForm::builder()
|
let comment_form = CommentInsertForm::builder()
|
||||||
.content("A test comment".into())
|
.content("A test comment".into())
|
||||||
|
@ -94,7 +94,7 @@ mod tests {
|
||||||
.post_id(inserted_post.id)
|
.post_id(inserted_post.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_comment = Comment::create(&mut *conn, &comment_form, None)
|
let inserted_comment = Comment::create(conn, &comment_form, None)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ mod tests {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_child_comment = Comment::create(
|
let inserted_child_comment = Comment::create(
|
||||||
&mut *conn,
|
conn,
|
||||||
&child_comment_form,
|
&child_comment_form,
|
||||||
Some(&inserted_comment.path),
|
Some(&inserted_comment.path),
|
||||||
)
|
)
|
||||||
|
@ -118,9 +118,9 @@ mod tests {
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
PostLike::like(&mut *conn, &post_like).await.unwrap();
|
PostLike::like(conn, &post_like).await.unwrap();
|
||||||
|
|
||||||
let post_aggs_before_delete = PostAggregates::read(&mut *conn, inserted_post.id)
|
let post_aggs_before_delete = PostAggregates::read(conn, inserted_post.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -136,9 +136,9 @@ mod tests {
|
||||||
score: -1,
|
score: -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
PostLike::like(&mut *conn, &post_dislike).await.unwrap();
|
PostLike::like(conn, &post_dislike).await.unwrap();
|
||||||
|
|
||||||
let post_aggs_after_dislike = PostAggregates::read(&mut *conn, inserted_post.id)
|
let post_aggs_after_dislike = PostAggregates::read(conn, inserted_post.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -148,13 +148,13 @@ mod tests {
|
||||||
assert_eq!(1, post_aggs_after_dislike.downvotes);
|
assert_eq!(1, post_aggs_after_dislike.downvotes);
|
||||||
|
|
||||||
// Remove the comments
|
// Remove the comments
|
||||||
Comment::delete(&mut *conn, inserted_comment.id)
|
Comment::delete(conn, inserted_comment.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Comment::delete(&mut *conn, inserted_child_comment.id)
|
Comment::delete(conn, inserted_child_comment.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let after_comment_delete = PostAggregates::read(&mut *conn, inserted_post.id)
|
let after_comment_delete = PostAggregates::read(conn, inserted_post.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(0, after_comment_delete.comments);
|
assert_eq!(0, after_comment_delete.comments);
|
||||||
|
@ -163,10 +163,10 @@ mod tests {
|
||||||
assert_eq!(1, after_comment_delete.downvotes);
|
assert_eq!(1, after_comment_delete.downvotes);
|
||||||
|
|
||||||
// Remove the first post like
|
// Remove the first post like
|
||||||
PostLike::remove(&mut *conn, inserted_person.id, inserted_post.id)
|
PostLike::remove(conn, inserted_person.id, inserted_post.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let after_like_remove = PostAggregates::read(&mut *conn, inserted_post.id)
|
let after_like_remove = PostAggregates::read(conn, inserted_post.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(0, after_like_remove.comments);
|
assert_eq!(0, after_like_remove.comments);
|
||||||
|
@ -175,25 +175,25 @@ mod tests {
|
||||||
assert_eq!(1, after_like_remove.downvotes);
|
assert_eq!(1, after_like_remove.downvotes);
|
||||||
|
|
||||||
// This should delete all the associated rows, and fire triggers
|
// This should delete all the associated rows, and fire triggers
|
||||||
Person::delete(&mut *conn, another_inserted_person.id)
|
Person::delete(conn, another_inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let person_num_deleted = Person::delete(&mut *conn, inserted_person.id)
|
let person_num_deleted = Person::delete(conn, inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, person_num_deleted);
|
assert_eq!(1, person_num_deleted);
|
||||||
|
|
||||||
// Delete the community
|
// Delete the community
|
||||||
let community_num_deleted = Community::delete(&mut *conn, inserted_community.id)
|
let community_num_deleted = Community::delete(conn, inserted_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, community_num_deleted);
|
assert_eq!(1, community_num_deleted);
|
||||||
|
|
||||||
// Should be none found, since the creator was deleted
|
// Should be none found, since the creator was deleted
|
||||||
let after_delete = PostAggregates::read(&mut *conn, inserted_post.id).await;
|
let after_delete = PostAggregates::read(conn, inserted_post.id).await;
|
||||||
assert!(after_delete.is_err());
|
assert!(after_delete.is_err());
|
||||||
|
|
||||||
Instance::delete(&mut *conn, inserted_instance.id)
|
Instance::delete(conn, inserted_instance.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use crate::{aggregates::structs::SiteAggregates, schema::site_aggregates, utils::DbConn};
|
use crate::{aggregates::structs::SiteAggregates, schema::site_aggregates, utils::GetConn};
|
||||||
use diesel::result::Error;
|
use diesel::result::Error;
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
impl SiteAggregates {
|
impl SiteAggregates {
|
||||||
pub async fn read(mut conn: impl DbConn) -> Result<Self, Error> {
|
pub async fn read(mut conn: impl GetConn) -> Result<Self, Error> {
|
||||||
site_aggregates::table.first::<Self>(&mut *conn).await
|
site_aggregates::table.first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ mod tests {
|
||||||
async fn test_crud() {
|
async fn test_crud() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
let inserted_instance = Instance::read_or_create(&mut *conn, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(conn, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -40,14 +40,14 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_person = Person::create(&mut *conn, &new_person).await.unwrap();
|
let inserted_person = Person::create(conn, &new_person).await.unwrap();
|
||||||
|
|
||||||
let site_form = SiteInsertForm::builder()
|
let site_form = SiteInsertForm::builder()
|
||||||
.name("test_site".into())
|
.name("test_site".into())
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_site = Site::create(&mut *conn, &site_form).await.unwrap();
|
let inserted_site = Site::create(conn, &site_form).await.unwrap();
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::builder()
|
let new_community = CommunityInsertForm::builder()
|
||||||
.name("TIL_site_agg".into())
|
.name("TIL_site_agg".into())
|
||||||
|
@ -56,7 +56,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_community = Community::create(&mut *conn, &new_community).await.unwrap();
|
let inserted_community = Community::create(conn, &new_community).await.unwrap();
|
||||||
|
|
||||||
let new_post = PostInsertForm::builder()
|
let new_post = PostInsertForm::builder()
|
||||||
.name("A test post".into())
|
.name("A test post".into())
|
||||||
|
@ -65,8 +65,8 @@ mod tests {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Insert two of those posts
|
// Insert two of those posts
|
||||||
let inserted_post = Post::create(&mut *conn, &new_post).await.unwrap();
|
let inserted_post = Post::create(conn, &new_post).await.unwrap();
|
||||||
let _inserted_post_again = Post::create(&mut *conn, &new_post).await.unwrap();
|
let _inserted_post_again = Post::create(conn, &new_post).await.unwrap();
|
||||||
|
|
||||||
let comment_form = CommentInsertForm::builder()
|
let comment_form = CommentInsertForm::builder()
|
||||||
.content("A test comment".into())
|
.content("A test comment".into())
|
||||||
|
@ -75,7 +75,7 @@ mod tests {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Insert two of those comments
|
// Insert two of those comments
|
||||||
let inserted_comment = Comment::create(&mut *conn, &comment_form, None)
|
let inserted_comment = Comment::create(conn, &comment_form, None)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -86,14 +86,14 @@ mod tests {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let _inserted_child_comment = Comment::create(
|
let _inserted_child_comment = Comment::create(
|
||||||
&mut *conn,
|
conn,
|
||||||
&child_comment_form,
|
&child_comment_form,
|
||||||
Some(&inserted_comment.path),
|
Some(&inserted_comment.path),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let site_aggregates_before_delete = SiteAggregates::read(&mut *conn).await.unwrap();
|
let site_aggregates_before_delete = SiteAggregates::read(conn).await.unwrap();
|
||||||
|
|
||||||
// TODO: this is unstable, sometimes it returns 0 users, sometimes 1
|
// TODO: this is unstable, sometimes it returns 0 users, sometimes 1
|
||||||
//assert_eq!(0, site_aggregates_before_delete.users);
|
//assert_eq!(0, site_aggregates_before_delete.users);
|
||||||
|
@ -102,32 +102,32 @@ mod tests {
|
||||||
assert_eq!(2, site_aggregates_before_delete.comments);
|
assert_eq!(2, site_aggregates_before_delete.comments);
|
||||||
|
|
||||||
// Try a post delete
|
// Try a post delete
|
||||||
Post::delete(&mut *conn, inserted_post.id).await.unwrap();
|
Post::delete(conn, inserted_post.id).await.unwrap();
|
||||||
let site_aggregates_after_post_delete = SiteAggregates::read(&mut *conn).await.unwrap();
|
let site_aggregates_after_post_delete = SiteAggregates::read(conn).await.unwrap();
|
||||||
assert_eq!(1, site_aggregates_after_post_delete.posts);
|
assert_eq!(1, site_aggregates_after_post_delete.posts);
|
||||||
assert_eq!(0, site_aggregates_after_post_delete.comments);
|
assert_eq!(0, site_aggregates_after_post_delete.comments);
|
||||||
|
|
||||||
// This shouuld delete all the associated rows, and fire triggers
|
// This shouuld delete all the associated rows, and fire triggers
|
||||||
let person_num_deleted = Person::delete(&mut *conn, inserted_person.id)
|
let person_num_deleted = Person::delete(conn, inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, person_num_deleted);
|
assert_eq!(1, person_num_deleted);
|
||||||
|
|
||||||
// Delete the community
|
// Delete the community
|
||||||
let community_num_deleted = Community::delete(&mut *conn, inserted_community.id)
|
let community_num_deleted = Community::delete(conn, inserted_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, community_num_deleted);
|
assert_eq!(1, community_num_deleted);
|
||||||
|
|
||||||
// Site should still exist, it can without a site creator.
|
// Site should still exist, it can without a site creator.
|
||||||
let after_delete_creator = SiteAggregates::read(&mut *conn).await;
|
let after_delete_creator = SiteAggregates::read(conn).await;
|
||||||
assert!(after_delete_creator.is_ok());
|
assert!(after_delete_creator.is_ok());
|
||||||
|
|
||||||
Site::delete(&mut *conn, inserted_site.id).await.unwrap();
|
Site::delete(conn, inserted_site.id).await.unwrap();
|
||||||
let after_delete_site = SiteAggregates::read(&mut *conn).await;
|
let after_delete_site = SiteAggregates::read(conn).await;
|
||||||
assert!(after_delete_site.is_err());
|
assert!(after_delete_site.is_err());
|
||||||
|
|
||||||
Instance::delete(&mut *conn, inserted_instance.id)
|
Instance::delete(conn, inserted_instance.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,52 +3,52 @@ use crate::{
|
||||||
schema::activity::dsl::{activity, ap_id},
|
schema::activity::dsl::{activity, ap_id},
|
||||||
source::activity::{Activity, ActivityInsertForm, ActivityUpdateForm},
|
source::activity::{Activity, ActivityInsertForm, ActivityUpdateForm},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::DbConn,
|
utils::GetConn,
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Crud for Activity {
|
impl Crud for Activity {
|
||||||
type InsertForm = ActivityInsertForm;
|
type InsertForm = ActivityInsertForm;
|
||||||
type UpdateForm = ActivityUpdateForm;
|
type UpdateForm = ActivityUpdateForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut conn: impl DbConn, activity_id: i32) -> Result<Self, Error> {
|
async fn read(mut conn: impl GetConn, activity_id: i32) -> Result<Self, Error> {
|
||||||
activity.find(activity_id).first::<Self>(&mut *conn).await
|
activity.find(activity_id).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut conn: impl DbConn, new_activity: &Self::InsertForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl GetConn, new_activity: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
insert_into(activity)
|
insert_into(activity)
|
||||||
.values(new_activity)
|
.values(new_activity)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
activity_id: i32,
|
activity_id: i32,
|
||||||
new_activity: &Self::UpdateForm,
|
new_activity: &Self::UpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
diesel::update(activity.find(activity_id))
|
diesel::update(activity.find(activity_id))
|
||||||
.set(new_activity)
|
.set(new_activity)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn delete(mut conn: impl DbConn, activity_id: i32) -> Result<usize, Error> {
|
async fn delete(mut conn: impl GetConn, activity_id: i32) -> Result<usize, Error> {
|
||||||
diesel::delete(activity.find(activity_id))
|
diesel::delete(activity.find(activity_id))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Activity {
|
impl Activity {
|
||||||
pub async fn read_from_apub_id(
|
pub async fn read_from_apub_id(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
object_id: &DbUrl,
|
object_id: &DbUrl,
|
||||||
) -> Result<Activity, Error> {
|
) -> Result<Activity, Error> {
|
||||||
activity
|
activity
|
||||||
.filter(ap_id.eq(object_id))
|
.filter(ap_id.eq(object_id))
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ mod tests {
|
||||||
async fn test_crud() {
|
async fn test_crud() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
let inserted_instance = Instance::read_or_create(&mut *conn, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(conn, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_creator = Person::create(&mut *conn, &creator_form).await.unwrap();
|
let inserted_creator = Person::create(conn, &creator_form).await.unwrap();
|
||||||
|
|
||||||
let ap_id_: DbUrl = Url::parse(
|
let ap_id_: DbUrl = Url::parse(
|
||||||
"https://enterprise.lemmy.ml/activities/delete/f1b5d57c-80f8-4e03-a615-688d552e946c",
|
"https://enterprise.lemmy.ml/activities/delete/f1b5d57c-80f8-4e03-a615-688d552e946c",
|
||||||
|
@ -113,7 +113,7 @@ mod tests {
|
||||||
updated: None,
|
updated: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_activity = Activity::create(&mut *conn, &activity_form).await.unwrap();
|
let inserted_activity = Activity::create(conn, &activity_form).await.unwrap();
|
||||||
|
|
||||||
let expected_activity = Activity {
|
let expected_activity = Activity {
|
||||||
ap_id: ap_id_.clone(),
|
ap_id: ap_id_.clone(),
|
||||||
|
@ -125,16 +125,16 @@ mod tests {
|
||||||
updated: None,
|
updated: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let read_activity = Activity::read(&mut *conn, inserted_activity.id)
|
let read_activity = Activity::read(conn, inserted_activity.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let read_activity_by_apub_id = Activity::read_from_apub_id(&mut *conn, &ap_id_)
|
let read_activity_by_apub_id = Activity::read_from_apub_id(conn, &ap_id_)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Person::delete(&mut *conn, inserted_creator.id)
|
Person::delete(conn, inserted_creator.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Activity::delete(&mut *conn, inserted_activity.id)
|
Activity::delete(conn, inserted_activity.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ use crate::{
|
||||||
language::Language,
|
language::Language,
|
||||||
site::Site,
|
site::Site,
|
||||||
},
|
},
|
||||||
utils::DbConn,
|
utils::GetConn,
|
||||||
};
|
};
|
||||||
use diesel::{
|
use diesel::{
|
||||||
delete,
|
delete,
|
||||||
|
@ -25,7 +25,7 @@ use diesel::{
|
||||||
ExpressionMethods,
|
ExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
use tokio::sync::OnceCell;
|
use tokio::sync::OnceCell;
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ pub const UNDETERMINED_ID: LanguageId = LanguageId(0);
|
||||||
|
|
||||||
impl LocalUserLanguage {
|
impl LocalUserLanguage {
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_local_user_id: LocalUserId,
|
for_local_user_id: LocalUserId,
|
||||||
) -> Result<Vec<LanguageId>, Error> {
|
) -> Result<Vec<LanguageId>, Error> {
|
||||||
use crate::schema::local_user_language::dsl::{
|
use crate::schema::local_user_language::dsl::{
|
||||||
|
@ -50,9 +50,9 @@ impl LocalUserLanguage {
|
||||||
.filter(local_user_id.eq(for_local_user_id))
|
.filter(local_user_id.eq(for_local_user_id))
|
||||||
.order(language_id)
|
.order(language_id)
|
||||||
.select(language_id)
|
.select(language_id)
|
||||||
.get_results(&mut *conn)
|
.get_results(conn)
|
||||||
.await?;
|
.await?;
|
||||||
convert_read_languages(&mut *conn, langs).await
|
convert_read_languages(conn, langs).await
|
||||||
}) as _
|
}) as _
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
|
@ -62,14 +62,14 @@ impl LocalUserLanguage {
|
||||||
///
|
///
|
||||||
/// If no language_id vector is given, it will show all languages
|
/// If no language_id vector is given, it will show all languages
|
||||||
pub async fn update(
|
pub async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
language_ids: Vec<LanguageId>,
|
language_ids: Vec<LanguageId>,
|
||||||
for_local_user_id: LocalUserId,
|
for_local_user_id: LocalUserId,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let mut lang_ids = convert_update_languages(&mut *conn, language_ids).await?;
|
let mut lang_ids = convert_update_languages(conn, language_ids).await?;
|
||||||
|
|
||||||
// No need to update if languages are unchanged
|
// No need to update if languages are unchanged
|
||||||
let current = LocalUserLanguage::read(&mut *conn, for_local_user_id).await?;
|
let current = LocalUserLanguage::read(conn, for_local_user_id).await?;
|
||||||
if current == lang_ids {
|
if current == lang_ids {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ impl LocalUserLanguage {
|
||||||
use crate::schema::local_user_language::dsl::{local_user_id, local_user_language};
|
use crate::schema::local_user_language::dsl::{local_user_id, local_user_language};
|
||||||
// Clear the current user languages
|
// Clear the current user languages
|
||||||
delete(local_user_language.filter(local_user_id.eq(for_local_user_id)))
|
delete(local_user_language.filter(local_user_id.eq(for_local_user_id)))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
for l in lang_ids {
|
for l in lang_ids {
|
||||||
|
@ -101,7 +101,7 @@ impl LocalUserLanguage {
|
||||||
};
|
};
|
||||||
insert_into(local_user_language)
|
insert_into(local_user_language)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -112,42 +112,42 @@ impl LocalUserLanguage {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SiteLanguage {
|
impl SiteLanguage {
|
||||||
pub async fn read_local_raw(mut conn: impl DbConn) -> Result<Vec<LanguageId>, Error> {
|
pub async fn read_local_raw(mut conn: impl GetConn) -> Result<Vec<LanguageId>, Error> {
|
||||||
site::table
|
site::table
|
||||||
.inner_join(local_site::table)
|
.inner_join(local_site::table)
|
||||||
.inner_join(site_language::table)
|
.inner_join(site_language::table)
|
||||||
.order(site_language::id)
|
.order(site_language::id)
|
||||||
.select(site_language::language_id)
|
.select(site_language::language_id)
|
||||||
.load(&mut *conn)
|
.load(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read_raw(mut conn: impl DbConn, for_site_id: SiteId) -> Result<Vec<LanguageId>, Error> {
|
async fn read_raw(mut conn: impl GetConn, for_site_id: SiteId) -> Result<Vec<LanguageId>, Error> {
|
||||||
site_language::table
|
site_language::table
|
||||||
.filter(site_language::site_id.eq(for_site_id))
|
.filter(site_language::site_id.eq(for_site_id))
|
||||||
.order(site_language::language_id)
|
.order(site_language::language_id)
|
||||||
.select(site_language::language_id)
|
.select(site_language::language_id)
|
||||||
.load(&mut *conn)
|
.load(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read(mut conn: impl DbConn, for_site_id: SiteId) -> Result<Vec<LanguageId>, Error> {
|
pub async fn read(mut conn: impl GetConn, for_site_id: SiteId) -> Result<Vec<LanguageId>, Error> {
|
||||||
let langs = Self::read_raw(&mut *conn, for_site_id).await?;
|
let langs = Self::read_raw(conn, for_site_id).await?;
|
||||||
|
|
||||||
convert_read_languages(&mut *conn, langs).await
|
convert_read_languages(conn, langs).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update(
|
pub async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
language_ids: Vec<LanguageId>,
|
language_ids: Vec<LanguageId>,
|
||||||
site: &Site,
|
site: &Site,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let for_site_id = site.id;
|
let for_site_id = site.id;
|
||||||
let instance_id = site.instance_id;
|
let instance_id = site.instance_id;
|
||||||
let lang_ids = convert_update_languages(&mut *conn, language_ids).await?;
|
let lang_ids = convert_update_languages(conn, language_ids).await?;
|
||||||
|
|
||||||
// No need to update if languages are unchanged
|
// No need to update if languages are unchanged
|
||||||
let current = SiteLanguage::read(&mut *conn, site.id).await?;
|
let current = SiteLanguage::read(conn, site.id).await?;
|
||||||
if current == lang_ids {
|
if current == lang_ids {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,7 @@ impl SiteLanguage {
|
||||||
|
|
||||||
// Clear the current languages
|
// Clear the current languages
|
||||||
delete(site_language.filter(site_id.eq(for_site_id)))
|
delete(site_language.filter(site_id.eq(for_site_id)))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
for l in lang_ids {
|
for l in lang_ids {
|
||||||
|
@ -170,11 +170,11 @@ impl SiteLanguage {
|
||||||
};
|
};
|
||||||
insert_into(site_language)
|
insert_into(site_language)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
CommunityLanguage::limit_languages(&mut *conn, instance_id).await?;
|
CommunityLanguage::limit_languages(conn, instance_id).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}) as _
|
}) as _
|
||||||
|
@ -186,7 +186,7 @@ impl SiteLanguage {
|
||||||
impl CommunityLanguage {
|
impl CommunityLanguage {
|
||||||
/// Returns true if the given language is one of configured languages for given community
|
/// Returns true if the given language is one of configured languages for given community
|
||||||
pub async fn is_allowed_community_language(
|
pub async fn is_allowed_community_language(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_language_id: Option<LanguageId>,
|
for_language_id: Option<LanguageId>,
|
||||||
for_community_id: CommunityId,
|
for_community_id: CommunityId,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
|
@ -198,7 +198,7 @@ impl CommunityLanguage {
|
||||||
.filter(language_id.eq(for_language_id))
|
.filter(language_id.eq(for_language_id))
|
||||||
.filter(community_id.eq(for_community_id)),
|
.filter(community_id.eq(for_community_id)),
|
||||||
))
|
))
|
||||||
.get_result(&mut *conn)
|
.get_result(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if is_allowed {
|
if is_allowed {
|
||||||
|
@ -216,7 +216,7 @@ impl CommunityLanguage {
|
||||||
/// community language, and it shouldnt be possible to post content in languages which are not
|
/// community language, and it shouldnt be possible to post content in languages which are not
|
||||||
/// allowed by local site.
|
/// allowed by local site.
|
||||||
async fn limit_languages(
|
async fn limit_languages(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_instance_id: InstanceId,
|
for_instance_id: InstanceId,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
use crate::schema::{
|
use crate::schema::{
|
||||||
|
@ -230,19 +230,19 @@ impl CommunityLanguage {
|
||||||
.filter(c::instance_id.eq(for_instance_id))
|
.filter(c::instance_id.eq(for_instance_id))
|
||||||
.filter(sl::language_id.is_null())
|
.filter(sl::language_id.is_null())
|
||||||
.select(cl::language_id)
|
.select(cl::language_id)
|
||||||
.get_results(&mut *conn)
|
.get_results(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
for c in community_languages {
|
for c in community_languages {
|
||||||
delete(cl::community_language.filter(cl::language_id.eq(c)))
|
delete(cl::community_language.filter(cl::language_id.eq(c)))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read_raw(
|
async fn read_raw(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_community_id: CommunityId,
|
for_community_id: CommunityId,
|
||||||
) -> Result<Vec<LanguageId>, Error> {
|
) -> Result<Vec<LanguageId>, Error> {
|
||||||
use crate::schema::community_language::dsl::{community_id, community_language, language_id};
|
use crate::schema::community_language::dsl::{community_id, community_language, language_id};
|
||||||
|
@ -250,30 +250,30 @@ impl CommunityLanguage {
|
||||||
.filter(community_id.eq(for_community_id))
|
.filter(community_id.eq(for_community_id))
|
||||||
.order(language_id)
|
.order(language_id)
|
||||||
.select(language_id)
|
.select(language_id)
|
||||||
.get_results(&mut *conn)
|
.get_results(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_community_id: CommunityId,
|
for_community_id: CommunityId,
|
||||||
) -> Result<Vec<LanguageId>, Error> {
|
) -> Result<Vec<LanguageId>, Error> {
|
||||||
let langs = Self::read_raw(&mut *conn, for_community_id).await?;
|
let langs = Self::read_raw(conn, for_community_id).await?;
|
||||||
convert_read_languages(&mut *conn, langs).await
|
convert_read_languages(conn, langs).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update(
|
pub async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
mut language_ids: Vec<LanguageId>,
|
mut language_ids: Vec<LanguageId>,
|
||||||
for_community_id: CommunityId,
|
for_community_id: CommunityId,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
if language_ids.is_empty() {
|
if language_ids.is_empty() {
|
||||||
language_ids = SiteLanguage::read_local_raw(&mut *conn).await?;
|
language_ids = SiteLanguage::read_local_raw(conn).await?;
|
||||||
}
|
}
|
||||||
let lang_ids = convert_update_languages(&mut *conn, language_ids).await?;
|
let lang_ids = convert_update_languages(conn, language_ids).await?;
|
||||||
|
|
||||||
// No need to update if languages are unchanged
|
// No need to update if languages are unchanged
|
||||||
let current = CommunityLanguage::read_raw(&mut *conn, for_community_id).await?;
|
let current = CommunityLanguage::read_raw(conn, for_community_id).await?;
|
||||||
if current == lang_ids {
|
if current == lang_ids {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -285,7 +285,7 @@ impl CommunityLanguage {
|
||||||
use crate::schema::community_language::dsl::{community_id, community_language};
|
use crate::schema::community_language::dsl::{community_id, community_language};
|
||||||
// Clear the current languages
|
// Clear the current languages
|
||||||
delete(community_language.filter(community_id.eq(for_community_id)))
|
delete(community_language.filter(community_id.eq(for_community_id)))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
for l in lang_ids {
|
for l in lang_ids {
|
||||||
|
@ -295,7 +295,7 @@ impl CommunityLanguage {
|
||||||
};
|
};
|
||||||
insert_into(community_language)
|
insert_into(community_language)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -306,7 +306,7 @@ impl CommunityLanguage {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn default_post_language(
|
pub async fn default_post_language(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
local_user_id: LocalUserId,
|
local_user_id: LocalUserId,
|
||||||
) -> Result<Option<LanguageId>, Error> {
|
) -> Result<Option<LanguageId>, Error> {
|
||||||
|
@ -316,7 +316,7 @@ pub async fn default_post_language(
|
||||||
.filter(ul::local_user_id.eq(local_user_id))
|
.filter(ul::local_user_id.eq(local_user_id))
|
||||||
.filter(cl::community_id.eq(community_id))
|
.filter(cl::community_id.eq(community_id))
|
||||||
.select(cl::language_id)
|
.select(cl::language_id)
|
||||||
.get_results::<LanguageId>(&mut *conn)
|
.get_results::<LanguageId>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if intersection.len() == 1 {
|
if intersection.len() == 1 {
|
||||||
|
@ -331,12 +331,12 @@ pub async fn default_post_language(
|
||||||
|
|
||||||
/// If no language is given, set all languages
|
/// If no language is given, set all languages
|
||||||
async fn convert_update_languages(
|
async fn convert_update_languages(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
language_ids: Vec<LanguageId>,
|
language_ids: Vec<LanguageId>,
|
||||||
) -> Result<Vec<LanguageId>, Error> {
|
) -> Result<Vec<LanguageId>, Error> {
|
||||||
if language_ids.is_empty() {
|
if language_ids.is_empty() {
|
||||||
Ok(
|
Ok(
|
||||||
Language::read_all_conn(&mut *conn)
|
Language::read_all_conn(conn)
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|l| l.id)
|
.map(|l| l.id)
|
||||||
|
@ -349,7 +349,7 @@ async fn convert_update_languages(
|
||||||
|
|
||||||
/// If all languages are returned, return empty vec instead
|
/// If all languages are returned, return empty vec instead
|
||||||
async fn convert_read_languages(
|
async fn convert_read_languages(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
language_ids: Vec<LanguageId>,
|
language_ids: Vec<LanguageId>,
|
||||||
) -> Result<Vec<LanguageId>, Error> {
|
) -> Result<Vec<LanguageId>, Error> {
|
||||||
static ALL_LANGUAGES_COUNT: OnceCell<usize> = OnceCell::const_new();
|
static ALL_LANGUAGES_COUNT: OnceCell<usize> = OnceCell::const_new();
|
||||||
|
@ -358,7 +358,7 @@ async fn convert_read_languages(
|
||||||
use crate::schema::language::dsl::{id, language};
|
use crate::schema::language::dsl::{id, language};
|
||||||
let count: i64 = language
|
let count: i64 = language
|
||||||
.select(count(id))
|
.select(count(id))
|
||||||
.first(&mut *conn)
|
.first(conn)
|
||||||
.await
|
.await
|
||||||
.expect("read number of languages");
|
.expect("read number of languages");
|
||||||
count as usize
|
count as usize
|
||||||
|
@ -381,7 +381,7 @@ mod tests {
|
||||||
convert_update_languages,
|
convert_update_languages,
|
||||||
default_post_language,
|
default_post_language,
|
||||||
CommunityLanguage,
|
CommunityLanguage,
|
||||||
DbConn,
|
GetConn,
|
||||||
Language,
|
Language,
|
||||||
LanguageId,
|
LanguageId,
|
||||||
LocalUserLanguage,
|
LocalUserLanguage,
|
||||||
|
@ -402,37 +402,37 @@ mod tests {
|
||||||
};
|
};
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
async fn test_langs1(mut conn: impl DbConn) -> Vec<LanguageId> {
|
async fn test_langs1(mut conn: impl GetConn) -> Vec<LanguageId> {
|
||||||
vec![
|
vec![
|
||||||
Language::read_id_from_code(&mut *conn, Some("en"))
|
Language::read_id_from_code(conn, Some("en"))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
Language::read_id_from_code(&mut *conn, Some("fr"))
|
Language::read_id_from_code(conn, Some("fr"))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
Language::read_id_from_code(&mut *conn, Some("ru"))
|
Language::read_id_from_code(conn, Some("ru"))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
async fn test_langs2(mut conn: impl DbConn) -> Vec<LanguageId> {
|
async fn test_langs2(mut conn: impl GetConn) -> Vec<LanguageId> {
|
||||||
vec![
|
vec![
|
||||||
Language::read_id_from_code(&mut *conn, Some("fi"))
|
Language::read_id_from_code(conn, Some("fi"))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
Language::read_id_from_code(&mut *conn, Some("se"))
|
Language::read_id_from_code(conn, Some("se"))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create_test_site(mut conn: impl DbConn) -> (Site, Instance) {
|
async fn create_test_site(mut conn: impl GetConn) -> (Site, Instance) {
|
||||||
let inserted_instance = Instance::read_or_create(&mut *conn, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(conn, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -440,11 +440,11 @@ mod tests {
|
||||||
.name("test site".to_string())
|
.name("test site".to_string())
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
let site = Site::create(&mut *conn, &site_form).await.unwrap();
|
let site = Site::create(conn, &site_form).await.unwrap();
|
||||||
|
|
||||||
// Create a local site, since this is necessary for local languages
|
// Create a local site, since this is necessary for local languages
|
||||||
let local_site_form = LocalSiteInsertForm::builder().site_id(site.id).build();
|
let local_site_form = LocalSiteInsertForm::builder().site_id(site.id).build();
|
||||||
LocalSite::create(&mut *conn, &local_site_form)
|
LocalSite::create(conn, &local_site_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -457,12 +457,12 @@ mod tests {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
// call with empty vec, returns all languages
|
// call with empty vec, returns all languages
|
||||||
let converted1 = convert_update_languages(&mut *conn, vec![]).await.unwrap();
|
let converted1 = convert_update_languages(conn, vec![]).await.unwrap();
|
||||||
assert_eq!(184, converted1.len());
|
assert_eq!(184, converted1.len());
|
||||||
|
|
||||||
// call with nonempty vec, returns same vec
|
// call with nonempty vec, returns same vec
|
||||||
let test_langs = test_langs1(&mut *conn).await;
|
let test_langs = test_langs1(conn).await;
|
||||||
let converted2 = convert_update_languages(&mut *conn, test_langs.clone())
|
let converted2 = convert_update_languages(conn, test_langs.clone())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(test_langs, converted2);
|
assert_eq!(test_langs, converted2);
|
||||||
|
@ -474,13 +474,13 @@ mod tests {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
// call with all languages, returns empty vec
|
// call with all languages, returns empty vec
|
||||||
let all_langs = language.select(id).get_results(&mut *conn).await.unwrap();
|
let all_langs = language.select(id).get_results(conn).await.unwrap();
|
||||||
let converted1: Vec<LanguageId> = convert_read_languages(&mut *conn, all_langs).await.unwrap();
|
let converted1: Vec<LanguageId> = convert_read_languages(conn, all_langs).await.unwrap();
|
||||||
assert_eq!(0, converted1.len());
|
assert_eq!(0, converted1.len());
|
||||||
|
|
||||||
// call with nonempty vec, returns same vec
|
// call with nonempty vec, returns same vec
|
||||||
let test_langs = test_langs1(&mut *conn).await;
|
let test_langs = test_langs1(conn).await;
|
||||||
let converted2 = convert_read_languages(&mut *conn, test_langs.clone())
|
let converted2 = convert_read_languages(conn, test_langs.clone())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(test_langs, converted2);
|
assert_eq!(test_langs, converted2);
|
||||||
|
@ -491,23 +491,23 @@ mod tests {
|
||||||
async fn test_site_languages() {
|
async fn test_site_languages() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
let (site, instance) = create_test_site(&mut *conn).await;
|
let (site, instance) = create_test_site(conn).await;
|
||||||
let site_languages1 = SiteLanguage::read_local_raw(&mut *conn).await.unwrap();
|
let site_languages1 = SiteLanguage::read_local_raw(conn).await.unwrap();
|
||||||
// site is created with all languages
|
// site is created with all languages
|
||||||
assert_eq!(184, site_languages1.len());
|
assert_eq!(184, site_languages1.len());
|
||||||
|
|
||||||
let test_langs = test_langs1(&mut *conn).await;
|
let test_langs = test_langs1(conn).await;
|
||||||
SiteLanguage::update(&mut *conn, test_langs.clone(), &site)
|
SiteLanguage::update(conn, test_langs.clone(), &site)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let site_languages2 = SiteLanguage::read_local_raw(&mut *conn).await.unwrap();
|
let site_languages2 = SiteLanguage::read_local_raw(conn).await.unwrap();
|
||||||
// after update, site only has new languages
|
// after update, site only has new languages
|
||||||
assert_eq!(test_langs, site_languages2);
|
assert_eq!(test_langs, site_languages2);
|
||||||
|
|
||||||
Site::delete(&mut *conn, site.id).await.unwrap();
|
Site::delete(conn, site.id).await.unwrap();
|
||||||
Instance::delete(&mut *conn, instance.id).await.unwrap();
|
Instance::delete(conn, instance.id).await.unwrap();
|
||||||
LocalSite::delete(&mut *conn).await.unwrap();
|
LocalSite::delete(conn).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
@ -515,9 +515,9 @@ mod tests {
|
||||||
async fn test_user_languages() {
|
async fn test_user_languages() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
let (site, instance) = create_test_site(&mut *conn).await;
|
let (site, instance) = create_test_site(conn).await;
|
||||||
let mut test_langs = test_langs1(&mut *conn).await;
|
let mut test_langs = test_langs1(conn).await;
|
||||||
SiteLanguage::update(&mut *conn, test_langs.clone(), &site)
|
SiteLanguage::update(conn, test_langs.clone(), &site)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -526,16 +526,16 @@ mod tests {
|
||||||
.public_key("pubkey".to_string())
|
.public_key("pubkey".to_string())
|
||||||
.instance_id(instance.id)
|
.instance_id(instance.id)
|
||||||
.build();
|
.build();
|
||||||
let person = Person::create(&mut *conn, &person_form).await.unwrap();
|
let person = Person::create(conn, &person_form).await.unwrap();
|
||||||
let local_user_form = LocalUserInsertForm::builder()
|
let local_user_form = LocalUserInsertForm::builder()
|
||||||
.person_id(person.id)
|
.person_id(person.id)
|
||||||
.password_encrypted("my_pw".to_string())
|
.password_encrypted("my_pw".to_string())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let local_user = LocalUser::create(&mut *conn, &local_user_form)
|
let local_user = LocalUser::create(conn, &local_user_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let local_user_langs1 = LocalUserLanguage::read(&mut *conn, local_user.id)
|
let local_user_langs1 = LocalUserLanguage::read(conn, local_user.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -546,37 +546,37 @@ mod tests {
|
||||||
assert_eq!(test_langs, local_user_langs1);
|
assert_eq!(test_langs, local_user_langs1);
|
||||||
|
|
||||||
// update user languages
|
// update user languages
|
||||||
let test_langs2 = test_langs2(&mut *conn).await;
|
let test_langs2 = test_langs2(conn).await;
|
||||||
LocalUserLanguage::update(&mut *conn, test_langs2, local_user.id)
|
LocalUserLanguage::update(conn, test_langs2, local_user.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let local_user_langs2 = LocalUserLanguage::read(&mut *conn, local_user.id)
|
let local_user_langs2 = LocalUserLanguage::read(conn, local_user.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(3, local_user_langs2.len());
|
assert_eq!(3, local_user_langs2.len());
|
||||||
|
|
||||||
Person::delete(&mut *conn, person.id).await.unwrap();
|
Person::delete(conn, person.id).await.unwrap();
|
||||||
LocalUser::delete(&mut *conn, local_user.id).await.unwrap();
|
LocalUser::delete(conn, local_user.id).await.unwrap();
|
||||||
Site::delete(&mut *conn, site.id).await.unwrap();
|
Site::delete(conn, site.id).await.unwrap();
|
||||||
LocalSite::delete(&mut *conn).await.unwrap();
|
LocalSite::delete(conn).await.unwrap();
|
||||||
Instance::delete(&mut *conn, instance.id).await.unwrap();
|
Instance::delete(conn, instance.id).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_community_languages() {
|
async fn test_community_languages() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
let (site, instance) = create_test_site(&mut *conn).await;
|
let (site, instance) = create_test_site(conn).await;
|
||||||
let test_langs = test_langs1(&mut *conn).await;
|
let test_langs = test_langs1(conn).await;
|
||||||
SiteLanguage::update(&mut *conn, test_langs.clone(), &site)
|
SiteLanguage::update(conn, test_langs.clone(), &site)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let read_site_langs = SiteLanguage::read(&mut *conn, site.id).await.unwrap();
|
let read_site_langs = SiteLanguage::read(conn, site.id).await.unwrap();
|
||||||
assert_eq!(test_langs, read_site_langs);
|
assert_eq!(test_langs, read_site_langs);
|
||||||
|
|
||||||
// Test the local ones are the same
|
// Test the local ones are the same
|
||||||
let read_local_site_langs = SiteLanguage::read_local_raw(&mut *conn).await.unwrap();
|
let read_local_site_langs = SiteLanguage::read_local_raw(conn).await.unwrap();
|
||||||
assert_eq!(test_langs, read_local_site_langs);
|
assert_eq!(test_langs, read_local_site_langs);
|
||||||
|
|
||||||
let community_form = CommunityInsertForm::builder()
|
let community_form = CommunityInsertForm::builder()
|
||||||
|
@ -585,10 +585,10 @@ mod tests {
|
||||||
.public_key("pubkey".to_string())
|
.public_key("pubkey".to_string())
|
||||||
.instance_id(instance.id)
|
.instance_id(instance.id)
|
||||||
.build();
|
.build();
|
||||||
let community = Community::create(&mut *conn, &community_form)
|
let community = Community::create(conn, &community_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let community_langs1 = CommunityLanguage::read(&mut *conn, community.id)
|
let community_langs1 = CommunityLanguage::read(conn, community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -596,16 +596,16 @@ mod tests {
|
||||||
assert_eq!(test_langs, community_langs1);
|
assert_eq!(test_langs, community_langs1);
|
||||||
|
|
||||||
let allowed_lang1 = CommunityLanguage::is_allowed_community_language(
|
let allowed_lang1 = CommunityLanguage::is_allowed_community_language(
|
||||||
&mut *conn,
|
conn,
|
||||||
Some(test_langs[0]),
|
Some(test_langs[0]),
|
||||||
community.id,
|
community.id,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
assert!(allowed_lang1.is_ok());
|
assert!(allowed_lang1.is_ok());
|
||||||
|
|
||||||
let test_langs2 = test_langs2(&mut *conn).await;
|
let test_langs2 = test_langs2(conn).await;
|
||||||
let allowed_lang2 = CommunityLanguage::is_allowed_community_language(
|
let allowed_lang2 = CommunityLanguage::is_allowed_community_language(
|
||||||
&mut *conn,
|
conn,
|
||||||
Some(test_langs2[0]),
|
Some(test_langs2[0]),
|
||||||
community.id,
|
community.id,
|
||||||
)
|
)
|
||||||
|
@ -614,36 +614,36 @@ mod tests {
|
||||||
|
|
||||||
// limit site languages to en, fi. after this, community languages should be updated to
|
// limit site languages to en, fi. after this, community languages should be updated to
|
||||||
// intersection of old languages (en, fr, ru) and (en, fi), which is only fi.
|
// intersection of old languages (en, fr, ru) and (en, fi), which is only fi.
|
||||||
SiteLanguage::update(&mut *conn, vec![test_langs[0], test_langs2[0]], &site)
|
SiteLanguage::update(conn, vec![test_langs[0], test_langs2[0]], &site)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let community_langs2 = CommunityLanguage::read(&mut *conn, community.id)
|
let community_langs2 = CommunityLanguage::read(conn, community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(vec![test_langs[0]], community_langs2);
|
assert_eq!(vec![test_langs[0]], community_langs2);
|
||||||
|
|
||||||
// update community languages to different ones
|
// update community languages to different ones
|
||||||
CommunityLanguage::update(&mut *conn, test_langs2.clone(), community.id)
|
CommunityLanguage::update(conn, test_langs2.clone(), community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let community_langs3 = CommunityLanguage::read(&mut *conn, community.id)
|
let community_langs3 = CommunityLanguage::read(conn, community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(test_langs2, community_langs3);
|
assert_eq!(test_langs2, community_langs3);
|
||||||
|
|
||||||
Community::delete(&mut *conn, community.id).await.unwrap();
|
Community::delete(conn, community.id).await.unwrap();
|
||||||
Site::delete(&mut *conn, site.id).await.unwrap();
|
Site::delete(conn, site.id).await.unwrap();
|
||||||
LocalSite::delete(&mut *conn).await.unwrap();
|
LocalSite::delete(conn).await.unwrap();
|
||||||
Instance::delete(&mut *conn, instance.id).await.unwrap();
|
Instance::delete(conn, instance.id).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_default_post_language() {
|
async fn test_default_post_language() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
let (site, instance) = create_test_site(&mut *conn).await;
|
let (site, instance) = create_test_site(conn).await;
|
||||||
let test_langs = test_langs1(&mut *conn).await;
|
let test_langs = test_langs1(conn).await;
|
||||||
let test_langs2 = test_langs2(&mut *conn).await;
|
let test_langs2 = test_langs2(conn).await;
|
||||||
|
|
||||||
let community_form = CommunityInsertForm::builder()
|
let community_form = CommunityInsertForm::builder()
|
||||||
.name("test community".to_string())
|
.name("test community".to_string())
|
||||||
|
@ -651,10 +651,10 @@ mod tests {
|
||||||
.public_key("pubkey".to_string())
|
.public_key("pubkey".to_string())
|
||||||
.instance_id(instance.id)
|
.instance_id(instance.id)
|
||||||
.build();
|
.build();
|
||||||
let community = Community::create(&mut *conn, &community_form)
|
let community = Community::create(conn, &community_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
CommunityLanguage::update(&mut *conn, test_langs, community.id)
|
CommunityLanguage::update(conn, test_langs, community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -663,55 +663,55 @@ mod tests {
|
||||||
.public_key("pubkey".to_string())
|
.public_key("pubkey".to_string())
|
||||||
.instance_id(instance.id)
|
.instance_id(instance.id)
|
||||||
.build();
|
.build();
|
||||||
let person = Person::create(&mut *conn, &person_form).await.unwrap();
|
let person = Person::create(conn, &person_form).await.unwrap();
|
||||||
let local_user_form = LocalUserInsertForm::builder()
|
let local_user_form = LocalUserInsertForm::builder()
|
||||||
.person_id(person.id)
|
.person_id(person.id)
|
||||||
.password_encrypted("my_pw".to_string())
|
.password_encrypted("my_pw".to_string())
|
||||||
.build();
|
.build();
|
||||||
let local_user = LocalUser::create(&mut *conn, &local_user_form)
|
let local_user = LocalUser::create(conn, &local_user_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
LocalUserLanguage::update(&mut *conn, test_langs2, local_user.id)
|
LocalUserLanguage::update(conn, test_langs2, local_user.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// no overlap in user/community languages, so defaults to undetermined
|
// no overlap in user/community languages, so defaults to undetermined
|
||||||
let def1 = default_post_language(&mut *conn, community.id, local_user.id)
|
let def1 = default_post_language(conn, community.id, local_user.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(None, def1);
|
assert_eq!(None, def1);
|
||||||
|
|
||||||
let ru = Language::read_id_from_code(&mut *conn, Some("ru"))
|
let ru = Language::read_id_from_code(conn, Some("ru"))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let test_langs3 = vec![
|
let test_langs3 = vec![
|
||||||
ru,
|
ru,
|
||||||
Language::read_id_from_code(&mut *conn, Some("fi"))
|
Language::read_id_from_code(conn, Some("fi"))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
Language::read_id_from_code(&mut *conn, Some("se"))
|
Language::read_id_from_code(conn, Some("se"))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
UNDETERMINED_ID,
|
UNDETERMINED_ID,
|
||||||
];
|
];
|
||||||
LocalUserLanguage::update(&mut *conn, test_langs3, local_user.id)
|
LocalUserLanguage::update(conn, test_langs3, local_user.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// this time, both have ru as common lang
|
// this time, both have ru as common lang
|
||||||
let def2 = default_post_language(&mut *conn, community.id, local_user.id)
|
let def2 = default_post_language(conn, community.id, local_user.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(Some(ru), def2);
|
assert_eq!(Some(ru), def2);
|
||||||
|
|
||||||
Person::delete(&mut *conn, person.id).await.unwrap();
|
Person::delete(conn, person.id).await.unwrap();
|
||||||
Community::delete(&mut *conn, community.id).await.unwrap();
|
Community::delete(conn, community.id).await.unwrap();
|
||||||
LocalUser::delete(&mut *conn, local_user.id).await.unwrap();
|
LocalUser::delete(conn, local_user.id).await.unwrap();
|
||||||
Site::delete(&mut *conn, site.id).await.unwrap();
|
Site::delete(conn, site.id).await.unwrap();
|
||||||
LocalSite::delete(&mut *conn).await.unwrap();
|
LocalSite::delete(conn).await.unwrap();
|
||||||
Instance::delete(&mut *conn, instance.id).await.unwrap();
|
Instance::delete(conn, instance.id).await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
schema::captcha_answer::dsl::{answer, captcha_answer, uuid},
|
schema::captcha_answer::dsl::{answer, captcha_answer, uuid},
|
||||||
source::captcha_answer::{CaptchaAnswer, CaptchaAnswerForm, CheckCaptchaAnswer},
|
source::captcha_answer::{CaptchaAnswer, CaptchaAnswerForm, CheckCaptchaAnswer},
|
||||||
utils::{functions::lower, DbConn},
|
utils::{functions::lower, GetConn},
|
||||||
};
|
};
|
||||||
use diesel::{
|
use diesel::{
|
||||||
delete,
|
delete,
|
||||||
|
@ -12,18 +12,18 @@ use diesel::{
|
||||||
ExpressionMethods,
|
ExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
impl CaptchaAnswer {
|
impl CaptchaAnswer {
|
||||||
pub async fn insert(mut conn: impl DbConn, captcha: &CaptchaAnswerForm) -> Result<Self, Error> {
|
pub async fn insert(mut conn: impl GetConn, captcha: &CaptchaAnswerForm) -> Result<Self, Error> {
|
||||||
insert_into(captcha_answer)
|
insert_into(captcha_answer)
|
||||||
.values(captcha)
|
.values(captcha)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn check_captcha(
|
pub async fn check_captcha(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
to_check: CheckCaptchaAnswer,
|
to_check: CheckCaptchaAnswer,
|
||||||
) -> Result<bool, Error> {
|
) -> Result<bool, Error> {
|
||||||
// fetch requested captcha
|
// fetch requested captcha
|
||||||
|
@ -32,12 +32,12 @@ impl CaptchaAnswer {
|
||||||
.filter((uuid).eq(to_check.uuid))
|
.filter((uuid).eq(to_check.uuid))
|
||||||
.filter(lower(answer).eq(to_check.answer.to_lowercase().clone())),
|
.filter(lower(answer).eq(to_check.answer.to_lowercase().clone())),
|
||||||
))
|
))
|
||||||
.get_result::<bool>(&mut *conn)
|
.get_result::<bool>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// delete checked captcha
|
// delete checked captcha
|
||||||
delete(captcha_answer.filter(uuid.eq(to_check.uuid)))
|
delete(captcha_answer.filter(uuid.eq(to_check.uuid)))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(captcha_exists)
|
Ok(captcha_exists)
|
||||||
|
@ -58,7 +58,7 @@ mod tests {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
let inserted = CaptchaAnswer::insert(
|
let inserted = CaptchaAnswer::insert(
|
||||||
&mut *conn,
|
conn,
|
||||||
&CaptchaAnswerForm {
|
&CaptchaAnswerForm {
|
||||||
answer: "XYZ".to_string(),
|
answer: "XYZ".to_string(),
|
||||||
},
|
},
|
||||||
|
@ -67,7 +67,7 @@ mod tests {
|
||||||
.expect("should not fail to insert captcha");
|
.expect("should not fail to insert captcha");
|
||||||
|
|
||||||
let result = CaptchaAnswer::check_captcha(
|
let result = CaptchaAnswer::check_captcha(
|
||||||
&mut *conn,
|
conn,
|
||||||
CheckCaptchaAnswer {
|
CheckCaptchaAnswer {
|
||||||
uuid: inserted.uuid,
|
uuid: inserted.uuid,
|
||||||
answer: "xyz".to_string(),
|
answer: "xyz".to_string(),
|
||||||
|
@ -85,7 +85,7 @@ mod tests {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
let inserted = CaptchaAnswer::insert(
|
let inserted = CaptchaAnswer::insert(
|
||||||
&mut *conn,
|
conn,
|
||||||
&CaptchaAnswerForm {
|
&CaptchaAnswerForm {
|
||||||
answer: "XYZ".to_string(),
|
answer: "XYZ".to_string(),
|
||||||
},
|
},
|
||||||
|
@ -94,7 +94,7 @@ mod tests {
|
||||||
.expect("should not fail to insert captcha");
|
.expect("should not fail to insert captcha");
|
||||||
|
|
||||||
let _result = CaptchaAnswer::check_captcha(
|
let _result = CaptchaAnswer::check_captcha(
|
||||||
&mut *conn,
|
conn,
|
||||||
CheckCaptchaAnswer {
|
CheckCaptchaAnswer {
|
||||||
uuid: inserted.uuid,
|
uuid: inserted.uuid,
|
||||||
answer: "xyz".to_string(),
|
answer: "xyz".to_string(),
|
||||||
|
@ -103,7 +103,7 @@ mod tests {
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let result_repeat = CaptchaAnswer::check_captcha(
|
let result_repeat = CaptchaAnswer::check_captcha(
|
||||||
&mut *conn,
|
conn,
|
||||||
CheckCaptchaAnswer {
|
CheckCaptchaAnswer {
|
||||||
uuid: inserted.uuid,
|
uuid: inserted.uuid,
|
||||||
answer: "xyz".to_string(),
|
answer: "xyz".to_string(),
|
||||||
|
|
|
@ -11,7 +11,7 @@ use crate::{
|
||||||
CommentUpdateForm,
|
CommentUpdateForm,
|
||||||
},
|
},
|
||||||
traits::{Crud, Likeable, Saveable},
|
traits::{Crud, Likeable, Saveable},
|
||||||
utils::{naive_now, DbConn, DELETED_REPLACEMENT_TEXT},
|
utils::{naive_now, GetConn, DELETED_REPLACEMENT_TEXT},
|
||||||
};
|
};
|
||||||
use diesel::{
|
use diesel::{
|
||||||
dsl::{insert_into, sql_query},
|
dsl::{insert_into, sql_query},
|
||||||
|
@ -19,13 +19,13 @@ use diesel::{
|
||||||
ExpressionMethods,
|
ExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use diesel_ltree::Ltree;
|
use diesel_ltree::Ltree;
|
||||||
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
impl Comment {
|
impl Comment {
|
||||||
pub async fn permadelete_for_creator(
|
pub async fn permadelete_for_creator(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_creator_id: PersonId,
|
for_creator_id: PersonId,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
diesel::update(comment.filter(creator_id.eq(for_creator_id)))
|
diesel::update(comment.filter(creator_id.eq(for_creator_id)))
|
||||||
|
@ -34,23 +34,23 @@ impl Comment {
|
||||||
deleted.eq(true),
|
deleted.eq(true),
|
||||||
updated.eq(naive_now()),
|
updated.eq(naive_now()),
|
||||||
))
|
))
|
||||||
.get_results::<Self>(&mut *conn)
|
.get_results::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_removed_for_creator(
|
pub async fn update_removed_for_creator(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_creator_id: PersonId,
|
for_creator_id: PersonId,
|
||||||
new_removed: bool,
|
new_removed: bool,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
diesel::update(comment.filter(creator_id.eq(for_creator_id)))
|
diesel::update(comment.filter(creator_id.eq(for_creator_id)))
|
||||||
.set((removed.eq(new_removed), updated.eq(naive_now())))
|
.set((removed.eq(new_removed), updated.eq(naive_now())))
|
||||||
.get_results::<Self>(&mut *conn)
|
.get_results::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create(
|
pub async fn create(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
comment_form: &CommentInsertForm,
|
comment_form: &CommentInsertForm,
|
||||||
parent_path: Option<&Ltree>,
|
parent_path: Option<&Ltree>,
|
||||||
) -> Result<Comment, Error> {
|
) -> Result<Comment, Error> {
|
||||||
|
@ -60,7 +60,7 @@ impl Comment {
|
||||||
.on_conflict(ap_id)
|
.on_conflict(ap_id)
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(comment_form)
|
.set(comment_form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
if let Ok(comment_insert) = inserted_comment {
|
if let Ok(comment_insert) = inserted_comment {
|
||||||
|
@ -78,7 +78,7 @@ impl Comment {
|
||||||
|
|
||||||
let updated_comment = diesel::update(comment.find(comment_id))
|
let updated_comment = diesel::update(comment.find(comment_id))
|
||||||
.set(path.eq(ltree))
|
.set(path.eq(ltree))
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
// Update the child count for the parent comment_aggregates
|
// Update the child count for the parent comment_aggregates
|
||||||
|
@ -111,7 +111,7 @@ where ca.comment_id = c.id"
|
||||||
);
|
);
|
||||||
|
|
||||||
sql_query(update_child_count_stmt)
|
sql_query(update_child_count_stmt)
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,14 +121,14 @@ where ca.comment_id = c.id"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub async fn read_from_apub_id(
|
pub async fn read_from_apub_id(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
object_id: Url,
|
object_id: Url,
|
||||||
) -> Result<Option<Self>, Error> {
|
) -> Result<Option<Self>, Error> {
|
||||||
let object_id: DbUrl = object_id.into();
|
let object_id: DbUrl = object_id.into();
|
||||||
Ok(
|
Ok(
|
||||||
comment
|
comment
|
||||||
.filter(ap_id.eq(object_id))
|
.filter(ap_id.eq(object_id))
|
||||||
.first::<Comment>(&mut *conn)
|
.first::<Comment>(conn)
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok()
|
||||||
.map(Into::into),
|
.map(Into::into),
|
||||||
|
@ -152,29 +152,29 @@ impl Crud for Comment {
|
||||||
type InsertForm = CommentInsertForm;
|
type InsertForm = CommentInsertForm;
|
||||||
type UpdateForm = CommentUpdateForm;
|
type UpdateForm = CommentUpdateForm;
|
||||||
type IdType = CommentId;
|
type IdType = CommentId;
|
||||||
async fn read(mut conn: impl DbConn, comment_id: CommentId) -> Result<Self, Error> {
|
async fn read(mut conn: impl GetConn, comment_id: CommentId) -> Result<Self, Error> {
|
||||||
comment.find(comment_id).first::<Self>(&mut *conn).await
|
comment.find(comment_id).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete(mut conn: impl DbConn, comment_id: CommentId) -> Result<usize, Error> {
|
async fn delete(mut conn: impl GetConn, comment_id: CommentId) -> Result<usize, Error> {
|
||||||
diesel::delete(comment.find(comment_id))
|
diesel::delete(comment.find(comment_id))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is unimplemented, use [[Comment::create]]
|
/// This is unimplemented, use [[Comment::create]]
|
||||||
async fn create(_conn: impl DbConn, _comment_form: &Self::InsertForm) -> Result<Self, Error> {
|
async fn create(_conn: impl GetConn, _comment_form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
comment_id: CommentId,
|
comment_id: CommentId,
|
||||||
comment_form: &Self::UpdateForm,
|
comment_form: &Self::UpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
diesel::update(comment.find(comment_id))
|
diesel::update(comment.find(comment_id))
|
||||||
.set(comment_form)
|
.set(comment_form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,18 +183,21 @@ impl Crud for Comment {
|
||||||
impl Likeable for CommentLike {
|
impl Likeable for CommentLike {
|
||||||
type Form = CommentLikeForm;
|
type Form = CommentLikeForm;
|
||||||
type IdType = CommentId;
|
type IdType = CommentId;
|
||||||
async fn like(mut conn: impl DbConn, comment_like_form: &CommentLikeForm) -> Result<Self, Error> {
|
async fn like(
|
||||||
|
mut conn: impl GetConn,
|
||||||
|
comment_like_form: &CommentLikeForm,
|
||||||
|
) -> Result<Self, Error> {
|
||||||
use crate::schema::comment_like::dsl::{comment_id, comment_like, person_id};
|
use crate::schema::comment_like::dsl::{comment_id, comment_like, person_id};
|
||||||
insert_into(comment_like)
|
insert_into(comment_like)
|
||||||
.values(comment_like_form)
|
.values(comment_like_form)
|
||||||
.on_conflict((comment_id, person_id))
|
.on_conflict((comment_id, person_id))
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(comment_like_form)
|
.set(comment_like_form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn remove(
|
async fn remove(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
person_id_: PersonId,
|
person_id_: PersonId,
|
||||||
comment_id_: CommentId,
|
comment_id_: CommentId,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
|
@ -204,7 +207,7 @@ impl Likeable for CommentLike {
|
||||||
.filter(comment_id.eq(comment_id_))
|
.filter(comment_id.eq(comment_id_))
|
||||||
.filter(person_id.eq(person_id_)),
|
.filter(person_id.eq(person_id_)),
|
||||||
)
|
)
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -213,7 +216,7 @@ impl Likeable for CommentLike {
|
||||||
impl Saveable for CommentSaved {
|
impl Saveable for CommentSaved {
|
||||||
type Form = CommentSavedForm;
|
type Form = CommentSavedForm;
|
||||||
async fn save(
|
async fn save(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
comment_saved_form: &CommentSavedForm,
|
comment_saved_form: &CommentSavedForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use crate::schema::comment_saved::dsl::{comment_id, comment_saved, person_id};
|
use crate::schema::comment_saved::dsl::{comment_id, comment_saved, person_id};
|
||||||
|
@ -222,11 +225,11 @@ impl Saveable for CommentSaved {
|
||||||
.on_conflict((comment_id, person_id))
|
.on_conflict((comment_id, person_id))
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(comment_saved_form)
|
.set(comment_saved_form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn unsave(
|
async fn unsave(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
comment_saved_form: &CommentSavedForm,
|
comment_saved_form: &CommentSavedForm,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
use crate::schema::comment_saved::dsl::{comment_id, comment_saved, person_id};
|
use crate::schema::comment_saved::dsl::{comment_id, comment_saved, person_id};
|
||||||
|
@ -235,7 +238,7 @@ impl Saveable for CommentSaved {
|
||||||
.filter(comment_id.eq(comment_saved_form.comment_id))
|
.filter(comment_id.eq(comment_saved_form.comment_id))
|
||||||
.filter(person_id.eq(comment_saved_form.person_id)),
|
.filter(person_id.eq(comment_saved_form.person_id)),
|
||||||
)
|
)
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,7 +273,7 @@ mod tests {
|
||||||
async fn test_crud() {
|
async fn test_crud() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
let inserted_instance = Instance::read_or_create(&mut *conn, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(conn, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -280,7 +283,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_person = Person::create(&mut *conn, &new_person).await.unwrap();
|
let inserted_person = Person::create(conn, &new_person).await.unwrap();
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::builder()
|
let new_community = CommunityInsertForm::builder()
|
||||||
.name("test community".to_string())
|
.name("test community".to_string())
|
||||||
|
@ -289,7 +292,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_community = Community::create(&mut *conn, &new_community).await.unwrap();
|
let inserted_community = Community::create(conn, &new_community).await.unwrap();
|
||||||
|
|
||||||
let new_post = PostInsertForm::builder()
|
let new_post = PostInsertForm::builder()
|
||||||
.name("A test post".into())
|
.name("A test post".into())
|
||||||
|
@ -297,7 +300,7 @@ mod tests {
|
||||||
.community_id(inserted_community.id)
|
.community_id(inserted_community.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_post = Post::create(&mut *conn, &new_post).await.unwrap();
|
let inserted_post = Post::create(conn, &new_post).await.unwrap();
|
||||||
|
|
||||||
let comment_form = CommentInsertForm::builder()
|
let comment_form = CommentInsertForm::builder()
|
||||||
.content("A test comment".into())
|
.content("A test comment".into())
|
||||||
|
@ -305,7 +308,7 @@ mod tests {
|
||||||
.post_id(inserted_post.id)
|
.post_id(inserted_post.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_comment = Comment::create(&mut *conn, &comment_form, None)
|
let inserted_comment = Comment::create(conn, &comment_form, None)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -332,7 +335,7 @@ mod tests {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_child_comment = Comment::create(
|
let inserted_child_comment = Comment::create(
|
||||||
&mut *conn,
|
conn,
|
||||||
&child_comment_form,
|
&child_comment_form,
|
||||||
Some(&inserted_comment.path),
|
Some(&inserted_comment.path),
|
||||||
)
|
)
|
||||||
|
@ -347,7 +350,7 @@ mod tests {
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_comment_like = CommentLike::like(&mut *conn, &comment_like_form)
|
let inserted_comment_like = CommentLike::like(conn, &comment_like_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -366,7 +369,7 @@ mod tests {
|
||||||
person_id: inserted_person.id,
|
person_id: inserted_person.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_comment_saved = CommentSaved::save(&mut *conn, &comment_saved_form)
|
let inserted_comment_saved = CommentSaved::save(conn, &comment_saved_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -381,33 +384,33 @@ mod tests {
|
||||||
.content(Some("A test comment".into()))
|
.content(Some("A test comment".into()))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let updated_comment = Comment::update(&mut *conn, inserted_comment.id, &comment_update_form)
|
let updated_comment = Comment::update(conn, inserted_comment.id, &comment_update_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let read_comment = Comment::read(&mut *conn, inserted_comment.id)
|
let read_comment = Comment::read(conn, inserted_comment.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let like_removed = CommentLike::remove(&mut *conn, inserted_person.id, inserted_comment.id)
|
let like_removed = CommentLike::remove(conn, inserted_person.id, inserted_comment.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let saved_removed = CommentSaved::unsave(&mut *conn, &comment_saved_form)
|
let saved_removed = CommentSaved::unsave(conn, &comment_saved_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let num_deleted = Comment::delete(&mut *conn, inserted_comment.id)
|
let num_deleted = Comment::delete(conn, inserted_comment.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Comment::delete(&mut *conn, inserted_child_comment.id)
|
Comment::delete(conn, inserted_child_comment.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Post::delete(&mut *conn, inserted_post.id).await.unwrap();
|
Post::delete(conn, inserted_post.id).await.unwrap();
|
||||||
Community::delete(&mut *conn, inserted_community.id)
|
Community::delete(conn, inserted_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Person::delete(&mut *conn, inserted_person.id)
|
Person::delete(conn, inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Instance::delete(&mut *conn, inserted_instance.id)
|
Instance::delete(conn, inserted_instance.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -3,25 +3,25 @@ use crate::{
|
||||||
schema::comment_reply::dsl::{comment_id, comment_reply, read, recipient_id},
|
schema::comment_reply::dsl::{comment_id, comment_reply, read, recipient_id},
|
||||||
source::comment_reply::{CommentReply, CommentReplyInsertForm, CommentReplyUpdateForm},
|
source::comment_reply::{CommentReply, CommentReplyInsertForm, CommentReplyUpdateForm},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::DbConn,
|
utils::GetConn,
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Crud for CommentReply {
|
impl Crud for CommentReply {
|
||||||
type InsertForm = CommentReplyInsertForm;
|
type InsertForm = CommentReplyInsertForm;
|
||||||
type UpdateForm = CommentReplyUpdateForm;
|
type UpdateForm = CommentReplyUpdateForm;
|
||||||
type IdType = CommentReplyId;
|
type IdType = CommentReplyId;
|
||||||
async fn read(mut conn: impl DbConn, comment_reply_id: CommentReplyId) -> Result<Self, Error> {
|
async fn read(mut conn: impl GetConn, comment_reply_id: CommentReplyId) -> Result<Self, Error> {
|
||||||
comment_reply
|
comment_reply
|
||||||
.find(comment_reply_id)
|
.find(comment_reply_id)
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(
|
async fn create(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
comment_reply_form: &Self::InsertForm,
|
comment_reply_form: &Self::InsertForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
// since the return here isnt utilized, we dont need to do an update
|
// since the return here isnt utilized, we dont need to do an update
|
||||||
|
@ -31,25 +31,25 @@ impl Crud for CommentReply {
|
||||||
.on_conflict((recipient_id, comment_id))
|
.on_conflict((recipient_id, comment_id))
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(comment_reply_form)
|
.set(comment_reply_form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
comment_reply_id: CommentReplyId,
|
comment_reply_id: CommentReplyId,
|
||||||
comment_reply_form: &Self::UpdateForm,
|
comment_reply_form: &Self::UpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
diesel::update(comment_reply.find(comment_reply_id))
|
diesel::update(comment_reply.find(comment_reply_id))
|
||||||
.set(comment_reply_form)
|
.set(comment_reply_form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CommentReply {
|
impl CommentReply {
|
||||||
pub async fn mark_all_as_read(
|
pub async fn mark_all_as_read(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_recipient_id: PersonId,
|
for_recipient_id: PersonId,
|
||||||
) -> Result<Vec<CommentReply>, Error> {
|
) -> Result<Vec<CommentReply>, Error> {
|
||||||
diesel::update(
|
diesel::update(
|
||||||
|
@ -58,17 +58,17 @@ impl CommentReply {
|
||||||
.filter(read.eq(false)),
|
.filter(read.eq(false)),
|
||||||
)
|
)
|
||||||
.set(read.eq(true))
|
.set(read.eq(true))
|
||||||
.get_results::<Self>(&mut *conn)
|
.get_results::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read_by_comment(
|
pub async fn read_by_comment(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_comment_id: CommentId,
|
for_comment_id: CommentId,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
comment_reply
|
comment_reply
|
||||||
.filter(comment_id.eq(for_comment_id))
|
.filter(comment_id.eq(for_comment_id))
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ mod tests {
|
||||||
async fn test_crud() {
|
async fn test_crud() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
let inserted_instance = Instance::read_or_create(&mut *conn, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(conn, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_person = Person::create(&mut *conn, &new_person).await.unwrap();
|
let inserted_person = Person::create(conn, &new_person).await.unwrap();
|
||||||
|
|
||||||
let recipient_form = PersonInsertForm::builder()
|
let recipient_form = PersonInsertForm::builder()
|
||||||
.name("terrylakes recipient".into())
|
.name("terrylakes recipient".into())
|
||||||
|
@ -112,7 +112,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_recipient = Person::create(&mut *conn, &recipient_form).await.unwrap();
|
let inserted_recipient = Person::create(conn, &recipient_form).await.unwrap();
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::builder()
|
let new_community = CommunityInsertForm::builder()
|
||||||
.name("test community lake".to_string())
|
.name("test community lake".to_string())
|
||||||
|
@ -121,7 +121,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_community = Community::create(&mut *conn, &new_community).await.unwrap();
|
let inserted_community = Community::create(conn, &new_community).await.unwrap();
|
||||||
|
|
||||||
let new_post = PostInsertForm::builder()
|
let new_post = PostInsertForm::builder()
|
||||||
.name("A test post".into())
|
.name("A test post".into())
|
||||||
|
@ -129,7 +129,7 @@ mod tests {
|
||||||
.community_id(inserted_community.id)
|
.community_id(inserted_community.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_post = Post::create(&mut *conn, &new_post).await.unwrap();
|
let inserted_post = Post::create(conn, &new_post).await.unwrap();
|
||||||
|
|
||||||
let comment_form = CommentInsertForm::builder()
|
let comment_form = CommentInsertForm::builder()
|
||||||
.content("A test comment".into())
|
.content("A test comment".into())
|
||||||
|
@ -137,7 +137,7 @@ mod tests {
|
||||||
.post_id(inserted_post.id)
|
.post_id(inserted_post.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_comment = Comment::create(&mut *conn, &comment_form, None)
|
let inserted_comment = Comment::create(conn, &comment_form, None)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ mod tests {
|
||||||
read: None,
|
read: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_reply = CommentReply::create(&mut *conn, &comment_reply_form)
|
let inserted_reply = CommentReply::create(conn, &comment_reply_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -159,30 +159,30 @@ mod tests {
|
||||||
published: inserted_reply.published,
|
published: inserted_reply.published,
|
||||||
};
|
};
|
||||||
|
|
||||||
let read_reply = CommentReply::read(&mut *conn, inserted_reply.id)
|
let read_reply = CommentReply::read(conn, inserted_reply.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let comment_reply_update_form = CommentReplyUpdateForm { read: Some(false) };
|
let comment_reply_update_form = CommentReplyUpdateForm { read: Some(false) };
|
||||||
let updated_reply =
|
let updated_reply =
|
||||||
CommentReply::update(&mut *conn, inserted_reply.id, &comment_reply_update_form)
|
CommentReply::update(conn, inserted_reply.id, &comment_reply_update_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
Comment::delete(&mut *conn, inserted_comment.id)
|
Comment::delete(conn, inserted_comment.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Post::delete(&mut *conn, inserted_post.id).await.unwrap();
|
Post::delete(conn, inserted_post.id).await.unwrap();
|
||||||
Community::delete(&mut *conn, inserted_community.id)
|
Community::delete(conn, inserted_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Person::delete(&mut *conn, inserted_person.id)
|
Person::delete(conn, inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Person::delete(&mut *conn, inserted_recipient.id)
|
Person::delete(conn, inserted_recipient.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Instance::delete(&mut *conn, inserted_instance.id)
|
Instance::delete(conn, inserted_instance.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::{
|
||||||
schema::comment_report::dsl::{comment_report, resolved, resolver_id, updated},
|
schema::comment_report::dsl::{comment_report, resolved, resolver_id, updated},
|
||||||
source::comment_report::{CommentReport, CommentReportForm},
|
source::comment_report::{CommentReport, CommentReportForm},
|
||||||
traits::Reportable,
|
traits::Reportable,
|
||||||
utils::{naive_now, DbConn},
|
utils::{naive_now, GetConn},
|
||||||
};
|
};
|
||||||
use diesel::{
|
use diesel::{
|
||||||
dsl::{insert_into, update},
|
dsl::{insert_into, update},
|
||||||
|
@ -11,7 +11,7 @@ use diesel::{
|
||||||
ExpressionMethods,
|
ExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Reportable for CommentReport {
|
impl Reportable for CommentReport {
|
||||||
|
@ -22,12 +22,12 @@ impl Reportable for CommentReport {
|
||||||
/// * `conn` - the postgres connection
|
/// * `conn` - the postgres connection
|
||||||
/// * `comment_report_form` - the filled CommentReportForm to insert
|
/// * `comment_report_form` - the filled CommentReportForm to insert
|
||||||
async fn report(
|
async fn report(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
comment_report_form: &CommentReportForm,
|
comment_report_form: &CommentReportForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
insert_into(comment_report)
|
insert_into(comment_report)
|
||||||
.values(comment_report_form)
|
.values(comment_report_form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ impl Reportable for CommentReport {
|
||||||
/// * `report_id` - the id of the report to resolve
|
/// * `report_id` - the id of the report to resolve
|
||||||
/// * `by_resolver_id` - the id of the user resolving the report
|
/// * `by_resolver_id` - the id of the user resolving the report
|
||||||
async fn resolve(
|
async fn resolve(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
report_id_: Self::IdType,
|
report_id_: Self::IdType,
|
||||||
by_resolver_id: PersonId,
|
by_resolver_id: PersonId,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
|
@ -47,7 +47,7 @@ impl Reportable for CommentReport {
|
||||||
resolver_id.eq(by_resolver_id),
|
resolver_id.eq(by_resolver_id),
|
||||||
updated.eq(naive_now()),
|
updated.eq(naive_now()),
|
||||||
))
|
))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ impl Reportable for CommentReport {
|
||||||
/// * `report_id` - the id of the report to unresolve
|
/// * `report_id` - the id of the report to unresolve
|
||||||
/// * `by_resolver_id` - the id of the user unresolving the report
|
/// * `by_resolver_id` - the id of the user unresolving the report
|
||||||
async fn unresolve(
|
async fn unresolve(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
report_id_: Self::IdType,
|
report_id_: Self::IdType,
|
||||||
by_resolver_id: PersonId,
|
by_resolver_id: PersonId,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
|
@ -67,7 +67,7 @@ impl Reportable for CommentReport {
|
||||||
resolver_id.eq(by_resolver_id),
|
resolver_id.eq(by_resolver_id),
|
||||||
updated.eq(naive_now()),
|
updated.eq(naive_now()),
|
||||||
))
|
))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,33 +16,33 @@ use crate::{
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
traits::{ApubActor, Bannable, Crud, Followable, Joinable},
|
traits::{ApubActor, Bannable, Crud, Followable, Joinable},
|
||||||
utils::{functions::lower, DbConn},
|
utils::{functions::lower, GetConn},
|
||||||
SubscribedType,
|
SubscribedType,
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Crud for Community {
|
impl Crud for Community {
|
||||||
type InsertForm = CommunityInsertForm;
|
type InsertForm = CommunityInsertForm;
|
||||||
type UpdateForm = CommunityUpdateForm;
|
type UpdateForm = CommunityUpdateForm;
|
||||||
type IdType = CommunityId;
|
type IdType = CommunityId;
|
||||||
async fn read(mut conn: impl DbConn, community_id: CommunityId) -> Result<Self, Error> {
|
async fn read(mut conn: impl GetConn, community_id: CommunityId) -> Result<Self, Error> {
|
||||||
community::table
|
community::table
|
||||||
.find(community_id)
|
.find(community_id)
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete(mut conn: impl DbConn, community_id: CommunityId) -> Result<usize, Error> {
|
async fn delete(mut conn: impl GetConn, community_id: CommunityId) -> Result<usize, Error> {
|
||||||
diesel::delete(community::table.find(community_id))
|
diesel::delete(community::table.find(community_id))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut conn: impl DbConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl GetConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
let is_new_community = match &form.actor_id {
|
let is_new_community = match &form.actor_id {
|
||||||
Some(id) => Community::read_from_apub_id(&mut *conn, id)
|
Some(id) => Community::read_from_apub_id(conn, id)
|
||||||
.await?
|
.await?
|
||||||
.is_none(),
|
.is_none(),
|
||||||
None => true,
|
None => true,
|
||||||
|
@ -54,25 +54,25 @@ impl Crud for Community {
|
||||||
.on_conflict(community::actor_id)
|
.on_conflict(community::actor_id)
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// Initialize languages for new community
|
// Initialize languages for new community
|
||||||
if is_new_community {
|
if is_new_community {
|
||||||
CommunityLanguage::update(&mut *conn, vec![], community_.id).await?;
|
CommunityLanguage::update(conn, vec![], community_.id).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(community_)
|
Ok(community_)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
form: &Self::UpdateForm,
|
form: &Self::UpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
diesel::update(community::table.find(community_id))
|
diesel::update(community::table.find(community_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,18 +81,18 @@ impl Crud for Community {
|
||||||
impl Joinable for CommunityModerator {
|
impl Joinable for CommunityModerator {
|
||||||
type Form = CommunityModeratorForm;
|
type Form = CommunityModeratorForm;
|
||||||
async fn join(
|
async fn join(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
community_moderator_form: &CommunityModeratorForm,
|
community_moderator_form: &CommunityModeratorForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use crate::schema::community_moderator::dsl::community_moderator;
|
use crate::schema::community_moderator::dsl::community_moderator;
|
||||||
insert_into(community_moderator)
|
insert_into(community_moderator)
|
||||||
.values(community_moderator_form)
|
.values(community_moderator_form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn leave(
|
async fn leave(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
community_moderator_form: &CommunityModeratorForm,
|
community_moderator_form: &CommunityModeratorForm,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
use crate::schema::community_moderator::dsl::{community_id, community_moderator, person_id};
|
use crate::schema::community_moderator::dsl::{community_id, community_moderator, person_id};
|
||||||
|
@ -101,7 +101,7 @@ impl Joinable for CommunityModerator {
|
||||||
.filter(community_id.eq(community_moderator_form.community_id))
|
.filter(community_id.eq(community_moderator_form.community_id))
|
||||||
.filter(person_id.eq(community_moderator_form.person_id)),
|
.filter(person_id.eq(community_moderator_form.person_id)),
|
||||||
)
|
)
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,21 +114,21 @@ pub enum CollectionType {
|
||||||
impl Community {
|
impl Community {
|
||||||
/// Get the community which has a given moderators or featured url, also return the collection type
|
/// Get the community which has a given moderators or featured url, also return the collection type
|
||||||
pub async fn get_by_collection_url(
|
pub async fn get_by_collection_url(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
url: &DbUrl,
|
url: &DbUrl,
|
||||||
) -> Result<(Community, CollectionType), Error> {
|
) -> Result<(Community, CollectionType), Error> {
|
||||||
use crate::schema::community::dsl::{featured_url, moderators_url};
|
use crate::schema::community::dsl::{featured_url, moderators_url};
|
||||||
use CollectionType::*;
|
use CollectionType::*;
|
||||||
let res = community::table
|
let res = community::table
|
||||||
.filter(moderators_url.eq(url))
|
.filter(moderators_url.eq(url))
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await;
|
.await;
|
||||||
if let Ok(c) = res {
|
if let Ok(c) = res {
|
||||||
return Ok((c, Moderators));
|
return Ok((c, Moderators));
|
||||||
}
|
}
|
||||||
let res = community::table
|
let res = community::table
|
||||||
.filter(featured_url.eq(url))
|
.filter(featured_url.eq(url))
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await;
|
.await;
|
||||||
if let Ok(c) = res {
|
if let Ok(c) = res {
|
||||||
return Ok((c, Featured));
|
return Ok((c, Featured));
|
||||||
|
@ -139,35 +139,35 @@ impl Community {
|
||||||
|
|
||||||
impl CommunityModerator {
|
impl CommunityModerator {
|
||||||
pub async fn delete_for_community(
|
pub async fn delete_for_community(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_community_id: CommunityId,
|
for_community_id: CommunityId,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
use crate::schema::community_moderator::dsl::{community_id, community_moderator};
|
use crate::schema::community_moderator::dsl::{community_id, community_moderator};
|
||||||
|
|
||||||
diesel::delete(community_moderator.filter(community_id.eq(for_community_id)))
|
diesel::delete(community_moderator.filter(community_id.eq(for_community_id)))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn leave_all_communities(
|
pub async fn leave_all_communities(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_person_id: PersonId,
|
for_person_id: PersonId,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
use crate::schema::community_moderator::dsl::{community_moderator, person_id};
|
use crate::schema::community_moderator::dsl::{community_moderator, person_id};
|
||||||
diesel::delete(community_moderator.filter(person_id.eq(for_person_id)))
|
diesel::delete(community_moderator.filter(person_id.eq(for_person_id)))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_person_moderated_communities(
|
pub async fn get_person_moderated_communities(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_person_id: PersonId,
|
for_person_id: PersonId,
|
||||||
) -> Result<Vec<CommunityId>, Error> {
|
) -> Result<Vec<CommunityId>, Error> {
|
||||||
use crate::schema::community_moderator::dsl::{community_id, community_moderator, person_id};
|
use crate::schema::community_moderator::dsl::{community_id, community_moderator, person_id};
|
||||||
community_moderator
|
community_moderator
|
||||||
.filter(person_id.eq(for_person_id))
|
.filter(person_id.eq(for_person_id))
|
||||||
.select(community_id)
|
.select(community_id)
|
||||||
.load::<CommunityId>(&mut *conn)
|
.load::<CommunityId>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@ impl CommunityModerator {
|
||||||
impl Bannable for CommunityPersonBan {
|
impl Bannable for CommunityPersonBan {
|
||||||
type Form = CommunityPersonBanForm;
|
type Form = CommunityPersonBanForm;
|
||||||
async fn ban(
|
async fn ban(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
community_person_ban_form: &CommunityPersonBanForm,
|
community_person_ban_form: &CommunityPersonBanForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use crate::schema::community_person_ban::dsl::{community_id, community_person_ban, person_id};
|
use crate::schema::community_person_ban::dsl::{community_id, community_person_ban, person_id};
|
||||||
|
@ -185,12 +185,12 @@ impl Bannable for CommunityPersonBan {
|
||||||
.on_conflict((community_id, person_id))
|
.on_conflict((community_id, person_id))
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(community_person_ban_form)
|
.set(community_person_ban_form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn unban(
|
async fn unban(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
community_person_ban_form: &CommunityPersonBanForm,
|
community_person_ban_form: &CommunityPersonBanForm,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
use crate::schema::community_person_ban::dsl::{community_id, community_person_ban, person_id};
|
use crate::schema::community_person_ban::dsl::{community_id, community_person_ban, person_id};
|
||||||
|
@ -199,7 +199,7 @@ impl Bannable for CommunityPersonBan {
|
||||||
.filter(community_id.eq(community_person_ban_form.community_id))
|
.filter(community_id.eq(community_person_ban_form.community_id))
|
||||||
.filter(person_id.eq(community_person_ban_form.person_id)),
|
.filter(person_id.eq(community_person_ban_form.person_id)),
|
||||||
)
|
)
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,18 +223,18 @@ impl CommunityFollower {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Followable for CommunityFollower {
|
impl Followable for CommunityFollower {
|
||||||
type Form = CommunityFollowerForm;
|
type Form = CommunityFollowerForm;
|
||||||
async fn follow(mut conn: impl DbConn, form: &CommunityFollowerForm) -> Result<Self, Error> {
|
async fn follow(mut conn: impl GetConn, form: &CommunityFollowerForm) -> Result<Self, Error> {
|
||||||
use crate::schema::community_follower::dsl::{community_follower, community_id, person_id};
|
use crate::schema::community_follower::dsl::{community_follower, community_id, person_id};
|
||||||
insert_into(community_follower)
|
insert_into(community_follower)
|
||||||
.values(form)
|
.values(form)
|
||||||
.on_conflict((community_id, person_id))
|
.on_conflict((community_id, person_id))
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn follow_accepted(
|
async fn follow_accepted(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
community_id_: CommunityId,
|
community_id_: CommunityId,
|
||||||
person_id_: PersonId,
|
person_id_: PersonId,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
|
@ -250,17 +250,17 @@ impl Followable for CommunityFollower {
|
||||||
.filter(person_id.eq(person_id_)),
|
.filter(person_id.eq(person_id_)),
|
||||||
)
|
)
|
||||||
.set(pending.eq(false))
|
.set(pending.eq(false))
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn unfollow(mut conn: impl DbConn, form: &CommunityFollowerForm) -> Result<usize, Error> {
|
async fn unfollow(mut conn: impl GetConn, form: &CommunityFollowerForm) -> Result<usize, Error> {
|
||||||
use crate::schema::community_follower::dsl::{community_follower, community_id, person_id};
|
use crate::schema::community_follower::dsl::{community_follower, community_id, person_id};
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
community_follower
|
community_follower
|
||||||
.filter(community_id.eq(&form.community_id))
|
.filter(community_id.eq(&form.community_id))
|
||||||
.filter(person_id.eq(&form.person_id)),
|
.filter(person_id.eq(&form.person_id)),
|
||||||
)
|
)
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -268,13 +268,13 @@ impl Followable for CommunityFollower {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ApubActor for Community {
|
impl ApubActor for Community {
|
||||||
async fn read_from_apub_id(
|
async fn read_from_apub_id(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
object_id: &DbUrl,
|
object_id: &DbUrl,
|
||||||
) -> Result<Option<Self>, Error> {
|
) -> Result<Option<Self>, Error> {
|
||||||
Ok(
|
Ok(
|
||||||
community::table
|
community::table
|
||||||
.filter(community::actor_id.eq(object_id))
|
.filter(community::actor_id.eq(object_id))
|
||||||
.first::<Community>(&mut *conn)
|
.first::<Community>(conn)
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok()
|
||||||
.map(Into::into),
|
.map(Into::into),
|
||||||
|
@ -282,7 +282,7 @@ impl ApubActor for Community {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read_from_name(
|
async fn read_from_name(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
community_name: &str,
|
community_name: &str,
|
||||||
include_deleted: bool,
|
include_deleted: bool,
|
||||||
) -> Result<Community, Error> {
|
) -> Result<Community, Error> {
|
||||||
|
@ -295,11 +295,11 @@ impl ApubActor for Community {
|
||||||
.filter(community::deleted.eq(false))
|
.filter(community::deleted.eq(false))
|
||||||
.filter(community::removed.eq(false));
|
.filter(community::removed.eq(false));
|
||||||
}
|
}
|
||||||
q.first::<Self>(&mut *conn).await
|
q.first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read_from_name_and_domain(
|
async fn read_from_name_and_domain(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
community_name: &str,
|
community_name: &str,
|
||||||
for_domain: &str,
|
for_domain: &str,
|
||||||
) -> Result<Community, Error> {
|
) -> Result<Community, Error> {
|
||||||
|
@ -308,7 +308,7 @@ impl ApubActor for Community {
|
||||||
.filter(lower(community::name).eq(community_name.to_lowercase()))
|
.filter(lower(community::name).eq(community_name.to_lowercase()))
|
||||||
.filter(instance::domain.eq(for_domain))
|
.filter(instance::domain.eq(for_domain))
|
||||||
.select(community::all_columns)
|
.select(community::all_columns)
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -341,7 +341,7 @@ mod tests {
|
||||||
async fn test_crud() {
|
async fn test_crud() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
let inserted_instance = Instance::read_or_create(&mut *conn, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(conn, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -351,7 +351,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_person = Person::create(&mut *conn, &new_person).await.unwrap();
|
let inserted_person = Person::create(conn, &new_person).await.unwrap();
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::builder()
|
let new_community = CommunityInsertForm::builder()
|
||||||
.name("TIL".into())
|
.name("TIL".into())
|
||||||
|
@ -360,7 +360,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_community = Community::create(&mut *conn, &new_community).await.unwrap();
|
let inserted_community = Community::create(conn, &new_community).await.unwrap();
|
||||||
|
|
||||||
let expected_community = Community {
|
let expected_community = Community {
|
||||||
id: inserted_community.id,
|
id: inserted_community.id,
|
||||||
|
@ -396,7 +396,7 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_community_follower =
|
let inserted_community_follower =
|
||||||
CommunityFollower::follow(&mut *conn, &community_follower_form)
|
CommunityFollower::follow(conn, &community_follower_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -414,7 +414,7 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_community_moderator =
|
let inserted_community_moderator =
|
||||||
CommunityModerator::join(&mut *conn, &community_moderator_form)
|
CommunityModerator::join(conn, &community_moderator_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -432,7 +432,7 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_community_person_ban =
|
let inserted_community_person_ban =
|
||||||
CommunityPersonBan::ban(&mut *conn, &community_person_ban_form)
|
CommunityPersonBan::ban(conn, &community_person_ban_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -444,7 +444,7 @@ mod tests {
|
||||||
expires: None,
|
expires: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let read_community = Community::read(&mut *conn, inserted_community.id)
|
let read_community = Community::read(conn, inserted_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -452,26 +452,26 @@ mod tests {
|
||||||
.title(Some("nada".to_owned()))
|
.title(Some("nada".to_owned()))
|
||||||
.build();
|
.build();
|
||||||
let updated_community =
|
let updated_community =
|
||||||
Community::update(&mut *conn, inserted_community.id, &update_community_form)
|
Community::update(conn, inserted_community.id, &update_community_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let ignored_community = CommunityFollower::unfollow(&mut *conn, &community_follower_form)
|
let ignored_community = CommunityFollower::unfollow(conn, &community_follower_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let left_community = CommunityModerator::leave(&mut *conn, &community_moderator_form)
|
let left_community = CommunityModerator::leave(conn, &community_moderator_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let unban = CommunityPersonBan::unban(&mut *conn, &community_person_ban_form)
|
let unban = CommunityPersonBan::unban(conn, &community_person_ban_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let num_deleted = Community::delete(&mut *conn, inserted_community.id)
|
let num_deleted = Community::delete(conn, inserted_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Person::delete(&mut *conn, inserted_person.id)
|
Person::delete(conn, inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Instance::delete(&mut *conn, inserted_instance.id)
|
Instance::delete(conn, inserted_instance.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -2,25 +2,25 @@ use crate::{
|
||||||
schema::community_block::dsl::{community_block, community_id, person_id},
|
schema::community_block::dsl::{community_block, community_id, person_id},
|
||||||
source::community_block::{CommunityBlock, CommunityBlockForm},
|
source::community_block::{CommunityBlock, CommunityBlockForm},
|
||||||
traits::Blockable,
|
traits::Blockable,
|
||||||
utils::DbConn,
|
utils::GetConn,
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Blockable for CommunityBlock {
|
impl Blockable for CommunityBlock {
|
||||||
type Form = CommunityBlockForm;
|
type Form = CommunityBlockForm;
|
||||||
async fn block(mut conn: impl DbConn, community_block_form: &Self::Form) -> Result<Self, Error> {
|
async fn block(mut conn: impl GetConn, community_block_form: &Self::Form) -> Result<Self, Error> {
|
||||||
insert_into(community_block)
|
insert_into(community_block)
|
||||||
.values(community_block_form)
|
.values(community_block_form)
|
||||||
.on_conflict((person_id, community_id))
|
.on_conflict((person_id, community_id))
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(community_block_form)
|
.set(community_block_form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn unblock(
|
async fn unblock(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
community_block_form: &Self::Form,
|
community_block_form: &Self::Form,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
|
@ -28,7 +28,7 @@ impl Blockable for CommunityBlock {
|
||||||
.filter(person_id.eq(community_block_form.person_id))
|
.filter(person_id.eq(community_block_form.person_id))
|
||||||
.filter(community_id.eq(community_block_form.community_id)),
|
.filter(community_id.eq(community_block_form.community_id)),
|
||||||
)
|
)
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,48 +8,48 @@ use crate::{
|
||||||
custom_emoji::{CustomEmoji, CustomEmojiInsertForm, CustomEmojiUpdateForm},
|
custom_emoji::{CustomEmoji, CustomEmojiInsertForm, CustomEmojiUpdateForm},
|
||||||
custom_emoji_keyword::{CustomEmojiKeyword, CustomEmojiKeywordInsertForm},
|
custom_emoji_keyword::{CustomEmojiKeyword, CustomEmojiKeywordInsertForm},
|
||||||
},
|
},
|
||||||
utils::DbConn,
|
utils::GetConn,
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
impl CustomEmoji {
|
impl CustomEmoji {
|
||||||
pub async fn create(mut conn: impl DbConn, form: &CustomEmojiInsertForm) -> Result<Self, Error> {
|
pub async fn create(mut conn: impl GetConn, form: &CustomEmojiInsertForm) -> Result<Self, Error> {
|
||||||
insert_into(custom_emoji)
|
insert_into(custom_emoji)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
pub async fn update(
|
pub async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
emoji_id: CustomEmojiId,
|
emoji_id: CustomEmojiId,
|
||||||
form: &CustomEmojiUpdateForm,
|
form: &CustomEmojiUpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
diesel::update(custom_emoji.find(emoji_id))
|
diesel::update(custom_emoji.find(emoji_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
pub async fn delete(mut conn: impl DbConn, emoji_id: CustomEmojiId) -> Result<usize, Error> {
|
pub async fn delete(mut conn: impl GetConn, emoji_id: CustomEmojiId) -> Result<usize, Error> {
|
||||||
diesel::delete(custom_emoji.find(emoji_id))
|
diesel::delete(custom_emoji.find(emoji_id))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CustomEmojiKeyword {
|
impl CustomEmojiKeyword {
|
||||||
pub async fn create(
|
pub async fn create(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
form: Vec<CustomEmojiKeywordInsertForm>,
|
form: Vec<CustomEmojiKeywordInsertForm>,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
insert_into(custom_emoji_keyword)
|
insert_into(custom_emoji_keyword)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_results::<Self>(&mut *conn)
|
.get_results::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
pub async fn delete(mut conn: impl DbConn, emoji_id: CustomEmojiId) -> Result<usize, Error> {
|
pub async fn delete(mut conn: impl GetConn, emoji_id: CustomEmojiId) -> Result<usize, Error> {
|
||||||
diesel::delete(custom_emoji_keyword.filter(custom_emoji_id.eq(emoji_id)))
|
diesel::delete(custom_emoji_keyword.filter(custom_emoji_id.eq(emoji_id)))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
||||||
verification_token,
|
verification_token,
|
||||||
},
|
},
|
||||||
source::email_verification::{EmailVerification, EmailVerificationForm},
|
source::email_verification::{EmailVerification, EmailVerificationForm},
|
||||||
utils::DbConn,
|
utils::GetConn,
|
||||||
};
|
};
|
||||||
use diesel::{
|
use diesel::{
|
||||||
dsl::{now, IntervalDsl},
|
dsl::{now, IntervalDsl},
|
||||||
|
@ -16,29 +16,29 @@ use diesel::{
|
||||||
ExpressionMethods,
|
ExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
impl EmailVerification {
|
impl EmailVerification {
|
||||||
pub async fn create(mut conn: impl DbConn, form: &EmailVerificationForm) -> Result<Self, Error> {
|
pub async fn create(mut conn: impl GetConn, form: &EmailVerificationForm) -> Result<Self, Error> {
|
||||||
insert_into(email_verification)
|
insert_into(email_verification)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read_for_token(mut conn: impl DbConn, token: &str) -> Result<Self, Error> {
|
pub async fn read_for_token(mut conn: impl GetConn, token: &str) -> Result<Self, Error> {
|
||||||
email_verification
|
email_verification
|
||||||
.filter(verification_token.eq(token))
|
.filter(verification_token.eq(token))
|
||||||
.filter(published.gt(now - 7.days()))
|
.filter(published.gt(now - 7.days()))
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
pub async fn delete_old_tokens_for_local_user(
|
pub async fn delete_old_tokens_for_local_user(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
local_user_id_: LocalUserId,
|
local_user_id_: LocalUserId,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
diesel::delete(email_verification.filter(local_user_id.eq(local_user_id_)))
|
diesel::delete(email_verification.filter(local_user_id.eq(local_user_id_)))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,23 +4,23 @@ use crate::{
|
||||||
federation_allowlist::{FederationAllowList, FederationAllowListForm},
|
federation_allowlist::{FederationAllowList, FederationAllowListForm},
|
||||||
instance::Instance,
|
instance::Instance,
|
||||||
},
|
},
|
||||||
utils::DbConn,
|
utils::GetConn,
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error};
|
use diesel::{dsl::insert_into, result::Error};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
impl FederationAllowList {
|
impl FederationAllowList {
|
||||||
pub async fn replace(mut conn: impl DbConn, list_opt: Option<Vec<String>>) -> Result<(), Error> {
|
pub async fn replace(mut conn: impl GetConn, list_opt: Option<Vec<String>>) -> Result<(), Error> {
|
||||||
conn
|
conn
|
||||||
.build_transaction()
|
.build_transaction()
|
||||||
.run(|conn| {
|
.run(|conn| {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
if let Some(list) = list_opt {
|
if let Some(list) = list_opt {
|
||||||
Self::clear(&mut *conn).await?;
|
Self::clear(conn).await?;
|
||||||
|
|
||||||
for domain in list {
|
for domain in list {
|
||||||
// Upsert all of these as instances
|
// Upsert all of these as instances
|
||||||
let instance = Instance::read_or_create_with_conn(&mut *conn, domain).await?;
|
let instance = Instance::read_or_create_with_conn(conn, domain).await?;
|
||||||
|
|
||||||
let form = FederationAllowListForm {
|
let form = FederationAllowListForm {
|
||||||
instance_id: instance.id,
|
instance_id: instance.id,
|
||||||
|
@ -28,7 +28,7 @@ impl FederationAllowList {
|
||||||
};
|
};
|
||||||
insert_into(federation_allowlist::table)
|
insert_into(federation_allowlist::table)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -40,9 +40,9 @@ impl FederationAllowList {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn clear(mut conn: impl DbConn) -> Result<usize, Error> {
|
async fn clear(mut conn: impl GetConn) -> Result<usize, Error> {
|
||||||
diesel::delete(federation_allowlist::table)
|
diesel::delete(federation_allowlist::table)
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,11 +66,11 @@ mod tests {
|
||||||
|
|
||||||
let allowed = Some(domains.clone());
|
let allowed = Some(domains.clone());
|
||||||
|
|
||||||
FederationAllowList::replace(&mut *conn, allowed)
|
FederationAllowList::replace(conn, allowed)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let allows = Instance::allowlist(&mut *conn).await.unwrap();
|
let allows = Instance::allowlist(conn).await.unwrap();
|
||||||
let allows_domains = allows
|
let allows_domains = allows
|
||||||
.iter()
|
.iter()
|
||||||
.map(|i| i.domain.clone())
|
.map(|i| i.domain.clone())
|
||||||
|
@ -82,13 +82,13 @@ mod tests {
|
||||||
// Now test clearing them via Some(empty vec)
|
// Now test clearing them via Some(empty vec)
|
||||||
let clear_allows = Some(Vec::new());
|
let clear_allows = Some(Vec::new());
|
||||||
|
|
||||||
FederationAllowList::replace(&mut *conn, clear_allows)
|
FederationAllowList::replace(conn, clear_allows)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let allows = Instance::allowlist(&mut *conn).await.unwrap();
|
let allows = Instance::allowlist(conn).await.unwrap();
|
||||||
|
|
||||||
assert_eq!(0, allows.len());
|
assert_eq!(0, allows.len());
|
||||||
|
|
||||||
Instance::delete_all(&mut *conn).await.unwrap();
|
Instance::delete_all(conn).await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,23 +4,23 @@ use crate::{
|
||||||
federation_blocklist::{FederationBlockList, FederationBlockListForm},
|
federation_blocklist::{FederationBlockList, FederationBlockListForm},
|
||||||
instance::Instance,
|
instance::Instance,
|
||||||
},
|
},
|
||||||
utils::DbConn,
|
utils::GetConn,
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error};
|
use diesel::{dsl::insert_into, result::Error};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
impl FederationBlockList {
|
impl FederationBlockList {
|
||||||
pub async fn replace(mut conn: impl DbConn, list_opt: Option<Vec<String>>) -> Result<(), Error> {
|
pub async fn replace(mut conn: impl GetConn, list_opt: Option<Vec<String>>) -> Result<(), Error> {
|
||||||
conn
|
conn
|
||||||
.build_transaction()
|
.build_transaction()
|
||||||
.run(|conn| {
|
.run(|conn| {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
if let Some(list) = list_opt {
|
if let Some(list) = list_opt {
|
||||||
Self::clear(&mut *conn).await?;
|
Self::clear(conn).await?;
|
||||||
|
|
||||||
for domain in list {
|
for domain in list {
|
||||||
// Upsert all of these as instances
|
// Upsert all of these as instances
|
||||||
let instance = Instance::read_or_create_with_conn(&mut *conn, domain).await?;
|
let instance = Instance::read_or_create_with_conn(conn, domain).await?;
|
||||||
|
|
||||||
let form = FederationBlockListForm {
|
let form = FederationBlockListForm {
|
||||||
instance_id: instance.id,
|
instance_id: instance.id,
|
||||||
|
@ -28,7 +28,7 @@ impl FederationBlockList {
|
||||||
};
|
};
|
||||||
insert_into(federation_blocklist::table)
|
insert_into(federation_blocklist::table)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -40,9 +40,9 @@ impl FederationBlockList {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn clear(mut conn: impl DbConn) -> Result<usize, Error> {
|
async fn clear(mut conn: impl GetConn) -> Result<usize, Error> {
|
||||||
diesel::delete(federation_blocklist::table)
|
diesel::delete(federation_blocklist::table)
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,21 +2,21 @@ use crate::{
|
||||||
newtypes::InstanceId,
|
newtypes::InstanceId,
|
||||||
schema::{federation_allowlist, federation_blocklist, instance},
|
schema::{federation_allowlist, federation_blocklist, instance},
|
||||||
source::instance::{Instance, InstanceForm},
|
source::instance::{Instance, InstanceForm},
|
||||||
utils::{naive_now, DbConn},
|
utils::{naive_now, GetConn},
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
impl Instance {
|
impl Instance {
|
||||||
pub(crate) async fn read_or_create_with_conn(
|
pub(crate) async fn read_or_create_with_conn(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
domain_: String,
|
domain_: String,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use crate::schema::instance::domain;
|
use crate::schema::instance::domain;
|
||||||
// First try to read the instance row and return directly if found
|
// First try to read the instance row and return directly if found
|
||||||
let instance = instance::table
|
let instance = instance::table
|
||||||
.filter(domain.eq(&domain_))
|
.filter(domain.eq(&domain_))
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await;
|
.await;
|
||||||
match instance {
|
match instance {
|
||||||
Ok(i) => Ok(i),
|
Ok(i) => Ok(i),
|
||||||
|
@ -33,7 +33,7 @@ impl Instance {
|
||||||
.on_conflict(instance::domain)
|
.on_conflict(instance::domain)
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(&form)
|
.set(&form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
e => e,
|
e => e,
|
||||||
|
@ -42,40 +42,40 @@ impl Instance {
|
||||||
|
|
||||||
/// Attempt to read Instance column for the given domain. If it doesnt exist, insert a new one.
|
/// Attempt to read Instance column for the given domain. If it doesnt exist, insert a new one.
|
||||||
/// There is no need for update as the domain of an existing instance cant change.
|
/// There is no need for update as the domain of an existing instance cant change.
|
||||||
pub async fn read_or_create(mut conn: impl DbConn, domain: String) -> Result<Self, Error> {
|
pub async fn read_or_create(mut conn: impl GetConn, domain: String) -> Result<Self, Error> {
|
||||||
Self::read_or_create_with_conn(&mut *conn, domain).await
|
Self::read_or_create_with_conn(conn, domain).await
|
||||||
}
|
}
|
||||||
pub async fn delete(mut conn: impl DbConn, instance_id: InstanceId) -> Result<usize, Error> {
|
pub async fn delete(mut conn: impl GetConn, instance_id: InstanceId) -> Result<usize, Error> {
|
||||||
diesel::delete(instance::table.find(instance_id))
|
diesel::delete(instance::table.find(instance_id))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub async fn delete_all(mut conn: impl DbConn) -> Result<usize, Error> {
|
pub async fn delete_all(mut conn: impl GetConn) -> Result<usize, Error> {
|
||||||
diesel::delete(instance::table).execute(&mut *conn).await
|
diesel::delete(instance::table).execute(conn).await
|
||||||
}
|
}
|
||||||
pub async fn allowlist(mut conn: impl DbConn) -> Result<Vec<Self>, Error> {
|
pub async fn allowlist(mut conn: impl GetConn) -> Result<Vec<Self>, Error> {
|
||||||
instance::table
|
instance::table
|
||||||
.inner_join(federation_allowlist::table)
|
.inner_join(federation_allowlist::table)
|
||||||
.select(instance::all_columns)
|
.select(instance::all_columns)
|
||||||
.get_results(&mut *conn)
|
.get_results(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn blocklist(mut conn: impl DbConn) -> Result<Vec<Self>, Error> {
|
pub async fn blocklist(mut conn: impl GetConn) -> Result<Vec<Self>, Error> {
|
||||||
instance::table
|
instance::table
|
||||||
.inner_join(federation_blocklist::table)
|
.inner_join(federation_blocklist::table)
|
||||||
.select(instance::all_columns)
|
.select(instance::all_columns)
|
||||||
.get_results(&mut *conn)
|
.get_results(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn linked(mut conn: impl DbConn) -> Result<Vec<Self>, Error> {
|
pub async fn linked(mut conn: impl GetConn) -> Result<Vec<Self>, Error> {
|
||||||
instance::table
|
instance::table
|
||||||
.left_join(federation_blocklist::table)
|
.left_join(federation_blocklist::table)
|
||||||
.filter(federation_blocklist::id.is_null())
|
.filter(federation_blocklist::id.is_null())
|
||||||
.select(instance::all_columns)
|
.select(instance::all_columns)
|
||||||
.get_results(&mut *conn)
|
.get_results(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,34 +3,34 @@ use crate::{
|
||||||
newtypes::LanguageId,
|
newtypes::LanguageId,
|
||||||
schema::language::dsl::{code, id, language},
|
schema::language::dsl::{code, id, language},
|
||||||
source::language::Language,
|
source::language::Language,
|
||||||
utils::DbConn,
|
utils::GetConn,
|
||||||
};
|
};
|
||||||
use diesel::{result::Error, QueryDsl};
|
use diesel::{result::Error, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
impl Language {
|
impl Language {
|
||||||
pub async fn read_all(mut conn: impl DbConn) -> Result<Vec<Language>, Error> {
|
pub async fn read_all(mut conn: impl GetConn) -> Result<Vec<Language>, Error> {
|
||||||
Self::read_all_conn(&mut *conn).await
|
Self::read_all_conn(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read_all_conn(mut conn: impl DbConn) -> Result<Vec<Language>, Error> {
|
pub async fn read_all_conn(mut conn: impl GetConn) -> Result<Vec<Language>, Error> {
|
||||||
language.load::<Self>(&mut *conn).await
|
language.load::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read_from_id(mut conn: impl DbConn, id_: LanguageId) -> Result<Language, Error> {
|
pub async fn read_from_id(mut conn: impl GetConn, id_: LanguageId) -> Result<Language, Error> {
|
||||||
language.filter(id.eq(id_)).first::<Self>(&mut *conn).await
|
language.filter(id.eq(id_)).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempts to find the given language code and return its ID. If not found, returns none.
|
/// Attempts to find the given language code and return its ID. If not found, returns none.
|
||||||
pub async fn read_id_from_code(
|
pub async fn read_id_from_code(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
code_: Option<&str>,
|
code_: Option<&str>,
|
||||||
) -> Result<Option<LanguageId>, Error> {
|
) -> Result<Option<LanguageId>, Error> {
|
||||||
if let Some(code_) = code_ {
|
if let Some(code_) = code_ {
|
||||||
Ok(
|
Ok(
|
||||||
language
|
language
|
||||||
.filter(code.eq(code_))
|
.filter(code.eq(code_))
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
.map(|l| l.id)
|
.map(|l| l.id)
|
||||||
.ok(),
|
.ok(),
|
||||||
|
@ -51,7 +51,7 @@ mod tests {
|
||||||
async fn test_languages() {
|
async fn test_languages() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
let all = Language::read_all(&mut *conn).await.unwrap();
|
let all = Language::read_all(conn).await.unwrap();
|
||||||
|
|
||||||
assert_eq!(184, all.len());
|
assert_eq!(184, all.len());
|
||||||
assert_eq!("ak", all[5].code);
|
assert_eq!("ak", all[5].code);
|
||||||
|
|
|
@ -1,28 +1,28 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
schema::local_site::dsl::local_site,
|
schema::local_site::dsl::local_site,
|
||||||
source::local_site::{LocalSite, LocalSiteInsertForm, LocalSiteUpdateForm},
|
source::local_site::{LocalSite, LocalSiteInsertForm, LocalSiteUpdateForm},
|
||||||
utils::DbConn,
|
utils::GetConn,
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error};
|
use diesel::{dsl::insert_into, result::Error};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
impl LocalSite {
|
impl LocalSite {
|
||||||
pub async fn create(mut conn: impl DbConn, form: &LocalSiteInsertForm) -> Result<Self, Error> {
|
pub async fn create(mut conn: impl GetConn, form: &LocalSiteInsertForm) -> Result<Self, Error> {
|
||||||
insert_into(local_site)
|
insert_into(local_site)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
pub async fn read(mut conn: impl DbConn) -> Result<Self, Error> {
|
pub async fn read(mut conn: impl GetConn) -> Result<Self, Error> {
|
||||||
local_site.first::<Self>(&mut *conn).await
|
local_site.first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
pub async fn update(mut conn: impl DbConn, form: &LocalSiteUpdateForm) -> Result<Self, Error> {
|
pub async fn update(mut conn: impl GetConn, form: &LocalSiteUpdateForm) -> Result<Self, Error> {
|
||||||
diesel::update(local_site)
|
diesel::update(local_site)
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
pub async fn delete(mut conn: impl DbConn) -> Result<usize, Error> {
|
pub async fn delete(mut conn: impl GetConn) -> Result<usize, Error> {
|
||||||
diesel::delete(local_site).execute(&mut *conn).await
|
diesel::delete(local_site).execute(conn).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,27 +5,27 @@ use crate::{
|
||||||
LocalSiteRateLimitInsertForm,
|
LocalSiteRateLimitInsertForm,
|
||||||
LocalSiteRateLimitUpdateForm,
|
LocalSiteRateLimitUpdateForm,
|
||||||
},
|
},
|
||||||
utils::DbConn,
|
utils::GetConn,
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error};
|
use diesel::{dsl::insert_into, result::Error};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
impl LocalSiteRateLimit {
|
impl LocalSiteRateLimit {
|
||||||
pub async fn read(mut conn: impl DbConn) -> Result<Self, Error> {
|
pub async fn read(mut conn: impl GetConn) -> Result<Self, Error> {
|
||||||
local_site_rate_limit::table.first::<Self>(&mut *conn).await
|
local_site_rate_limit::table.first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create(
|
pub async fn create(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
form: &LocalSiteRateLimitInsertForm,
|
form: &LocalSiteRateLimitInsertForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
insert_into(local_site_rate_limit::table)
|
insert_into(local_site_rate_limit::table)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
pub async fn update(
|
pub async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
form: &LocalSiteRateLimitUpdateForm,
|
form: &LocalSiteRateLimitUpdateForm,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
// avoid error "There are no changes to save. This query cannot be built"
|
// avoid error "There are no changes to save. This query cannot be built"
|
||||||
|
@ -34,7 +34,7 @@ impl LocalSiteRateLimit {
|
||||||
}
|
}
|
||||||
diesel::update(local_site_rate_limit::table)
|
diesel::update(local_site_rate_limit::table)
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,15 +13,15 @@ use crate::{
|
||||||
local_user::{LocalUser, LocalUserInsertForm, LocalUserUpdateForm},
|
local_user::{LocalUser, LocalUserInsertForm, LocalUserUpdateForm},
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::{naive_now, DbConn},
|
utils::{naive_now, GetConn},
|
||||||
};
|
};
|
||||||
use bcrypt::{hash, DEFAULT_COST};
|
use bcrypt::{hash, DEFAULT_COST};
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
impl LocalUser {
|
impl LocalUser {
|
||||||
pub async fn update_password(
|
pub async fn update_password(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
local_user_id: LocalUserId,
|
local_user_id: LocalUserId,
|
||||||
new_password: &str,
|
new_password: &str,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
|
@ -32,30 +32,30 @@ impl LocalUser {
|
||||||
password_encrypted.eq(password_hash),
|
password_encrypted.eq(password_hash),
|
||||||
validator_time.eq(naive_now()),
|
validator_time.eq(naive_now()),
|
||||||
))
|
))
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn set_all_users_email_verified(mut conn: impl DbConn) -> Result<Vec<Self>, Error> {
|
pub async fn set_all_users_email_verified(mut conn: impl GetConn) -> Result<Vec<Self>, Error> {
|
||||||
diesel::update(local_user)
|
diesel::update(local_user)
|
||||||
.set(email_verified.eq(true))
|
.set(email_verified.eq(true))
|
||||||
.get_results::<Self>(&mut *conn)
|
.get_results::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn set_all_users_registration_applications_accepted(
|
pub async fn set_all_users_registration_applications_accepted(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
diesel::update(local_user)
|
diesel::update(local_user)
|
||||||
.set(accepted_application.eq(true))
|
.set(accepted_application.eq(true))
|
||||||
.get_results::<Self>(&mut *conn)
|
.get_results::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn is_email_taken(mut conn: impl DbConn, email_: &str) -> Result<bool, Error> {
|
pub async fn is_email_taken(mut conn: impl GetConn, email_: &str) -> Result<bool, Error> {
|
||||||
use diesel::dsl::{exists, select};
|
use diesel::dsl::{exists, select};
|
||||||
select(exists(local_user.filter(email.eq(email_))))
|
select(exists(local_user.filter(email.eq(email_))))
|
||||||
.get_result(&mut *conn)
|
.get_result(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,18 +65,18 @@ impl Crud for LocalUser {
|
||||||
type InsertForm = LocalUserInsertForm;
|
type InsertForm = LocalUserInsertForm;
|
||||||
type UpdateForm = LocalUserUpdateForm;
|
type UpdateForm = LocalUserUpdateForm;
|
||||||
type IdType = LocalUserId;
|
type IdType = LocalUserId;
|
||||||
async fn read(mut conn: impl DbConn, local_user_id: LocalUserId) -> Result<Self, Error> {
|
async fn read(mut conn: impl GetConn, local_user_id: LocalUserId) -> Result<Self, Error> {
|
||||||
local_user
|
local_user
|
||||||
.find(local_user_id)
|
.find(local_user_id)
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn delete(mut conn: impl DbConn, local_user_id: LocalUserId) -> Result<usize, Error> {
|
async fn delete(mut conn: impl GetConn, local_user_id: LocalUserId) -> Result<usize, Error> {
|
||||||
diesel::delete(local_user.find(local_user_id))
|
diesel::delete(local_user.find(local_user_id))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn create(mut conn: impl DbConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl GetConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
let mut form_with_encrypted_password = form.clone();
|
let mut form_with_encrypted_password = form.clone();
|
||||||
let password_hash =
|
let password_hash =
|
||||||
hash(&form.password_encrypted, DEFAULT_COST).expect("Couldn't hash password");
|
hash(&form.password_encrypted, DEFAULT_COST).expect("Couldn't hash password");
|
||||||
|
@ -84,29 +84,29 @@ impl Crud for LocalUser {
|
||||||
|
|
||||||
let local_user_ = insert_into(local_user)
|
let local_user_ = insert_into(local_user)
|
||||||
.values(form_with_encrypted_password)
|
.values(form_with_encrypted_password)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let site_languages = SiteLanguage::read_local_raw(&mut *conn).await;
|
let site_languages = SiteLanguage::read_local_raw(conn).await;
|
||||||
if let Ok(langs) = site_languages {
|
if let Ok(langs) = site_languages {
|
||||||
// if site exists, init user with site languages
|
// if site exists, init user with site languages
|
||||||
LocalUserLanguage::update(&mut *conn, langs, local_user_.id).await?;
|
LocalUserLanguage::update(conn, langs, local_user_.id).await?;
|
||||||
} else {
|
} else {
|
||||||
// otherwise, init with all languages (this only happens during tests and
|
// otherwise, init with all languages (this only happens during tests and
|
||||||
// for first admin user, which is created before site)
|
// for first admin user, which is created before site)
|
||||||
LocalUserLanguage::update(&mut *conn, vec![], local_user_.id).await?;
|
LocalUserLanguage::update(conn, vec![], local_user_.id).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(local_user_)
|
Ok(local_user_)
|
||||||
}
|
}
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
local_user_id: LocalUserId,
|
local_user_id: LocalUserId,
|
||||||
form: &Self::UpdateForm,
|
form: &Self::UpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
diesel::update(local_user.find(local_user_id))
|
diesel::update(local_user.find(local_user_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,41 +32,41 @@ use crate::{
|
||||||
ModTransferCommunityForm,
|
ModTransferCommunityForm,
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::DbConn,
|
utils::GetConn,
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Crud for ModRemovePost {
|
impl Crud for ModRemovePost {
|
||||||
type InsertForm = ModRemovePostForm;
|
type InsertForm = ModRemovePostForm;
|
||||||
type UpdateForm = ModRemovePostForm;
|
type UpdateForm = ModRemovePostForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut conn: impl DbConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(mut conn: impl GetConn, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_remove_post::dsl::mod_remove_post;
|
use crate::schema::mod_remove_post::dsl::mod_remove_post;
|
||||||
mod_remove_post
|
mod_remove_post
|
||||||
.find(from_id)
|
.find(from_id)
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut conn: impl DbConn, form: &ModRemovePostForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl GetConn, form: &ModRemovePostForm) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_remove_post::dsl::mod_remove_post;
|
use crate::schema::mod_remove_post::dsl::mod_remove_post;
|
||||||
insert_into(mod_remove_post)
|
insert_into(mod_remove_post)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
from_id: i32,
|
from_id: i32,
|
||||||
form: &ModRemovePostForm,
|
form: &ModRemovePostForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_remove_post::dsl::mod_remove_post;
|
use crate::schema::mod_remove_post::dsl::mod_remove_post;
|
||||||
diesel::update(mod_remove_post.find(from_id))
|
diesel::update(mod_remove_post.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,28 +76,28 @@ impl Crud for ModLockPost {
|
||||||
type InsertForm = ModLockPostForm;
|
type InsertForm = ModLockPostForm;
|
||||||
type UpdateForm = ModLockPostForm;
|
type UpdateForm = ModLockPostForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut conn: impl DbConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(mut conn: impl GetConn, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_lock_post::dsl::mod_lock_post;
|
use crate::schema::mod_lock_post::dsl::mod_lock_post;
|
||||||
mod_lock_post.find(from_id).first::<Self>(&mut *conn).await
|
mod_lock_post.find(from_id).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut conn: impl DbConn, form: &ModLockPostForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl GetConn, form: &ModLockPostForm) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_lock_post::dsl::mod_lock_post;
|
use crate::schema::mod_lock_post::dsl::mod_lock_post;
|
||||||
insert_into(mod_lock_post)
|
insert_into(mod_lock_post)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
from_id: i32,
|
from_id: i32,
|
||||||
form: &ModLockPostForm,
|
form: &ModLockPostForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_lock_post::dsl::mod_lock_post;
|
use crate::schema::mod_lock_post::dsl::mod_lock_post;
|
||||||
diesel::update(mod_lock_post.find(from_id))
|
diesel::update(mod_lock_post.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,31 +107,31 @@ impl Crud for ModFeaturePost {
|
||||||
type InsertForm = ModFeaturePostForm;
|
type InsertForm = ModFeaturePostForm;
|
||||||
type UpdateForm = ModFeaturePostForm;
|
type UpdateForm = ModFeaturePostForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut conn: impl DbConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(mut conn: impl GetConn, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_feature_post::dsl::mod_feature_post;
|
use crate::schema::mod_feature_post::dsl::mod_feature_post;
|
||||||
mod_feature_post
|
mod_feature_post
|
||||||
.find(from_id)
|
.find(from_id)
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut conn: impl DbConn, form: &ModFeaturePostForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl GetConn, form: &ModFeaturePostForm) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_feature_post::dsl::mod_feature_post;
|
use crate::schema::mod_feature_post::dsl::mod_feature_post;
|
||||||
insert_into(mod_feature_post)
|
insert_into(mod_feature_post)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
from_id: i32,
|
from_id: i32,
|
||||||
form: &ModFeaturePostForm,
|
form: &ModFeaturePostForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_feature_post::dsl::mod_feature_post;
|
use crate::schema::mod_feature_post::dsl::mod_feature_post;
|
||||||
diesel::update(mod_feature_post.find(from_id))
|
diesel::update(mod_feature_post.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,31 +141,31 @@ impl Crud for ModRemoveComment {
|
||||||
type InsertForm = ModRemoveCommentForm;
|
type InsertForm = ModRemoveCommentForm;
|
||||||
type UpdateForm = ModRemoveCommentForm;
|
type UpdateForm = ModRemoveCommentForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut conn: impl DbConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(mut conn: impl GetConn, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_remove_comment::dsl::mod_remove_comment;
|
use crate::schema::mod_remove_comment::dsl::mod_remove_comment;
|
||||||
mod_remove_comment
|
mod_remove_comment
|
||||||
.find(from_id)
|
.find(from_id)
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut conn: impl DbConn, form: &ModRemoveCommentForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl GetConn, form: &ModRemoveCommentForm) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_remove_comment::dsl::mod_remove_comment;
|
use crate::schema::mod_remove_comment::dsl::mod_remove_comment;
|
||||||
insert_into(mod_remove_comment)
|
insert_into(mod_remove_comment)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
from_id: i32,
|
from_id: i32,
|
||||||
form: &ModRemoveCommentForm,
|
form: &ModRemoveCommentForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_remove_comment::dsl::mod_remove_comment;
|
use crate::schema::mod_remove_comment::dsl::mod_remove_comment;
|
||||||
diesel::update(mod_remove_comment.find(from_id))
|
diesel::update(mod_remove_comment.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -175,31 +175,31 @@ impl Crud for ModRemoveCommunity {
|
||||||
type InsertForm = ModRemoveCommunityForm;
|
type InsertForm = ModRemoveCommunityForm;
|
||||||
type UpdateForm = ModRemoveCommunityForm;
|
type UpdateForm = ModRemoveCommunityForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut conn: impl DbConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(mut conn: impl GetConn, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_remove_community::dsl::mod_remove_community;
|
use crate::schema::mod_remove_community::dsl::mod_remove_community;
|
||||||
mod_remove_community
|
mod_remove_community
|
||||||
.find(from_id)
|
.find(from_id)
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut conn: impl DbConn, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl GetConn, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_remove_community::dsl::mod_remove_community;
|
use crate::schema::mod_remove_community::dsl::mod_remove_community;
|
||||||
insert_into(mod_remove_community)
|
insert_into(mod_remove_community)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
from_id: i32,
|
from_id: i32,
|
||||||
form: &ModRemoveCommunityForm,
|
form: &ModRemoveCommunityForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_remove_community::dsl::mod_remove_community;
|
use crate::schema::mod_remove_community::dsl::mod_remove_community;
|
||||||
diesel::update(mod_remove_community.find(from_id))
|
diesel::update(mod_remove_community.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,31 +209,31 @@ impl Crud for ModBanFromCommunity {
|
||||||
type InsertForm = ModBanFromCommunityForm;
|
type InsertForm = ModBanFromCommunityForm;
|
||||||
type UpdateForm = ModBanFromCommunityForm;
|
type UpdateForm = ModBanFromCommunityForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut conn: impl DbConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(mut conn: impl GetConn, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community;
|
use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community;
|
||||||
mod_ban_from_community
|
mod_ban_from_community
|
||||||
.find(from_id)
|
.find(from_id)
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut conn: impl DbConn, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl GetConn, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community;
|
use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community;
|
||||||
insert_into(mod_ban_from_community)
|
insert_into(mod_ban_from_community)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
from_id: i32,
|
from_id: i32,
|
||||||
form: &ModBanFromCommunityForm,
|
form: &ModBanFromCommunityForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community;
|
use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community;
|
||||||
diesel::update(mod_ban_from_community.find(from_id))
|
diesel::update(mod_ban_from_community.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -243,24 +243,24 @@ impl Crud for ModBan {
|
||||||
type InsertForm = ModBanForm;
|
type InsertForm = ModBanForm;
|
||||||
type UpdateForm = ModBanForm;
|
type UpdateForm = ModBanForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut conn: impl DbConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(mut conn: impl GetConn, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_ban::dsl::mod_ban;
|
use crate::schema::mod_ban::dsl::mod_ban;
|
||||||
mod_ban.find(from_id).first::<Self>(&mut *conn).await
|
mod_ban.find(from_id).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut conn: impl DbConn, form: &ModBanForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl GetConn, form: &ModBanForm) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_ban::dsl::mod_ban;
|
use crate::schema::mod_ban::dsl::mod_ban;
|
||||||
insert_into(mod_ban)
|
insert_into(mod_ban)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(mut conn: impl DbConn, from_id: i32, form: &ModBanForm) -> Result<Self, Error> {
|
async fn update(mut conn: impl GetConn, from_id: i32, form: &ModBanForm) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_ban::dsl::mod_ban;
|
use crate::schema::mod_ban::dsl::mod_ban;
|
||||||
diesel::update(mod_ban.find(from_id))
|
diesel::update(mod_ban.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -271,31 +271,31 @@ impl Crud for ModHideCommunity {
|
||||||
type UpdateForm = ModHideCommunityForm;
|
type UpdateForm = ModHideCommunityForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
|
|
||||||
async fn read(mut conn: impl DbConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(mut conn: impl GetConn, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_hide_community::dsl::mod_hide_community;
|
use crate::schema::mod_hide_community::dsl::mod_hide_community;
|
||||||
mod_hide_community
|
mod_hide_community
|
||||||
.find(from_id)
|
.find(from_id)
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut conn: impl DbConn, form: &ModHideCommunityForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl GetConn, form: &ModHideCommunityForm) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_hide_community::dsl::mod_hide_community;
|
use crate::schema::mod_hide_community::dsl::mod_hide_community;
|
||||||
insert_into(mod_hide_community)
|
insert_into(mod_hide_community)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
from_id: i32,
|
from_id: i32,
|
||||||
form: &ModHideCommunityForm,
|
form: &ModHideCommunityForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_hide_community::dsl::mod_hide_community;
|
use crate::schema::mod_hide_community::dsl::mod_hide_community;
|
||||||
diesel::update(mod_hide_community.find(from_id))
|
diesel::update(mod_hide_community.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -305,31 +305,31 @@ impl Crud for ModAddCommunity {
|
||||||
type InsertForm = ModAddCommunityForm;
|
type InsertForm = ModAddCommunityForm;
|
||||||
type UpdateForm = ModAddCommunityForm;
|
type UpdateForm = ModAddCommunityForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut conn: impl DbConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(mut conn: impl GetConn, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_add_community::dsl::mod_add_community;
|
use crate::schema::mod_add_community::dsl::mod_add_community;
|
||||||
mod_add_community
|
mod_add_community
|
||||||
.find(from_id)
|
.find(from_id)
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut conn: impl DbConn, form: &ModAddCommunityForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl GetConn, form: &ModAddCommunityForm) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_add_community::dsl::mod_add_community;
|
use crate::schema::mod_add_community::dsl::mod_add_community;
|
||||||
insert_into(mod_add_community)
|
insert_into(mod_add_community)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
from_id: i32,
|
from_id: i32,
|
||||||
form: &ModAddCommunityForm,
|
form: &ModAddCommunityForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_add_community::dsl::mod_add_community;
|
use crate::schema::mod_add_community::dsl::mod_add_community;
|
||||||
diesel::update(mod_add_community.find(from_id))
|
diesel::update(mod_add_community.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -339,31 +339,31 @@ impl Crud for ModTransferCommunity {
|
||||||
type InsertForm = ModTransferCommunityForm;
|
type InsertForm = ModTransferCommunityForm;
|
||||||
type UpdateForm = ModTransferCommunityForm;
|
type UpdateForm = ModTransferCommunityForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut conn: impl DbConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(mut conn: impl GetConn, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_transfer_community::dsl::mod_transfer_community;
|
use crate::schema::mod_transfer_community::dsl::mod_transfer_community;
|
||||||
mod_transfer_community
|
mod_transfer_community
|
||||||
.find(from_id)
|
.find(from_id)
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut conn: impl DbConn, form: &ModTransferCommunityForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl GetConn, form: &ModTransferCommunityForm) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_transfer_community::dsl::mod_transfer_community;
|
use crate::schema::mod_transfer_community::dsl::mod_transfer_community;
|
||||||
insert_into(mod_transfer_community)
|
insert_into(mod_transfer_community)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
from_id: i32,
|
from_id: i32,
|
||||||
form: &ModTransferCommunityForm,
|
form: &ModTransferCommunityForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_transfer_community::dsl::mod_transfer_community;
|
use crate::schema::mod_transfer_community::dsl::mod_transfer_community;
|
||||||
diesel::update(mod_transfer_community.find(from_id))
|
diesel::update(mod_transfer_community.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -373,24 +373,24 @@ impl Crud for ModAdd {
|
||||||
type InsertForm = ModAddForm;
|
type InsertForm = ModAddForm;
|
||||||
type UpdateForm = ModAddForm;
|
type UpdateForm = ModAddForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut conn: impl DbConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(mut conn: impl GetConn, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_add::dsl::mod_add;
|
use crate::schema::mod_add::dsl::mod_add;
|
||||||
mod_add.find(from_id).first::<Self>(&mut *conn).await
|
mod_add.find(from_id).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut conn: impl DbConn, form: &ModAddForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl GetConn, form: &ModAddForm) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_add::dsl::mod_add;
|
use crate::schema::mod_add::dsl::mod_add;
|
||||||
insert_into(mod_add)
|
insert_into(mod_add)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(mut conn: impl DbConn, from_id: i32, form: &ModAddForm) -> Result<Self, Error> {
|
async fn update(mut conn: impl GetConn, from_id: i32, form: &ModAddForm) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_add::dsl::mod_add;
|
use crate::schema::mod_add::dsl::mod_add;
|
||||||
diesel::update(mod_add.find(from_id))
|
diesel::update(mod_add.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -400,31 +400,31 @@ impl Crud for AdminPurgePerson {
|
||||||
type InsertForm = AdminPurgePersonForm;
|
type InsertForm = AdminPurgePersonForm;
|
||||||
type UpdateForm = AdminPurgePersonForm;
|
type UpdateForm = AdminPurgePersonForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut conn: impl DbConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(mut conn: impl GetConn, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::admin_purge_person::dsl::admin_purge_person;
|
use crate::schema::admin_purge_person::dsl::admin_purge_person;
|
||||||
admin_purge_person
|
admin_purge_person
|
||||||
.find(from_id)
|
.find(from_id)
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut conn: impl DbConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl GetConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
use crate::schema::admin_purge_person::dsl::admin_purge_person;
|
use crate::schema::admin_purge_person::dsl::admin_purge_person;
|
||||||
insert_into(admin_purge_person)
|
insert_into(admin_purge_person)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
from_id: i32,
|
from_id: i32,
|
||||||
form: &Self::InsertForm,
|
form: &Self::InsertForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use crate::schema::admin_purge_person::dsl::admin_purge_person;
|
use crate::schema::admin_purge_person::dsl::admin_purge_person;
|
||||||
diesel::update(admin_purge_person.find(from_id))
|
diesel::update(admin_purge_person.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -434,31 +434,31 @@ impl Crud for AdminPurgeCommunity {
|
||||||
type InsertForm = AdminPurgeCommunityForm;
|
type InsertForm = AdminPurgeCommunityForm;
|
||||||
type UpdateForm = AdminPurgeCommunityForm;
|
type UpdateForm = AdminPurgeCommunityForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut conn: impl DbConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(mut conn: impl GetConn, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::admin_purge_community::dsl::admin_purge_community;
|
use crate::schema::admin_purge_community::dsl::admin_purge_community;
|
||||||
admin_purge_community
|
admin_purge_community
|
||||||
.find(from_id)
|
.find(from_id)
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut conn: impl DbConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl GetConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
use crate::schema::admin_purge_community::dsl::admin_purge_community;
|
use crate::schema::admin_purge_community::dsl::admin_purge_community;
|
||||||
insert_into(admin_purge_community)
|
insert_into(admin_purge_community)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
from_id: i32,
|
from_id: i32,
|
||||||
form: &Self::InsertForm,
|
form: &Self::InsertForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use crate::schema::admin_purge_community::dsl::admin_purge_community;
|
use crate::schema::admin_purge_community::dsl::admin_purge_community;
|
||||||
diesel::update(admin_purge_community.find(from_id))
|
diesel::update(admin_purge_community.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -468,31 +468,31 @@ impl Crud for AdminPurgePost {
|
||||||
type InsertForm = AdminPurgePostForm;
|
type InsertForm = AdminPurgePostForm;
|
||||||
type UpdateForm = AdminPurgePostForm;
|
type UpdateForm = AdminPurgePostForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut conn: impl DbConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(mut conn: impl GetConn, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::admin_purge_post::dsl::admin_purge_post;
|
use crate::schema::admin_purge_post::dsl::admin_purge_post;
|
||||||
admin_purge_post
|
admin_purge_post
|
||||||
.find(from_id)
|
.find(from_id)
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut conn: impl DbConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl GetConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
use crate::schema::admin_purge_post::dsl::admin_purge_post;
|
use crate::schema::admin_purge_post::dsl::admin_purge_post;
|
||||||
insert_into(admin_purge_post)
|
insert_into(admin_purge_post)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
from_id: i32,
|
from_id: i32,
|
||||||
form: &Self::InsertForm,
|
form: &Self::InsertForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use crate::schema::admin_purge_post::dsl::admin_purge_post;
|
use crate::schema::admin_purge_post::dsl::admin_purge_post;
|
||||||
diesel::update(admin_purge_post.find(from_id))
|
diesel::update(admin_purge_post.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -502,31 +502,31 @@ impl Crud for AdminPurgeComment {
|
||||||
type InsertForm = AdminPurgeCommentForm;
|
type InsertForm = AdminPurgeCommentForm;
|
||||||
type UpdateForm = AdminPurgeCommentForm;
|
type UpdateForm = AdminPurgeCommentForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut conn: impl DbConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(mut conn: impl GetConn, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::admin_purge_comment::dsl::admin_purge_comment;
|
use crate::schema::admin_purge_comment::dsl::admin_purge_comment;
|
||||||
admin_purge_comment
|
admin_purge_comment
|
||||||
.find(from_id)
|
.find(from_id)
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut conn: impl DbConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl GetConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
use crate::schema::admin_purge_comment::dsl::admin_purge_comment;
|
use crate::schema::admin_purge_comment::dsl::admin_purge_comment;
|
||||||
insert_into(admin_purge_comment)
|
insert_into(admin_purge_comment)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
from_id: i32,
|
from_id: i32,
|
||||||
form: &Self::InsertForm,
|
form: &Self::InsertForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use crate::schema::admin_purge_comment::dsl::admin_purge_comment;
|
use crate::schema::admin_purge_comment::dsl::admin_purge_comment;
|
||||||
diesel::update(admin_purge_comment.find(from_id))
|
diesel::update(admin_purge_comment.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -571,7 +571,7 @@ mod tests {
|
||||||
async fn test_crud() {
|
async fn test_crud() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
let inserted_instance = Instance::read_or_create(&mut *conn, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(conn, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -581,7 +581,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_mod = Person::create(&mut *conn, &new_mod).await.unwrap();
|
let inserted_mod = Person::create(conn, &new_mod).await.unwrap();
|
||||||
|
|
||||||
let new_person = PersonInsertForm::builder()
|
let new_person = PersonInsertForm::builder()
|
||||||
.name("jim2".into())
|
.name("jim2".into())
|
||||||
|
@ -589,7 +589,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_person = Person::create(&mut *conn, &new_person).await.unwrap();
|
let inserted_person = Person::create(conn, &new_person).await.unwrap();
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::builder()
|
let new_community = CommunityInsertForm::builder()
|
||||||
.name("mod_community".to_string())
|
.name("mod_community".to_string())
|
||||||
|
@ -598,7 +598,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_community = Community::create(&mut *conn, &new_community).await.unwrap();
|
let inserted_community = Community::create(conn, &new_community).await.unwrap();
|
||||||
|
|
||||||
let new_post = PostInsertForm::builder()
|
let new_post = PostInsertForm::builder()
|
||||||
.name("A test post thweep".into())
|
.name("A test post thweep".into())
|
||||||
|
@ -606,7 +606,7 @@ mod tests {
|
||||||
.community_id(inserted_community.id)
|
.community_id(inserted_community.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_post = Post::create(&mut *conn, &new_post).await.unwrap();
|
let inserted_post = Post::create(conn, &new_post).await.unwrap();
|
||||||
|
|
||||||
let comment_form = CommentInsertForm::builder()
|
let comment_form = CommentInsertForm::builder()
|
||||||
.content("A test comment".into())
|
.content("A test comment".into())
|
||||||
|
@ -614,7 +614,7 @@ mod tests {
|
||||||
.post_id(inserted_post.id)
|
.post_id(inserted_post.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_comment = Comment::create(&mut *conn, &comment_form, None)
|
let inserted_comment = Comment::create(conn, &comment_form, None)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -627,10 +627,10 @@ mod tests {
|
||||||
reason: None,
|
reason: None,
|
||||||
removed: None,
|
removed: None,
|
||||||
};
|
};
|
||||||
let inserted_mod_remove_post = ModRemovePost::create(&mut *conn, &mod_remove_post_form)
|
let inserted_mod_remove_post = ModRemovePost::create(conn, &mod_remove_post_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let read_mod_remove_post = ModRemovePost::read(&mut *conn, inserted_mod_remove_post.id)
|
let read_mod_remove_post = ModRemovePost::read(conn, inserted_mod_remove_post.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let expected_mod_remove_post = ModRemovePost {
|
let expected_mod_remove_post = ModRemovePost {
|
||||||
|
@ -649,10 +649,10 @@ mod tests {
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
locked: None,
|
locked: None,
|
||||||
};
|
};
|
||||||
let inserted_mod_lock_post = ModLockPost::create(&mut *conn, &mod_lock_post_form)
|
let inserted_mod_lock_post = ModLockPost::create(conn, &mod_lock_post_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let read_mod_lock_post = ModLockPost::read(&mut *conn, inserted_mod_lock_post.id)
|
let read_mod_lock_post = ModLockPost::read(conn, inserted_mod_lock_post.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let expected_mod_lock_post = ModLockPost {
|
let expected_mod_lock_post = ModLockPost {
|
||||||
|
@ -671,10 +671,10 @@ mod tests {
|
||||||
featured: false,
|
featured: false,
|
||||||
is_featured_community: true,
|
is_featured_community: true,
|
||||||
};
|
};
|
||||||
let inserted_mod_feature_post = ModFeaturePost::create(&mut *conn, &mod_feature_post_form)
|
let inserted_mod_feature_post = ModFeaturePost::create(conn, &mod_feature_post_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let read_mod_feature_post = ModFeaturePost::read(&mut *conn, inserted_mod_feature_post.id)
|
let read_mod_feature_post = ModFeaturePost::read(conn, inserted_mod_feature_post.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let expected_mod_feature_post = ModFeaturePost {
|
let expected_mod_feature_post = ModFeaturePost {
|
||||||
|
@ -695,11 +695,11 @@ mod tests {
|
||||||
removed: None,
|
removed: None,
|
||||||
};
|
};
|
||||||
let inserted_mod_remove_comment =
|
let inserted_mod_remove_comment =
|
||||||
ModRemoveComment::create(&mut *conn, &mod_remove_comment_form)
|
ModRemoveComment::create(conn, &mod_remove_comment_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let read_mod_remove_comment =
|
let read_mod_remove_comment =
|
||||||
ModRemoveComment::read(&mut *conn, inserted_mod_remove_comment.id)
|
ModRemoveComment::read(conn, inserted_mod_remove_comment.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let expected_mod_remove_comment = ModRemoveComment {
|
let expected_mod_remove_comment = ModRemoveComment {
|
||||||
|
@ -721,11 +721,11 @@ mod tests {
|
||||||
expires: None,
|
expires: None,
|
||||||
};
|
};
|
||||||
let inserted_mod_remove_community =
|
let inserted_mod_remove_community =
|
||||||
ModRemoveCommunity::create(&mut *conn, &mod_remove_community_form)
|
ModRemoveCommunity::create(conn, &mod_remove_community_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let read_mod_remove_community =
|
let read_mod_remove_community =
|
||||||
ModRemoveCommunity::read(&mut *conn, inserted_mod_remove_community.id)
|
ModRemoveCommunity::read(conn, inserted_mod_remove_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let expected_mod_remove_community = ModRemoveCommunity {
|
let expected_mod_remove_community = ModRemoveCommunity {
|
||||||
|
@ -749,11 +749,11 @@ mod tests {
|
||||||
expires: None,
|
expires: None,
|
||||||
};
|
};
|
||||||
let inserted_mod_ban_from_community =
|
let inserted_mod_ban_from_community =
|
||||||
ModBanFromCommunity::create(&mut *conn, &mod_ban_from_community_form)
|
ModBanFromCommunity::create(conn, &mod_ban_from_community_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let read_mod_ban_from_community =
|
let read_mod_ban_from_community =
|
||||||
ModBanFromCommunity::read(&mut *conn, inserted_mod_ban_from_community.id)
|
ModBanFromCommunity::read(conn, inserted_mod_ban_from_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let expected_mod_ban_from_community = ModBanFromCommunity {
|
let expected_mod_ban_from_community = ModBanFromCommunity {
|
||||||
|
@ -776,8 +776,8 @@ mod tests {
|
||||||
banned: None,
|
banned: None,
|
||||||
expires: None,
|
expires: None,
|
||||||
};
|
};
|
||||||
let inserted_mod_ban = ModBan::create(&mut *conn, &mod_ban_form).await.unwrap();
|
let inserted_mod_ban = ModBan::create(conn, &mod_ban_form).await.unwrap();
|
||||||
let read_mod_ban = ModBan::read(&mut *conn, inserted_mod_ban.id).await.unwrap();
|
let read_mod_ban = ModBan::read(conn, inserted_mod_ban.id).await.unwrap();
|
||||||
let expected_mod_ban = ModBan {
|
let expected_mod_ban = ModBan {
|
||||||
id: inserted_mod_ban.id,
|
id: inserted_mod_ban.id,
|
||||||
mod_person_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
|
@ -796,10 +796,10 @@ mod tests {
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
};
|
};
|
||||||
let inserted_mod_add_community = ModAddCommunity::create(&mut *conn, &mod_add_community_form)
|
let inserted_mod_add_community = ModAddCommunity::create(conn, &mod_add_community_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let read_mod_add_community = ModAddCommunity::read(&mut *conn, inserted_mod_add_community.id)
|
let read_mod_add_community = ModAddCommunity::read(conn, inserted_mod_add_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let expected_mod_add_community = ModAddCommunity {
|
let expected_mod_add_community = ModAddCommunity {
|
||||||
|
@ -818,8 +818,8 @@ mod tests {
|
||||||
other_person_id: inserted_person.id,
|
other_person_id: inserted_person.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
};
|
};
|
||||||
let inserted_mod_add = ModAdd::create(&mut *conn, &mod_add_form).await.unwrap();
|
let inserted_mod_add = ModAdd::create(conn, &mod_add_form).await.unwrap();
|
||||||
let read_mod_add = ModAdd::read(&mut *conn, inserted_mod_add.id).await.unwrap();
|
let read_mod_add = ModAdd::read(conn, inserted_mod_add.id).await.unwrap();
|
||||||
let expected_mod_add = ModAdd {
|
let expected_mod_add = ModAdd {
|
||||||
id: inserted_mod_add.id,
|
id: inserted_mod_add.id,
|
||||||
mod_person_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
|
@ -828,18 +828,18 @@ mod tests {
|
||||||
when_: inserted_mod_add.when_,
|
when_: inserted_mod_add.when_,
|
||||||
};
|
};
|
||||||
|
|
||||||
Comment::delete(&mut *conn, inserted_comment.id)
|
Comment::delete(conn, inserted_comment.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Post::delete(&mut *conn, inserted_post.id).await.unwrap();
|
Post::delete(conn, inserted_post.id).await.unwrap();
|
||||||
Community::delete(&mut *conn, inserted_community.id)
|
Community::delete(conn, inserted_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Person::delete(&mut *conn, inserted_person.id)
|
Person::delete(conn, inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Person::delete(&mut *conn, inserted_mod.id).await.unwrap();
|
Person::delete(conn, inserted_mod.id).await.unwrap();
|
||||||
Instance::delete(&mut *conn, inserted_instance.id)
|
Instance::delete(conn, inserted_instance.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
source::password_reset_request::{PasswordResetRequest, PasswordResetRequestForm},
|
source::password_reset_request::{PasswordResetRequest, PasswordResetRequestForm},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::DbConn,
|
utils::GetConn,
|
||||||
};
|
};
|
||||||
use diesel::{
|
use diesel::{
|
||||||
dsl::{insert_into, now, IntervalDsl},
|
dsl::{insert_into, now, IntervalDsl},
|
||||||
|
@ -16,7 +16,7 @@ use diesel::{
|
||||||
ExpressionMethods,
|
ExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
|
@ -24,33 +24,33 @@ impl Crud for PasswordResetRequest {
|
||||||
type InsertForm = PasswordResetRequestForm;
|
type InsertForm = PasswordResetRequestForm;
|
||||||
type UpdateForm = PasswordResetRequestForm;
|
type UpdateForm = PasswordResetRequestForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut conn: impl DbConn, password_reset_request_id: i32) -> Result<Self, Error> {
|
async fn read(mut conn: impl GetConn, password_reset_request_id: i32) -> Result<Self, Error> {
|
||||||
password_reset_request
|
password_reset_request
|
||||||
.find(password_reset_request_id)
|
.find(password_reset_request_id)
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn create(mut conn: impl DbConn, form: &PasswordResetRequestForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl GetConn, form: &PasswordResetRequestForm) -> Result<Self, Error> {
|
||||||
insert_into(password_reset_request)
|
insert_into(password_reset_request)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
password_reset_request_id: i32,
|
password_reset_request_id: i32,
|
||||||
form: &PasswordResetRequestForm,
|
form: &PasswordResetRequestForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
diesel::update(password_reset_request.find(password_reset_request_id))
|
diesel::update(password_reset_request.find(password_reset_request_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PasswordResetRequest {
|
impl PasswordResetRequest {
|
||||||
pub async fn create_token(
|
pub async fn create_token(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
from_local_user_id: LocalUserId,
|
from_local_user_id: LocalUserId,
|
||||||
token: &str,
|
token: &str,
|
||||||
) -> Result<PasswordResetRequest, Error> {
|
) -> Result<PasswordResetRequest, Error> {
|
||||||
|
@ -63,10 +63,10 @@ impl PasswordResetRequest {
|
||||||
token_encrypted: token_hash,
|
token_encrypted: token_hash,
|
||||||
};
|
};
|
||||||
|
|
||||||
Self::create(&mut *conn, &form).await
|
Self::create(conn, &form).await
|
||||||
}
|
}
|
||||||
pub async fn read_from_token(
|
pub async fn read_from_token(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
token: &str,
|
token: &str,
|
||||||
) -> Result<PasswordResetRequest, Error> {
|
) -> Result<PasswordResetRequest, Error> {
|
||||||
let mut hasher = Sha256::new();
|
let mut hasher = Sha256::new();
|
||||||
|
@ -75,19 +75,19 @@ impl PasswordResetRequest {
|
||||||
password_reset_request
|
password_reset_request
|
||||||
.filter(token_encrypted.eq(token_hash))
|
.filter(token_encrypted.eq(token_hash))
|
||||||
.filter(published.gt(now - 1.days()))
|
.filter(published.gt(now - 1.days()))
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_recent_password_resets_count(
|
pub async fn get_recent_password_resets_count(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
user_id: LocalUserId,
|
user_id: LocalUserId,
|
||||||
) -> Result<i64, Error> {
|
) -> Result<i64, Error> {
|
||||||
password_reset_request
|
password_reset_request
|
||||||
.filter(local_user_id.eq(user_id))
|
.filter(local_user_id.eq(user_id))
|
||||||
.filter(published.gt(now - 1.days()))
|
.filter(published.gt(now - 1.days()))
|
||||||
.count()
|
.count()
|
||||||
.get_result(&mut *conn)
|
.get_result(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ mod tests {
|
||||||
async fn test_crud() {
|
async fn test_crud() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
let inserted_instance = Instance::read_or_create(&mut *conn, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(conn, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -129,14 +129,14 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_person = Person::create(&mut *conn, &new_person).await.unwrap();
|
let inserted_person = Person::create(conn, &new_person).await.unwrap();
|
||||||
|
|
||||||
let new_local_user = LocalUserInsertForm::builder()
|
let new_local_user = LocalUserInsertForm::builder()
|
||||||
.person_id(inserted_person.id)
|
.person_id(inserted_person.id)
|
||||||
.password_encrypted("pass".to_string())
|
.password_encrypted("pass".to_string())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_local_user = LocalUser::create(&mut *conn, &new_local_user)
|
let inserted_local_user = LocalUser::create(conn, &new_local_user)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ mod tests {
|
||||||
let token_encrypted_ = "ca3704aa0b06f5954c79ee837faa152d84d6b2d42838f0637a15eda8337dbdce";
|
let token_encrypted_ = "ca3704aa0b06f5954c79ee837faa152d84d6b2d42838f0637a15eda8337dbdce";
|
||||||
|
|
||||||
let inserted_password_reset_request =
|
let inserted_password_reset_request =
|
||||||
PasswordResetRequest::create_token(&mut *conn, inserted_local_user.id, token)
|
PasswordResetRequest::create_token(conn, inserted_local_user.id, token)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -155,13 +155,13 @@ mod tests {
|
||||||
published: inserted_password_reset_request.published,
|
published: inserted_password_reset_request.published,
|
||||||
};
|
};
|
||||||
|
|
||||||
let read_password_reset_request = PasswordResetRequest::read_from_token(&mut *conn, token)
|
let read_password_reset_request = PasswordResetRequest::read_from_token(conn, token)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let num_deleted = Person::delete(&mut *conn, inserted_person.id)
|
let num_deleted = Person::delete(conn, inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Instance::delete(&mut *conn, inserted_instance.id)
|
Instance::delete(conn, inserted_instance.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -9,42 +9,42 @@ use crate::{
|
||||||
PersonUpdateForm,
|
PersonUpdateForm,
|
||||||
},
|
},
|
||||||
traits::{ApubActor, Crud, Followable},
|
traits::{ApubActor, Crud, Followable},
|
||||||
utils::{functions::lower, naive_now, DbConn},
|
utils::{functions::lower, naive_now, GetConn},
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, JoinOnDsl, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, JoinOnDsl, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Crud for Person {
|
impl Crud for Person {
|
||||||
type InsertForm = PersonInsertForm;
|
type InsertForm = PersonInsertForm;
|
||||||
type UpdateForm = PersonUpdateForm;
|
type UpdateForm = PersonUpdateForm;
|
||||||
type IdType = PersonId;
|
type IdType = PersonId;
|
||||||
async fn read(mut conn: impl DbConn, person_id: PersonId) -> Result<Self, Error> {
|
async fn read(mut conn: impl GetConn, person_id: PersonId) -> Result<Self, Error> {
|
||||||
person::table
|
person::table
|
||||||
.filter(person::deleted.eq(false))
|
.filter(person::deleted.eq(false))
|
||||||
.find(person_id)
|
.find(person_id)
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn delete(mut conn: impl DbConn, person_id: PersonId) -> Result<usize, Error> {
|
async fn delete(mut conn: impl GetConn, person_id: PersonId) -> Result<usize, Error> {
|
||||||
diesel::delete(person::table.find(person_id))
|
diesel::delete(person::table.find(person_id))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn create(mut conn: impl DbConn, form: &PersonInsertForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl GetConn, form: &PersonInsertForm) -> Result<Self, Error> {
|
||||||
insert_into(person::table)
|
insert_into(person::table)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
person_id: PersonId,
|
person_id: PersonId,
|
||||||
form: &PersonUpdateForm,
|
form: &PersonUpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
diesel::update(person::table.find(person_id))
|
diesel::update(person::table.find(person_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,23 +53,26 @@ impl Person {
|
||||||
/// Update or insert the person.
|
/// Update or insert the person.
|
||||||
///
|
///
|
||||||
/// This is necessary for federation, because Activitypub doesnt distinguish between these actions.
|
/// This is necessary for federation, because Activitypub doesnt distinguish between these actions.
|
||||||
pub async fn upsert(mut conn: impl DbConn, form: &PersonInsertForm) -> Result<Self, Error> {
|
pub async fn upsert(mut conn: impl GetConn, form: &PersonInsertForm) -> Result<Self, Error> {
|
||||||
insert_into(person::table)
|
insert_into(person::table)
|
||||||
.values(form)
|
.values(form)
|
||||||
.on_conflict(person::actor_id)
|
.on_conflict(person::actor_id)
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
pub async fn delete_account(mut conn: impl DbConn, person_id: PersonId) -> Result<Person, Error> {
|
pub async fn delete_account(
|
||||||
|
mut conn: impl GetConn,
|
||||||
|
person_id: PersonId,
|
||||||
|
) -> Result<Person, Error> {
|
||||||
// Set the local user info to none
|
// Set the local user info to none
|
||||||
diesel::update(local_user::table.filter(local_user::person_id.eq(person_id)))
|
diesel::update(local_user::table.filter(local_user::person_id.eq(person_id)))
|
||||||
.set((
|
.set((
|
||||||
local_user::email.eq::<Option<String>>(None),
|
local_user::email.eq::<Option<String>>(None),
|
||||||
local_user::validator_time.eq(naive_now()),
|
local_user::validator_time.eq(naive_now()),
|
||||||
))
|
))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
diesel::update(person::table.find(person_id))
|
diesel::update(person::table.find(person_id))
|
||||||
|
@ -82,7 +85,7 @@ impl Person {
|
||||||
person::deleted.eq(true),
|
person::deleted.eq(true),
|
||||||
person::updated.eq(naive_now()),
|
person::updated.eq(naive_now()),
|
||||||
))
|
))
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,14 +101,14 @@ pub fn is_banned(banned_: bool, expires: Option<chrono::NaiveDateTime>) -> bool
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ApubActor for Person {
|
impl ApubActor for Person {
|
||||||
async fn read_from_apub_id(
|
async fn read_from_apub_id(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
object_id: &DbUrl,
|
object_id: &DbUrl,
|
||||||
) -> Result<Option<Self>, Error> {
|
) -> Result<Option<Self>, Error> {
|
||||||
Ok(
|
Ok(
|
||||||
person::table
|
person::table
|
||||||
.filter(person::deleted.eq(false))
|
.filter(person::deleted.eq(false))
|
||||||
.filter(person::actor_id.eq(object_id))
|
.filter(person::actor_id.eq(object_id))
|
||||||
.first::<Person>(&mut *conn)
|
.first::<Person>(conn)
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok()
|
||||||
.map(Into::into),
|
.map(Into::into),
|
||||||
|
@ -113,7 +116,7 @@ impl ApubActor for Person {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read_from_name(
|
async fn read_from_name(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
from_name: &str,
|
from_name: &str,
|
||||||
include_deleted: bool,
|
include_deleted: bool,
|
||||||
) -> Result<Person, Error> {
|
) -> Result<Person, Error> {
|
||||||
|
@ -124,11 +127,11 @@ impl ApubActor for Person {
|
||||||
if !include_deleted {
|
if !include_deleted {
|
||||||
q = q.filter(person::deleted.eq(false))
|
q = q.filter(person::deleted.eq(false))
|
||||||
}
|
}
|
||||||
q.first::<Self>(&mut *conn).await
|
q.first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read_from_name_and_domain(
|
async fn read_from_name_and_domain(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
person_name: &str,
|
person_name: &str,
|
||||||
for_domain: &str,
|
for_domain: &str,
|
||||||
) -> Result<Person, Error> {
|
) -> Result<Person, Error> {
|
||||||
|
@ -137,7 +140,7 @@ impl ApubActor for Person {
|
||||||
.filter(lower(person::name).eq(person_name.to_lowercase()))
|
.filter(lower(person::name).eq(person_name.to_lowercase()))
|
||||||
.filter(instance::domain.eq(for_domain))
|
.filter(instance::domain.eq(for_domain))
|
||||||
.select(person::all_columns)
|
.select(person::all_columns)
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,41 +148,41 @@ impl ApubActor for Person {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Followable for PersonFollower {
|
impl Followable for PersonFollower {
|
||||||
type Form = PersonFollowerForm;
|
type Form = PersonFollowerForm;
|
||||||
async fn follow(mut conn: impl DbConn, form: &PersonFollowerForm) -> Result<Self, Error> {
|
async fn follow(mut conn: impl GetConn, form: &PersonFollowerForm) -> Result<Self, Error> {
|
||||||
use crate::schema::person_follower::dsl::{follower_id, person_follower, person_id};
|
use crate::schema::person_follower::dsl::{follower_id, person_follower, person_id};
|
||||||
insert_into(person_follower)
|
insert_into(person_follower)
|
||||||
.values(form)
|
.values(form)
|
||||||
.on_conflict((follower_id, person_id))
|
.on_conflict((follower_id, person_id))
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn follow_accepted(_: impl DbConn, _: CommunityId, _: PersonId) -> Result<Self, Error> {
|
async fn follow_accepted(_: impl GetConn, _: CommunityId, _: PersonId) -> Result<Self, Error> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
async fn unfollow(mut conn: impl DbConn, form: &PersonFollowerForm) -> Result<usize, Error> {
|
async fn unfollow(mut conn: impl GetConn, form: &PersonFollowerForm) -> Result<usize, Error> {
|
||||||
use crate::schema::person_follower::dsl::{follower_id, person_follower, person_id};
|
use crate::schema::person_follower::dsl::{follower_id, person_follower, person_id};
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
person_follower
|
person_follower
|
||||||
.filter(follower_id.eq(&form.follower_id))
|
.filter(follower_id.eq(&form.follower_id))
|
||||||
.filter(person_id.eq(&form.person_id)),
|
.filter(person_id.eq(&form.person_id)),
|
||||||
)
|
)
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PersonFollower {
|
impl PersonFollower {
|
||||||
pub async fn list_followers(
|
pub async fn list_followers(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_person_id: PersonId,
|
for_person_id: PersonId,
|
||||||
) -> Result<Vec<Person>, Error> {
|
) -> Result<Vec<Person>, Error> {
|
||||||
person_follower::table
|
person_follower::table
|
||||||
.inner_join(person::table.on(person_follower::follower_id.eq(person::id)))
|
.inner_join(person::table.on(person_follower::follower_id.eq(person::id)))
|
||||||
.filter(person_follower::person_id.eq(for_person_id))
|
.filter(person_follower::person_id.eq(for_person_id))
|
||||||
.select(person::all_columns)
|
.select(person::all_columns)
|
||||||
.load(&mut *conn)
|
.load(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,7 +204,7 @@ mod tests {
|
||||||
async fn test_crud() {
|
async fn test_crud() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
let inserted_instance = Instance::read_or_create(&mut *conn, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(conn, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -211,7 +214,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_person = Person::create(&mut *conn, &new_person).await.unwrap();
|
let inserted_person = Person::create(conn, &new_person).await.unwrap();
|
||||||
|
|
||||||
let expected_person = Person {
|
let expected_person = Person {
|
||||||
id: inserted_person.id,
|
id: inserted_person.id,
|
||||||
|
@ -238,19 +241,19 @@ mod tests {
|
||||||
instance_id: inserted_instance.id,
|
instance_id: inserted_instance.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
let read_person = Person::read(&mut *conn, inserted_person.id).await.unwrap();
|
let read_person = Person::read(conn, inserted_person.id).await.unwrap();
|
||||||
|
|
||||||
let update_person_form = PersonUpdateForm::builder()
|
let update_person_form = PersonUpdateForm::builder()
|
||||||
.actor_id(Some(inserted_person.actor_id.clone()))
|
.actor_id(Some(inserted_person.actor_id.clone()))
|
||||||
.build();
|
.build();
|
||||||
let updated_person = Person::update(&mut *conn, inserted_person.id, &update_person_form)
|
let updated_person = Person::update(conn, inserted_person.id, &update_person_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let num_deleted = Person::delete(&mut *conn, inserted_person.id)
|
let num_deleted = Person::delete(conn, inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Instance::delete(&mut *conn, inserted_instance.id)
|
Instance::delete(conn, inserted_instance.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -264,7 +267,7 @@ mod tests {
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn follow() {
|
async fn follow() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
let inserted_instance = Instance::read_or_create(&mut *conn, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(conn, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -273,32 +276,32 @@ mod tests {
|
||||||
.public_key("pubkey".to_string())
|
.public_key("pubkey".to_string())
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
let person_1 = Person::create(&mut *conn, &person_form_1).await.unwrap();
|
let person_1 = Person::create(conn, &person_form_1).await.unwrap();
|
||||||
let person_form_2 = PersonInsertForm::builder()
|
let person_form_2 = PersonInsertForm::builder()
|
||||||
.name("michele".into())
|
.name("michele".into())
|
||||||
.public_key("pubkey".to_string())
|
.public_key("pubkey".to_string())
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
let person_2 = Person::create(&mut *conn, &person_form_2).await.unwrap();
|
let person_2 = Person::create(conn, &person_form_2).await.unwrap();
|
||||||
|
|
||||||
let follow_form = PersonFollowerForm {
|
let follow_form = PersonFollowerForm {
|
||||||
person_id: person_1.id,
|
person_id: person_1.id,
|
||||||
follower_id: person_2.id,
|
follower_id: person_2.id,
|
||||||
pending: false,
|
pending: false,
|
||||||
};
|
};
|
||||||
let person_follower = PersonFollower::follow(&mut *conn, &follow_form)
|
let person_follower = PersonFollower::follow(conn, &follow_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(person_1.id, person_follower.person_id);
|
assert_eq!(person_1.id, person_follower.person_id);
|
||||||
assert_eq!(person_2.id, person_follower.follower_id);
|
assert_eq!(person_2.id, person_follower.follower_id);
|
||||||
assert!(!person_follower.pending);
|
assert!(!person_follower.pending);
|
||||||
|
|
||||||
let followers = PersonFollower::list_followers(&mut *conn, person_1.id)
|
let followers = PersonFollower::list_followers(conn, person_1.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(vec![person_2], followers);
|
assert_eq!(vec![person_2], followers);
|
||||||
|
|
||||||
let unfollow = PersonFollower::unfollow(&mut *conn, &follow_form)
|
let unfollow = PersonFollower::unfollow(conn, &follow_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, unfollow);
|
assert_eq!(1, unfollow);
|
||||||
|
|
|
@ -3,21 +3,21 @@ use crate::{
|
||||||
schema::person_block::dsl::{person_block, person_id, target_id},
|
schema::person_block::dsl::{person_block, person_id, target_id},
|
||||||
source::person_block::{PersonBlock, PersonBlockForm},
|
source::person_block::{PersonBlock, PersonBlockForm},
|
||||||
traits::Blockable,
|
traits::Blockable,
|
||||||
utils::DbConn,
|
utils::GetConn,
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
impl PersonBlock {
|
impl PersonBlock {
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_person_id: PersonId,
|
for_person_id: PersonId,
|
||||||
for_recipient_id: PersonId,
|
for_recipient_id: PersonId,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
person_block
|
person_block
|
||||||
.filter(person_id.eq(for_person_id))
|
.filter(person_id.eq(for_person_id))
|
||||||
.filter(target_id.eq(for_recipient_id))
|
.filter(target_id.eq(for_recipient_id))
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ impl PersonBlock {
|
||||||
impl Blockable for PersonBlock {
|
impl Blockable for PersonBlock {
|
||||||
type Form = PersonBlockForm;
|
type Form = PersonBlockForm;
|
||||||
async fn block(
|
async fn block(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
person_block_form: &PersonBlockForm,
|
person_block_form: &PersonBlockForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
insert_into(person_block)
|
insert_into(person_block)
|
||||||
|
@ -34,16 +34,16 @@ impl Blockable for PersonBlock {
|
||||||
.on_conflict((person_id, target_id))
|
.on_conflict((person_id, target_id))
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(person_block_form)
|
.set(person_block_form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn unblock(mut conn: impl DbConn, person_block_form: &Self::Form) -> Result<usize, Error> {
|
async fn unblock(mut conn: impl GetConn, person_block_form: &Self::Form) -> Result<usize, Error> {
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
person_block
|
person_block
|
||||||
.filter(person_id.eq(person_block_form.person_id))
|
.filter(person_id.eq(person_block_form.person_id))
|
||||||
.filter(target_id.eq(person_block_form.target_id)),
|
.filter(target_id.eq(person_block_form.target_id)),
|
||||||
)
|
)
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,25 +3,25 @@ use crate::{
|
||||||
schema::person_mention::dsl::{comment_id, person_mention, read, recipient_id},
|
schema::person_mention::dsl::{comment_id, person_mention, read, recipient_id},
|
||||||
source::person_mention::{PersonMention, PersonMentionInsertForm, PersonMentionUpdateForm},
|
source::person_mention::{PersonMention, PersonMentionInsertForm, PersonMentionUpdateForm},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::DbConn,
|
utils::GetConn,
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Crud for PersonMention {
|
impl Crud for PersonMention {
|
||||||
type InsertForm = PersonMentionInsertForm;
|
type InsertForm = PersonMentionInsertForm;
|
||||||
type UpdateForm = PersonMentionUpdateForm;
|
type UpdateForm = PersonMentionUpdateForm;
|
||||||
type IdType = PersonMentionId;
|
type IdType = PersonMentionId;
|
||||||
async fn read(mut conn: impl DbConn, person_mention_id: PersonMentionId) -> Result<Self, Error> {
|
async fn read(mut conn: impl GetConn, person_mention_id: PersonMentionId) -> Result<Self, Error> {
|
||||||
person_mention
|
person_mention
|
||||||
.find(person_mention_id)
|
.find(person_mention_id)
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(
|
async fn create(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
person_mention_form: &Self::InsertForm,
|
person_mention_form: &Self::InsertForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
// since the return here isnt utilized, we dont need to do an update
|
// since the return here isnt utilized, we dont need to do an update
|
||||||
|
@ -31,25 +31,25 @@ impl Crud for PersonMention {
|
||||||
.on_conflict((recipient_id, comment_id))
|
.on_conflict((recipient_id, comment_id))
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(person_mention_form)
|
.set(person_mention_form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
person_mention_id: PersonMentionId,
|
person_mention_id: PersonMentionId,
|
||||||
person_mention_form: &Self::UpdateForm,
|
person_mention_form: &Self::UpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
diesel::update(person_mention.find(person_mention_id))
|
diesel::update(person_mention.find(person_mention_id))
|
||||||
.set(person_mention_form)
|
.set(person_mention_form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PersonMention {
|
impl PersonMention {
|
||||||
pub async fn mark_all_as_read(
|
pub async fn mark_all_as_read(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_recipient_id: PersonId,
|
for_recipient_id: PersonId,
|
||||||
) -> Result<Vec<PersonMention>, Error> {
|
) -> Result<Vec<PersonMention>, Error> {
|
||||||
diesel::update(
|
diesel::update(
|
||||||
|
@ -58,19 +58,19 @@ impl PersonMention {
|
||||||
.filter(read.eq(false)),
|
.filter(read.eq(false)),
|
||||||
)
|
)
|
||||||
.set(read.eq(true))
|
.set(read.eq(true))
|
||||||
.get_results::<Self>(&mut *conn)
|
.get_results::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read_by_comment_and_person(
|
pub async fn read_by_comment_and_person(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_comment_id: CommentId,
|
for_comment_id: CommentId,
|
||||||
for_recipient_id: PersonId,
|
for_recipient_id: PersonId,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
person_mention
|
person_mention
|
||||||
.filter(comment_id.eq(for_comment_id))
|
.filter(comment_id.eq(for_comment_id))
|
||||||
.filter(recipient_id.eq(for_recipient_id))
|
.filter(recipient_id.eq(for_recipient_id))
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ mod tests {
|
||||||
async fn test_crud() {
|
async fn test_crud() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
let inserted_instance = Instance::read_or_create(&mut *conn, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(conn, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_person = Person::create(&mut *conn, &new_person).await.unwrap();
|
let inserted_person = Person::create(conn, &new_person).await.unwrap();
|
||||||
|
|
||||||
let recipient_form = PersonInsertForm::builder()
|
let recipient_form = PersonInsertForm::builder()
|
||||||
.name("terrylakes recipient".into())
|
.name("terrylakes recipient".into())
|
||||||
|
@ -114,7 +114,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_recipient = Person::create(&mut *conn, &recipient_form).await.unwrap();
|
let inserted_recipient = Person::create(conn, &recipient_form).await.unwrap();
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::builder()
|
let new_community = CommunityInsertForm::builder()
|
||||||
.name("test community lake".to_string())
|
.name("test community lake".to_string())
|
||||||
|
@ -123,7 +123,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_community = Community::create(&mut *conn, &new_community).await.unwrap();
|
let inserted_community = Community::create(conn, &new_community).await.unwrap();
|
||||||
|
|
||||||
let new_post = PostInsertForm::builder()
|
let new_post = PostInsertForm::builder()
|
||||||
.name("A test post".into())
|
.name("A test post".into())
|
||||||
|
@ -131,7 +131,7 @@ mod tests {
|
||||||
.community_id(inserted_community.id)
|
.community_id(inserted_community.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_post = Post::create(&mut *conn, &new_post).await.unwrap();
|
let inserted_post = Post::create(conn, &new_post).await.unwrap();
|
||||||
|
|
||||||
let comment_form = CommentInsertForm::builder()
|
let comment_form = CommentInsertForm::builder()
|
||||||
.content("A test comment".into())
|
.content("A test comment".into())
|
||||||
|
@ -139,7 +139,7 @@ mod tests {
|
||||||
.post_id(inserted_post.id)
|
.post_id(inserted_post.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_comment = Comment::create(&mut *conn, &comment_form, None)
|
let inserted_comment = Comment::create(conn, &comment_form, None)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ mod tests {
|
||||||
read: None,
|
read: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_mention = PersonMention::create(&mut *conn, &person_mention_form)
|
let inserted_mention = PersonMention::create(conn, &person_mention_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -161,29 +161,29 @@ mod tests {
|
||||||
published: inserted_mention.published,
|
published: inserted_mention.published,
|
||||||
};
|
};
|
||||||
|
|
||||||
let read_mention = PersonMention::read(&mut *conn, inserted_mention.id)
|
let read_mention = PersonMention::read(conn, inserted_mention.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let person_mention_update_form = PersonMentionUpdateForm { read: Some(false) };
|
let person_mention_update_form = PersonMentionUpdateForm { read: Some(false) };
|
||||||
let updated_mention =
|
let updated_mention =
|
||||||
PersonMention::update(&mut *conn, inserted_mention.id, &person_mention_update_form)
|
PersonMention::update(conn, inserted_mention.id, &person_mention_update_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Comment::delete(&mut *conn, inserted_comment.id)
|
Comment::delete(conn, inserted_comment.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Post::delete(&mut *conn, inserted_post.id).await.unwrap();
|
Post::delete(conn, inserted_post.id).await.unwrap();
|
||||||
Community::delete(&mut *conn, inserted_community.id)
|
Community::delete(conn, inserted_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Person::delete(&mut *conn, inserted_person.id)
|
Person::delete(conn, inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Person::delete(&mut *conn, inserted_recipient.id)
|
Person::delete(conn, inserted_recipient.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Instance::delete(&mut *conn, inserted_instance.id)
|
Instance::delete(conn, inserted_instance.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -27,50 +27,50 @@ use crate::{
|
||||||
PostUpdateForm,
|
PostUpdateForm,
|
||||||
},
|
},
|
||||||
traits::{Crud, Likeable, Readable, Saveable},
|
traits::{Crud, Likeable, Readable, Saveable},
|
||||||
utils::{naive_now, DbConn, DELETED_REPLACEMENT_TEXT, FETCH_LIMIT_MAX},
|
utils::{naive_now, GetConn, DELETED_REPLACEMENT_TEXT, FETCH_LIMIT_MAX},
|
||||||
};
|
};
|
||||||
use ::url::Url;
|
use ::url::Url;
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl, TextExpressionMethods};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl, TextExpressionMethods};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Crud for Post {
|
impl Crud for Post {
|
||||||
type InsertForm = PostInsertForm;
|
type InsertForm = PostInsertForm;
|
||||||
type UpdateForm = PostUpdateForm;
|
type UpdateForm = PostUpdateForm;
|
||||||
type IdType = PostId;
|
type IdType = PostId;
|
||||||
async fn read(mut conn: impl DbConn, post_id: PostId) -> Result<Self, Error> {
|
async fn read(mut conn: impl GetConn, post_id: PostId) -> Result<Self, Error> {
|
||||||
post.find(post_id).first::<Self>(&mut *conn).await
|
post.find(post_id).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete(mut conn: impl DbConn, post_id: PostId) -> Result<usize, Error> {
|
async fn delete(mut conn: impl GetConn, post_id: PostId) -> Result<usize, Error> {
|
||||||
diesel::delete(post.find(post_id)).execute(&mut *conn).await
|
diesel::delete(post.find(post_id)).execute(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut conn: impl DbConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl GetConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
insert_into(post)
|
insert_into(post)
|
||||||
.values(form)
|
.values(form)
|
||||||
.on_conflict(ap_id)
|
.on_conflict(ap_id)
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
post_id: PostId,
|
post_id: PostId,
|
||||||
new_post: &Self::UpdateForm,
|
new_post: &Self::UpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
diesel::update(post.find(post_id))
|
diesel::update(post.find(post_id))
|
||||||
.set(new_post)
|
.set(new_post)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Post {
|
impl Post {
|
||||||
pub async fn list_for_community(
|
pub async fn list_for_community(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
the_community_id: CommunityId,
|
the_community_id: CommunityId,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
post
|
post
|
||||||
|
@ -80,12 +80,12 @@ impl Post {
|
||||||
.then_order_by(featured_community.desc())
|
.then_order_by(featured_community.desc())
|
||||||
.then_order_by(published.desc())
|
.then_order_by(published.desc())
|
||||||
.limit(FETCH_LIMIT_MAX)
|
.limit(FETCH_LIMIT_MAX)
|
||||||
.load::<Self>(&mut *conn)
|
.load::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list_featured_for_community(
|
pub async fn list_featured_for_community(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
the_community_id: CommunityId,
|
the_community_id: CommunityId,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
post
|
post
|
||||||
|
@ -95,12 +95,12 @@ impl Post {
|
||||||
.filter(featured_community.eq(true))
|
.filter(featured_community.eq(true))
|
||||||
.then_order_by(published.desc())
|
.then_order_by(published.desc())
|
||||||
.limit(FETCH_LIMIT_MAX)
|
.limit(FETCH_LIMIT_MAX)
|
||||||
.load::<Self>(&mut *conn)
|
.load::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn permadelete_for_creator(
|
pub async fn permadelete_for_creator(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_creator_id: PersonId,
|
for_creator_id: PersonId,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
diesel::update(post.filter(creator_id.eq(for_creator_id)))
|
diesel::update(post.filter(creator_id.eq(for_creator_id)))
|
||||||
|
@ -111,12 +111,12 @@ impl Post {
|
||||||
deleted.eq(true),
|
deleted.eq(true),
|
||||||
updated.eq(naive_now()),
|
updated.eq(naive_now()),
|
||||||
))
|
))
|
||||||
.get_results::<Self>(&mut *conn)
|
.get_results::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_removed_for_creator(
|
pub async fn update_removed_for_creator(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_creator_id: PersonId,
|
for_creator_id: PersonId,
|
||||||
for_community_id: Option<CommunityId>,
|
for_community_id: Option<CommunityId>,
|
||||||
new_removed: bool,
|
new_removed: bool,
|
||||||
|
@ -130,7 +130,7 @@ impl Post {
|
||||||
|
|
||||||
update
|
update
|
||||||
.set((removed.eq(new_removed), updated.eq(naive_now())))
|
.set((removed.eq(new_removed), updated.eq(naive_now())))
|
||||||
.get_results::<Self>(&mut *conn)
|
.get_results::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,14 +139,14 @@ impl Post {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read_from_apub_id(
|
pub async fn read_from_apub_id(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
object_id: Url,
|
object_id: Url,
|
||||||
) -> Result<Option<Self>, Error> {
|
) -> Result<Option<Self>, Error> {
|
||||||
let object_id: DbUrl = object_id.into();
|
let object_id: DbUrl = object_id.into();
|
||||||
Ok(
|
Ok(
|
||||||
post
|
post
|
||||||
.filter(ap_id.eq(object_id))
|
.filter(ap_id.eq(object_id))
|
||||||
.first::<Post>(&mut *conn)
|
.first::<Post>(conn)
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok()
|
||||||
.map(Into::into),
|
.map(Into::into),
|
||||||
|
@ -154,7 +154,7 @@ impl Post {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fetch_pictrs_posts_for_creator(
|
pub async fn fetch_pictrs_posts_for_creator(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_creator_id: PersonId,
|
for_creator_id: PersonId,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
let pictrs_search = "%pictrs/image%";
|
let pictrs_search = "%pictrs/image%";
|
||||||
|
@ -162,13 +162,13 @@ impl Post {
|
||||||
post
|
post
|
||||||
.filter(creator_id.eq(for_creator_id))
|
.filter(creator_id.eq(for_creator_id))
|
||||||
.filter(url.like(pictrs_search))
|
.filter(url.like(pictrs_search))
|
||||||
.load::<Self>(&mut *conn)
|
.load::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the url and thumbnails fields to None
|
/// Sets the url and thumbnails fields to None
|
||||||
pub async fn remove_pictrs_post_images_and_thumbnails_for_creator(
|
pub async fn remove_pictrs_post_images_and_thumbnails_for_creator(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_creator_id: PersonId,
|
for_creator_id: PersonId,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
let pictrs_search = "%pictrs/image%";
|
let pictrs_search = "%pictrs/image%";
|
||||||
|
@ -182,25 +182,25 @@ impl Post {
|
||||||
url.eq::<Option<String>>(None),
|
url.eq::<Option<String>>(None),
|
||||||
thumbnail_url.eq::<Option<String>>(None),
|
thumbnail_url.eq::<Option<String>>(None),
|
||||||
))
|
))
|
||||||
.get_results::<Self>(&mut *conn)
|
.get_results::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fetch_pictrs_posts_for_community(
|
pub async fn fetch_pictrs_posts_for_community(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_community_id: CommunityId,
|
for_community_id: CommunityId,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
let pictrs_search = "%pictrs/image%";
|
let pictrs_search = "%pictrs/image%";
|
||||||
post
|
post
|
||||||
.filter(community_id.eq(for_community_id))
|
.filter(community_id.eq(for_community_id))
|
||||||
.filter(url.like(pictrs_search))
|
.filter(url.like(pictrs_search))
|
||||||
.load::<Self>(&mut *conn)
|
.load::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the url and thumbnails fields to None
|
/// Sets the url and thumbnails fields to None
|
||||||
pub async fn remove_pictrs_post_images_and_thumbnails_for_community(
|
pub async fn remove_pictrs_post_images_and_thumbnails_for_community(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_community_id: CommunityId,
|
for_community_id: CommunityId,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
let pictrs_search = "%pictrs/image%";
|
let pictrs_search = "%pictrs/image%";
|
||||||
|
@ -214,7 +214,7 @@ impl Post {
|
||||||
url.eq::<Option<String>>(None),
|
url.eq::<Option<String>>(None),
|
||||||
thumbnail_url.eq::<Option<String>>(None),
|
thumbnail_url.eq::<Option<String>>(None),
|
||||||
))
|
))
|
||||||
.get_results::<Self>(&mut *conn)
|
.get_results::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,18 +223,18 @@ impl Post {
|
||||||
impl Likeable for PostLike {
|
impl Likeable for PostLike {
|
||||||
type Form = PostLikeForm;
|
type Form = PostLikeForm;
|
||||||
type IdType = PostId;
|
type IdType = PostId;
|
||||||
async fn like(mut conn: impl DbConn, post_like_form: &PostLikeForm) -> Result<Self, Error> {
|
async fn like(mut conn: impl GetConn, post_like_form: &PostLikeForm) -> Result<Self, Error> {
|
||||||
use crate::schema::post_like::dsl::{person_id, post_id, post_like};
|
use crate::schema::post_like::dsl::{person_id, post_id, post_like};
|
||||||
insert_into(post_like)
|
insert_into(post_like)
|
||||||
.values(post_like_form)
|
.values(post_like_form)
|
||||||
.on_conflict((post_id, person_id))
|
.on_conflict((post_id, person_id))
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(post_like_form)
|
.set(post_like_form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn remove(
|
async fn remove(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
person_id: PersonId,
|
person_id: PersonId,
|
||||||
post_id: PostId,
|
post_id: PostId,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
|
@ -244,7 +244,7 @@ impl Likeable for PostLike {
|
||||||
.filter(dsl::post_id.eq(post_id))
|
.filter(dsl::post_id.eq(post_id))
|
||||||
.filter(dsl::person_id.eq(person_id)),
|
.filter(dsl::person_id.eq(person_id)),
|
||||||
)
|
)
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -252,24 +252,24 @@ impl Likeable for PostLike {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Saveable for PostSaved {
|
impl Saveable for PostSaved {
|
||||||
type Form = PostSavedForm;
|
type Form = PostSavedForm;
|
||||||
async fn save(mut conn: impl DbConn, post_saved_form: &PostSavedForm) -> Result<Self, Error> {
|
async fn save(mut conn: impl GetConn, post_saved_form: &PostSavedForm) -> Result<Self, Error> {
|
||||||
use crate::schema::post_saved::dsl::{person_id, post_id, post_saved};
|
use crate::schema::post_saved::dsl::{person_id, post_id, post_saved};
|
||||||
insert_into(post_saved)
|
insert_into(post_saved)
|
||||||
.values(post_saved_form)
|
.values(post_saved_form)
|
||||||
.on_conflict((post_id, person_id))
|
.on_conflict((post_id, person_id))
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(post_saved_form)
|
.set(post_saved_form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn unsave(mut conn: impl DbConn, post_saved_form: &PostSavedForm) -> Result<usize, Error> {
|
async fn unsave(mut conn: impl GetConn, post_saved_form: &PostSavedForm) -> Result<usize, Error> {
|
||||||
use crate::schema::post_saved::dsl::{person_id, post_id, post_saved};
|
use crate::schema::post_saved::dsl::{person_id, post_id, post_saved};
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
post_saved
|
post_saved
|
||||||
.filter(post_id.eq(post_saved_form.post_id))
|
.filter(post_id.eq(post_saved_form.post_id))
|
||||||
.filter(person_id.eq(post_saved_form.person_id)),
|
.filter(person_id.eq(post_saved_form.person_id)),
|
||||||
)
|
)
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -278,7 +278,7 @@ impl Saveable for PostSaved {
|
||||||
impl Readable for PostRead {
|
impl Readable for PostRead {
|
||||||
type Form = PostReadForm;
|
type Form = PostReadForm;
|
||||||
async fn mark_as_read(
|
async fn mark_as_read(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
post_read_form: &PostReadForm,
|
post_read_form: &PostReadForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use crate::schema::post_read::dsl::{person_id, post_id, post_read};
|
use crate::schema::post_read::dsl::{person_id, post_id, post_read};
|
||||||
|
@ -287,12 +287,12 @@ impl Readable for PostRead {
|
||||||
.on_conflict((post_id, person_id))
|
.on_conflict((post_id, person_id))
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(post_read_form)
|
.set(post_read_form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn mark_as_unread(
|
async fn mark_as_unread(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
post_read_form: &PostReadForm,
|
post_read_form: &PostReadForm,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
use crate::schema::post_read::dsl::{person_id, post_id, post_read};
|
use crate::schema::post_read::dsl::{person_id, post_id, post_read};
|
||||||
|
@ -301,7 +301,7 @@ impl Readable for PostRead {
|
||||||
.filter(post_id.eq(post_read_form.post_id))
|
.filter(post_id.eq(post_read_form.post_id))
|
||||||
.filter(person_id.eq(post_read_form.person_id)),
|
.filter(person_id.eq(post_read_form.person_id)),
|
||||||
)
|
)
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -335,7 +335,7 @@ mod tests {
|
||||||
async fn test_crud() {
|
async fn test_crud() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
let inserted_instance = Instance::read_or_create(&mut *conn, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(conn, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -345,7 +345,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_person = Person::create(&mut *conn, &new_person).await.unwrap();
|
let inserted_person = Person::create(conn, &new_person).await.unwrap();
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::builder()
|
let new_community = CommunityInsertForm::builder()
|
||||||
.name("test community_3".to_string())
|
.name("test community_3".to_string())
|
||||||
|
@ -354,7 +354,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_community = Community::create(&mut *conn, &new_community).await.unwrap();
|
let inserted_community = Community::create(conn, &new_community).await.unwrap();
|
||||||
|
|
||||||
let new_post = PostInsertForm::builder()
|
let new_post = PostInsertForm::builder()
|
||||||
.name("A test post".into())
|
.name("A test post".into())
|
||||||
|
@ -362,7 +362,7 @@ mod tests {
|
||||||
.community_id(inserted_community.id)
|
.community_id(inserted_community.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_post = Post::create(&mut *conn, &new_post).await.unwrap();
|
let inserted_post = Post::create(conn, &new_post).await.unwrap();
|
||||||
|
|
||||||
let expected_post = Post {
|
let expected_post = Post {
|
||||||
id: inserted_post.id,
|
id: inserted_post.id,
|
||||||
|
@ -395,7 +395,7 @@ mod tests {
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_post_like = PostLike::like(&mut *conn, &post_like_form).await.unwrap();
|
let inserted_post_like = PostLike::like(conn, &post_like_form).await.unwrap();
|
||||||
|
|
||||||
let expected_post_like = PostLike {
|
let expected_post_like = PostLike {
|
||||||
id: inserted_post_like.id,
|
id: inserted_post_like.id,
|
||||||
|
@ -411,7 +411,7 @@ mod tests {
|
||||||
person_id: inserted_person.id,
|
person_id: inserted_person.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_post_saved = PostSaved::save(&mut *conn, &post_saved_form).await.unwrap();
|
let inserted_post_saved = PostSaved::save(conn, &post_saved_form).await.unwrap();
|
||||||
|
|
||||||
let expected_post_saved = PostSaved {
|
let expected_post_saved = PostSaved {
|
||||||
id: inserted_post_saved.id,
|
id: inserted_post_saved.id,
|
||||||
|
@ -426,7 +426,7 @@ mod tests {
|
||||||
person_id: inserted_person.id,
|
person_id: inserted_person.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_post_read = PostRead::mark_as_read(&mut *conn, &post_read_form)
|
let inserted_post_read = PostRead::mark_as_read(conn, &post_read_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -437,32 +437,32 @@ mod tests {
|
||||||
published: inserted_post_read.published,
|
published: inserted_post_read.published,
|
||||||
};
|
};
|
||||||
|
|
||||||
let read_post = Post::read(&mut *conn, inserted_post.id).await.unwrap();
|
let read_post = Post::read(conn, inserted_post.id).await.unwrap();
|
||||||
|
|
||||||
let new_post_update = PostUpdateForm::builder()
|
let new_post_update = PostUpdateForm::builder()
|
||||||
.name(Some("A test post".into()))
|
.name(Some("A test post".into()))
|
||||||
.build();
|
.build();
|
||||||
let updated_post = Post::update(&mut *conn, inserted_post.id, &new_post_update)
|
let updated_post = Post::update(conn, inserted_post.id, &new_post_update)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let like_removed = PostLike::remove(&mut *conn, inserted_person.id, inserted_post.id)
|
let like_removed = PostLike::remove(conn, inserted_person.id, inserted_post.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let saved_removed = PostSaved::unsave(&mut *conn, &post_saved_form)
|
let saved_removed = PostSaved::unsave(conn, &post_saved_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let read_removed = PostRead::mark_as_unread(&mut *conn, &post_read_form)
|
let read_removed = PostRead::mark_as_unread(conn, &post_read_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let num_deleted = Post::delete(&mut *conn, inserted_post.id).await.unwrap();
|
let num_deleted = Post::delete(conn, inserted_post.id).await.unwrap();
|
||||||
Community::delete(&mut *conn, inserted_community.id)
|
Community::delete(conn, inserted_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Person::delete(&mut *conn, inserted_person.id)
|
Person::delete(conn, inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Instance::delete(&mut *conn, inserted_instance.id)
|
Instance::delete(conn, inserted_instance.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::{
|
||||||
schema::post_report::dsl::{post_report, resolved, resolver_id, updated},
|
schema::post_report::dsl::{post_report, resolved, resolver_id, updated},
|
||||||
source::post_report::{PostReport, PostReportForm},
|
source::post_report::{PostReport, PostReportForm},
|
||||||
traits::Reportable,
|
traits::Reportable,
|
||||||
utils::{naive_now, DbConn},
|
utils::{naive_now, GetConn},
|
||||||
};
|
};
|
||||||
use diesel::{
|
use diesel::{
|
||||||
dsl::{insert_into, update},
|
dsl::{insert_into, update},
|
||||||
|
@ -11,22 +11,25 @@ use diesel::{
|
||||||
ExpressionMethods,
|
ExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Reportable for PostReport {
|
impl Reportable for PostReport {
|
||||||
type Form = PostReportForm;
|
type Form = PostReportForm;
|
||||||
type IdType = PostReportId;
|
type IdType = PostReportId;
|
||||||
|
|
||||||
async fn report(mut conn: impl DbConn, post_report_form: &PostReportForm) -> Result<Self, Error> {
|
async fn report(
|
||||||
|
mut conn: impl GetConn,
|
||||||
|
post_report_form: &PostReportForm,
|
||||||
|
) -> Result<Self, Error> {
|
||||||
insert_into(post_report)
|
insert_into(post_report)
|
||||||
.values(post_report_form)
|
.values(post_report_form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn resolve(
|
async fn resolve(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
report_id: Self::IdType,
|
report_id: Self::IdType,
|
||||||
by_resolver_id: PersonId,
|
by_resolver_id: PersonId,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
|
@ -36,12 +39,12 @@ impl Reportable for PostReport {
|
||||||
resolver_id.eq(by_resolver_id),
|
resolver_id.eq(by_resolver_id),
|
||||||
updated.eq(naive_now()),
|
updated.eq(naive_now()),
|
||||||
))
|
))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn unresolve(
|
async fn unresolve(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
report_id: Self::IdType,
|
report_id: Self::IdType,
|
||||||
by_resolver_id: PersonId,
|
by_resolver_id: PersonId,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
|
@ -51,7 +54,7 @@ impl Reportable for PostReport {
|
||||||
resolver_id.eq(by_resolver_id),
|
resolver_id.eq(by_resolver_id),
|
||||||
updated.eq(naive_now()),
|
updated.eq(naive_now()),
|
||||||
))
|
))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,10 @@ use crate::{
|
||||||
schema::private_message::dsl::{ap_id, private_message, read, recipient_id},
|
schema::private_message::dsl::{ap_id, private_message, read, recipient_id},
|
||||||
source::private_message::{PrivateMessage, PrivateMessageInsertForm, PrivateMessageUpdateForm},
|
source::private_message::{PrivateMessage, PrivateMessageInsertForm, PrivateMessageUpdateForm},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::DbConn,
|
utils::GetConn,
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
@ -16,45 +16,45 @@ impl Crud for PrivateMessage {
|
||||||
type UpdateForm = PrivateMessageUpdateForm;
|
type UpdateForm = PrivateMessageUpdateForm;
|
||||||
type IdType = PrivateMessageId;
|
type IdType = PrivateMessageId;
|
||||||
async fn read(
|
async fn read(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
private_message_id: PrivateMessageId,
|
private_message_id: PrivateMessageId,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
private_message
|
private_message
|
||||||
.find(private_message_id)
|
.find(private_message_id)
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut conn: impl DbConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl GetConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
insert_into(private_message)
|
insert_into(private_message)
|
||||||
.values(form)
|
.values(form)
|
||||||
.on_conflict(ap_id)
|
.on_conflict(ap_id)
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
private_message_id: PrivateMessageId,
|
private_message_id: PrivateMessageId,
|
||||||
form: &Self::UpdateForm,
|
form: &Self::UpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
diesel::update(private_message.find(private_message_id))
|
diesel::update(private_message.find(private_message_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn delete(mut conn: impl DbConn, pm_id: Self::IdType) -> Result<usize, Error> {
|
async fn delete(mut conn: impl GetConn, pm_id: Self::IdType) -> Result<usize, Error> {
|
||||||
diesel::delete(private_message.find(pm_id))
|
diesel::delete(private_message.find(pm_id))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PrivateMessage {
|
impl PrivateMessage {
|
||||||
pub async fn mark_all_as_read(
|
pub async fn mark_all_as_read(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_recipient_id: PersonId,
|
for_recipient_id: PersonId,
|
||||||
) -> Result<Vec<PrivateMessage>, Error> {
|
) -> Result<Vec<PrivateMessage>, Error> {
|
||||||
diesel::update(
|
diesel::update(
|
||||||
|
@ -63,19 +63,19 @@ impl PrivateMessage {
|
||||||
.filter(read.eq(false)),
|
.filter(read.eq(false)),
|
||||||
)
|
)
|
||||||
.set(read.eq(true))
|
.set(read.eq(true))
|
||||||
.get_results::<Self>(&mut *conn)
|
.get_results::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read_from_apub_id(
|
pub async fn read_from_apub_id(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
object_id: Url,
|
object_id: Url,
|
||||||
) -> Result<Option<Self>, LemmyError> {
|
) -> Result<Option<Self>, LemmyError> {
|
||||||
let object_id: DbUrl = object_id.into();
|
let object_id: DbUrl = object_id.into();
|
||||||
Ok(
|
Ok(
|
||||||
private_message
|
private_message
|
||||||
.filter(ap_id.eq(object_id))
|
.filter(ap_id.eq(object_id))
|
||||||
.first::<PrivateMessage>(&mut *conn)
|
.first::<PrivateMessage>(conn)
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok()
|
||||||
.map(Into::into),
|
.map(Into::into),
|
||||||
|
@ -101,7 +101,7 @@ mod tests {
|
||||||
async fn test_crud() {
|
async fn test_crud() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
let inserted_instance = Instance::read_or_create(&mut *conn, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(conn, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_creator = Person::create(&mut *conn, &creator_form).await.unwrap();
|
let inserted_creator = Person::create(conn, &creator_form).await.unwrap();
|
||||||
|
|
||||||
let recipient_form = PersonInsertForm::builder()
|
let recipient_form = PersonInsertForm::builder()
|
||||||
.name("recipient_pm".into())
|
.name("recipient_pm".into())
|
||||||
|
@ -119,7 +119,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_recipient = Person::create(&mut *conn, &recipient_form).await.unwrap();
|
let inserted_recipient = Person::create(conn, &recipient_form).await.unwrap();
|
||||||
|
|
||||||
let private_message_form = PrivateMessageInsertForm::builder()
|
let private_message_form = PrivateMessageInsertForm::builder()
|
||||||
.content("A test private message".into())
|
.content("A test private message".into())
|
||||||
|
@ -127,7 +127,7 @@ mod tests {
|
||||||
.recipient_id(inserted_recipient.id)
|
.recipient_id(inserted_recipient.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_private_message = PrivateMessage::create(&mut *conn, &private_message_form)
|
let inserted_private_message = PrivateMessage::create(conn, &private_message_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ mod tests {
|
||||||
local: true,
|
local: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
let read_private_message = PrivateMessage::read(&mut *conn, inserted_private_message.id)
|
let read_private_message = PrivateMessage::read(conn, inserted_private_message.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ mod tests {
|
||||||
.content(Some("A test private message".into()))
|
.content(Some("A test private message".into()))
|
||||||
.build();
|
.build();
|
||||||
let updated_private_message = PrivateMessage::update(
|
let updated_private_message = PrivateMessage::update(
|
||||||
&mut *conn,
|
conn,
|
||||||
inserted_private_message.id,
|
inserted_private_message.id,
|
||||||
&private_message_update_form,
|
&private_message_update_form,
|
||||||
)
|
)
|
||||||
|
@ -160,7 +160,7 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let deleted_private_message = PrivateMessage::update(
|
let deleted_private_message = PrivateMessage::update(
|
||||||
&mut *conn,
|
conn,
|
||||||
inserted_private_message.id,
|
inserted_private_message.id,
|
||||||
&PrivateMessageUpdateForm::builder()
|
&PrivateMessageUpdateForm::builder()
|
||||||
.deleted(Some(true))
|
.deleted(Some(true))
|
||||||
|
@ -169,19 +169,19 @@ mod tests {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let marked_read_private_message = PrivateMessage::update(
|
let marked_read_private_message = PrivateMessage::update(
|
||||||
&mut *conn,
|
conn,
|
||||||
inserted_private_message.id,
|
inserted_private_message.id,
|
||||||
&PrivateMessageUpdateForm::builder().read(Some(true)).build(),
|
&PrivateMessageUpdateForm::builder().read(Some(true)).build(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Person::delete(&mut *conn, inserted_creator.id)
|
Person::delete(conn, inserted_creator.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Person::delete(&mut *conn, inserted_recipient.id)
|
Person::delete(conn, inserted_recipient.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Instance::delete(&mut *conn, inserted_instance.id)
|
Instance::delete(conn, inserted_instance.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::{
|
||||||
schema::private_message_report::dsl::{private_message_report, resolved, resolver_id, updated},
|
schema::private_message_report::dsl::{private_message_report, resolved, resolver_id, updated},
|
||||||
source::private_message_report::{PrivateMessageReport, PrivateMessageReportForm},
|
source::private_message_report::{PrivateMessageReport, PrivateMessageReportForm},
|
||||||
traits::Reportable,
|
traits::Reportable,
|
||||||
utils::{naive_now, DbConn},
|
utils::{naive_now, GetConn},
|
||||||
};
|
};
|
||||||
use diesel::{
|
use diesel::{
|
||||||
dsl::{insert_into, update},
|
dsl::{insert_into, update},
|
||||||
|
@ -11,7 +11,7 @@ use diesel::{
|
||||||
ExpressionMethods,
|
ExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Reportable for PrivateMessageReport {
|
impl Reportable for PrivateMessageReport {
|
||||||
|
@ -19,17 +19,17 @@ impl Reportable for PrivateMessageReport {
|
||||||
type IdType = PrivateMessageReportId;
|
type IdType = PrivateMessageReportId;
|
||||||
|
|
||||||
async fn report(
|
async fn report(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
pm_report_form: &PrivateMessageReportForm,
|
pm_report_form: &PrivateMessageReportForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
insert_into(private_message_report)
|
insert_into(private_message_report)
|
||||||
.values(pm_report_form)
|
.values(pm_report_form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn resolve(
|
async fn resolve(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
report_id: Self::IdType,
|
report_id: Self::IdType,
|
||||||
by_resolver_id: PersonId,
|
by_resolver_id: PersonId,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
|
@ -39,12 +39,12 @@ impl Reportable for PrivateMessageReport {
|
||||||
resolver_id.eq(by_resolver_id),
|
resolver_id.eq(by_resolver_id),
|
||||||
updated.eq(naive_now()),
|
updated.eq(naive_now()),
|
||||||
))
|
))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn unresolve(
|
async fn unresolve(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
report_id: Self::IdType,
|
report_id: Self::IdType,
|
||||||
by_resolver_id: PersonId,
|
by_resolver_id: PersonId,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
|
@ -54,7 +54,7 @@ impl Reportable for PrivateMessageReport {
|
||||||
resolver_id.eq(by_resolver_id),
|
resolver_id.eq(by_resolver_id),
|
||||||
updated.eq(naive_now()),
|
updated.eq(naive_now()),
|
||||||
))
|
))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,10 @@ use crate::{
|
||||||
RegistrationApplicationUpdateForm,
|
RegistrationApplicationUpdateForm,
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::DbConn,
|
utils::GetConn,
|
||||||
};
|
};
|
||||||
use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Crud for RegistrationApplication {
|
impl Crud for RegistrationApplication {
|
||||||
|
@ -18,46 +18,46 @@ impl Crud for RegistrationApplication {
|
||||||
type UpdateForm = RegistrationApplicationUpdateForm;
|
type UpdateForm = RegistrationApplicationUpdateForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
|
|
||||||
async fn create(mut conn: impl DbConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl GetConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
insert_into(registration_application)
|
insert_into(registration_application)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read(mut conn: impl DbConn, id_: Self::IdType) -> Result<Self, Error> {
|
async fn read(mut conn: impl GetConn, id_: Self::IdType) -> Result<Self, Error> {
|
||||||
registration_application
|
registration_application
|
||||||
.find(id_)
|
.find(id_)
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
id_: Self::IdType,
|
id_: Self::IdType,
|
||||||
form: &Self::UpdateForm,
|
form: &Self::UpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
diesel::update(registration_application.find(id_))
|
diesel::update(registration_application.find(id_))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete(mut conn: impl DbConn, id_: Self::IdType) -> Result<usize, Error> {
|
async fn delete(mut conn: impl GetConn, id_: Self::IdType) -> Result<usize, Error> {
|
||||||
diesel::delete(registration_application.find(id_))
|
diesel::delete(registration_application.find(id_))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RegistrationApplication {
|
impl RegistrationApplication {
|
||||||
pub async fn find_by_local_user_id(
|
pub async fn find_by_local_user_id(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
local_user_id_: LocalUserId,
|
local_user_id_: LocalUserId,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
registration_application
|
registration_application
|
||||||
.filter(local_user_id.eq(local_user_id_))
|
.filter(local_user_id.eq(local_user_id_))
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
use crate::{schema::secret::dsl::secret, source::secret::Secret, utils::DbConn};
|
use crate::{schema::secret::dsl::secret, source::secret::Secret, utils::GetConn};
|
||||||
use diesel::result::Error;
|
use diesel::result::Error;
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
impl Secret {
|
impl Secret {
|
||||||
/// Initialize the Secrets from the DB.
|
/// Initialize the Secrets from the DB.
|
||||||
/// Warning: You should only call this once.
|
/// Warning: You should only call this once.
|
||||||
pub async fn init(mut conn: impl DbConn) -> Result<Secret, Error> {
|
pub async fn init(mut conn: impl GetConn) -> Result<Secret, Error> {
|
||||||
Self::read_secrets(&mut *conn).await
|
Self::read_secrets(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read_secrets(mut conn: impl DbConn) -> Result<Secret, Error> {
|
async fn read_secrets(mut conn: impl GetConn) -> Result<Secret, Error> {
|
||||||
secret.first::<Secret>(&mut *conn).await
|
secret.first::<Secret>(conn).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,10 @@ use crate::{
|
||||||
site::{Site, SiteInsertForm, SiteUpdateForm},
|
site::{Site, SiteInsertForm, SiteUpdateForm},
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::DbConn,
|
utils::GetConn,
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
|
@ -19,13 +19,13 @@ impl Crud for Site {
|
||||||
type IdType = SiteId;
|
type IdType = SiteId;
|
||||||
|
|
||||||
/// Use SiteView::read_local, or Site::read_from_apub_id instead
|
/// Use SiteView::read_local, or Site::read_from_apub_id instead
|
||||||
async fn read(_conn: impl DbConn, _site_id: SiteId) -> Result<Self, Error> {
|
async fn read(_conn: impl GetConn, _site_id: SiteId) -> Result<Self, Error> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut conn: impl DbConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl GetConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
let is_new_site = match &form.actor_id {
|
let is_new_site = match &form.actor_id {
|
||||||
Some(id_) => Site::read_from_apub_id(&mut *conn, id_).await?.is_none(),
|
Some(id_) => Site::read_from_apub_id(conn, id_).await?.is_none(),
|
||||||
None => true,
|
None => true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -35,42 +35,42 @@ impl Crud for Site {
|
||||||
.on_conflict(actor_id)
|
.on_conflict(actor_id)
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// initialize languages if site is newly created
|
// initialize languages if site is newly created
|
||||||
if is_new_site {
|
if is_new_site {
|
||||||
// initialize with all languages
|
// initialize with all languages
|
||||||
SiteLanguage::update(&mut *conn, vec![], &site_).await?;
|
SiteLanguage::update(conn, vec![], &site_).await?;
|
||||||
}
|
}
|
||||||
Ok(site_)
|
Ok(site_)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
site_id: SiteId,
|
site_id: SiteId,
|
||||||
new_site: &Self::UpdateForm,
|
new_site: &Self::UpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
diesel::update(site.find(site_id))
|
diesel::update(site.find(site_id))
|
||||||
.set(new_site)
|
.set(new_site)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete(mut conn: impl DbConn, site_id: SiteId) -> Result<usize, Error> {
|
async fn delete(mut conn: impl GetConn, site_id: SiteId) -> Result<usize, Error> {
|
||||||
diesel::delete(site.find(site_id)).execute(&mut *conn).await
|
diesel::delete(site.find(site_id)).execute(conn).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Site {
|
impl Site {
|
||||||
pub async fn read_from_apub_id(
|
pub async fn read_from_apub_id(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
object_id: &DbUrl,
|
object_id: &DbUrl,
|
||||||
) -> Result<Option<Self>, Error> {
|
) -> Result<Option<Self>, Error> {
|
||||||
Ok(
|
Ok(
|
||||||
site
|
site
|
||||||
.filter(actor_id.eq(object_id))
|
.filter(actor_id.eq(object_id))
|
||||||
.first::<Site>(&mut *conn)
|
.first::<Site>(conn)
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok()
|
||||||
.map(Into::into),
|
.map(Into::into),
|
||||||
|
@ -78,11 +78,11 @@ impl Site {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO this needs fixed
|
// TODO this needs fixed
|
||||||
pub async fn read_remote_sites(mut conn: impl DbConn) -> Result<Vec<Self>, Error> {
|
pub async fn read_remote_sites(mut conn: impl GetConn) -> Result<Vec<Self>, Error> {
|
||||||
site
|
site
|
||||||
.order_by(id)
|
.order_by(id)
|
||||||
.offset(1)
|
.offset(1)
|
||||||
.get_results::<Self>(&mut *conn)
|
.get_results::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,14 +2,14 @@ use crate::{
|
||||||
newtypes::LocalSiteId,
|
newtypes::LocalSiteId,
|
||||||
schema::tagline::dsl::{local_site_id, tagline},
|
schema::tagline::dsl::{local_site_id, tagline},
|
||||||
source::tagline::{Tagline, TaglineForm},
|
source::tagline::{Tagline, TaglineForm},
|
||||||
utils::DbConn,
|
utils::GetConn,
|
||||||
};
|
};
|
||||||
use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use lemmy_db_schema::utils::RunQueryDsl;
|
||||||
|
|
||||||
impl Tagline {
|
impl Tagline {
|
||||||
pub async fn replace(
|
pub async fn replace(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_local_site_id: LocalSiteId,
|
for_local_site_id: LocalSiteId,
|
||||||
list_content: Option<Vec<String>>,
|
list_content: Option<Vec<String>>,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
|
@ -18,7 +18,7 @@ impl Tagline {
|
||||||
.build_transaction()
|
.build_transaction()
|
||||||
.run(|conn| {
|
.run(|conn| {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
Self::clear(&mut *conn).await?;
|
Self::clear(conn).await?;
|
||||||
|
|
||||||
for item in list {
|
for item in list {
|
||||||
let form = TaglineForm {
|
let form = TaglineForm {
|
||||||
|
@ -28,35 +28,35 @@ impl Tagline {
|
||||||
};
|
};
|
||||||
insert_into(tagline)
|
insert_into(tagline)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
Self::get_all_conn(&mut *conn, for_local_site_id).await
|
Self::get_all_conn(conn, for_local_site_id).await
|
||||||
}) as _
|
}) as _
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
} else {
|
} else {
|
||||||
Self::get_all_conn(&mut *conn, for_local_site_id).await
|
Self::get_all_conn(conn, for_local_site_id).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn clear(mut conn: impl DbConn) -> Result<usize, Error> {
|
async fn clear(mut conn: impl GetConn) -> Result<usize, Error> {
|
||||||
diesel::delete(tagline).execute(&mut *conn).await
|
diesel::delete(tagline).execute(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_all_conn(
|
async fn get_all_conn(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_local_site_id: LocalSiteId,
|
for_local_site_id: LocalSiteId,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
tagline
|
tagline
|
||||||
.filter(local_site_id.eq(for_local_site_id))
|
.filter(local_site_id.eq(for_local_site_id))
|
||||||
.get_results::<Self>(&mut *conn)
|
.get_results::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
pub async fn get_all(
|
pub async fn get_all(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_local_site_id: LocalSiteId,
|
for_local_site_id: LocalSiteId,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
Self::get_all_conn(&mut *conn, for_local_site_id).await
|
Self::get_all_conn(conn, for_local_site_id).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
newtypes::{CommunityId, DbUrl, PersonId},
|
newtypes::{CommunityId, DbUrl, PersonId},
|
||||||
utils::DbConn,
|
utils::GetConn,
|
||||||
};
|
};
|
||||||
use diesel::result::Error;
|
use diesel::result::Error;
|
||||||
|
|
||||||
|
@ -9,21 +9,21 @@ pub trait Crud {
|
||||||
type InsertForm;
|
type InsertForm;
|
||||||
type UpdateForm;
|
type UpdateForm;
|
||||||
type IdType;
|
type IdType;
|
||||||
async fn create(mut conn: impl DbConn, form: &Self::InsertForm) -> Result<Self, Error>
|
async fn create(mut conn: impl GetConn, form: &Self::InsertForm) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn read(mut conn: impl DbConn, id: Self::IdType) -> Result<Self, Error>
|
async fn read(mut conn: impl GetConn, id: Self::IdType) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
/// when you want to null out a column, you have to send Some(None)), since sending None means you just don't want to update that column.
|
/// when you want to null out a column, you have to send Some(None)), since sending None means you just don't want to update that column.
|
||||||
async fn update(
|
async fn update(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
id: Self::IdType,
|
id: Self::IdType,
|
||||||
form: &Self::UpdateForm,
|
form: &Self::UpdateForm,
|
||||||
) -> Result<Self, Error>
|
) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn delete(_conn: impl DbConn, _id: Self::IdType) -> Result<usize, Error>
|
async fn delete(_conn: impl GetConn, _id: Self::IdType) -> Result<usize, Error>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
Self::IdType: Send,
|
Self::IdType: Send,
|
||||||
|
@ -35,17 +35,17 @@ pub trait Crud {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Followable {
|
pub trait Followable {
|
||||||
type Form;
|
type Form;
|
||||||
async fn follow(mut conn: impl DbConn, form: &Self::Form) -> Result<Self, Error>
|
async fn follow(mut conn: impl GetConn, form: &Self::Form) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn follow_accepted(
|
async fn follow_accepted(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
person_id: PersonId,
|
person_id: PersonId,
|
||||||
) -> Result<Self, Error>
|
) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn unfollow(mut conn: impl DbConn, form: &Self::Form) -> Result<usize, Error>
|
async fn unfollow(mut conn: impl GetConn, form: &Self::Form) -> Result<usize, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
}
|
}
|
||||||
|
@ -53,10 +53,10 @@ pub trait Followable {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Joinable {
|
pub trait Joinable {
|
||||||
type Form;
|
type Form;
|
||||||
async fn join(mut conn: impl DbConn, form: &Self::Form) -> Result<Self, Error>
|
async fn join(mut conn: impl GetConn, form: &Self::Form) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn leave(mut conn: impl DbConn, form: &Self::Form) -> Result<usize, Error>
|
async fn leave(mut conn: impl GetConn, form: &Self::Form) -> Result<usize, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
}
|
}
|
||||||
|
@ -65,11 +65,11 @@ pub trait Joinable {
|
||||||
pub trait Likeable {
|
pub trait Likeable {
|
||||||
type Form;
|
type Form;
|
||||||
type IdType;
|
type IdType;
|
||||||
async fn like(mut conn: impl DbConn, form: &Self::Form) -> Result<Self, Error>
|
async fn like(mut conn: impl GetConn, form: &Self::Form) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn remove(
|
async fn remove(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
person_id: PersonId,
|
person_id: PersonId,
|
||||||
item_id: Self::IdType,
|
item_id: Self::IdType,
|
||||||
) -> Result<usize, Error>
|
) -> Result<usize, Error>
|
||||||
|
@ -80,10 +80,10 @@ pub trait Likeable {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Bannable {
|
pub trait Bannable {
|
||||||
type Form;
|
type Form;
|
||||||
async fn ban(mut conn: impl DbConn, form: &Self::Form) -> Result<Self, Error>
|
async fn ban(mut conn: impl GetConn, form: &Self::Form) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn unban(mut conn: impl DbConn, form: &Self::Form) -> Result<usize, Error>
|
async fn unban(mut conn: impl GetConn, form: &Self::Form) -> Result<usize, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
}
|
}
|
||||||
|
@ -91,10 +91,10 @@ pub trait Bannable {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Saveable {
|
pub trait Saveable {
|
||||||
type Form;
|
type Form;
|
||||||
async fn save(mut conn: impl DbConn, form: &Self::Form) -> Result<Self, Error>
|
async fn save(mut conn: impl GetConn, form: &Self::Form) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn unsave(mut conn: impl DbConn, form: &Self::Form) -> Result<usize, Error>
|
async fn unsave(mut conn: impl GetConn, form: &Self::Form) -> Result<usize, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
}
|
}
|
||||||
|
@ -102,10 +102,10 @@ pub trait Saveable {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Blockable {
|
pub trait Blockable {
|
||||||
type Form;
|
type Form;
|
||||||
async fn block(mut conn: impl DbConn, form: &Self::Form) -> Result<Self, Error>
|
async fn block(mut conn: impl GetConn, form: &Self::Form) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn unblock(mut conn: impl DbConn, form: &Self::Form) -> Result<usize, Error>
|
async fn unblock(mut conn: impl GetConn, form: &Self::Form) -> Result<usize, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
}
|
}
|
||||||
|
@ -113,10 +113,10 @@ pub trait Blockable {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Readable {
|
pub trait Readable {
|
||||||
type Form;
|
type Form;
|
||||||
async fn mark_as_read(mut conn: impl DbConn, form: &Self::Form) -> Result<Self, Error>
|
async fn mark_as_read(mut conn: impl GetConn, form: &Self::Form) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn mark_as_unread(mut conn: impl DbConn, form: &Self::Form) -> Result<usize, Error>
|
async fn mark_as_unread(mut conn: impl GetConn, form: &Self::Form) -> Result<usize, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
}
|
}
|
||||||
|
@ -125,18 +125,18 @@ pub trait Readable {
|
||||||
pub trait Reportable {
|
pub trait Reportable {
|
||||||
type Form;
|
type Form;
|
||||||
type IdType;
|
type IdType;
|
||||||
async fn report(mut conn: impl DbConn, form: &Self::Form) -> Result<Self, Error>
|
async fn report(mut conn: impl GetConn, form: &Self::Form) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn resolve(
|
async fn resolve(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
report_id: Self::IdType,
|
report_id: Self::IdType,
|
||||||
resolver_id: PersonId,
|
resolver_id: PersonId,
|
||||||
) -> Result<usize, Error>
|
) -> Result<usize, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn unresolve(
|
async fn unresolve(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
report_id: Self::IdType,
|
report_id: Self::IdType,
|
||||||
resolver_id: PersonId,
|
resolver_id: PersonId,
|
||||||
) -> Result<usize, Error>
|
) -> Result<usize, Error>
|
||||||
|
@ -154,7 +154,7 @@ pub trait JoinView {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait ApubActor {
|
pub trait ApubActor {
|
||||||
async fn read_from_apub_id(
|
async fn read_from_apub_id(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
object_id: &DbUrl,
|
object_id: &DbUrl,
|
||||||
) -> Result<Option<Self>, Error>
|
) -> Result<Option<Self>, Error>
|
||||||
where
|
where
|
||||||
|
@ -162,14 +162,14 @@ pub trait ApubActor {
|
||||||
/// - actor_name is the name of the community or user to read.
|
/// - actor_name is the name of the community or user to read.
|
||||||
/// - include_deleted, if true, will return communities or users that were deleted/removed
|
/// - include_deleted, if true, will return communities or users that were deleted/removed
|
||||||
async fn read_from_name(
|
async fn read_from_name(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
actor_name: &str,
|
actor_name: &str,
|
||||||
include_deleted: bool,
|
include_deleted: bool,
|
||||||
) -> Result<Self, Error>
|
) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn read_from_name_and_domain(
|
async fn read_from_name_and_domain(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
actor_name: &str,
|
actor_name: &str,
|
||||||
protocol_domain: &str,
|
protocol_domain: &str,
|
||||||
) -> Result<Self, Error>
|
) -> Result<Self, Error>
|
||||||
|
|
|
@ -23,6 +23,7 @@ use diesel_async::{
|
||||||
deadpool::{Object as PooledConnection, Pool},
|
deadpool::{Object as PooledConnection, Pool},
|
||||||
AsyncDieselConnectionManager,
|
AsyncDieselConnectionManager,
|
||||||
},
|
},
|
||||||
|
scoped_futures::ScopedBoxFuture,
|
||||||
};
|
};
|
||||||
use diesel_migrations::EmbeddedMigrations;
|
use diesel_migrations::EmbeddedMigrations;
|
||||||
use futures_util::{future::BoxFuture, FutureExt};
|
use futures_util::{future::BoxFuture, FutureExt};
|
||||||
|
@ -49,8 +50,93 @@ const POOL_TIMEOUT: Option<Duration> = Some(Duration::from_secs(5));
|
||||||
pub type DbPool = Pool<AsyncPgConnection>;
|
pub type DbPool = Pool<AsyncPgConnection>;
|
||||||
pub type DbPooledConn = PooledConnection<AsyncPgConnection>;
|
pub type DbPooledConn = PooledConnection<AsyncPgConnection>;
|
||||||
|
|
||||||
pub trait DbConn: std::ops::DerefMut<Target = AsyncPgConnection> + Send {}
|
#[async_trait]
|
||||||
impl<T: std::ops::DerefMut<Target = AsyncPgConnection> + Send> DbConn for T {}
|
pub trait GetConn {
|
||||||
|
type Conn: std::ops::DerefMut<Target = AsyncPgConnection> + Send;
|
||||||
|
|
||||||
|
async fn conn(self) -> Result<Self::Conn, DieselError>;
|
||||||
|
|
||||||
|
async fn transaction<'a, R, E, F>(&mut self, callback: F) -> Result<R, E>
|
||||||
|
where
|
||||||
|
F: for<'r> FnOnce(&'r mut Self::Conn) -> ScopedBoxFuture<'a, 'r, Result<R, E>> + Send + 'a,
|
||||||
|
E: From<diesel::result::Error> + Send + 'a,
|
||||||
|
R: Send + 'a,
|
||||||
|
{
|
||||||
|
let conn = self.conn().await?;
|
||||||
|
conn.transaction(callback).await?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl<'a> GetConn for &'a mut AsyncPgConnection {
|
||||||
|
type Conn = Self;
|
||||||
|
|
||||||
|
async fn conn(self) -> Result<Self::Conn, DieselError> {
|
||||||
|
Ok(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl<'a> GetConn for &'a DbPool {
|
||||||
|
type Conn = PooledConnection<AsyncPgConnection>;
|
||||||
|
|
||||||
|
async fn conn(self) -> Result<Self::Conn, DieselError> {
|
||||||
|
get_conn(self).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
pub trait RunQueryDsl<Conn: GetConn>: diesel_async::RunQueryDsl<Conn::Conn> {
|
||||||
|
async fn execute<'conn, 'query>(self, conn: Conn) -> Result<usize, DieselError>
|
||||||
|
where
|
||||||
|
Self: diesel_async::methods::ExecuteDsl<Conn::Conn> + 'query,
|
||||||
|
{
|
||||||
|
Ok(diesel_async::RunQueryDsl::execute(self, &mut conn.conn().await?).await?)
|
||||||
|
}
|
||||||
|
async fn load<'query, 'conn, U>(self, conn: Conn) -> Result<Vec<U>, DieselError>
|
||||||
|
where
|
||||||
|
U: Send,
|
||||||
|
Self: diesel_async::methods::LoadQuery<'query, Conn::Conn, U> + 'query,
|
||||||
|
{
|
||||||
|
Ok(diesel_async::RunQueryDsl::load(self, &mut conn.conn().await?).await?)
|
||||||
|
}
|
||||||
|
/* unsued
|
||||||
|
async fn load_stream<'conn, 'query, U>(
|
||||||
|
self,
|
||||||
|
conn: Conn,
|
||||||
|
) -> <Self::LoadFuture<'conn> as Future>::Output
|
||||||
|
where
|
||||||
|
U: 'conn,
|
||||||
|
Self: diesel_async::methods::LoadQuery<'query, Conn::Conn, U> + 'query,
|
||||||
|
{
|
||||||
|
Ok(diesel_async::RunQueryDsl::load_stream(self, &mut conn.conn().await?).await?)
|
||||||
|
}*/
|
||||||
|
async fn get_result<'query, 'conn, U>(self, conn: Conn) -> Result<U, DieselError>
|
||||||
|
where
|
||||||
|
U: Send + 'conn,
|
||||||
|
Self: diesel_async::methods::LoadQuery<'query, Conn::Conn, U> + 'query,
|
||||||
|
{
|
||||||
|
Ok(diesel_async::RunQueryDsl::get_result(self, &mut conn.conn().await?).await?)
|
||||||
|
}
|
||||||
|
async fn get_results<'query, 'conn, U>(self, conn: Conn) -> Result<Vec<U>, DieselError>
|
||||||
|
where
|
||||||
|
U: Send,
|
||||||
|
Self: diesel_async::methods::LoadQuery<'query, Conn::Conn, U> + 'query,
|
||||||
|
{
|
||||||
|
Ok(diesel_async::RunQueryDsl::get_results(self, &mut conn.conn().await?).await?)
|
||||||
|
}
|
||||||
|
async fn first<'query, 'conn, U>(self, conn: Conn) -> Result<U, DieselError>
|
||||||
|
where
|
||||||
|
U: Send + 'conn,
|
||||||
|
Self: diesel::query_dsl::methods::LimitDsl,
|
||||||
|
diesel::helper_types::Limit<Self>:
|
||||||
|
diesel_async::methods::LoadQuery<'query, Conn::Conn, U> + Send + 'query,
|
||||||
|
{
|
||||||
|
Ok(diesel_async::RunQueryDsl::execute(self, &mut conn.conn().await?).await?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Conn: GetConn, T> RunQueryDsl<Conn> for T where T: diesel_async::RunQueryDsl<Conn::Conn> {}
|
||||||
|
|
||||||
pub async fn get_conn(pool: &DbPool) -> Result<PooledConnection<AsyncPgConnection>, DieselError> {
|
pub async fn get_conn(pool: &DbPool) -> Result<PooledConnection<AsyncPgConnection>, DieselError> {
|
||||||
pool.get().await.map_err(|e| QueryBuilderError(e.into()))
|
pool.get().await.map_err(|e| QueryBuilderError(e.into()))
|
||||||
|
@ -220,7 +306,7 @@ pub fn run_migrations(db_url: &str) {
|
||||||
let mut conn =
|
let mut conn =
|
||||||
PgConnection::establish(db_url).unwrap_or_else(|e| panic!("Error connecting to {db_url}: {e}"));
|
PgConnection::establish(db_url).unwrap_or_else(|e| panic!("Error connecting to {db_url}: {e}"));
|
||||||
info!("Running Database migrations (This may take a long time)...");
|
info!("Running Database migrations (This may take a long time)...");
|
||||||
let _ = &mut *conn
|
let _ = conn
|
||||||
.run_pending_migrations(MIGRATIONS)
|
.run_pending_migrations(MIGRATIONS)
|
||||||
.unwrap_or_else(|e| panic!("Couldn't run DB Migrations: {e}"));
|
.unwrap_or_else(|e| panic!("Couldn't run DB Migrations: {e}"));
|
||||||
info!("Database migrations complete.");
|
info!("Database migrations complete.");
|
||||||
|
|
|
@ -8,7 +8,6 @@ use diesel::{
|
||||||
NullableExpressionMethods,
|
NullableExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
aggregates::structs::CommentAggregates,
|
aggregates::structs::CommentAggregates,
|
||||||
newtypes::{CommentReportId, CommunityId, PersonId},
|
newtypes::{CommentReportId, CommunityId, PersonId},
|
||||||
|
@ -31,7 +30,7 @@ use lemmy_db_schema::{
|
||||||
post::Post,
|
post::Post,
|
||||||
},
|
},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbConn},
|
utils::{limit_and_offset, GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
use typed_builder::TypedBuilder;
|
use typed_builder::TypedBuilder;
|
||||||
|
|
||||||
|
@ -40,7 +39,7 @@ impl CommentReportView {
|
||||||
///
|
///
|
||||||
/// * `report_id` - the report id to obtain
|
/// * `report_id` - the report id to obtain
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
report_id: CommentReportId,
|
report_id: CommentReportId,
|
||||||
my_person_id: PersonId,
|
my_person_id: PersonId,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
|
@ -86,7 +85,7 @@ impl CommentReportView {
|
||||||
comment_like::score.nullable(),
|
comment_like::score.nullable(),
|
||||||
person_alias_2.fields(person::all_columns).nullable(),
|
person_alias_2.fields(person::all_columns).nullable(),
|
||||||
))
|
))
|
||||||
.first::<<CommentReportView as JoinView>::JoinTuple>(&mut *conn)
|
.first::<<CommentReportView as JoinView>::JoinTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(Self::from_tuple(res))
|
Ok(Self::from_tuple(res))
|
||||||
|
@ -94,7 +93,7 @@ impl CommentReportView {
|
||||||
|
|
||||||
/// Returns the current unresolved post report count for the communities you mod
|
/// Returns the current unresolved post report count for the communities you mod
|
||||||
pub async fn get_report_count(
|
pub async fn get_report_count(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
my_person_id: PersonId,
|
my_person_id: PersonId,
|
||||||
admin: bool,
|
admin: bool,
|
||||||
community_id: Option<CommunityId>,
|
community_id: Option<CommunityId>,
|
||||||
|
@ -122,12 +121,12 @@ impl CommentReportView {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.select(count(comment_report::id))
|
.select(count(comment_report::id))
|
||||||
.first::<i64>(&mut *conn)
|
.first::<i64>(conn)
|
||||||
.await
|
.await
|
||||||
} else {
|
} else {
|
||||||
query
|
query
|
||||||
.select(count(comment_report::id))
|
.select(count(comment_report::id))
|
||||||
.first::<i64>(&mut *conn)
|
.first::<i64>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,7 +147,7 @@ pub struct CommentReportQuery<Conn> {
|
||||||
unresolved_only: Option<bool>,
|
unresolved_only: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Conn: DbConn> CommentReportQuery<Conn> {
|
impl<Conn: GetConn> CommentReportQuery<Conn> {
|
||||||
pub async fn list(self) -> Result<Vec<CommentReportView>, Error> {
|
pub async fn list(self) -> Result<Vec<CommentReportView>, Error> {
|
||||||
let mut conn = self.conn;
|
let mut conn = self.conn;
|
||||||
|
|
||||||
|
@ -225,11 +224,11 @@ impl<Conn: DbConn> CommentReportQuery<Conn> {
|
||||||
.and(community_moderator::person_id.eq(self.my_person_id)),
|
.and(community_moderator::person_id.eq(self.my_person_id)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.load::<<CommentReportView as JoinView>::JoinTuple>(&mut *conn)
|
.load::<<CommentReportView as JoinView>::JoinTuple>(conn)
|
||||||
.await?
|
.await?
|
||||||
} else {
|
} else {
|
||||||
query
|
query
|
||||||
.load::<<CommentReportView as JoinView>::JoinTuple>(&mut *conn)
|
.load::<<CommentReportView as JoinView>::JoinTuple>(conn)
|
||||||
.await?
|
.await?
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -290,7 +289,7 @@ mod tests {
|
||||||
async fn test_crud() {
|
async fn test_crud() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
let inserted_instance = Instance::read_or_create(&mut *conn, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(conn, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -300,7 +299,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_timmy = Person::create(&mut *conn, &new_person).await.unwrap();
|
let inserted_timmy = Person::create(conn, &new_person).await.unwrap();
|
||||||
|
|
||||||
let new_person_2 = PersonInsertForm::builder()
|
let new_person_2 = PersonInsertForm::builder()
|
||||||
.name("sara_crv".into())
|
.name("sara_crv".into())
|
||||||
|
@ -308,7 +307,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_sara = Person::create(&mut *conn, &new_person_2).await.unwrap();
|
let inserted_sara = Person::create(conn, &new_person_2).await.unwrap();
|
||||||
|
|
||||||
// Add a third person, since new ppl can only report something once.
|
// Add a third person, since new ppl can only report something once.
|
||||||
let new_person_3 = PersonInsertForm::builder()
|
let new_person_3 = PersonInsertForm::builder()
|
||||||
|
@ -317,7 +316,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_jessica = Person::create(&mut *conn, &new_person_3).await.unwrap();
|
let inserted_jessica = Person::create(conn, &new_person_3).await.unwrap();
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::builder()
|
let new_community = CommunityInsertForm::builder()
|
||||||
.name("test community crv".to_string())
|
.name("test community crv".to_string())
|
||||||
|
@ -326,7 +325,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_community = Community::create(&mut *conn, &new_community).await.unwrap();
|
let inserted_community = Community::create(conn, &new_community).await.unwrap();
|
||||||
|
|
||||||
// Make timmy a mod
|
// Make timmy a mod
|
||||||
let timmy_moderator_form = CommunityModeratorForm {
|
let timmy_moderator_form = CommunityModeratorForm {
|
||||||
|
@ -334,7 +333,7 @@ mod tests {
|
||||||
person_id: inserted_timmy.id,
|
person_id: inserted_timmy.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
let _inserted_moderator = CommunityModerator::join(&mut *conn, &timmy_moderator_form)
|
let _inserted_moderator = CommunityModerator::join(conn, &timmy_moderator_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -344,7 +343,7 @@ mod tests {
|
||||||
.community_id(inserted_community.id)
|
.community_id(inserted_community.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_post = Post::create(&mut *conn, &new_post).await.unwrap();
|
let inserted_post = Post::create(conn, &new_post).await.unwrap();
|
||||||
|
|
||||||
let comment_form = CommentInsertForm::builder()
|
let comment_form = CommentInsertForm::builder()
|
||||||
.content("A test comment 32".into())
|
.content("A test comment 32".into())
|
||||||
|
@ -352,7 +351,7 @@ mod tests {
|
||||||
.post_id(inserted_post.id)
|
.post_id(inserted_post.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_comment = Comment::create(&mut *conn, &comment_form, None)
|
let inserted_comment = Comment::create(conn, &comment_form, None)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -364,7 +363,7 @@ mod tests {
|
||||||
reason: "from sara".into(),
|
reason: "from sara".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_sara_report = CommentReport::report(&mut *conn, &sara_report_form)
|
let inserted_sara_report = CommentReport::report(conn, &sara_report_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -376,16 +375,16 @@ mod tests {
|
||||||
reason: "from jessica".into(),
|
reason: "from jessica".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_jessica_report = CommentReport::report(&mut *conn, &jessica_report_form)
|
let inserted_jessica_report = CommentReport::report(conn, &jessica_report_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let agg = CommentAggregates::read(&mut *conn, inserted_comment.id)
|
let agg = CommentAggregates::read(conn, inserted_comment.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let read_jessica_report_view =
|
let read_jessica_report_view =
|
||||||
CommentReportView::read(&mut *conn, inserted_jessica_report.id, inserted_timmy.id)
|
CommentReportView::read(conn, inserted_jessica_report.id, inserted_timmy.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let expected_jessica_report_view = CommentReportView {
|
let expected_jessica_report_view = CommentReportView {
|
||||||
|
@ -512,7 +511,7 @@ mod tests {
|
||||||
|
|
||||||
// Do a batch read of timmys reports
|
// Do a batch read of timmys reports
|
||||||
let reports = CommentReportQuery::builder()
|
let reports = CommentReportQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.my_person_id(inserted_timmy.id)
|
.my_person_id(inserted_timmy.id)
|
||||||
.admin(false)
|
.admin(false)
|
||||||
.build()
|
.build()
|
||||||
|
@ -530,17 +529,17 @@ mod tests {
|
||||||
|
|
||||||
// Make sure the counts are correct
|
// Make sure the counts are correct
|
||||||
let report_count =
|
let report_count =
|
||||||
CommentReportView::get_report_count(&mut *conn, inserted_timmy.id, false, None)
|
CommentReportView::get_report_count(conn, inserted_timmy.id, false, None)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(2, report_count);
|
assert_eq!(2, report_count);
|
||||||
|
|
||||||
// Try to resolve the report
|
// Try to resolve the report
|
||||||
CommentReport::resolve(&mut *conn, inserted_jessica_report.id, inserted_timmy.id)
|
CommentReport::resolve(conn, inserted_jessica_report.id, inserted_timmy.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let read_jessica_report_view_after_resolve =
|
let read_jessica_report_view_after_resolve =
|
||||||
CommentReportView::read(&mut *conn, inserted_jessica_report.id, inserted_timmy.id)
|
CommentReportView::read(conn, inserted_jessica_report.id, inserted_timmy.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -589,7 +588,7 @@ mod tests {
|
||||||
// Do a batch read of timmys reports
|
// Do a batch read of timmys reports
|
||||||
// It should only show saras, which is unresolved
|
// It should only show saras, which is unresolved
|
||||||
let reports_after_resolve = CommentReportQuery::builder()
|
let reports_after_resolve = CommentReportQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.my_person_id(inserted_timmy.id)
|
.my_person_id(inserted_timmy.id)
|
||||||
.admin(false)
|
.admin(false)
|
||||||
.unresolved_only(Some(true))
|
.unresolved_only(Some(true))
|
||||||
|
@ -602,20 +601,20 @@ mod tests {
|
||||||
|
|
||||||
// Make sure the counts are correct
|
// Make sure the counts are correct
|
||||||
let report_count_after_resolved =
|
let report_count_after_resolved =
|
||||||
CommentReportView::get_report_count(&mut *conn, inserted_timmy.id, false, None)
|
CommentReportView::get_report_count(conn, inserted_timmy.id, false, None)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, report_count_after_resolved);
|
assert_eq!(1, report_count_after_resolved);
|
||||||
|
|
||||||
Person::delete(&mut *conn, inserted_timmy.id).await.unwrap();
|
Person::delete(conn, inserted_timmy.id).await.unwrap();
|
||||||
Person::delete(&mut *conn, inserted_sara.id).await.unwrap();
|
Person::delete(conn, inserted_sara.id).await.unwrap();
|
||||||
Person::delete(&mut *conn, inserted_jessica.id)
|
Person::delete(conn, inserted_jessica.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Community::delete(&mut *conn, inserted_community.id)
|
Community::delete(conn, inserted_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Instance::delete(&mut *conn, inserted_instance.id)
|
Instance::delete(conn, inserted_instance.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ use diesel::{
|
||||||
PgTextExpressionMethods,
|
PgTextExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use diesel_ltree::{nlevel, subpath, Ltree, LtreeExtensions};
|
use diesel_ltree::{nlevel, subpath, Ltree, LtreeExtensions};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
aggregates::structs::CommentAggregates,
|
aggregates::structs::CommentAggregates,
|
||||||
|
@ -36,7 +35,7 @@ use lemmy_db_schema::{
|
||||||
post::Post,
|
post::Post,
|
||||||
},
|
},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{fuzzy_search, limit_and_offset, DbConn},
|
utils::{fuzzy_search, limit_and_offset, GetConn, RunQueryDsl},
|
||||||
CommentSortType,
|
CommentSortType,
|
||||||
ListingType,
|
ListingType,
|
||||||
};
|
};
|
||||||
|
@ -57,7 +56,7 @@ type CommentViewTuple = (
|
||||||
|
|
||||||
impl CommentView {
|
impl CommentView {
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
comment_id: CommentId,
|
comment_id: CommentId,
|
||||||
my_person_id: Option<PersonId>,
|
my_person_id: Option<PersonId>,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
|
@ -128,7 +127,7 @@ impl CommentView {
|
||||||
person_block::all_columns.nullable(),
|
person_block::all_columns.nullable(),
|
||||||
comment_like::score.nullable(),
|
comment_like::score.nullable(),
|
||||||
))
|
))
|
||||||
.first::<CommentViewTuple>(&mut *conn)
|
.first::<CommentViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// If a person is given, then my_vote, if None, should be 0, not null
|
// If a person is given, then my_vote, if None, should be 0, not null
|
||||||
|
@ -174,7 +173,7 @@ pub struct CommentQuery<'a, Conn> {
|
||||||
max_depth: Option<i32>,
|
max_depth: Option<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Conn: DbConn> CommentQuery<'a, Conn> {
|
impl<'a, Conn: GetConn> CommentQuery<'a, Conn> {
|
||||||
pub async fn list(self) -> Result<Vec<CommentView>, Error> {
|
pub async fn list(self) -> Result<Vec<CommentView>, Error> {
|
||||||
let mut conn = self.conn;
|
let mut conn = self.conn;
|
||||||
|
|
||||||
|
@ -357,7 +356,7 @@ impl<'a, Conn: DbConn> CommentQuery<'a, Conn> {
|
||||||
let res = query
|
let res = query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.load::<CommentViewTuple>(&mut *conn)
|
.load::<CommentViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(res.into_iter().map(CommentView::from_tuple).collect())
|
Ok(res.into_iter().map(CommentView::from_tuple).collect())
|
||||||
|
@ -411,7 +410,7 @@ mod tests {
|
||||||
post::PostInsertForm,
|
post::PostInsertForm,
|
||||||
},
|
},
|
||||||
traits::{Blockable, Crud, Likeable},
|
traits::{Blockable, Crud, Likeable},
|
||||||
utils::{build_db_conn_for_tests, DbConn},
|
utils::{build_db_conn_for_tests, GetConn},
|
||||||
SubscribedType,
|
SubscribedType,
|
||||||
};
|
};
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
@ -428,8 +427,8 @@ mod tests {
|
||||||
inserted_community: Community,
|
inserted_community: Community,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn init_data(mut conn: impl DbConn) -> Data {
|
async fn init_data(mut conn: impl GetConn) -> Data {
|
||||||
let inserted_instance = Instance::read_or_create(&mut *conn, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(conn, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -438,12 +437,12 @@ mod tests {
|
||||||
.public_key("pubkey".to_string())
|
.public_key("pubkey".to_string())
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
let inserted_person = Person::create(&mut *conn, &new_person).await.unwrap();
|
let inserted_person = Person::create(conn, &new_person).await.unwrap();
|
||||||
let local_user_form = LocalUserInsertForm::builder()
|
let local_user_form = LocalUserInsertForm::builder()
|
||||||
.person_id(inserted_person.id)
|
.person_id(inserted_person.id)
|
||||||
.password_encrypted(String::new())
|
.password_encrypted(String::new())
|
||||||
.build();
|
.build();
|
||||||
let inserted_local_user = LocalUser::create(&mut *conn, &local_user_form)
|
let inserted_local_user = LocalUser::create(conn, &local_user_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -452,7 +451,7 @@ mod tests {
|
||||||
.public_key("pubkey".to_string())
|
.public_key("pubkey".to_string())
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
let inserted_person_2 = Person::create(&mut *conn, &new_person_2).await.unwrap();
|
let inserted_person_2 = Person::create(conn, &new_person_2).await.unwrap();
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::builder()
|
let new_community = CommunityInsertForm::builder()
|
||||||
.name("test community 5".to_string())
|
.name("test community 5".to_string())
|
||||||
|
@ -461,7 +460,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_community = Community::create(&mut *conn, &new_community).await.unwrap();
|
let inserted_community = Community::create(conn, &new_community).await.unwrap();
|
||||||
|
|
||||||
let new_post = PostInsertForm::builder()
|
let new_post = PostInsertForm::builder()
|
||||||
.name("A test post 2".into())
|
.name("A test post 2".into())
|
||||||
|
@ -469,8 +468,8 @@ mod tests {
|
||||||
.community_id(inserted_community.id)
|
.community_id(inserted_community.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_post = Post::create(&mut *conn, &new_post).await.unwrap();
|
let inserted_post = Post::create(conn, &new_post).await.unwrap();
|
||||||
let english_id = Language::read_id_from_code(&mut *conn, Some("en"))
|
let english_id = Language::read_id_from_code(conn, Some("en"))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -489,7 +488,7 @@ mod tests {
|
||||||
.language_id(english_id)
|
.language_id(english_id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_comment_0 = Comment::create(&mut *conn, &comment_form_0, None)
|
let inserted_comment_0 = Comment::create(conn, &comment_form_0, None)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -501,11 +500,11 @@ mod tests {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_comment_1 =
|
let inserted_comment_1 =
|
||||||
Comment::create(&mut *conn, &comment_form_1, Some(&inserted_comment_0.path))
|
Comment::create(conn, &comment_form_1, Some(&inserted_comment_0.path))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let finnish_id = Language::read_id_from_code(&mut *conn, Some("fi"))
|
let finnish_id = Language::read_id_from_code(conn, Some("fi"))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let comment_form_2 = CommentInsertForm::builder()
|
let comment_form_2 = CommentInsertForm::builder()
|
||||||
|
@ -516,7 +515,7 @@ mod tests {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_comment_2 =
|
let inserted_comment_2 =
|
||||||
Comment::create(&mut *conn, &comment_form_2, Some(&inserted_comment_0.path))
|
Comment::create(conn, &comment_form_2, Some(&inserted_comment_0.path))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -528,11 +527,11 @@ mod tests {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let _inserted_comment_3 =
|
let _inserted_comment_3 =
|
||||||
Comment::create(&mut *conn, &comment_form_3, Some(&inserted_comment_1.path))
|
Comment::create(conn, &comment_form_3, Some(&inserted_comment_1.path))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let polish_id = Language::read_id_from_code(&mut *conn, Some("pl"))
|
let polish_id = Language::read_id_from_code(conn, Some("pl"))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -544,7 +543,7 @@ mod tests {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_comment_4 =
|
let inserted_comment_4 =
|
||||||
Comment::create(&mut *conn, &comment_form_4, Some(&inserted_comment_1.path))
|
Comment::create(conn, &comment_form_4, Some(&inserted_comment_1.path))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -555,7 +554,7 @@ mod tests {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let _inserted_comment_5 =
|
let _inserted_comment_5 =
|
||||||
Comment::create(&mut *conn, &comment_form_5, Some(&inserted_comment_4.path))
|
Comment::create(conn, &comment_form_5, Some(&inserted_comment_4.path))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -564,7 +563,7 @@ mod tests {
|
||||||
target_id: inserted_person_2.id,
|
target_id: inserted_person_2.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_block = PersonBlock::block(&mut *conn, &timmy_blocks_sara_form)
|
let inserted_block = PersonBlock::block(conn, &timmy_blocks_sara_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -583,7 +582,7 @@ mod tests {
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
let _inserted_comment_like = CommentLike::like(&mut *conn, &comment_like_form)
|
let _inserted_comment_like = CommentLike::like(conn, &comment_like_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -604,15 +603,15 @@ mod tests {
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_crud() {
|
async fn test_crud() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
let data = init_data(&mut *conn).await;
|
let data = init_data(conn).await;
|
||||||
|
|
||||||
let expected_comment_view_no_person = expected_comment_view(&data, &mut *conn).await;
|
let expected_comment_view_no_person = expected_comment_view(&data, conn).await;
|
||||||
|
|
||||||
let mut expected_comment_view_with_person = expected_comment_view_no_person.clone();
|
let mut expected_comment_view_with_person = expected_comment_view_no_person.clone();
|
||||||
expected_comment_view_with_person.my_vote = Some(1);
|
expected_comment_view_with_person.my_vote = Some(1);
|
||||||
|
|
||||||
let read_comment_views_no_person = CommentQuery::builder()
|
let read_comment_views_no_person = CommentQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.sort(Some(CommentSortType::Old))
|
.sort(Some(CommentSortType::Old))
|
||||||
.post_id(Some(data.inserted_post.id))
|
.post_id(Some(data.inserted_post.id))
|
||||||
.build()
|
.build()
|
||||||
|
@ -626,7 +625,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let read_comment_views_with_person = CommentQuery::builder()
|
let read_comment_views_with_person = CommentQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.sort(Some(CommentSortType::Old))
|
.sort(Some(CommentSortType::Old))
|
||||||
.post_id(Some(data.inserted_post.id))
|
.post_id(Some(data.inserted_post.id))
|
||||||
.local_user(Some(&data.inserted_local_user))
|
.local_user(Some(&data.inserted_local_user))
|
||||||
|
@ -644,7 +643,7 @@ mod tests {
|
||||||
assert_eq!(5, read_comment_views_with_person.len());
|
assert_eq!(5, read_comment_views_with_person.len());
|
||||||
|
|
||||||
let read_comment_from_blocked_person = CommentView::read(
|
let read_comment_from_blocked_person = CommentView::read(
|
||||||
&mut *conn,
|
conn,
|
||||||
data.inserted_comment_1.id,
|
data.inserted_comment_1.id,
|
||||||
Some(data.inserted_person.id),
|
Some(data.inserted_person.id),
|
||||||
)
|
)
|
||||||
|
@ -654,18 +653,18 @@ mod tests {
|
||||||
// Make sure block set the creator blocked
|
// Make sure block set the creator blocked
|
||||||
assert!(read_comment_from_blocked_person.creator_blocked);
|
assert!(read_comment_from_blocked_person.creator_blocked);
|
||||||
|
|
||||||
cleanup(data, &mut *conn).await;
|
cleanup(data, conn).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_comment_tree() {
|
async fn test_comment_tree() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
let data = init_data(&mut *conn).await;
|
let data = init_data(conn).await;
|
||||||
|
|
||||||
let top_path = data.inserted_comment_0.path.clone();
|
let top_path = data.inserted_comment_0.path.clone();
|
||||||
let read_comment_views_top_path = CommentQuery::builder()
|
let read_comment_views_top_path = CommentQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.post_id(Some(data.inserted_post.id))
|
.post_id(Some(data.inserted_post.id))
|
||||||
.parent_path(Some(top_path))
|
.parent_path(Some(top_path))
|
||||||
.build()
|
.build()
|
||||||
|
@ -675,7 +674,7 @@ mod tests {
|
||||||
|
|
||||||
let child_path = data.inserted_comment_1.path.clone();
|
let child_path = data.inserted_comment_1.path.clone();
|
||||||
let read_comment_views_child_path = CommentQuery::builder()
|
let read_comment_views_child_path = CommentQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.post_id(Some(data.inserted_post.id))
|
.post_id(Some(data.inserted_post.id))
|
||||||
.parent_path(Some(child_path))
|
.parent_path(Some(child_path))
|
||||||
.build()
|
.build()
|
||||||
|
@ -696,7 +695,7 @@ mod tests {
|
||||||
assert!(!child_comments.contains(&data.inserted_comment_2));
|
assert!(!child_comments.contains(&data.inserted_comment_2));
|
||||||
|
|
||||||
let read_comment_views_top_max_depth = CommentQuery::builder()
|
let read_comment_views_top_max_depth = CommentQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.post_id(Some(data.inserted_post.id))
|
.post_id(Some(data.inserted_post.id))
|
||||||
.max_depth(Some(1))
|
.max_depth(Some(1))
|
||||||
.build()
|
.build()
|
||||||
|
@ -706,14 +705,14 @@ mod tests {
|
||||||
|
|
||||||
// Make sure a depth limited one only has the top comment
|
// Make sure a depth limited one only has the top comment
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
expected_comment_view(&data, &mut *conn).await,
|
expected_comment_view(&data, conn).await,
|
||||||
read_comment_views_top_max_depth[0]
|
read_comment_views_top_max_depth[0]
|
||||||
);
|
);
|
||||||
assert_eq!(1, read_comment_views_top_max_depth.len());
|
assert_eq!(1, read_comment_views_top_max_depth.len());
|
||||||
|
|
||||||
let child_path = data.inserted_comment_1.path.clone();
|
let child_path = data.inserted_comment_1.path.clone();
|
||||||
let read_comment_views_parent_max_depth = CommentQuery::builder()
|
let read_comment_views_parent_max_depth = CommentQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.post_id(Some(data.inserted_post.id))
|
.post_id(Some(data.inserted_post.id))
|
||||||
.parent_path(Some(child_path))
|
.parent_path(Some(child_path))
|
||||||
.max_depth(Some(1))
|
.max_depth(Some(1))
|
||||||
|
@ -730,19 +729,19 @@ mod tests {
|
||||||
.eq("Comment 3"));
|
.eq("Comment 3"));
|
||||||
assert_eq!(3, read_comment_views_parent_max_depth.len());
|
assert_eq!(3, read_comment_views_parent_max_depth.len());
|
||||||
|
|
||||||
cleanup(data, &mut *conn).await;
|
cleanup(data, conn).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_languages() {
|
async fn test_languages() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
let data = init_data(&mut *conn).await;
|
let data = init_data(conn).await;
|
||||||
|
|
||||||
// by default, user has all languages enabled and should see all comments
|
// by default, user has all languages enabled and should see all comments
|
||||||
// (except from blocked user)
|
// (except from blocked user)
|
||||||
let all_languages = CommentQuery::builder()
|
let all_languages = CommentQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.local_user(Some(&data.inserted_local_user))
|
.local_user(Some(&data.inserted_local_user))
|
||||||
.build()
|
.build()
|
||||||
.list()
|
.list()
|
||||||
|
@ -751,15 +750,15 @@ mod tests {
|
||||||
assert_eq!(5, all_languages.len());
|
assert_eq!(5, all_languages.len());
|
||||||
|
|
||||||
// change user lang to finnish, should only show one post in finnish and one undetermined
|
// change user lang to finnish, should only show one post in finnish and one undetermined
|
||||||
let finnish_id = Language::read_id_from_code(&mut *conn, Some("fi"))
|
let finnish_id = Language::read_id_from_code(conn, Some("fi"))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
LocalUserLanguage::update(&mut *conn, vec![finnish_id], data.inserted_local_user.id)
|
LocalUserLanguage::update(conn, vec![finnish_id], data.inserted_local_user.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let finnish_comments = CommentQuery::builder()
|
let finnish_comments = CommentQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.local_user(Some(&data.inserted_local_user))
|
.local_user(Some(&data.inserted_local_user))
|
||||||
.build()
|
.build()
|
||||||
.list()
|
.list()
|
||||||
|
@ -777,14 +776,14 @@ mod tests {
|
||||||
|
|
||||||
// now show all comments with undetermined language (which is the default value)
|
// now show all comments with undetermined language (which is the default value)
|
||||||
LocalUserLanguage::update(
|
LocalUserLanguage::update(
|
||||||
&mut *conn,
|
conn,
|
||||||
vec![UNDETERMINED_ID],
|
vec![UNDETERMINED_ID],
|
||||||
data.inserted_local_user.id,
|
data.inserted_local_user.id,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let undetermined_comment = CommentQuery::builder()
|
let undetermined_comment = CommentQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.local_user(Some(&data.inserted_local_user))
|
.local_user(Some(&data.inserted_local_user))
|
||||||
.build()
|
.build()
|
||||||
.list()
|
.list()
|
||||||
|
@ -792,42 +791,42 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, undetermined_comment.len());
|
assert_eq!(1, undetermined_comment.len());
|
||||||
|
|
||||||
cleanup(data, &mut *conn).await;
|
cleanup(data, conn).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn cleanup(data: Data, mut conn: impl DbConn) {
|
async fn cleanup(data: Data, mut conn: impl GetConn) {
|
||||||
CommentLike::remove(
|
CommentLike::remove(
|
||||||
&mut *conn,
|
conn,
|
||||||
data.inserted_person.id,
|
data.inserted_person.id,
|
||||||
data.inserted_comment_0.id,
|
data.inserted_comment_0.id,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Comment::delete(&mut *conn, data.inserted_comment_0.id)
|
Comment::delete(conn, data.inserted_comment_0.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Comment::delete(&mut *conn, data.inserted_comment_1.id)
|
Comment::delete(conn, data.inserted_comment_1.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Post::delete(&mut *conn, data.inserted_post.id)
|
Post::delete(conn, data.inserted_post.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Community::delete(&mut *conn, data.inserted_community.id)
|
Community::delete(conn, data.inserted_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Person::delete(&mut *conn, data.inserted_person.id)
|
Person::delete(conn, data.inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Person::delete(&mut *conn, data.inserted_person_2.id)
|
Person::delete(conn, data.inserted_person_2.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Instance::delete(&mut *conn, data.inserted_instance.id)
|
Instance::delete(conn, data.inserted_instance.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn expected_comment_view(data: &Data, mut conn: impl DbConn) -> CommentView {
|
async fn expected_comment_view(data: &Data, mut conn: impl GetConn) -> CommentView {
|
||||||
let agg = CommentAggregates::read(&mut *conn, data.inserted_comment_0.id)
|
let agg = CommentAggregates::read(conn, data.inserted_comment_0.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
CommentView {
|
CommentView {
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
use crate::structs::CustomEmojiView;
|
use crate::structs::CustomEmojiView;
|
||||||
use diesel::{result::Error, ExpressionMethods, JoinOnDsl, NullableExpressionMethods, QueryDsl};
|
use diesel::{result::Error, ExpressionMethods, JoinOnDsl, NullableExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CustomEmojiId, LocalSiteId},
|
newtypes::{CustomEmojiId, LocalSiteId},
|
||||||
schema::{custom_emoji, custom_emoji_keyword},
|
schema::{custom_emoji, custom_emoji_keyword},
|
||||||
source::{custom_emoji::CustomEmoji, custom_emoji_keyword::CustomEmojiKeyword},
|
source::{custom_emoji::CustomEmoji, custom_emoji_keyword::CustomEmojiKeyword},
|
||||||
utils::DbConn,
|
utils::{GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
type CustomEmojiTuple = (CustomEmoji, Option<CustomEmojiKeyword>);
|
type CustomEmojiTuple = (CustomEmoji, Option<CustomEmojiKeyword>);
|
||||||
|
|
||||||
impl CustomEmojiView {
|
impl CustomEmojiView {
|
||||||
pub async fn get(mut conn: impl DbConn, emoji_id: CustomEmojiId) -> Result<Self, Error> {
|
pub async fn get(mut conn: impl GetConn, emoji_id: CustomEmojiId) -> Result<Self, Error> {
|
||||||
let emojis = custom_emoji::table
|
let emojis = custom_emoji::table
|
||||||
.find(emoji_id)
|
.find(emoji_id)
|
||||||
.left_join(
|
.left_join(
|
||||||
|
@ -22,7 +21,7 @@ impl CustomEmojiView {
|
||||||
custom_emoji::all_columns,
|
custom_emoji::all_columns,
|
||||||
custom_emoji_keyword::all_columns.nullable(), // (or all the columns if you want)
|
custom_emoji_keyword::all_columns.nullable(), // (or all the columns if you want)
|
||||||
))
|
))
|
||||||
.load::<CustomEmojiTuple>(&mut *conn)
|
.load::<CustomEmojiTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
if let Some(emoji) = CustomEmojiView::from_tuple_to_vec(emojis)
|
if let Some(emoji) = CustomEmojiView::from_tuple_to_vec(emojis)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -35,7 +34,7 @@ impl CustomEmojiView {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_all(
|
pub async fn get_all(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
for_local_site_id: LocalSiteId,
|
for_local_site_id: LocalSiteId,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
let emojis = custom_emoji::table
|
let emojis = custom_emoji::table
|
||||||
|
@ -49,7 +48,7 @@ impl CustomEmojiView {
|
||||||
custom_emoji::all_columns,
|
custom_emoji::all_columns,
|
||||||
custom_emoji_keyword::all_columns.nullable(), // (or all the columns if you want)
|
custom_emoji_keyword::all_columns.nullable(), // (or all the columns if you want)
|
||||||
))
|
))
|
||||||
.load::<CustomEmojiTuple>(&mut *conn)
|
.load::<CustomEmojiTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(CustomEmojiView::from_tuple_to_vec(emojis))
|
Ok(CustomEmojiView::from_tuple_to_vec(emojis))
|
||||||
|
|
|
@ -1,19 +1,18 @@
|
||||||
use crate::structs::LocalUserView;
|
use crate::structs::LocalUserView;
|
||||||
use diesel::{result::Error, BoolExpressionMethods, ExpressionMethods, JoinOnDsl, QueryDsl};
|
use diesel::{result::Error, BoolExpressionMethods, ExpressionMethods, JoinOnDsl, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
aggregates::structs::PersonAggregates,
|
aggregates::structs::PersonAggregates,
|
||||||
newtypes::{LocalUserId, PersonId},
|
newtypes::{LocalUserId, PersonId},
|
||||||
schema::{local_user, person, person_aggregates},
|
schema::{local_user, person, person_aggregates},
|
||||||
source::{local_user::LocalUser, person::Person},
|
source::{local_user::LocalUser, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{functions::lower, DbConn},
|
utils::{functions::lower, GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
|
|
||||||
type LocalUserViewTuple = (LocalUser, Person, PersonAggregates);
|
type LocalUserViewTuple = (LocalUser, Person, PersonAggregates);
|
||||||
|
|
||||||
impl LocalUserView {
|
impl LocalUserView {
|
||||||
pub async fn read(mut conn: impl DbConn, local_user_id: LocalUserId) -> Result<Self, Error> {
|
pub async fn read(mut conn: impl GetConn, local_user_id: LocalUserId) -> Result<Self, Error> {
|
||||||
let (local_user, person, counts) = local_user::table
|
let (local_user, person, counts) = local_user::table
|
||||||
.find(local_user_id)
|
.find(local_user_id)
|
||||||
.inner_join(person::table)
|
.inner_join(person::table)
|
||||||
|
@ -23,7 +22,7 @@ impl LocalUserView {
|
||||||
person::all_columns,
|
person::all_columns,
|
||||||
person_aggregates::all_columns,
|
person_aggregates::all_columns,
|
||||||
))
|
))
|
||||||
.first::<LocalUserViewTuple>(&mut *conn)
|
.first::<LocalUserViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
local_user,
|
local_user,
|
||||||
|
@ -32,7 +31,7 @@ impl LocalUserView {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read_person(mut conn: impl DbConn, person_id: PersonId) -> Result<Self, Error> {
|
pub async fn read_person(mut conn: impl GetConn, person_id: PersonId) -> Result<Self, Error> {
|
||||||
let (local_user, person, counts) = local_user::table
|
let (local_user, person, counts) = local_user::table
|
||||||
.filter(person::id.eq(person_id))
|
.filter(person::id.eq(person_id))
|
||||||
.inner_join(person::table)
|
.inner_join(person::table)
|
||||||
|
@ -42,7 +41,7 @@ impl LocalUserView {
|
||||||
person::all_columns,
|
person::all_columns,
|
||||||
person_aggregates::all_columns,
|
person_aggregates::all_columns,
|
||||||
))
|
))
|
||||||
.first::<LocalUserViewTuple>(&mut *conn)
|
.first::<LocalUserViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
local_user,
|
local_user,
|
||||||
|
@ -51,7 +50,7 @@ impl LocalUserView {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read_from_name(mut conn: impl DbConn, name: &str) -> Result<Self, Error> {
|
pub async fn read_from_name(mut conn: impl GetConn, name: &str) -> Result<Self, Error> {
|
||||||
let (local_user, person, counts) = local_user::table
|
let (local_user, person, counts) = local_user::table
|
||||||
.filter(lower(person::name).eq(name.to_lowercase()))
|
.filter(lower(person::name).eq(name.to_lowercase()))
|
||||||
.inner_join(person::table)
|
.inner_join(person::table)
|
||||||
|
@ -61,7 +60,7 @@ impl LocalUserView {
|
||||||
person::all_columns,
|
person::all_columns,
|
||||||
person_aggregates::all_columns,
|
person_aggregates::all_columns,
|
||||||
))
|
))
|
||||||
.first::<LocalUserViewTuple>(&mut *conn)
|
.first::<LocalUserViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
local_user,
|
local_user,
|
||||||
|
@ -71,7 +70,7 @@ impl LocalUserView {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn find_by_email_or_name(
|
pub async fn find_by_email_or_name(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
name_or_email: &str,
|
name_or_email: &str,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let (local_user, person, counts) = local_user::table
|
let (local_user, person, counts) = local_user::table
|
||||||
|
@ -87,7 +86,7 @@ impl LocalUserView {
|
||||||
person::all_columns,
|
person::all_columns,
|
||||||
person_aggregates::all_columns,
|
person_aggregates::all_columns,
|
||||||
))
|
))
|
||||||
.first::<LocalUserViewTuple>(&mut *conn)
|
.first::<LocalUserViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
local_user,
|
local_user,
|
||||||
|
@ -96,7 +95,7 @@ impl LocalUserView {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn find_by_email(mut conn: impl DbConn, from_email: &str) -> Result<Self, Error> {
|
pub async fn find_by_email(mut conn: impl GetConn, from_email: &str) -> Result<Self, Error> {
|
||||||
let (local_user, person, counts) = local_user::table
|
let (local_user, person, counts) = local_user::table
|
||||||
.inner_join(person::table)
|
.inner_join(person::table)
|
||||||
.inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id)))
|
.inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id)))
|
||||||
|
@ -106,7 +105,7 @@ impl LocalUserView {
|
||||||
person::all_columns,
|
person::all_columns,
|
||||||
person_aggregates::all_columns,
|
person_aggregates::all_columns,
|
||||||
))
|
))
|
||||||
.first::<LocalUserViewTuple>(&mut *conn)
|
.first::<LocalUserViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
local_user,
|
local_user,
|
||||||
|
@ -115,7 +114,7 @@ impl LocalUserView {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list_admins_with_emails(mut conn: impl DbConn) -> Result<Vec<Self>, Error> {
|
pub async fn list_admins_with_emails(mut conn: impl GetConn) -> Result<Vec<Self>, Error> {
|
||||||
let res = local_user::table
|
let res = local_user::table
|
||||||
.filter(person::admin.eq(true))
|
.filter(person::admin.eq(true))
|
||||||
.filter(local_user::email.is_not_null())
|
.filter(local_user::email.is_not_null())
|
||||||
|
@ -126,7 +125,7 @@ impl LocalUserView {
|
||||||
person::all_columns,
|
person::all_columns,
|
||||||
person_aggregates::all_columns,
|
person_aggregates::all_columns,
|
||||||
))
|
))
|
||||||
.load::<LocalUserViewTuple>(&mut *conn)
|
.load::<LocalUserViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(res.into_iter().map(LocalUserView::from_tuple).collect())
|
Ok(res.into_iter().map(LocalUserView::from_tuple).collect())
|
||||||
|
|
|
@ -7,7 +7,6 @@ use diesel::{
|
||||||
NullableExpressionMethods,
|
NullableExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
aggregates::structs::PostAggregates,
|
aggregates::structs::PostAggregates,
|
||||||
newtypes::{CommunityId, PersonId, PostReportId},
|
newtypes::{CommunityId, PersonId, PostReportId},
|
||||||
|
@ -28,7 +27,7 @@ use lemmy_db_schema::{
|
||||||
post_report::PostReport,
|
post_report::PostReport,
|
||||||
},
|
},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbConn},
|
utils::{limit_and_offset, GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
use typed_builder::TypedBuilder;
|
use typed_builder::TypedBuilder;
|
||||||
|
|
||||||
|
@ -49,7 +48,7 @@ impl PostReportView {
|
||||||
///
|
///
|
||||||
/// * `report_id` - the report id to obtain
|
/// * `report_id` - the report id to obtain
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
report_id: PostReportId,
|
report_id: PostReportId,
|
||||||
my_person_id: PersonId,
|
my_person_id: PersonId,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
|
@ -100,7 +99,7 @@ impl PostReportView {
|
||||||
post_aggregates::all_columns,
|
post_aggregates::all_columns,
|
||||||
person_alias_2.fields(person::all_columns.nullable()),
|
person_alias_2.fields(person::all_columns.nullable()),
|
||||||
))
|
))
|
||||||
.first::<PostReportViewTuple>(&mut *conn)
|
.first::<PostReportViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let my_vote = post_like;
|
let my_vote = post_like;
|
||||||
|
@ -120,7 +119,7 @@ impl PostReportView {
|
||||||
|
|
||||||
/// returns the current unresolved post report count for the communities you mod
|
/// returns the current unresolved post report count for the communities you mod
|
||||||
pub async fn get_report_count(
|
pub async fn get_report_count(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
my_person_id: PersonId,
|
my_person_id: PersonId,
|
||||||
admin: bool,
|
admin: bool,
|
||||||
community_id: Option<CommunityId>,
|
community_id: Option<CommunityId>,
|
||||||
|
@ -146,12 +145,12 @@ impl PostReportView {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.select(count(post_report::id))
|
.select(count(post_report::id))
|
||||||
.first::<i64>(&mut *conn)
|
.first::<i64>(conn)
|
||||||
.await
|
.await
|
||||||
} else {
|
} else {
|
||||||
query
|
query
|
||||||
.select(count(post_report::id))
|
.select(count(post_report::id))
|
||||||
.first::<i64>(&mut *conn)
|
.first::<i64>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,7 +171,7 @@ pub struct PostReportQuery<Conn> {
|
||||||
unresolved_only: Option<bool>,
|
unresolved_only: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Conn: DbConn> PostReportQuery<Conn> {
|
impl<Conn: GetConn> PostReportQuery<Conn> {
|
||||||
pub async fn list(self) -> Result<Vec<PostReportView>, Error> {
|
pub async fn list(self) -> Result<Vec<PostReportView>, Error> {
|
||||||
let mut conn = self.conn;
|
let mut conn = self.conn;
|
||||||
let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2);
|
let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2);
|
||||||
|
@ -238,10 +237,10 @@ impl<Conn: DbConn> PostReportQuery<Conn> {
|
||||||
.and(community_moderator::person_id.eq(self.my_person_id)),
|
.and(community_moderator::person_id.eq(self.my_person_id)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.load::<PostReportViewTuple>(&mut *conn)
|
.load::<PostReportViewTuple>(conn)
|
||||||
.await?
|
.await?
|
||||||
} else {
|
} else {
|
||||||
query.load::<PostReportViewTuple>(&mut *conn).await?
|
query.load::<PostReportViewTuple>(conn).await?
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(res.into_iter().map(PostReportView::from_tuple).collect())
|
Ok(res.into_iter().map(PostReportView::from_tuple).collect())
|
||||||
|
@ -287,7 +286,7 @@ mod tests {
|
||||||
async fn test_crud() {
|
async fn test_crud() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
let inserted_instance = Instance::read_or_create(&mut *conn, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(conn, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -297,7 +296,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_timmy = Person::create(&mut *conn, &new_person).await.unwrap();
|
let inserted_timmy = Person::create(conn, &new_person).await.unwrap();
|
||||||
|
|
||||||
let new_person_2 = PersonInsertForm::builder()
|
let new_person_2 = PersonInsertForm::builder()
|
||||||
.name("sara_prv".into())
|
.name("sara_prv".into())
|
||||||
|
@ -305,7 +304,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_sara = Person::create(&mut *conn, &new_person_2).await.unwrap();
|
let inserted_sara = Person::create(conn, &new_person_2).await.unwrap();
|
||||||
|
|
||||||
// Add a third person, since new ppl can only report something once.
|
// Add a third person, since new ppl can only report something once.
|
||||||
let new_person_3 = PersonInsertForm::builder()
|
let new_person_3 = PersonInsertForm::builder()
|
||||||
|
@ -314,7 +313,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_jessica = Person::create(&mut *conn, &new_person_3).await.unwrap();
|
let inserted_jessica = Person::create(conn, &new_person_3).await.unwrap();
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::builder()
|
let new_community = CommunityInsertForm::builder()
|
||||||
.name("test community prv".to_string())
|
.name("test community prv".to_string())
|
||||||
|
@ -323,7 +322,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_community = Community::create(&mut *conn, &new_community).await.unwrap();
|
let inserted_community = Community::create(conn, &new_community).await.unwrap();
|
||||||
|
|
||||||
// Make timmy a mod
|
// Make timmy a mod
|
||||||
let timmy_moderator_form = CommunityModeratorForm {
|
let timmy_moderator_form = CommunityModeratorForm {
|
||||||
|
@ -331,7 +330,7 @@ mod tests {
|
||||||
person_id: inserted_timmy.id,
|
person_id: inserted_timmy.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
let _inserted_moderator = CommunityModerator::join(&mut *conn, &timmy_moderator_form)
|
let _inserted_moderator = CommunityModerator::join(conn, &timmy_moderator_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -341,7 +340,7 @@ mod tests {
|
||||||
.community_id(inserted_community.id)
|
.community_id(inserted_community.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_post = Post::create(&mut *conn, &new_post).await.unwrap();
|
let inserted_post = Post::create(conn, &new_post).await.unwrap();
|
||||||
|
|
||||||
// sara reports
|
// sara reports
|
||||||
let sara_report_form = PostReportForm {
|
let sara_report_form = PostReportForm {
|
||||||
|
@ -353,7 +352,7 @@ mod tests {
|
||||||
reason: "from sara".into(),
|
reason: "from sara".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_sara_report = PostReport::report(&mut *conn, &sara_report_form)
|
let inserted_sara_report = PostReport::report(conn, &sara_report_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -367,16 +366,16 @@ mod tests {
|
||||||
reason: "from jessica".into(),
|
reason: "from jessica".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_jessica_report = PostReport::report(&mut *conn, &jessica_report_form)
|
let inserted_jessica_report = PostReport::report(conn, &jessica_report_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let agg = PostAggregates::read(&mut *conn, inserted_post.id)
|
let agg = PostAggregates::read(conn, inserted_post.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let read_jessica_report_view =
|
let read_jessica_report_view =
|
||||||
PostReportView::read(&mut *conn, inserted_jessica_report.id, inserted_timmy.id)
|
PostReportView::read(conn, inserted_jessica_report.id, inserted_timmy.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let expected_jessica_report_view = PostReportView {
|
let expected_jessica_report_view = PostReportView {
|
||||||
|
@ -508,7 +507,7 @@ mod tests {
|
||||||
|
|
||||||
// Do a batch read of timmys reports
|
// Do a batch read of timmys reports
|
||||||
let reports = PostReportQuery::builder()
|
let reports = PostReportQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.my_person_id(inserted_timmy.id)
|
.my_person_id(inserted_timmy.id)
|
||||||
.admin(false)
|
.admin(false)
|
||||||
.build()
|
.build()
|
||||||
|
@ -525,17 +524,17 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Make sure the counts are correct
|
// Make sure the counts are correct
|
||||||
let report_count = PostReportView::get_report_count(&mut *conn, inserted_timmy.id, false, None)
|
let report_count = PostReportView::get_report_count(conn, inserted_timmy.id, false, None)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(2, report_count);
|
assert_eq!(2, report_count);
|
||||||
|
|
||||||
// Try to resolve the report
|
// Try to resolve the report
|
||||||
PostReport::resolve(&mut *conn, inserted_jessica_report.id, inserted_timmy.id)
|
PostReport::resolve(conn, inserted_jessica_report.id, inserted_timmy.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let read_jessica_report_view_after_resolve =
|
let read_jessica_report_view_after_resolve =
|
||||||
PostReportView::read(&mut *conn, inserted_jessica_report.id, inserted_timmy.id)
|
PostReportView::read(conn, inserted_jessica_report.id, inserted_timmy.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -582,7 +581,7 @@ mod tests {
|
||||||
// Do a batch read of timmys reports
|
// Do a batch read of timmys reports
|
||||||
// It should only show saras, which is unresolved
|
// It should only show saras, which is unresolved
|
||||||
let reports_after_resolve = PostReportQuery::builder()
|
let reports_after_resolve = PostReportQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.my_person_id(inserted_timmy.id)
|
.my_person_id(inserted_timmy.id)
|
||||||
.admin(false)
|
.admin(false)
|
||||||
.unresolved_only(Some(true))
|
.unresolved_only(Some(true))
|
||||||
|
@ -594,20 +593,20 @@ mod tests {
|
||||||
|
|
||||||
// Make sure the counts are correct
|
// Make sure the counts are correct
|
||||||
let report_count_after_resolved =
|
let report_count_after_resolved =
|
||||||
PostReportView::get_report_count(&mut *conn, inserted_timmy.id, false, None)
|
PostReportView::get_report_count(conn, inserted_timmy.id, false, None)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, report_count_after_resolved);
|
assert_eq!(1, report_count_after_resolved);
|
||||||
|
|
||||||
Person::delete(&mut *conn, inserted_timmy.id).await.unwrap();
|
Person::delete(conn, inserted_timmy.id).await.unwrap();
|
||||||
Person::delete(&mut *conn, inserted_sara.id).await.unwrap();
|
Person::delete(conn, inserted_sara.id).await.unwrap();
|
||||||
Person::delete(&mut *conn, inserted_jessica.id)
|
Person::delete(conn, inserted_jessica.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Community::delete(&mut *conn, inserted_community.id)
|
Community::delete(conn, inserted_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Instance::delete(&mut *conn, inserted_instance.id)
|
Instance::delete(conn, inserted_instance.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ use diesel::{
|
||||||
PgTextExpressionMethods,
|
PgTextExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
aggregates::structs::PostAggregates,
|
aggregates::structs::PostAggregates,
|
||||||
newtypes::{CommunityId, LocalUserId, PersonId, PostId},
|
newtypes::{CommunityId, LocalUserId, PersonId, PostId},
|
||||||
|
@ -40,7 +39,7 @@ use lemmy_db_schema::{
|
||||||
post::{Post, PostRead, PostSaved},
|
post::{Post, PostRead, PostSaved},
|
||||||
},
|
},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{fuzzy_search, limit_and_offset, DbConn},
|
utils::{fuzzy_search, limit_and_offset, GetConn, RunQueryDsl},
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
|
@ -65,7 +64,7 @@ sql_function!(fn coalesce(x: sql_types::Nullable<sql_types::BigInt>, y: sql_type
|
||||||
|
|
||||||
impl PostView {
|
impl PostView {
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
post_id: PostId,
|
post_id: PostId,
|
||||||
my_person_id: Option<PersonId>,
|
my_person_id: Option<PersonId>,
|
||||||
is_mod_or_admin: Option<bool>,
|
is_mod_or_admin: Option<bool>,
|
||||||
|
@ -165,7 +164,7 @@ impl PostView {
|
||||||
creator_blocked,
|
creator_blocked,
|
||||||
post_like,
|
post_like,
|
||||||
unread_comments,
|
unread_comments,
|
||||||
) = query.first::<PostViewTuple>(&mut *conn).await?;
|
) = query.first::<PostViewTuple>(conn).await?;
|
||||||
|
|
||||||
// If a person is given, then my_vote, if None, should be 0, not null
|
// If a person is given, then my_vote, if None, should be 0, not null
|
||||||
// Necessary to differentiate between other person's votes
|
// Necessary to differentiate between other person's votes
|
||||||
|
@ -210,7 +209,7 @@ pub struct PostQuery<'a, Conn> {
|
||||||
limit: Option<i64>,
|
limit: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Conn: DbConn> PostQuery<'a, Conn> {
|
impl<'a, Conn: GetConn> PostQuery<'a, Conn> {
|
||||||
pub async fn list(self) -> Result<Vec<PostView>, Error> {
|
pub async fn list(self) -> Result<Vec<PostView>, Error> {
|
||||||
let mut conn = self.conn;
|
let mut conn = self.conn;
|
||||||
|
|
||||||
|
@ -448,7 +447,7 @@ impl<'a, Conn: DbConn> PostQuery<'a, Conn> {
|
||||||
|
|
||||||
debug!("Post View Query: {:?}", debug_query::<Pg, _>(&query));
|
debug!("Post View Query: {:?}", debug_query::<Pg, _>(&query));
|
||||||
|
|
||||||
let res = query.load::<PostViewTuple>(&mut *conn).await?;
|
let res = query.load::<PostViewTuple>(conn).await?;
|
||||||
|
|
||||||
Ok(res.into_iter().map(PostView::from_tuple).collect())
|
Ok(res.into_iter().map(PostView::from_tuple).collect())
|
||||||
}
|
}
|
||||||
|
@ -492,7 +491,7 @@ mod tests {
|
||||||
post::{Post, PostInsertForm, PostLike, PostLikeForm, PostUpdateForm},
|
post::{Post, PostInsertForm, PostLike, PostLikeForm, PostUpdateForm},
|
||||||
},
|
},
|
||||||
traits::{Blockable, Crud, Likeable},
|
traits::{Blockable, Crud, Likeable},
|
||||||
utils::{build_db_conn_for_tests, DbConn},
|
utils::{build_db_conn_for_tests, GetConn},
|
||||||
SortType,
|
SortType,
|
||||||
SubscribedType,
|
SubscribedType,
|
||||||
};
|
};
|
||||||
|
@ -508,8 +507,8 @@ mod tests {
|
||||||
inserted_post: Post,
|
inserted_post: Post,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn init_data(mut conn: impl DbConn) -> Data {
|
async fn init_data(mut conn: impl GetConn) -> Data {
|
||||||
let inserted_instance = Instance::read_or_create(&mut *conn, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(conn, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -521,13 +520,13 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_person = Person::create(&mut *conn, &new_person).await.unwrap();
|
let inserted_person = Person::create(conn, &new_person).await.unwrap();
|
||||||
|
|
||||||
let local_user_form = LocalUserInsertForm::builder()
|
let local_user_form = LocalUserInsertForm::builder()
|
||||||
.person_id(inserted_person.id)
|
.person_id(inserted_person.id)
|
||||||
.password_encrypted(String::new())
|
.password_encrypted(String::new())
|
||||||
.build();
|
.build();
|
||||||
let inserted_local_user = LocalUser::create(&mut *conn, &local_user_form)
|
let inserted_local_user = LocalUser::create(conn, &local_user_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -538,7 +537,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_bot = Person::create(&mut *conn, &new_bot).await.unwrap();
|
let inserted_bot = Person::create(conn, &new_bot).await.unwrap();
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::builder()
|
let new_community = CommunityInsertForm::builder()
|
||||||
.name("test_community_3".to_string())
|
.name("test_community_3".to_string())
|
||||||
|
@ -547,7 +546,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_community = Community::create(&mut *conn, &new_community).await.unwrap();
|
let inserted_community = Community::create(conn, &new_community).await.unwrap();
|
||||||
|
|
||||||
// Test a person block, make sure the post query doesn't include their post
|
// Test a person block, make sure the post query doesn't include their post
|
||||||
let blocked_person = PersonInsertForm::builder()
|
let blocked_person = PersonInsertForm::builder()
|
||||||
|
@ -556,7 +555,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_blocked_person = Person::create(&mut *conn, &blocked_person).await.unwrap();
|
let inserted_blocked_person = Person::create(conn, &blocked_person).await.unwrap();
|
||||||
|
|
||||||
let post_from_blocked_person = PostInsertForm::builder()
|
let post_from_blocked_person = PostInsertForm::builder()
|
||||||
.name("blocked_person_post".to_string())
|
.name("blocked_person_post".to_string())
|
||||||
|
@ -565,7 +564,7 @@ mod tests {
|
||||||
.language_id(Some(LanguageId(1)))
|
.language_id(Some(LanguageId(1)))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Post::create(&mut *conn, &post_from_blocked_person)
|
Post::create(conn, &post_from_blocked_person)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -575,7 +574,7 @@ mod tests {
|
||||||
target_id: inserted_blocked_person.id,
|
target_id: inserted_blocked_person.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
PersonBlock::block(&mut *conn, &person_block).await.unwrap();
|
PersonBlock::block(conn, &person_block).await.unwrap();
|
||||||
|
|
||||||
// A sample post
|
// A sample post
|
||||||
let new_post = PostInsertForm::builder()
|
let new_post = PostInsertForm::builder()
|
||||||
|
@ -585,7 +584,7 @@ mod tests {
|
||||||
.language_id(Some(LanguageId(47)))
|
.language_id(Some(LanguageId(47)))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_post = Post::create(&mut *conn, &new_post).await.unwrap();
|
let inserted_post = Post::create(conn, &new_post).await.unwrap();
|
||||||
|
|
||||||
let new_bot_post = PostInsertForm::builder()
|
let new_bot_post = PostInsertForm::builder()
|
||||||
.name("test bot post".to_string())
|
.name("test bot post".to_string())
|
||||||
|
@ -593,7 +592,7 @@ mod tests {
|
||||||
.community_id(inserted_community.id)
|
.community_id(inserted_community.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let _inserted_bot_post = Post::create(&mut *conn, &new_bot_post).await.unwrap();
|
let _inserted_bot_post = Post::create(conn, &new_bot_post).await.unwrap();
|
||||||
|
|
||||||
Data {
|
Data {
|
||||||
inserted_instance,
|
inserted_instance,
|
||||||
|
@ -610,18 +609,18 @@ mod tests {
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn post_listing_with_person() {
|
async fn post_listing_with_person() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
let data = init_data(&mut *conn).await;
|
let data = init_data(conn).await;
|
||||||
|
|
||||||
let local_user_form = LocalUserUpdateForm::builder()
|
let local_user_form = LocalUserUpdateForm::builder()
|
||||||
.show_bot_accounts(Some(false))
|
.show_bot_accounts(Some(false))
|
||||||
.build();
|
.build();
|
||||||
let inserted_local_user =
|
let inserted_local_user =
|
||||||
LocalUser::update(&mut *conn, data.inserted_local_user.id, &local_user_form)
|
LocalUser::update(conn, data.inserted_local_user.id, &local_user_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let read_post_listing = PostQuery::builder()
|
let read_post_listing = PostQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.sort(Some(SortType::New))
|
.sort(Some(SortType::New))
|
||||||
.community_id(Some(data.inserted_community.id))
|
.community_id(Some(data.inserted_community.id))
|
||||||
.local_user(Some(&inserted_local_user))
|
.local_user(Some(&inserted_local_user))
|
||||||
|
@ -631,7 +630,7 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let post_listing_single_with_person = PostView::read(
|
let post_listing_single_with_person = PostView::read(
|
||||||
&mut *conn,
|
conn,
|
||||||
data.inserted_post.id,
|
data.inserted_post.id,
|
||||||
Some(data.inserted_person.id),
|
Some(data.inserted_person.id),
|
||||||
None,
|
None,
|
||||||
|
@ -639,7 +638,7 @@ mod tests {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut expected_post_listing_with_user = expected_post_view(&data, &mut *conn).await;
|
let mut expected_post_listing_with_user = expected_post_view(&data, conn).await;
|
||||||
|
|
||||||
// Should be only one person, IE the bot post, and blocked should be missing
|
// Should be only one person, IE the bot post, and blocked should be missing
|
||||||
assert_eq!(1, read_post_listing.len());
|
assert_eq!(1, read_post_listing.len());
|
||||||
|
@ -655,12 +654,12 @@ mod tests {
|
||||||
.show_bot_accounts(Some(true))
|
.show_bot_accounts(Some(true))
|
||||||
.build();
|
.build();
|
||||||
let inserted_local_user =
|
let inserted_local_user =
|
||||||
LocalUser::update(&mut *conn, data.inserted_local_user.id, &local_user_form)
|
LocalUser::update(conn, data.inserted_local_user.id, &local_user_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let post_listings_with_bots = PostQuery::builder()
|
let post_listings_with_bots = PostQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.sort(Some(SortType::New))
|
.sort(Some(SortType::New))
|
||||||
.community_id(Some(data.inserted_community.id))
|
.community_id(Some(data.inserted_community.id))
|
||||||
.local_user(Some(&inserted_local_user))
|
.local_user(Some(&inserted_local_user))
|
||||||
|
@ -671,17 +670,17 @@ mod tests {
|
||||||
// should include bot post which has "undetermined" language
|
// should include bot post which has "undetermined" language
|
||||||
assert_eq!(2, post_listings_with_bots.len());
|
assert_eq!(2, post_listings_with_bots.len());
|
||||||
|
|
||||||
cleanup(data, &mut *conn).await;
|
cleanup(data, conn).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn post_listing_no_person() {
|
async fn post_listing_no_person() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
let data = init_data(&mut *conn).await;
|
let data = init_data(conn).await;
|
||||||
|
|
||||||
let read_post_listing_multiple_no_person = PostQuery::builder()
|
let read_post_listing_multiple_no_person = PostQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.sort(Some(SortType::New))
|
.sort(Some(SortType::New))
|
||||||
.community_id(Some(data.inserted_community.id))
|
.community_id(Some(data.inserted_community.id))
|
||||||
.build()
|
.build()
|
||||||
|
@ -690,11 +689,11 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let read_post_listing_single_no_person =
|
let read_post_listing_single_no_person =
|
||||||
PostView::read(&mut *conn, data.inserted_post.id, None, None)
|
PostView::read(conn, data.inserted_post.id, None, None)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let expected_post_listing_no_person = expected_post_view(&data, &mut *conn).await;
|
let expected_post_listing_no_person = expected_post_view(&data, conn).await;
|
||||||
|
|
||||||
// Should be 2 posts, with the bot post, and the blocked
|
// Should be 2 posts, with the bot post, and the blocked
|
||||||
assert_eq!(3, read_post_listing_multiple_no_person.len());
|
assert_eq!(3, read_post_listing_multiple_no_person.len());
|
||||||
|
@ -708,25 +707,25 @@ mod tests {
|
||||||
read_post_listing_single_no_person
|
read_post_listing_single_no_person
|
||||||
);
|
);
|
||||||
|
|
||||||
cleanup(data, &mut *conn).await;
|
cleanup(data, conn).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn post_listing_block_community() {
|
async fn post_listing_block_community() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
let data = init_data(&mut *conn).await;
|
let data = init_data(conn).await;
|
||||||
|
|
||||||
let community_block = CommunityBlockForm {
|
let community_block = CommunityBlockForm {
|
||||||
person_id: data.inserted_person.id,
|
person_id: data.inserted_person.id,
|
||||||
community_id: data.inserted_community.id,
|
community_id: data.inserted_community.id,
|
||||||
};
|
};
|
||||||
CommunityBlock::block(&mut *conn, &community_block)
|
CommunityBlock::block(conn, &community_block)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let read_post_listings_with_person_after_block = PostQuery::builder()
|
let read_post_listings_with_person_after_block = PostQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.sort(Some(SortType::New))
|
.sort(Some(SortType::New))
|
||||||
.community_id(Some(data.inserted_community.id))
|
.community_id(Some(data.inserted_community.id))
|
||||||
.local_user(Some(&data.inserted_local_user))
|
.local_user(Some(&data.inserted_local_user))
|
||||||
|
@ -737,17 +736,17 @@ mod tests {
|
||||||
// Should be 0 posts after the community block
|
// Should be 0 posts after the community block
|
||||||
assert_eq!(0, read_post_listings_with_person_after_block.len());
|
assert_eq!(0, read_post_listings_with_person_after_block.len());
|
||||||
|
|
||||||
CommunityBlock::unblock(&mut *conn, &community_block)
|
CommunityBlock::unblock(conn, &community_block)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
cleanup(data, &mut *conn).await;
|
cleanup(data, conn).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn post_listing_like() {
|
async fn post_listing_like() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
let data = init_data(&mut *conn).await;
|
let data = init_data(conn).await;
|
||||||
|
|
||||||
let post_like_form = PostLikeForm {
|
let post_like_form = PostLikeForm {
|
||||||
post_id: data.inserted_post.id,
|
post_id: data.inserted_post.id,
|
||||||
|
@ -755,7 +754,7 @@ mod tests {
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_post_like = PostLike::like(&mut *conn, &post_like_form).await.unwrap();
|
let inserted_post_like = PostLike::like(conn, &post_like_form).await.unwrap();
|
||||||
|
|
||||||
let expected_post_like = PostLike {
|
let expected_post_like = PostLike {
|
||||||
id: inserted_post_like.id,
|
id: inserted_post_like.id,
|
||||||
|
@ -767,7 +766,7 @@ mod tests {
|
||||||
assert_eq!(expected_post_like, inserted_post_like);
|
assert_eq!(expected_post_like, inserted_post_like);
|
||||||
|
|
||||||
let post_listing_single_with_person = PostView::read(
|
let post_listing_single_with_person = PostView::read(
|
||||||
&mut *conn,
|
conn,
|
||||||
data.inserted_post.id,
|
data.inserted_post.id,
|
||||||
Some(data.inserted_person.id),
|
Some(data.inserted_person.id),
|
||||||
None,
|
None,
|
||||||
|
@ -775,7 +774,7 @@ mod tests {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut expected_post_with_upvote = expected_post_view(&data, &mut *conn).await;
|
let mut expected_post_with_upvote = expected_post_view(&data, conn).await;
|
||||||
expected_post_with_upvote.my_vote = Some(1);
|
expected_post_with_upvote.my_vote = Some(1);
|
||||||
expected_post_with_upvote.counts.score = 1;
|
expected_post_with_upvote.counts.score = 1;
|
||||||
expected_post_with_upvote.counts.upvotes = 1;
|
expected_post_with_upvote.counts.upvotes = 1;
|
||||||
|
@ -785,12 +784,12 @@ mod tests {
|
||||||
.show_bot_accounts(Some(false))
|
.show_bot_accounts(Some(false))
|
||||||
.build();
|
.build();
|
||||||
let inserted_local_user =
|
let inserted_local_user =
|
||||||
LocalUser::update(&mut *conn, data.inserted_local_user.id, &local_user_form)
|
LocalUser::update(conn, data.inserted_local_user.id, &local_user_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let read_post_listing = PostQuery::builder()
|
let read_post_listing = PostQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.sort(Some(SortType::New))
|
.sort(Some(SortType::New))
|
||||||
.community_id(Some(data.inserted_community.id))
|
.community_id(Some(data.inserted_community.id))
|
||||||
.local_user(Some(&inserted_local_user))
|
.local_user(Some(&inserted_local_user))
|
||||||
|
@ -802,20 +801,20 @@ mod tests {
|
||||||
|
|
||||||
assert_eq!(expected_post_with_upvote, read_post_listing[0]);
|
assert_eq!(expected_post_with_upvote, read_post_listing[0]);
|
||||||
|
|
||||||
let like_removed = PostLike::remove(&mut *conn, data.inserted_person.id, data.inserted_post.id)
|
let like_removed = PostLike::remove(conn, data.inserted_person.id, data.inserted_post.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, like_removed);
|
assert_eq!(1, like_removed);
|
||||||
cleanup(data, &mut *conn).await;
|
cleanup(data, conn).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn post_listing_person_language() {
|
async fn post_listing_person_language() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
let data = init_data(&mut *conn).await;
|
let data = init_data(conn).await;
|
||||||
|
|
||||||
let spanish_id = Language::read_id_from_code(&mut *conn, Some("es"))
|
let spanish_id = Language::read_id_from_code(conn, Some("es"))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -826,10 +825,10 @@ mod tests {
|
||||||
.language_id(Some(spanish_id))
|
.language_id(Some(spanish_id))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Post::create(&mut *conn, &post_spanish).await.unwrap();
|
Post::create(conn, &post_spanish).await.unwrap();
|
||||||
|
|
||||||
let post_listings_all = PostQuery::builder()
|
let post_listings_all = PostQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.sort(Some(SortType::New))
|
.sort(Some(SortType::New))
|
||||||
.local_user(Some(&data.inserted_local_user))
|
.local_user(Some(&data.inserted_local_user))
|
||||||
.build()
|
.build()
|
||||||
|
@ -840,16 +839,16 @@ mod tests {
|
||||||
// no language filters specified, all posts should be returned
|
// no language filters specified, all posts should be returned
|
||||||
assert_eq!(3, post_listings_all.len());
|
assert_eq!(3, post_listings_all.len());
|
||||||
|
|
||||||
let french_id = Language::read_id_from_code(&mut *conn, Some("fr"))
|
let french_id = Language::read_id_from_code(conn, Some("fr"))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
LocalUserLanguage::update(&mut *conn, vec![french_id], data.inserted_local_user.id)
|
LocalUserLanguage::update(conn, vec![french_id], data.inserted_local_user.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let post_listing_french = PostQuery::builder()
|
let post_listing_french = PostQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.sort(Some(SortType::New))
|
.sort(Some(SortType::New))
|
||||||
.local_user(Some(&data.inserted_local_user))
|
.local_user(Some(&data.inserted_local_user))
|
||||||
.build()
|
.build()
|
||||||
|
@ -864,14 +863,14 @@ mod tests {
|
||||||
.any(|p| p.post.language_id == french_id));
|
.any(|p| p.post.language_id == french_id));
|
||||||
|
|
||||||
LocalUserLanguage::update(
|
LocalUserLanguage::update(
|
||||||
&mut *conn,
|
conn,
|
||||||
vec![french_id, UNDETERMINED_ID],
|
vec![french_id, UNDETERMINED_ID],
|
||||||
data.inserted_local_user.id,
|
data.inserted_local_user.id,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let post_listings_french_und = PostQuery::builder()
|
let post_listings_french_und = PostQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.sort(Some(SortType::New))
|
.sort(Some(SortType::New))
|
||||||
.local_user(Some(&data.inserted_local_user))
|
.local_user(Some(&data.inserted_local_user))
|
||||||
.build()
|
.build()
|
||||||
|
@ -887,18 +886,18 @@ mod tests {
|
||||||
);
|
);
|
||||||
assert_eq!(french_id, post_listings_french_und[1].post.language_id);
|
assert_eq!(french_id, post_listings_french_und[1].post.language_id);
|
||||||
|
|
||||||
cleanup(data, &mut *conn).await;
|
cleanup(data, conn).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn post_listings_deleted() {
|
async fn post_listings_deleted() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
let data = init_data(&mut *conn).await;
|
let data = init_data(conn).await;
|
||||||
|
|
||||||
// Delete the post
|
// Delete the post
|
||||||
Post::update(
|
Post::update(
|
||||||
&mut *conn,
|
conn,
|
||||||
data.inserted_post.id,
|
data.inserted_post.id,
|
||||||
&PostUpdateForm::builder().deleted(Some(true)).build(),
|
&PostUpdateForm::builder().deleted(Some(true)).build(),
|
||||||
)
|
)
|
||||||
|
@ -907,7 +906,7 @@ mod tests {
|
||||||
|
|
||||||
// Make sure you don't see the deleted post in the results
|
// Make sure you don't see the deleted post in the results
|
||||||
let post_listings_no_admin = PostQuery::builder()
|
let post_listings_no_admin = PostQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.sort(Some(SortType::New))
|
.sort(Some(SortType::New))
|
||||||
.local_user(Some(&data.inserted_local_user))
|
.local_user(Some(&data.inserted_local_user))
|
||||||
.is_mod_or_admin(Some(false))
|
.is_mod_or_admin(Some(false))
|
||||||
|
@ -920,7 +919,7 @@ mod tests {
|
||||||
|
|
||||||
// Make sure they see both
|
// Make sure they see both
|
||||||
let post_listings_is_admin = PostQuery::builder()
|
let post_listings_is_admin = PostQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.sort(Some(SortType::New))
|
.sort(Some(SortType::New))
|
||||||
.local_user(Some(&data.inserted_local_user))
|
.local_user(Some(&data.inserted_local_user))
|
||||||
.is_mod_or_admin(Some(true))
|
.is_mod_or_admin(Some(true))
|
||||||
|
@ -931,38 +930,38 @@ mod tests {
|
||||||
|
|
||||||
assert_eq!(2, post_listings_is_admin.len());
|
assert_eq!(2, post_listings_is_admin.len());
|
||||||
|
|
||||||
cleanup(data, &mut *conn).await;
|
cleanup(data, conn).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn cleanup(data: Data, mut conn: impl DbConn) {
|
async fn cleanup(data: Data, mut conn: impl GetConn) {
|
||||||
let num_deleted = Post::delete(&mut *conn, data.inserted_post.id)
|
let num_deleted = Post::delete(conn, data.inserted_post.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Community::delete(&mut *conn, data.inserted_community.id)
|
Community::delete(conn, data.inserted_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Person::delete(&mut *conn, data.inserted_person.id)
|
Person::delete(conn, data.inserted_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Person::delete(&mut *conn, data.inserted_bot.id)
|
Person::delete(conn, data.inserted_bot.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Person::delete(&mut *conn, data.inserted_blocked_person.id)
|
Person::delete(conn, data.inserted_blocked_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Instance::delete(&mut *conn, data.inserted_instance.id)
|
Instance::delete(conn, data.inserted_instance.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, num_deleted);
|
assert_eq!(1, num_deleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn expected_post_view(data: &Data, mut conn: impl DbConn) -> PostView {
|
async fn expected_post_view(data: &Data, mut conn: impl GetConn) -> PostView {
|
||||||
let (inserted_person, inserted_community, inserted_post) = (
|
let (inserted_person, inserted_community, inserted_post) = (
|
||||||
&data.inserted_person,
|
&data.inserted_person,
|
||||||
&data.inserted_community,
|
&data.inserted_community,
|
||||||
&data.inserted_post,
|
&data.inserted_post,
|
||||||
);
|
);
|
||||||
let agg = PostAggregates::read(&mut *conn, inserted_post.id)
|
let agg = PostAggregates::read(conn, inserted_post.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::structs::PrivateMessageReportView;
|
use crate::structs::PrivateMessageReportView;
|
||||||
use diesel::{result::Error, ExpressionMethods, JoinOnDsl, NullableExpressionMethods, QueryDsl};
|
use diesel::{result::Error, ExpressionMethods, JoinOnDsl, NullableExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PrivateMessageReportId,
|
newtypes::PrivateMessageReportId,
|
||||||
schema::{person, private_message, private_message_report},
|
schema::{person, private_message, private_message_report},
|
||||||
|
@ -10,7 +9,7 @@ use lemmy_db_schema::{
|
||||||
private_message_report::PrivateMessageReport,
|
private_message_report::PrivateMessageReport,
|
||||||
},
|
},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbConn},
|
utils::{limit_and_offset, GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
use typed_builder::TypedBuilder;
|
use typed_builder::TypedBuilder;
|
||||||
|
|
||||||
|
@ -27,7 +26,7 @@ impl PrivateMessageReportView {
|
||||||
///
|
///
|
||||||
/// * `report_id` - the report id to obtain
|
/// * `report_id` - the report id to obtain
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
report_id: PrivateMessageReportId,
|
report_id: PrivateMessageReportId,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2);
|
let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2);
|
||||||
|
@ -53,7 +52,7 @@ impl PrivateMessageReportView {
|
||||||
person_alias_1.fields(person::all_columns),
|
person_alias_1.fields(person::all_columns),
|
||||||
person_alias_2.fields(person::all_columns).nullable(),
|
person_alias_2.fields(person::all_columns).nullable(),
|
||||||
))
|
))
|
||||||
.first::<PrivateMessageReportViewTuple>(&mut *conn)
|
.first::<PrivateMessageReportViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
@ -66,7 +65,7 @@ impl PrivateMessageReportView {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the current unresolved post report count for the communities you mod
|
/// Returns the current unresolved post report count for the communities you mod
|
||||||
pub async fn get_report_count(mut conn: impl DbConn) -> Result<i64, Error> {
|
pub async fn get_report_count(mut conn: impl GetConn) -> Result<i64, Error> {
|
||||||
use diesel::dsl::count;
|
use diesel::dsl::count;
|
||||||
|
|
||||||
private_message_report::table
|
private_message_report::table
|
||||||
|
@ -74,7 +73,7 @@ impl PrivateMessageReportView {
|
||||||
.filter(private_message_report::resolved.eq(false))
|
.filter(private_message_report::resolved.eq(false))
|
||||||
.into_boxed()
|
.into_boxed()
|
||||||
.select(count(private_message_report::id))
|
.select(count(private_message_report::id))
|
||||||
.first::<i64>(&mut *conn)
|
.first::<i64>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,7 +88,7 @@ pub struct PrivateMessageReportQuery<Conn> {
|
||||||
unresolved_only: Option<bool>,
|
unresolved_only: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Conn: DbConn> PrivateMessageReportQuery<Conn> {
|
impl<Conn: GetConn> PrivateMessageReportQuery<Conn> {
|
||||||
pub async fn list(self) -> Result<Vec<PrivateMessageReportView>, Error> {
|
pub async fn list(self) -> Result<Vec<PrivateMessageReportView>, Error> {
|
||||||
let mut conn = self.conn;
|
let mut conn = self.conn;
|
||||||
let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2);
|
let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2);
|
||||||
|
@ -125,7 +124,7 @@ impl<Conn: DbConn> PrivateMessageReportQuery<Conn> {
|
||||||
.offset(offset);
|
.offset(offset);
|
||||||
|
|
||||||
let res = query
|
let res = query
|
||||||
.load::<PrivateMessageReportViewTuple>(&mut *conn)
|
.load::<PrivateMessageReportViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(
|
Ok(
|
||||||
|
@ -170,7 +169,7 @@ mod tests {
|
||||||
async fn test_crud() {
|
async fn test_crud() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
let inserted_instance = Instance::read_or_create(&mut *conn, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(conn, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -179,14 +178,14 @@ mod tests {
|
||||||
.public_key("pubkey".to_string())
|
.public_key("pubkey".to_string())
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
let inserted_timmy = Person::create(&mut *conn, &new_person_1).await.unwrap();
|
let inserted_timmy = Person::create(conn, &new_person_1).await.unwrap();
|
||||||
|
|
||||||
let new_person_2 = PersonInsertForm::builder()
|
let new_person_2 = PersonInsertForm::builder()
|
||||||
.name("jessica_mrv".into())
|
.name("jessica_mrv".into())
|
||||||
.public_key("pubkey".to_string())
|
.public_key("pubkey".to_string())
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
let inserted_jessica = Person::create(&mut *conn, &new_person_2).await.unwrap();
|
let inserted_jessica = Person::create(conn, &new_person_2).await.unwrap();
|
||||||
|
|
||||||
// timmy sends private message to jessica
|
// timmy sends private message to jessica
|
||||||
let pm_form = PrivateMessageInsertForm::builder()
|
let pm_form = PrivateMessageInsertForm::builder()
|
||||||
|
@ -194,7 +193,7 @@ mod tests {
|
||||||
.recipient_id(inserted_jessica.id)
|
.recipient_id(inserted_jessica.id)
|
||||||
.content("something offensive".to_string())
|
.content("something offensive".to_string())
|
||||||
.build();
|
.build();
|
||||||
let pm = PrivateMessage::create(&mut *conn, &pm_form).await.unwrap();
|
let pm = PrivateMessage::create(conn, &pm_form).await.unwrap();
|
||||||
|
|
||||||
// jessica reports private message
|
// jessica reports private message
|
||||||
let pm_report_form = PrivateMessageReportForm {
|
let pm_report_form = PrivateMessageReportForm {
|
||||||
|
@ -203,12 +202,12 @@ mod tests {
|
||||||
private_message_id: pm.id,
|
private_message_id: pm.id,
|
||||||
reason: "its offensive".to_string(),
|
reason: "its offensive".to_string(),
|
||||||
};
|
};
|
||||||
let pm_report = PrivateMessageReport::report(&mut *conn, &pm_report_form)
|
let pm_report = PrivateMessageReport::report(conn, &pm_report_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let reports = PrivateMessageReportQuery::builder()
|
let reports = PrivateMessageReportQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.build()
|
.build()
|
||||||
.list()
|
.list()
|
||||||
.await
|
.await
|
||||||
|
@ -225,15 +224,15 @@ mod tests {
|
||||||
.public_key("pubkey".to_string())
|
.public_key("pubkey".to_string())
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
let inserted_admin = Person::create(&mut *conn, &new_person_3).await.unwrap();
|
let inserted_admin = Person::create(conn, &new_person_3).await.unwrap();
|
||||||
|
|
||||||
// admin resolves the report (after taking appropriate action)
|
// admin resolves the report (after taking appropriate action)
|
||||||
PrivateMessageReport::resolve(&mut *conn, pm_report.id, inserted_admin.id)
|
PrivateMessageReport::resolve(conn, pm_report.id, inserted_admin.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let reports = PrivateMessageReportQuery::builder()
|
let reports = PrivateMessageReportQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.unresolved_only(Some(false))
|
.unresolved_only(Some(false))
|
||||||
.build()
|
.build()
|
||||||
.list()
|
.list()
|
||||||
|
@ -247,7 +246,7 @@ mod tests {
|
||||||
reports[0].resolver.as_ref().unwrap().name
|
reports[0].resolver.as_ref().unwrap().name
|
||||||
);
|
);
|
||||||
|
|
||||||
Instance::delete(&mut *conn, inserted_instance.id)
|
Instance::delete(conn, inserted_instance.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,13 +8,12 @@ use diesel::{
|
||||||
JoinOnDsl,
|
JoinOnDsl,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{PersonId, PrivateMessageId},
|
newtypes::{PersonId, PrivateMessageId},
|
||||||
schema::{person, private_message},
|
schema::{person, private_message},
|
||||||
source::{person::Person, private_message::PrivateMessage},
|
source::{person::Person, private_message::PrivateMessage},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbConn},
|
utils::{limit_and_offset, GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
use typed_builder::TypedBuilder;
|
use typed_builder::TypedBuilder;
|
||||||
|
@ -23,7 +22,7 @@ type PrivateMessageViewTuple = (PrivateMessage, Person, Person);
|
||||||
|
|
||||||
impl PrivateMessageView {
|
impl PrivateMessageView {
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
private_message_id: PrivateMessageId,
|
private_message_id: PrivateMessageId,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
|
@ -40,7 +39,7 @@ impl PrivateMessageView {
|
||||||
person::all_columns,
|
person::all_columns,
|
||||||
person_alias_1.fields(person::all_columns),
|
person_alias_1.fields(person::all_columns),
|
||||||
))
|
))
|
||||||
.first::<PrivateMessageViewTuple>(&mut *conn)
|
.first::<PrivateMessageViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(PrivateMessageView {
|
Ok(PrivateMessageView {
|
||||||
|
@ -52,7 +51,7 @@ impl PrivateMessageView {
|
||||||
|
|
||||||
/// Gets the number of unread messages
|
/// Gets the number of unread messages
|
||||||
pub async fn get_unread_messages(
|
pub async fn get_unread_messages(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
my_person_id: PersonId,
|
my_person_id: PersonId,
|
||||||
) -> Result<i64, Error> {
|
) -> Result<i64, Error> {
|
||||||
use diesel::dsl::count;
|
use diesel::dsl::count;
|
||||||
|
@ -61,7 +60,7 @@ impl PrivateMessageView {
|
||||||
.filter(private_message::recipient_id.eq(my_person_id))
|
.filter(private_message::recipient_id.eq(my_person_id))
|
||||||
.filter(private_message::deleted.eq(false))
|
.filter(private_message::deleted.eq(false))
|
||||||
.select(count(private_message::id))
|
.select(count(private_message::id))
|
||||||
.first::<i64>(&mut *conn)
|
.first::<i64>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +77,7 @@ pub struct PrivateMessageQuery<Conn> {
|
||||||
limit: Option<i64>,
|
limit: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Conn: DbConn> PrivateMessageQuery<Conn> {
|
impl<Conn: GetConn> PrivateMessageQuery<Conn> {
|
||||||
pub async fn list(self) -> Result<Vec<PrivateMessageView>, Error> {
|
pub async fn list(self) -> Result<Vec<PrivateMessageView>, Error> {
|
||||||
let mut conn = self.conn;
|
let mut conn = self.conn;
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
|
@ -123,7 +122,7 @@ impl<Conn: DbConn> PrivateMessageQuery<Conn> {
|
||||||
debug_query::<Pg, _>(&query)
|
debug_query::<Pg, _>(&query)
|
||||||
);
|
);
|
||||||
|
|
||||||
let res = query.load::<PrivateMessageViewTuple>(&mut *conn).await?;
|
let res = query.load::<PrivateMessageViewTuple>(conn).await?;
|
||||||
|
|
||||||
Ok(
|
Ok(
|
||||||
res
|
res
|
||||||
|
|
|
@ -7,7 +7,6 @@ use diesel::{
|
||||||
NullableExpressionMethods,
|
NullableExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
schema::{local_user, person, registration_application},
|
schema::{local_user, person, registration_application},
|
||||||
source::{
|
source::{
|
||||||
|
@ -16,7 +15,7 @@ use lemmy_db_schema::{
|
||||||
registration_application::RegistrationApplication,
|
registration_application::RegistrationApplication,
|
||||||
},
|
},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbConn},
|
utils::{limit_and_offset, GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
use typed_builder::TypedBuilder;
|
use typed_builder::TypedBuilder;
|
||||||
|
|
||||||
|
@ -25,7 +24,7 @@ type RegistrationApplicationViewTuple =
|
||||||
|
|
||||||
impl RegistrationApplicationView {
|
impl RegistrationApplicationView {
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
registration_application_id: i32,
|
registration_application_id: i32,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
|
@ -48,7 +47,7 @@ impl RegistrationApplicationView {
|
||||||
person::all_columns,
|
person::all_columns,
|
||||||
person_alias_1.fields(person::all_columns).nullable(),
|
person_alias_1.fields(person::all_columns).nullable(),
|
||||||
))
|
))
|
||||||
.first::<RegistrationApplicationViewTuple>(&mut *conn)
|
.first::<RegistrationApplicationViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(RegistrationApplicationView {
|
Ok(RegistrationApplicationView {
|
||||||
|
@ -61,7 +60,7 @@ impl RegistrationApplicationView {
|
||||||
|
|
||||||
/// Returns the current unread registration_application count
|
/// Returns the current unread registration_application count
|
||||||
pub async fn get_unread_count(
|
pub async fn get_unread_count(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
verified_email_only: bool,
|
verified_email_only: bool,
|
||||||
) -> Result<i64, Error> {
|
) -> Result<i64, Error> {
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
|
@ -82,7 +81,7 @@ impl RegistrationApplicationView {
|
||||||
|
|
||||||
query
|
query
|
||||||
.select(count(registration_application::id))
|
.select(count(registration_application::id))
|
||||||
.first::<i64>(&mut *conn)
|
.first::<i64>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,7 +97,7 @@ pub struct RegistrationApplicationQuery<Conn> {
|
||||||
limit: Option<i64>,
|
limit: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Conn: DbConn> RegistrationApplicationQuery<Conn> {
|
impl<Conn: GetConn> RegistrationApplicationQuery<Conn> {
|
||||||
pub async fn list(self) -> Result<Vec<RegistrationApplicationView>, Error> {
|
pub async fn list(self) -> Result<Vec<RegistrationApplicationView>, Error> {
|
||||||
let mut conn = self.conn;
|
let mut conn = self.conn;
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
|
@ -135,7 +134,7 @@ impl<Conn: DbConn> RegistrationApplicationQuery<Conn> {
|
||||||
.order_by(registration_application::published.desc());
|
.order_by(registration_application::published.desc());
|
||||||
|
|
||||||
let res = query
|
let res = query
|
||||||
.load::<RegistrationApplicationViewTuple>(&mut *conn)
|
.load::<RegistrationApplicationViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(
|
Ok(
|
||||||
|
@ -186,7 +185,7 @@ mod tests {
|
||||||
async fn test_crud() {
|
async fn test_crud() {
|
||||||
let mut conn = build_db_conn_for_tests().await;
|
let mut conn = build_db_conn_for_tests().await;
|
||||||
|
|
||||||
let inserted_instance = Instance::read_or_create(&mut *conn, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(conn, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -197,7 +196,7 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_timmy_person = Person::create(&mut *conn, &timmy_person_form)
|
let inserted_timmy_person = Person::create(conn, &timmy_person_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -206,7 +205,7 @@ mod tests {
|
||||||
.password_encrypted("nada".to_string())
|
.password_encrypted("nada".to_string())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let _inserted_timmy_local_user = LocalUser::create(&mut *conn, &timmy_local_user_form)
|
let _inserted_timmy_local_user = LocalUser::create(conn, &timmy_local_user_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -216,14 +215,14 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_sara_person = Person::create(&mut *conn, &sara_person_form).await.unwrap();
|
let inserted_sara_person = Person::create(conn, &sara_person_form).await.unwrap();
|
||||||
|
|
||||||
let sara_local_user_form = LocalUserInsertForm::builder()
|
let sara_local_user_form = LocalUserInsertForm::builder()
|
||||||
.person_id(inserted_sara_person.id)
|
.person_id(inserted_sara_person.id)
|
||||||
.password_encrypted("nada".to_string())
|
.password_encrypted("nada".to_string())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_sara_local_user = LocalUser::create(&mut *conn, &sara_local_user_form)
|
let inserted_sara_local_user = LocalUser::create(conn, &sara_local_user_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -233,11 +232,11 @@ mod tests {
|
||||||
answer: "LET ME IIIIINN".to_string(),
|
answer: "LET ME IIIIINN".to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let sara_app = RegistrationApplication::create(&mut *conn, &sara_app_form)
|
let sara_app = RegistrationApplication::create(conn, &sara_app_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let read_sara_app_view = RegistrationApplicationView::read(&mut *conn, sara_app.id)
|
let read_sara_app_view = RegistrationApplicationView::read(conn, sara_app.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -247,14 +246,14 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_jess_person = Person::create(&mut *conn, &jess_person_form).await.unwrap();
|
let inserted_jess_person = Person::create(conn, &jess_person_form).await.unwrap();
|
||||||
|
|
||||||
let jess_local_user_form = LocalUserInsertForm::builder()
|
let jess_local_user_form = LocalUserInsertForm::builder()
|
||||||
.person_id(inserted_jess_person.id)
|
.person_id(inserted_jess_person.id)
|
||||||
.password_encrypted("nada".to_string())
|
.password_encrypted("nada".to_string())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_jess_local_user = LocalUser::create(&mut *conn, &jess_local_user_form)
|
let inserted_jess_local_user = LocalUser::create(conn, &jess_local_user_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -264,11 +263,11 @@ mod tests {
|
||||||
answer: "LET ME IIIIINN".to_string(),
|
answer: "LET ME IIIIINN".to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let jess_app = RegistrationApplication::create(&mut *conn, &jess_app_form)
|
let jess_app = RegistrationApplication::create(conn, &jess_app_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let read_jess_app_view = RegistrationApplicationView::read(&mut *conn, jess_app.id)
|
let read_jess_app_view = RegistrationApplicationView::read(conn, jess_app.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -328,7 +327,7 @@ mod tests {
|
||||||
|
|
||||||
// Do a batch read of the applications
|
// Do a batch read of the applications
|
||||||
let apps = RegistrationApplicationQuery::builder()
|
let apps = RegistrationApplicationQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.unread_only(Some(true))
|
.unread_only(Some(true))
|
||||||
.build()
|
.build()
|
||||||
.list()
|
.list()
|
||||||
|
@ -341,7 +340,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Make sure the counts are correct
|
// Make sure the counts are correct
|
||||||
let unread_count = RegistrationApplicationView::get_unread_count(&mut *conn, false)
|
let unread_count = RegistrationApplicationView::get_unread_count(conn, false)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(unread_count, 2);
|
assert_eq!(unread_count, 2);
|
||||||
|
@ -352,7 +351,7 @@ mod tests {
|
||||||
deny_reason: None,
|
deny_reason: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
RegistrationApplication::update(&mut *conn, sara_app.id, &approve_form)
|
RegistrationApplication::update(conn, sara_app.id, &approve_form)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -362,7 +361,7 @@ mod tests {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
LocalUser::update(
|
LocalUser::update(
|
||||||
&mut *conn,
|
conn,
|
||||||
inserted_sara_local_user.id,
|
inserted_sara_local_user.id,
|
||||||
&approve_local_user_form,
|
&approve_local_user_form,
|
||||||
)
|
)
|
||||||
|
@ -370,7 +369,7 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let read_sara_app_view_after_approve =
|
let read_sara_app_view_after_approve =
|
||||||
RegistrationApplicationView::read(&mut *conn, sara_app.id)
|
RegistrationApplicationView::read(conn, sara_app.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
@ -409,7 +408,7 @@ mod tests {
|
||||||
// Do a batch read of apps again
|
// Do a batch read of apps again
|
||||||
// It should show only jessicas which is unresolved
|
// It should show only jessicas which is unresolved
|
||||||
let apps_after_resolve = RegistrationApplicationQuery::builder()
|
let apps_after_resolve = RegistrationApplicationQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.unread_only(Some(true))
|
.unread_only(Some(true))
|
||||||
.build()
|
.build()
|
||||||
.list()
|
.list()
|
||||||
|
@ -419,30 +418,30 @@ mod tests {
|
||||||
|
|
||||||
// Make sure the counts are correct
|
// Make sure the counts are correct
|
||||||
let unread_count_after_approve =
|
let unread_count_after_approve =
|
||||||
RegistrationApplicationView::get_unread_count(&mut *conn, false)
|
RegistrationApplicationView::get_unread_count(conn, false)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(unread_count_after_approve, 1);
|
assert_eq!(unread_count_after_approve, 1);
|
||||||
|
|
||||||
// Make sure the not undenied_only has all the apps
|
// Make sure the not undenied_only has all the apps
|
||||||
let all_apps = RegistrationApplicationQuery::builder()
|
let all_apps = RegistrationApplicationQuery::builder()
|
||||||
.conn(&mut *conn)
|
.conn(conn)
|
||||||
.build()
|
.build()
|
||||||
.list()
|
.list()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(all_apps.len(), 2);
|
assert_eq!(all_apps.len(), 2);
|
||||||
|
|
||||||
Person::delete(&mut *conn, inserted_timmy_person.id)
|
Person::delete(conn, inserted_timmy_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Person::delete(&mut *conn, inserted_sara_person.id)
|
Person::delete(conn, inserted_sara_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Person::delete(&mut *conn, inserted_jess_person.id)
|
Person::delete(conn, inserted_jess_person.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
Instance::delete(&mut *conn, inserted_instance.id)
|
Instance::delete(conn, inserted_instance.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
use crate::structs::SiteView;
|
use crate::structs::SiteView;
|
||||||
use diesel::{result::Error, ExpressionMethods, JoinOnDsl, QueryDsl};
|
use diesel::{result::Error, ExpressionMethods, JoinOnDsl, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
aggregates::structs::SiteAggregates,
|
aggregates::structs::SiteAggregates,
|
||||||
schema::{local_site, local_site_rate_limit, site, site_aggregates},
|
schema::{local_site, local_site_rate_limit, site, site_aggregates},
|
||||||
source::{local_site::LocalSite, local_site_rate_limit::LocalSiteRateLimit, site::Site},
|
source::{local_site::LocalSite, local_site_rate_limit::LocalSiteRateLimit, site::Site},
|
||||||
utils::DbConn,
|
utils::{GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl SiteView {
|
impl SiteView {
|
||||||
pub async fn read_local(mut conn: impl DbConn) -> Result<Self, Error> {
|
pub async fn read_local(mut conn: impl GetConn) -> Result<Self, Error> {
|
||||||
let (mut site, local_site, local_site_rate_limit, counts) = site::table
|
let (mut site, local_site, local_site_rate_limit, counts) = site::table
|
||||||
.inner_join(local_site::table)
|
.inner_join(local_site::table)
|
||||||
.inner_join(
|
.inner_join(
|
||||||
|
@ -22,7 +21,7 @@ impl SiteView {
|
||||||
local_site_rate_limit::all_columns,
|
local_site_rate_limit::all_columns,
|
||||||
site_aggregates::all_columns,
|
site_aggregates::all_columns,
|
||||||
))
|
))
|
||||||
.first::<(Site, LocalSite, LocalSiteRateLimit, SiteAggregates)>(&mut *conn)
|
.first::<(Site, LocalSite, LocalSiteRateLimit, SiteAggregates)>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
site.private_key = None;
|
site.private_key = None;
|
||||||
|
|
|
@ -7,7 +7,6 @@ use diesel::{
|
||||||
NullableExpressionMethods,
|
NullableExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
aggregates::structs::CommentAggregates,
|
aggregates::structs::CommentAggregates,
|
||||||
newtypes::{CommentReplyId, PersonId},
|
newtypes::{CommentReplyId, PersonId},
|
||||||
|
@ -33,7 +32,7 @@ use lemmy_db_schema::{
|
||||||
post::Post,
|
post::Post,
|
||||||
},
|
},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbConn},
|
utils::{limit_and_offset, GetConn, RunQueryDsl},
|
||||||
CommentSortType,
|
CommentSortType,
|
||||||
};
|
};
|
||||||
use typed_builder::TypedBuilder;
|
use typed_builder::TypedBuilder;
|
||||||
|
@ -55,7 +54,7 @@ type CommentReplyViewTuple = (
|
||||||
|
|
||||||
impl CommentReplyView {
|
impl CommentReplyView {
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
comment_reply_id: CommentReplyId,
|
comment_reply_id: CommentReplyId,
|
||||||
my_person_id: Option<PersonId>,
|
my_person_id: Option<PersonId>,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
|
@ -134,7 +133,7 @@ impl CommentReplyView {
|
||||||
person_block::all_columns.nullable(),
|
person_block::all_columns.nullable(),
|
||||||
comment_like::score.nullable(),
|
comment_like::score.nullable(),
|
||||||
))
|
))
|
||||||
.first::<CommentReplyViewTuple>(&mut *conn)
|
.first::<CommentReplyViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(CommentReplyView {
|
Ok(CommentReplyView {
|
||||||
|
@ -155,7 +154,7 @@ impl CommentReplyView {
|
||||||
|
|
||||||
/// Gets the number of unread replies
|
/// Gets the number of unread replies
|
||||||
pub async fn get_unread_replies(
|
pub async fn get_unread_replies(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
my_person_id: PersonId,
|
my_person_id: PersonId,
|
||||||
) -> Result<i64, Error> {
|
) -> Result<i64, Error> {
|
||||||
use diesel::dsl::count;
|
use diesel::dsl::count;
|
||||||
|
@ -167,7 +166,7 @@ impl CommentReplyView {
|
||||||
.filter(comment::deleted.eq(false))
|
.filter(comment::deleted.eq(false))
|
||||||
.filter(comment::removed.eq(false))
|
.filter(comment::removed.eq(false))
|
||||||
.select(count(comment_reply::id))
|
.select(count(comment_reply::id))
|
||||||
.first::<i64>(&mut *conn)
|
.first::<i64>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,7 +185,7 @@ pub struct CommentReplyQuery<Conn> {
|
||||||
limit: Option<i64>,
|
limit: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Conn: DbConn> CommentReplyQuery<Conn> {
|
impl<Conn: GetConn> CommentReplyQuery<Conn> {
|
||||||
pub async fn list(self) -> Result<Vec<CommentReplyView>, Error> {
|
pub async fn list(self) -> Result<Vec<CommentReplyView>, Error> {
|
||||||
let mut conn = self.conn;
|
let mut conn = self.conn;
|
||||||
|
|
||||||
|
@ -277,7 +276,7 @@ impl<Conn: DbConn> CommentReplyQuery<Conn> {
|
||||||
let res = query
|
let res = query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.load::<CommentReplyViewTuple>(&mut *conn)
|
.load::<CommentReplyViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(res.into_iter().map(CommentReplyView::from_tuple).collect())
|
Ok(res.into_iter().map(CommentReplyView::from_tuple).collect())
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
use crate::structs::CommunityBlockView;
|
use crate::structs::CommunityBlockView;
|
||||||
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
schema::{community, community_block, person},
|
schema::{community, community_block, person},
|
||||||
source::{community::Community, person::Person},
|
source::{community::Community, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::DbConn,
|
utils::{GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
|
|
||||||
type CommunityBlockViewTuple = (Person, Community);
|
type CommunityBlockViewTuple = (Person, Community);
|
||||||
|
|
||||||
impl CommunityBlockView {
|
impl CommunityBlockView {
|
||||||
pub async fn for_person(mut conn: impl DbConn, person_id: PersonId) -> Result<Vec<Self>, Error> {
|
pub async fn for_person(mut conn: impl GetConn, person_id: PersonId) -> Result<Vec<Self>, Error> {
|
||||||
let res = community_block::table
|
let res = community_block::table
|
||||||
.inner_join(person::table)
|
.inner_join(person::table)
|
||||||
.inner_join(community::table)
|
.inner_join(community::table)
|
||||||
|
@ -21,7 +20,7 @@ impl CommunityBlockView {
|
||||||
.filter(community::deleted.eq(false))
|
.filter(community::deleted.eq(false))
|
||||||
.filter(community::removed.eq(false))
|
.filter(community::removed.eq(false))
|
||||||
.order_by(community_block::published)
|
.order_by(community_block::published)
|
||||||
.load::<CommunityBlockViewTuple>(&mut *conn)
|
.load::<CommunityBlockViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(res.into_iter().map(Self::from_tuple).collect())
|
Ok(res.into_iter().map(Self::from_tuple).collect())
|
||||||
|
|
|
@ -1,19 +1,18 @@
|
||||||
use crate::structs::CommunityFollowerView;
|
use crate::structs::CommunityFollowerView;
|
||||||
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommunityId, PersonId},
|
newtypes::{CommunityId, PersonId},
|
||||||
schema::{community, community_follower, person},
|
schema::{community, community_follower, person},
|
||||||
source::{community::Community, person::Person},
|
source::{community::Community, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::DbConn,
|
utils::{GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
|
|
||||||
type CommunityFollowerViewTuple = (Community, Person);
|
type CommunityFollowerViewTuple = (Community, Person);
|
||||||
|
|
||||||
impl CommunityFollowerView {
|
impl CommunityFollowerView {
|
||||||
pub async fn for_community(
|
pub async fn for_community(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
let res = community_follower::table
|
let res = community_follower::table
|
||||||
|
@ -22,13 +21,13 @@ impl CommunityFollowerView {
|
||||||
.select((community::all_columns, person::all_columns))
|
.select((community::all_columns, person::all_columns))
|
||||||
.filter(community_follower::community_id.eq(community_id))
|
.filter(community_follower::community_id.eq(community_id))
|
||||||
.order_by(community::title)
|
.order_by(community::title)
|
||||||
.load::<CommunityFollowerViewTuple>(&mut *conn)
|
.load::<CommunityFollowerViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(res.into_iter().map(Self::from_tuple).collect())
|
Ok(res.into_iter().map(Self::from_tuple).collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn for_person(mut conn: impl DbConn, person_id: PersonId) -> Result<Vec<Self>, Error> {
|
pub async fn for_person(mut conn: impl GetConn, person_id: PersonId) -> Result<Vec<Self>, Error> {
|
||||||
let res = community_follower::table
|
let res = community_follower::table
|
||||||
.inner_join(community::table)
|
.inner_join(community::table)
|
||||||
.inner_join(person::table)
|
.inner_join(person::table)
|
||||||
|
@ -37,7 +36,7 @@ impl CommunityFollowerView {
|
||||||
.filter(community::deleted.eq(false))
|
.filter(community::deleted.eq(false))
|
||||||
.filter(community::removed.eq(false))
|
.filter(community::removed.eq(false))
|
||||||
.order_by(community::title)
|
.order_by(community::title)
|
||||||
.load::<CommunityFollowerViewTuple>(&mut *conn)
|
.load::<CommunityFollowerViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(res.into_iter().map(Self::from_tuple).collect())
|
Ok(res.into_iter().map(Self::from_tuple).collect())
|
||||||
|
|
|
@ -1,19 +1,18 @@
|
||||||
use crate::structs::CommunityModeratorView;
|
use crate::structs::CommunityModeratorView;
|
||||||
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommunityId, PersonId},
|
newtypes::{CommunityId, PersonId},
|
||||||
schema::{community, community_moderator, person},
|
schema::{community, community_moderator, person},
|
||||||
source::{community::Community, person::Person},
|
source::{community::Community, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::DbConn,
|
utils::{GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
|
|
||||||
type CommunityModeratorViewTuple = (Community, Person);
|
type CommunityModeratorViewTuple = (Community, Person);
|
||||||
|
|
||||||
impl CommunityModeratorView {
|
impl CommunityModeratorView {
|
||||||
pub async fn for_community(
|
pub async fn for_community(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
let res = community_moderator::table
|
let res = community_moderator::table
|
||||||
|
@ -21,13 +20,13 @@ impl CommunityModeratorView {
|
||||||
.inner_join(person::table)
|
.inner_join(person::table)
|
||||||
.select((community::all_columns, person::all_columns))
|
.select((community::all_columns, person::all_columns))
|
||||||
.filter(community_moderator::community_id.eq(community_id))
|
.filter(community_moderator::community_id.eq(community_id))
|
||||||
.load::<CommunityModeratorViewTuple>(&mut *conn)
|
.load::<CommunityModeratorViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(res.into_iter().map(Self::from_tuple).collect())
|
Ok(res.into_iter().map(Self::from_tuple).collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn for_person(mut conn: impl DbConn, person_id: PersonId) -> Result<Vec<Self>, Error> {
|
pub async fn for_person(mut conn: impl GetConn, person_id: PersonId) -> Result<Vec<Self>, Error> {
|
||||||
let res = community_moderator::table
|
let res = community_moderator::table
|
||||||
.inner_join(community::table)
|
.inner_join(community::table)
|
||||||
.inner_join(person::table)
|
.inner_join(person::table)
|
||||||
|
@ -35,7 +34,7 @@ impl CommunityModeratorView {
|
||||||
.filter(community_moderator::person_id.eq(person_id))
|
.filter(community_moderator::person_id.eq(person_id))
|
||||||
.filter(community::deleted.eq(false))
|
.filter(community::deleted.eq(false))
|
||||||
.filter(community::removed.eq(false))
|
.filter(community::removed.eq(false))
|
||||||
.load::<CommunityModeratorViewTuple>(&mut *conn)
|
.load::<CommunityModeratorViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(res.into_iter().map(Self::from_tuple).collect())
|
Ok(res.into_iter().map(Self::from_tuple).collect())
|
||||||
|
@ -43,7 +42,7 @@ impl CommunityModeratorView {
|
||||||
|
|
||||||
/// Finds all communities first mods / creators
|
/// Finds all communities first mods / creators
|
||||||
/// Ideally this should be a group by, but diesel doesn't support it yet
|
/// Ideally this should be a group by, but diesel doesn't support it yet
|
||||||
pub async fn get_community_first_mods(mut conn: impl DbConn) -> Result<Vec<Self>, Error> {
|
pub async fn get_community_first_mods(mut conn: impl GetConn) -> Result<Vec<Self>, Error> {
|
||||||
let res = community_moderator::table
|
let res = community_moderator::table
|
||||||
.inner_join(community::table)
|
.inner_join(community::table)
|
||||||
.inner_join(person::table)
|
.inner_join(person::table)
|
||||||
|
@ -55,7 +54,7 @@ impl CommunityModeratorView {
|
||||||
community_moderator::community_id,
|
community_moderator::community_id,
|
||||||
community_moderator::person_id,
|
community_moderator::person_id,
|
||||||
))
|
))
|
||||||
.load::<CommunityModeratorViewTuple>(&mut *conn)
|
.load::<CommunityModeratorViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(res.into_iter().map(Self::from_tuple).collect())
|
Ok(res.into_iter().map(Self::from_tuple).collect())
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
use crate::structs::CommunityPersonBanView;
|
use crate::structs::CommunityPersonBanView;
|
||||||
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommunityId, PersonId},
|
newtypes::{CommunityId, PersonId},
|
||||||
schema::{community, community_person_ban, person},
|
schema::{community, community_person_ban, person},
|
||||||
source::{community::Community, person::Person},
|
source::{community::Community, person::Person},
|
||||||
utils::DbConn,
|
utils::{GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl CommunityPersonBanView {
|
impl CommunityPersonBanView {
|
||||||
pub async fn get(
|
pub async fn get(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
from_person_id: PersonId,
|
from_person_id: PersonId,
|
||||||
from_community_id: CommunityId,
|
from_community_id: CommunityId,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
|
@ -21,7 +20,7 @@ impl CommunityPersonBanView {
|
||||||
.filter(community_person_ban::community_id.eq(from_community_id))
|
.filter(community_person_ban::community_id.eq(from_community_id))
|
||||||
.filter(community_person_ban::person_id.eq(from_person_id))
|
.filter(community_person_ban::person_id.eq(from_person_id))
|
||||||
.order_by(community_person_ban::published)
|
.order_by(community_person_ban::published)
|
||||||
.first::<(Community, Person)>(&mut *conn)
|
.first::<(Community, Person)>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(CommunityPersonBanView { community, person })
|
Ok(CommunityPersonBanView { community, person })
|
||||||
|
|
|
@ -8,7 +8,6 @@ use diesel::{
|
||||||
PgTextExpressionMethods,
|
PgTextExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
aggregates::structs::CommunityAggregates,
|
aggregates::structs::CommunityAggregates,
|
||||||
newtypes::{CommunityId, PersonId},
|
newtypes::{CommunityId, PersonId},
|
||||||
|
@ -19,7 +18,7 @@ use lemmy_db_schema::{
|
||||||
local_user::LocalUser,
|
local_user::LocalUser,
|
||||||
},
|
},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{fuzzy_search, limit_and_offset, DbConn},
|
utils::{fuzzy_search, limit_and_offset, GetConn, RunQueryDsl},
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
|
@ -34,7 +33,7 @@ type CommunityViewTuple = (
|
||||||
|
|
||||||
impl CommunityView {
|
impl CommunityView {
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
my_person_id: Option<PersonId>,
|
my_person_id: Option<PersonId>,
|
||||||
is_mod_or_admin: Option<bool>,
|
is_mod_or_admin: Option<bool>,
|
||||||
|
@ -75,7 +74,7 @@ impl CommunityView {
|
||||||
}
|
}
|
||||||
|
|
||||||
let (community, counts, follower, blocked) =
|
let (community, counts, follower, blocked) =
|
||||||
query.first::<CommunityViewTuple>(&mut *conn).await?;
|
query.first::<CommunityViewTuple>(conn).await?;
|
||||||
|
|
||||||
Ok(CommunityView {
|
Ok(CommunityView {
|
||||||
community,
|
community,
|
||||||
|
@ -86,11 +85,11 @@ impl CommunityView {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn is_mod_or_admin(
|
pub async fn is_mod_or_admin(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
person_id: PersonId,
|
person_id: PersonId,
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
) -> Result<bool, Error> {
|
) -> Result<bool, Error> {
|
||||||
let is_mod = CommunityModeratorView::for_community(&mut *conn, community_id)
|
let is_mod = CommunityModeratorView::for_community(conn, community_id)
|
||||||
.await
|
.await
|
||||||
.map(|v| {
|
.map(|v| {
|
||||||
v.into_iter()
|
v.into_iter()
|
||||||
|
@ -103,7 +102,7 @@ impl CommunityView {
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
let is_admin = PersonView::admins(&mut *conn)
|
let is_admin = PersonView::admins(conn)
|
||||||
.await
|
.await
|
||||||
.map(|v| {
|
.map(|v| {
|
||||||
v.into_iter()
|
v.into_iter()
|
||||||
|
@ -131,7 +130,7 @@ pub struct CommunityQuery<'a, Conn> {
|
||||||
limit: Option<i64>,
|
limit: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Conn: DbConn> CommunityQuery<'a, Conn> {
|
impl<'a, Conn: GetConn> CommunityQuery<'a, Conn> {
|
||||||
pub async fn list(self) -> Result<Vec<CommunityView>, Error> {
|
pub async fn list(self) -> Result<Vec<CommunityView>, Error> {
|
||||||
use SortType::*;
|
use SortType::*;
|
||||||
|
|
||||||
|
@ -224,7 +223,7 @@ impl<'a, Conn: DbConn> CommunityQuery<'a, Conn> {
|
||||||
let res = query
|
let res = query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.load::<CommunityViewTuple>(&mut *conn)
|
.load::<CommunityViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(res.into_iter().map(CommunityView::from_tuple).collect())
|
Ok(res.into_iter().map(CommunityView::from_tuple).collect())
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
use crate::structs::PersonBlockView;
|
use crate::structs::PersonBlockView;
|
||||||
use diesel::{result::Error, ExpressionMethods, JoinOnDsl, QueryDsl};
|
use diesel::{result::Error, ExpressionMethods, JoinOnDsl, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
schema::{person, person_block},
|
schema::{person, person_block},
|
||||||
source::person::Person,
|
source::person::Person,
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::DbConn,
|
utils::{GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
|
|
||||||
type PersonBlockViewTuple = (Person, Person);
|
type PersonBlockViewTuple = (Person, Person);
|
||||||
|
|
||||||
impl PersonBlockView {
|
impl PersonBlockView {
|
||||||
pub async fn for_person(mut conn: impl DbConn, person_id: PersonId) -> Result<Vec<Self>, Error> {
|
pub async fn for_person(mut conn: impl GetConn, person_id: PersonId) -> Result<Vec<Self>, Error> {
|
||||||
let target_person_alias = diesel::alias!(person as person1);
|
let target_person_alias = diesel::alias!(person as person1);
|
||||||
|
|
||||||
let res = person_block::table
|
let res = person_block::table
|
||||||
|
@ -27,7 +26,7 @@ impl PersonBlockView {
|
||||||
.filter(person_block::person_id.eq(person_id))
|
.filter(person_block::person_id.eq(person_id))
|
||||||
.filter(target_person_alias.field(person::deleted).eq(false))
|
.filter(target_person_alias.field(person::deleted).eq(false))
|
||||||
.order_by(person_block::published)
|
.order_by(person_block::published)
|
||||||
.load::<PersonBlockViewTuple>(&mut *conn)
|
.load::<PersonBlockViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(res.into_iter().map(Self::from_tuple).collect())
|
Ok(res.into_iter().map(Self::from_tuple).collect())
|
||||||
|
|
|
@ -8,7 +8,6 @@ use diesel::{
|
||||||
NullableExpressionMethods,
|
NullableExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
aggregates::structs::CommentAggregates,
|
aggregates::structs::CommentAggregates,
|
||||||
newtypes::{PersonId, PersonMentionId},
|
newtypes::{PersonId, PersonMentionId},
|
||||||
|
@ -34,7 +33,7 @@ use lemmy_db_schema::{
|
||||||
post::Post,
|
post::Post,
|
||||||
},
|
},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbConn},
|
utils::{limit_and_offset, GetConn, RunQueryDsl},
|
||||||
CommentSortType,
|
CommentSortType,
|
||||||
};
|
};
|
||||||
use typed_builder::TypedBuilder;
|
use typed_builder::TypedBuilder;
|
||||||
|
@ -56,7 +55,7 @@ type PersonMentionViewTuple = (
|
||||||
|
|
||||||
impl PersonMentionView {
|
impl PersonMentionView {
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
person_mention_id: PersonMentionId,
|
person_mention_id: PersonMentionId,
|
||||||
my_person_id: Option<PersonId>,
|
my_person_id: Option<PersonId>,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
|
@ -135,7 +134,7 @@ impl PersonMentionView {
|
||||||
person_block::all_columns.nullable(),
|
person_block::all_columns.nullable(),
|
||||||
comment_like::score.nullable(),
|
comment_like::score.nullable(),
|
||||||
))
|
))
|
||||||
.first::<PersonMentionViewTuple>(&mut *conn)
|
.first::<PersonMentionViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(PersonMentionView {
|
Ok(PersonMentionView {
|
||||||
|
@ -156,7 +155,7 @@ impl PersonMentionView {
|
||||||
|
|
||||||
/// Gets the number of unread mentions
|
/// Gets the number of unread mentions
|
||||||
pub async fn get_unread_mentions(
|
pub async fn get_unread_mentions(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
my_person_id: PersonId,
|
my_person_id: PersonId,
|
||||||
) -> Result<i64, Error> {
|
) -> Result<i64, Error> {
|
||||||
use diesel::dsl::count;
|
use diesel::dsl::count;
|
||||||
|
@ -168,7 +167,7 @@ impl PersonMentionView {
|
||||||
.filter(comment::deleted.eq(false))
|
.filter(comment::deleted.eq(false))
|
||||||
.filter(comment::removed.eq(false))
|
.filter(comment::removed.eq(false))
|
||||||
.select(count(person_mention::id))
|
.select(count(person_mention::id))
|
||||||
.first::<i64>(&mut *conn)
|
.first::<i64>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,7 +186,7 @@ pub struct PersonMentionQuery<Conn> {
|
||||||
limit: Option<i64>,
|
limit: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Conn: DbConn> PersonMentionQuery<Conn> {
|
impl<Conn: GetConn> PersonMentionQuery<Conn> {
|
||||||
pub async fn list(self) -> Result<Vec<PersonMentionView>, Error> {
|
pub async fn list(self) -> Result<Vec<PersonMentionView>, Error> {
|
||||||
let mut conn = self.conn;
|
let mut conn = self.conn;
|
||||||
|
|
||||||
|
@ -283,7 +282,7 @@ impl<Conn: DbConn> PersonMentionQuery<Conn> {
|
||||||
let res = query
|
let res = query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.load::<PersonMentionViewTuple>(&mut *conn)
|
.load::<PersonMentionViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(res.into_iter().map(PersonMentionView::from_tuple).collect())
|
Ok(res.into_iter().map(PersonMentionView::from_tuple).collect())
|
||||||
|
|
|
@ -7,14 +7,13 @@ use diesel::{
|
||||||
PgTextExpressionMethods,
|
PgTextExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
aggregates::structs::PersonAggregates,
|
aggregates::structs::PersonAggregates,
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
schema::{person, person_aggregates},
|
schema::{person, person_aggregates},
|
||||||
source::person::Person,
|
source::person::Person,
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{fuzzy_search, limit_and_offset, DbConn},
|
utils::{fuzzy_search, limit_and_offset, GetConn, RunQueryDsl},
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
use std::iter::Iterator;
|
use std::iter::Iterator;
|
||||||
|
@ -23,30 +22,30 @@ use typed_builder::TypedBuilder;
|
||||||
type PersonViewTuple = (Person, PersonAggregates);
|
type PersonViewTuple = (Person, PersonAggregates);
|
||||||
|
|
||||||
impl PersonView {
|
impl PersonView {
|
||||||
pub async fn read(mut conn: impl DbConn, person_id: PersonId) -> Result<Self, Error> {
|
pub async fn read(mut conn: impl GetConn, person_id: PersonId) -> Result<Self, Error> {
|
||||||
let res = person::table
|
let res = person::table
|
||||||
.find(person_id)
|
.find(person_id)
|
||||||
.inner_join(person_aggregates::table)
|
.inner_join(person_aggregates::table)
|
||||||
.select((person::all_columns, person_aggregates::all_columns))
|
.select((person::all_columns, person_aggregates::all_columns))
|
||||||
.first::<PersonViewTuple>(&mut *conn)
|
.first::<PersonViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(Self::from_tuple(res))
|
Ok(Self::from_tuple(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn admins(mut conn: impl DbConn) -> Result<Vec<Self>, Error> {
|
pub async fn admins(mut conn: impl GetConn) -> Result<Vec<Self>, Error> {
|
||||||
let admins = person::table
|
let admins = person::table
|
||||||
.inner_join(person_aggregates::table)
|
.inner_join(person_aggregates::table)
|
||||||
.select((person::all_columns, person_aggregates::all_columns))
|
.select((person::all_columns, person_aggregates::all_columns))
|
||||||
.filter(person::admin.eq(true))
|
.filter(person::admin.eq(true))
|
||||||
.filter(person::deleted.eq(false))
|
.filter(person::deleted.eq(false))
|
||||||
.order_by(person::published)
|
.order_by(person::published)
|
||||||
.load::<PersonViewTuple>(&mut *conn)
|
.load::<PersonViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(admins.into_iter().map(Self::from_tuple).collect())
|
Ok(admins.into_iter().map(Self::from_tuple).collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn banned(mut conn: impl DbConn) -> Result<Vec<Self>, Error> {
|
pub async fn banned(mut conn: impl GetConn) -> Result<Vec<Self>, Error> {
|
||||||
let banned = person::table
|
let banned = person::table
|
||||||
.inner_join(person_aggregates::table)
|
.inner_join(person_aggregates::table)
|
||||||
.select((person::all_columns, person_aggregates::all_columns))
|
.select((person::all_columns, person_aggregates::all_columns))
|
||||||
|
@ -58,7 +57,7 @@ impl PersonView {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.filter(person::deleted.eq(false))
|
.filter(person::deleted.eq(false))
|
||||||
.load::<PersonViewTuple>(&mut *conn)
|
.load::<PersonViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(banned.into_iter().map(Self::from_tuple).collect())
|
Ok(banned.into_iter().map(Self::from_tuple).collect())
|
||||||
|
@ -76,7 +75,7 @@ pub struct PersonQuery<Conn> {
|
||||||
limit: Option<i64>,
|
limit: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Conn: DbConn> PersonQuery<Conn> {
|
impl<Conn: GetConn> PersonQuery<Conn> {
|
||||||
pub async fn list(self) -> Result<Vec<PersonView>, Error> {
|
pub async fn list(self) -> Result<Vec<PersonView>, Error> {
|
||||||
let mut conn = self.conn;
|
let mut conn = self.conn;
|
||||||
let mut query = person::table
|
let mut query = person::table
|
||||||
|
@ -133,7 +132,7 @@ impl<Conn: DbConn> PersonQuery<Conn> {
|
||||||
let (limit, offset) = limit_and_offset(self.page, self.limit)?;
|
let (limit, offset) = limit_and_offset(self.page, self.limit)?;
|
||||||
query = query.limit(limit).offset(offset);
|
query = query.limit(limit).offset(offset);
|
||||||
|
|
||||||
let res = query.load::<PersonViewTuple>(&mut *conn).await?;
|
let res = query.load::<PersonViewTuple>(conn).await?;
|
||||||
|
|
||||||
Ok(res.into_iter().map(PersonView::from_tuple).collect())
|
Ok(res.into_iter().map(PersonView::from_tuple).collect())
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,19 +8,18 @@ use diesel::{
|
||||||
NullableExpressionMethods,
|
NullableExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
schema::{admin_purge_comment, person, post},
|
schema::{admin_purge_comment, person, post},
|
||||||
source::{moderator::AdminPurgeComment, person::Person, post::Post},
|
source::{moderator::AdminPurgeComment, person::Person, post::Post},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbConn},
|
utils::{limit_and_offset, GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
|
|
||||||
type AdminPurgeCommentViewTuple = (AdminPurgeComment, Option<Person>, Post);
|
type AdminPurgeCommentViewTuple = (AdminPurgeComment, Option<Person>, Post);
|
||||||
|
|
||||||
impl AdminPurgeCommentView {
|
impl AdminPurgeCommentView {
|
||||||
pub async fn list(mut conn: impl DbConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
pub async fn list(mut conn: impl GetConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
||||||
|
@ -49,7 +48,7 @@ impl AdminPurgeCommentView {
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.order_by(admin_purge_comment::when_.desc())
|
.order_by(admin_purge_comment::when_.desc())
|
||||||
.load::<AdminPurgeCommentViewTuple>(&mut *conn)
|
.load::<AdminPurgeCommentViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||||
|
|
|
@ -8,19 +8,18 @@ use diesel::{
|
||||||
NullableExpressionMethods,
|
NullableExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
schema::{admin_purge_community, person},
|
schema::{admin_purge_community, person},
|
||||||
source::{moderator::AdminPurgeCommunity, person::Person},
|
source::{moderator::AdminPurgeCommunity, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbConn},
|
utils::{limit_and_offset, GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
|
|
||||||
type AdminPurgeCommunityViewTuple = (AdminPurgeCommunity, Option<Person>);
|
type AdminPurgeCommunityViewTuple = (AdminPurgeCommunity, Option<Person>);
|
||||||
|
|
||||||
impl AdminPurgeCommunityView {
|
impl AdminPurgeCommunityView {
|
||||||
pub async fn list(mut conn: impl DbConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
pub async fn list(mut conn: impl GetConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
||||||
|
@ -47,7 +46,7 @@ impl AdminPurgeCommunityView {
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.order_by(admin_purge_community::when_.desc())
|
.order_by(admin_purge_community::when_.desc())
|
||||||
.load::<AdminPurgeCommunityViewTuple>(&mut *conn)
|
.load::<AdminPurgeCommunityViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||||
|
|
|
@ -8,19 +8,18 @@ use diesel::{
|
||||||
NullableExpressionMethods,
|
NullableExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
schema::{admin_purge_person, person},
|
schema::{admin_purge_person, person},
|
||||||
source::{moderator::AdminPurgePerson, person::Person},
|
source::{moderator::AdminPurgePerson, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbConn},
|
utils::{limit_and_offset, GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
|
|
||||||
type AdminPurgePersonViewTuple = (AdminPurgePerson, Option<Person>);
|
type AdminPurgePersonViewTuple = (AdminPurgePerson, Option<Person>);
|
||||||
|
|
||||||
impl AdminPurgePersonView {
|
impl AdminPurgePersonView {
|
||||||
pub async fn list(mut conn: impl DbConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
pub async fn list(mut conn: impl GetConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
||||||
|
@ -46,7 +45,7 @@ impl AdminPurgePersonView {
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.order_by(admin_purge_person::when_.desc())
|
.order_by(admin_purge_person::when_.desc())
|
||||||
.load::<AdminPurgePersonViewTuple>(&mut *conn)
|
.load::<AdminPurgePersonViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||||
|
|
|
@ -8,19 +8,18 @@ use diesel::{
|
||||||
NullableExpressionMethods,
|
NullableExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
schema::{admin_purge_post, community, person},
|
schema::{admin_purge_post, community, person},
|
||||||
source::{community::Community, moderator::AdminPurgePost, person::Person},
|
source::{community::Community, moderator::AdminPurgePost, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbConn},
|
utils::{limit_and_offset, GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
|
|
||||||
type AdminPurgePostViewTuple = (AdminPurgePost, Option<Person>, Community);
|
type AdminPurgePostViewTuple = (AdminPurgePost, Option<Person>, Community);
|
||||||
|
|
||||||
impl AdminPurgePostView {
|
impl AdminPurgePostView {
|
||||||
pub async fn list(mut conn: impl DbConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
pub async fn list(mut conn: impl GetConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
||||||
|
@ -48,7 +47,7 @@ impl AdminPurgePostView {
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.order_by(admin_purge_post::when_.desc())
|
.order_by(admin_purge_post::when_.desc())
|
||||||
.load::<AdminPurgePostViewTuple>(&mut *conn)
|
.load::<AdminPurgePostViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||||
|
|
|
@ -8,19 +8,18 @@ use diesel::{
|
||||||
NullableExpressionMethods,
|
NullableExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
schema::{community, mod_add_community, person},
|
schema::{community, mod_add_community, person},
|
||||||
source::{community::Community, moderator::ModAddCommunity, person::Person},
|
source::{community::Community, moderator::ModAddCommunity, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbConn},
|
utils::{limit_and_offset, GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModAddCommunityViewTuple = (ModAddCommunity, Option<Person>, Community, Person);
|
type ModAddCommunityViewTuple = (ModAddCommunity, Option<Person>, Community, Person);
|
||||||
|
|
||||||
impl ModAddCommunityView {
|
impl ModAddCommunityView {
|
||||||
pub async fn list(mut conn: impl DbConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
pub async fn list(mut conn: impl GetConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
|
@ -61,7 +60,7 @@ impl ModAddCommunityView {
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.order_by(mod_add_community::when_.desc())
|
.order_by(mod_add_community::when_.desc())
|
||||||
.load::<ModAddCommunityViewTuple>(&mut *conn)
|
.load::<ModAddCommunityViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||||
|
|
|
@ -8,19 +8,18 @@ use diesel::{
|
||||||
NullableExpressionMethods,
|
NullableExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
schema::{mod_add, person},
|
schema::{mod_add, person},
|
||||||
source::{moderator::ModAdd, person::Person},
|
source::{moderator::ModAdd, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbConn},
|
utils::{limit_and_offset, GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModAddViewTuple = (ModAdd, Option<Person>, Person);
|
type ModAddViewTuple = (ModAdd, Option<Person>, Person);
|
||||||
|
|
||||||
impl ModAddView {
|
impl ModAddView {
|
||||||
pub async fn list(mut conn: impl DbConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
pub async fn list(mut conn: impl GetConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
|
@ -53,7 +52,7 @@ impl ModAddView {
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.order_by(mod_add::when_.desc())
|
.order_by(mod_add::when_.desc())
|
||||||
.load::<ModAddViewTuple>(&mut *conn)
|
.load::<ModAddViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||||
|
|
|
@ -8,19 +8,18 @@ use diesel::{
|
||||||
NullableExpressionMethods,
|
NullableExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
schema::{community, mod_ban_from_community, person},
|
schema::{community, mod_ban_from_community, person},
|
||||||
source::{community::Community, moderator::ModBanFromCommunity, person::Person},
|
source::{community::Community, moderator::ModBanFromCommunity, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbConn},
|
utils::{limit_and_offset, GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModBanFromCommunityViewTuple = (ModBanFromCommunity, Option<Person>, Community, Person);
|
type ModBanFromCommunityViewTuple = (ModBanFromCommunity, Option<Person>, Community, Person);
|
||||||
|
|
||||||
impl ModBanFromCommunityView {
|
impl ModBanFromCommunityView {
|
||||||
pub async fn list(mut conn: impl DbConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
pub async fn list(mut conn: impl GetConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
|
@ -62,7 +61,7 @@ impl ModBanFromCommunityView {
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.order_by(mod_ban_from_community::when_.desc())
|
.order_by(mod_ban_from_community::when_.desc())
|
||||||
.load::<ModBanFromCommunityViewTuple>(&mut *conn)
|
.load::<ModBanFromCommunityViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||||
|
|
|
@ -8,19 +8,18 @@ use diesel::{
|
||||||
NullableExpressionMethods,
|
NullableExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
schema::{mod_ban, person},
|
schema::{mod_ban, person},
|
||||||
source::{moderator::ModBan, person::Person},
|
source::{moderator::ModBan, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbConn},
|
utils::{limit_and_offset, GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModBanViewTuple = (ModBan, Option<Person>, Person);
|
type ModBanViewTuple = (ModBan, Option<Person>, Person);
|
||||||
|
|
||||||
impl ModBanView {
|
impl ModBanView {
|
||||||
pub async fn list(mut conn: impl DbConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
pub async fn list(mut conn: impl GetConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
|
@ -53,7 +52,7 @@ impl ModBanView {
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.order_by(mod_ban::when_.desc())
|
.order_by(mod_ban::when_.desc())
|
||||||
.load::<ModBanViewTuple>(&mut *conn)
|
.load::<ModBanViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||||
|
|
|
@ -8,19 +8,18 @@ use diesel::{
|
||||||
NullableExpressionMethods,
|
NullableExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
schema::{community, mod_feature_post, person, post},
|
schema::{community, mod_feature_post, person, post},
|
||||||
source::{community::Community, moderator::ModFeaturePost, person::Person, post::Post},
|
source::{community::Community, moderator::ModFeaturePost, person::Person, post::Post},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbConn},
|
utils::{limit_and_offset, GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModFeaturePostViewTuple = (ModFeaturePost, Option<Person>, Post, Community);
|
type ModFeaturePostViewTuple = (ModFeaturePost, Option<Person>, Post, Community);
|
||||||
|
|
||||||
impl ModFeaturePostView {
|
impl ModFeaturePostView {
|
||||||
pub async fn list(mut conn: impl DbConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
pub async fn list(mut conn: impl GetConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
|
@ -60,7 +59,7 @@ impl ModFeaturePostView {
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.order_by(mod_feature_post::when_.desc())
|
.order_by(mod_feature_post::when_.desc())
|
||||||
.load::<ModFeaturePostViewTuple>(&mut *conn)
|
.load::<ModFeaturePostViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||||
|
|
|
@ -8,20 +8,19 @@ use diesel::{
|
||||||
NullableExpressionMethods,
|
NullableExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
schema::{community, mod_hide_community, person},
|
schema::{community, mod_hide_community, person},
|
||||||
source::{community::Community, moderator::ModHideCommunity, person::Person},
|
source::{community::Community, moderator::ModHideCommunity, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbConn},
|
utils::{limit_and_offset, GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModHideCommunityViewTuple = (ModHideCommunity, Option<Person>, Community);
|
type ModHideCommunityViewTuple = (ModHideCommunity, Option<Person>, Community);
|
||||||
|
|
||||||
impl ModHideCommunityView {
|
impl ModHideCommunityView {
|
||||||
// Pass in mod_id as admin_id because only admins can do this action
|
// Pass in mod_id as admin_id because only admins can do this action
|
||||||
pub async fn list(mut conn: impl DbConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
pub async fn list(mut conn: impl GetConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
||||||
|
@ -53,7 +52,7 @@ impl ModHideCommunityView {
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.order_by(mod_hide_community::when_.desc())
|
.order_by(mod_hide_community::when_.desc())
|
||||||
.load::<ModHideCommunityViewTuple>(&mut *conn)
|
.load::<ModHideCommunityViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||||
|
|
|
@ -8,19 +8,18 @@ use diesel::{
|
||||||
NullableExpressionMethods,
|
NullableExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
schema::{community, mod_lock_post, person, post},
|
schema::{community, mod_lock_post, person, post},
|
||||||
source::{community::Community, moderator::ModLockPost, person::Person, post::Post},
|
source::{community::Community, moderator::ModLockPost, person::Person, post::Post},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbConn},
|
utils::{limit_and_offset, GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModLockPostViewTuple = (ModLockPost, Option<Person>, Post, Community);
|
type ModLockPostViewTuple = (ModLockPost, Option<Person>, Post, Community);
|
||||||
|
|
||||||
impl ModLockPostView {
|
impl ModLockPostView {
|
||||||
pub async fn list(mut conn: impl DbConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
pub async fn list(mut conn: impl GetConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
|
@ -60,7 +59,7 @@ impl ModLockPostView {
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.order_by(mod_lock_post::when_.desc())
|
.order_by(mod_lock_post::when_.desc())
|
||||||
.load::<ModLockPostViewTuple>(&mut *conn)
|
.load::<ModLockPostViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||||
|
|
|
@ -8,7 +8,6 @@ use diesel::{
|
||||||
NullableExpressionMethods,
|
NullableExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
schema::{comment, community, mod_remove_comment, person, post},
|
schema::{comment, community, mod_remove_comment, person, post},
|
||||||
|
@ -20,7 +19,7 @@ use lemmy_db_schema::{
|
||||||
post::Post,
|
post::Post,
|
||||||
},
|
},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbConn},
|
utils::{limit_and_offset, GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModRemoveCommentViewTuple = (
|
type ModRemoveCommentViewTuple = (
|
||||||
|
@ -33,7 +32,7 @@ type ModRemoveCommentViewTuple = (
|
||||||
);
|
);
|
||||||
|
|
||||||
impl ModRemoveCommentView {
|
impl ModRemoveCommentView {
|
||||||
pub async fn list(mut conn: impl DbConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
pub async fn list(mut conn: impl GetConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
let person_alias_1 = diesel::alias!(lemmy_db_schema::schema::person as person1);
|
let person_alias_1 = diesel::alias!(lemmy_db_schema::schema::person as person1);
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
|
@ -76,7 +75,7 @@ impl ModRemoveCommentView {
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.order_by(mod_remove_comment::when_.desc())
|
.order_by(mod_remove_comment::when_.desc())
|
||||||
.load::<ModRemoveCommentViewTuple>(&mut *conn)
|
.load::<ModRemoveCommentViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||||
|
|
|
@ -8,19 +8,18 @@ use diesel::{
|
||||||
NullableExpressionMethods,
|
NullableExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
schema::{community, mod_remove_community, person},
|
schema::{community, mod_remove_community, person},
|
||||||
source::{community::Community, moderator::ModRemoveCommunity, person::Person},
|
source::{community::Community, moderator::ModRemoveCommunity, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbConn},
|
utils::{limit_and_offset, GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModRemoveCommunityTuple = (ModRemoveCommunity, Option<Person>, Community);
|
type ModRemoveCommunityTuple = (ModRemoveCommunity, Option<Person>, Community);
|
||||||
|
|
||||||
impl ModRemoveCommunityView {
|
impl ModRemoveCommunityView {
|
||||||
pub async fn list(mut conn: impl DbConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
pub async fn list(mut conn: impl GetConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
||||||
|
@ -48,7 +47,7 @@ impl ModRemoveCommunityView {
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.order_by(mod_remove_community::when_.desc())
|
.order_by(mod_remove_community::when_.desc())
|
||||||
.load::<ModRemoveCommunityTuple>(&mut *conn)
|
.load::<ModRemoveCommunityTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||||
|
|
|
@ -8,19 +8,18 @@ use diesel::{
|
||||||
NullableExpressionMethods,
|
NullableExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
schema::{community, mod_remove_post, person, post},
|
schema::{community, mod_remove_post, person, post},
|
||||||
source::{community::Community, moderator::ModRemovePost, person::Person, post::Post},
|
source::{community::Community, moderator::ModRemovePost, person::Person, post::Post},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbConn},
|
utils::{limit_and_offset, GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModRemovePostViewTuple = (ModRemovePost, Option<Person>, Post, Community);
|
type ModRemovePostViewTuple = (ModRemovePost, Option<Person>, Post, Community);
|
||||||
|
|
||||||
impl ModRemovePostView {
|
impl ModRemovePostView {
|
||||||
pub async fn list(mut conn: impl DbConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
pub async fn list(mut conn: impl GetConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
|
@ -60,7 +59,7 @@ impl ModRemovePostView {
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.order_by(mod_remove_post::when_.desc())
|
.order_by(mod_remove_post::when_.desc())
|
||||||
.load::<ModRemovePostViewTuple>(&mut *conn)
|
.load::<ModRemovePostViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||||
|
|
|
@ -8,19 +8,18 @@ use diesel::{
|
||||||
NullableExpressionMethods,
|
NullableExpressionMethods,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
schema::{community, mod_transfer_community, person},
|
schema::{community, mod_transfer_community, person},
|
||||||
source::{community::Community, moderator::ModTransferCommunity, person::Person},
|
source::{community::Community, moderator::ModTransferCommunity, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbConn},
|
utils::{limit_and_offset, GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModTransferCommunityViewTuple = (ModTransferCommunity, Option<Person>, Community, Person);
|
type ModTransferCommunityViewTuple = (ModTransferCommunity, Option<Person>, Community, Person);
|
||||||
|
|
||||||
impl ModTransferCommunityView {
|
impl ModTransferCommunityView {
|
||||||
pub async fn list(mut conn: impl DbConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
pub async fn list(mut conn: impl GetConn, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
|
@ -62,7 +61,7 @@ impl ModTransferCommunityView {
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.order_by(mod_transfer_community::when_.desc())
|
.order_by(mod_transfer_community::when_.desc())
|
||||||
.load::<ModTransferCommunityViewTuple>(&mut *conn)
|
.load::<ModTransferCommunityViewTuple>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||||
|
|
|
@ -7,7 +7,6 @@ use diesel::{
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
TextExpressionMethods,
|
TextExpressionMethods,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
lemmy_db_views::structs::SiteView,
|
lemmy_db_views::structs::SiteView,
|
||||||
utils::{
|
utils::{
|
||||||
|
@ -33,33 +32,33 @@ use lemmy_db_schema::{
|
||||||
site::{Site, SiteInsertForm, SiteUpdateForm},
|
site::{Site, SiteInsertForm, SiteUpdateForm},
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::{naive_now, DbConn},
|
utils::{naive_now, GetConn, RunQueryDsl},
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, settings::structs::Settings};
|
use lemmy_utils::{error::LemmyError, settings::structs::Settings};
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
pub async fn run_advanced_migrations(
|
pub async fn run_advanced_migrations(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
settings: &Settings,
|
settings: &Settings,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let protocol_and_hostname = &settings.get_protocol_and_hostname();
|
let protocol_and_hostname = &settings.get_protocol_and_hostname();
|
||||||
user_updates_2020_04_02(&mut *conn, protocol_and_hostname).await?;
|
user_updates_2020_04_02(conn, protocol_and_hostname).await?;
|
||||||
community_updates_2020_04_02(&mut *conn, protocol_and_hostname).await?;
|
community_updates_2020_04_02(conn, protocol_and_hostname).await?;
|
||||||
post_updates_2020_04_03(&mut *conn, protocol_and_hostname).await?;
|
post_updates_2020_04_03(conn, protocol_and_hostname).await?;
|
||||||
comment_updates_2020_04_03(&mut *conn, protocol_and_hostname).await?;
|
comment_updates_2020_04_03(conn, protocol_and_hostname).await?;
|
||||||
private_message_updates_2020_05_05(&mut *conn, protocol_and_hostname).await?;
|
private_message_updates_2020_05_05(conn, protocol_and_hostname).await?;
|
||||||
post_thumbnail_url_updates_2020_07_27(&mut *conn, protocol_and_hostname).await?;
|
post_thumbnail_url_updates_2020_07_27(conn, protocol_and_hostname).await?;
|
||||||
apub_columns_2021_02_02(&mut *conn).await?;
|
apub_columns_2021_02_02(conn).await?;
|
||||||
instance_actor_2022_01_28(&mut *conn, protocol_and_hostname).await?;
|
instance_actor_2022_01_28(conn, protocol_and_hostname).await?;
|
||||||
regenerate_public_keys_2022_07_05(&mut *conn).await?;
|
regenerate_public_keys_2022_07_05(conn).await?;
|
||||||
initialize_local_site_2022_10_10(&mut *conn, settings).await?;
|
initialize_local_site_2022_10_10(conn, settings).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn user_updates_2020_04_02(
|
async fn user_updates_2020_04_02(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
protocol_and_hostname: &str,
|
protocol_and_hostname: &str,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
use lemmy_db_schema::schema::person::dsl::{actor_id, local, person};
|
use lemmy_db_schema::schema::person::dsl::{actor_id, local, person};
|
||||||
|
@ -70,7 +69,7 @@ async fn user_updates_2020_04_02(
|
||||||
let incorrect_persons = person
|
let incorrect_persons = person
|
||||||
.filter(actor_id.like("http://changeme%"))
|
.filter(actor_id.like("http://changeme%"))
|
||||||
.filter(local.eq(true))
|
.filter(local.eq(true))
|
||||||
.load::<Person>(&mut *conn)
|
.load::<Person>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
for cperson in &incorrect_persons {
|
for cperson in &incorrect_persons {
|
||||||
|
@ -87,7 +86,7 @@ async fn user_updates_2020_04_02(
|
||||||
.last_refreshed_at(Some(naive_now()))
|
.last_refreshed_at(Some(naive_now()))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Person::update(&mut *conn, cperson.id, &form).await?;
|
Person::update(conn, cperson.id, &form).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("{} person rows updated.", incorrect_persons.len());
|
info!("{} person rows updated.", incorrect_persons.len());
|
||||||
|
@ -96,7 +95,7 @@ async fn user_updates_2020_04_02(
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn community_updates_2020_04_02(
|
async fn community_updates_2020_04_02(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
protocol_and_hostname: &str,
|
protocol_and_hostname: &str,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
use lemmy_db_schema::schema::community::dsl::{actor_id, community, local};
|
use lemmy_db_schema::schema::community::dsl::{actor_id, community, local};
|
||||||
|
@ -107,7 +106,7 @@ async fn community_updates_2020_04_02(
|
||||||
let incorrect_communities = community
|
let incorrect_communities = community
|
||||||
.filter(actor_id.like("http://changeme%"))
|
.filter(actor_id.like("http://changeme%"))
|
||||||
.filter(local.eq(true))
|
.filter(local.eq(true))
|
||||||
.load::<Community>(&mut *conn)
|
.load::<Community>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
for ccommunity in &incorrect_communities {
|
for ccommunity in &incorrect_communities {
|
||||||
|
@ -125,7 +124,7 @@ async fn community_updates_2020_04_02(
|
||||||
.last_refreshed_at(Some(naive_now()))
|
.last_refreshed_at(Some(naive_now()))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Community::update(&mut *conn, ccommunity.id, &form).await?;
|
Community::update(conn, ccommunity.id, &form).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("{} community rows updated.", incorrect_communities.len());
|
info!("{} community rows updated.", incorrect_communities.len());
|
||||||
|
@ -134,7 +133,7 @@ async fn community_updates_2020_04_02(
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn post_updates_2020_04_03(
|
async fn post_updates_2020_04_03(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
protocol_and_hostname: &str,
|
protocol_and_hostname: &str,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
use lemmy_db_schema::schema::post::dsl::{ap_id, local, post};
|
use lemmy_db_schema::schema::post::dsl::{ap_id, local, post};
|
||||||
|
@ -145,7 +144,7 @@ async fn post_updates_2020_04_03(
|
||||||
let incorrect_posts = post
|
let incorrect_posts = post
|
||||||
.filter(ap_id.like("http://changeme%"))
|
.filter(ap_id.like("http://changeme%"))
|
||||||
.filter(local.eq(true))
|
.filter(local.eq(true))
|
||||||
.load::<Post>(&mut *conn)
|
.load::<Post>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
for cpost in &incorrect_posts {
|
for cpost in &incorrect_posts {
|
||||||
|
@ -155,7 +154,7 @@ async fn post_updates_2020_04_03(
|
||||||
protocol_and_hostname,
|
protocol_and_hostname,
|
||||||
)?;
|
)?;
|
||||||
Post::update(
|
Post::update(
|
||||||
&mut *conn,
|
conn,
|
||||||
cpost.id,
|
cpost.id,
|
||||||
&PostUpdateForm::builder().ap_id(Some(apub_id)).build(),
|
&PostUpdateForm::builder().ap_id(Some(apub_id)).build(),
|
||||||
)
|
)
|
||||||
|
@ -168,7 +167,7 @@ async fn post_updates_2020_04_03(
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn comment_updates_2020_04_03(
|
async fn comment_updates_2020_04_03(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
protocol_and_hostname: &str,
|
protocol_and_hostname: &str,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
use lemmy_db_schema::schema::comment::dsl::{ap_id, comment, local};
|
use lemmy_db_schema::schema::comment::dsl::{ap_id, comment, local};
|
||||||
|
@ -179,7 +178,7 @@ async fn comment_updates_2020_04_03(
|
||||||
let incorrect_comments = comment
|
let incorrect_comments = comment
|
||||||
.filter(ap_id.like("http://changeme%"))
|
.filter(ap_id.like("http://changeme%"))
|
||||||
.filter(local.eq(true))
|
.filter(local.eq(true))
|
||||||
.load::<Comment>(&mut *conn)
|
.load::<Comment>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
for ccomment in &incorrect_comments {
|
for ccomment in &incorrect_comments {
|
||||||
|
@ -189,7 +188,7 @@ async fn comment_updates_2020_04_03(
|
||||||
protocol_and_hostname,
|
protocol_and_hostname,
|
||||||
)?;
|
)?;
|
||||||
Comment::update(
|
Comment::update(
|
||||||
&mut *conn,
|
conn,
|
||||||
ccomment.id,
|
ccomment.id,
|
||||||
&CommentUpdateForm::builder().ap_id(Some(apub_id)).build(),
|
&CommentUpdateForm::builder().ap_id(Some(apub_id)).build(),
|
||||||
)
|
)
|
||||||
|
@ -202,7 +201,7 @@ async fn comment_updates_2020_04_03(
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn private_message_updates_2020_05_05(
|
async fn private_message_updates_2020_05_05(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
protocol_and_hostname: &str,
|
protocol_and_hostname: &str,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
use lemmy_db_schema::schema::private_message::dsl::{ap_id, local, private_message};
|
use lemmy_db_schema::schema::private_message::dsl::{ap_id, local, private_message};
|
||||||
|
@ -213,7 +212,7 @@ async fn private_message_updates_2020_05_05(
|
||||||
let incorrect_pms = private_message
|
let incorrect_pms = private_message
|
||||||
.filter(ap_id.like("http://changeme%"))
|
.filter(ap_id.like("http://changeme%"))
|
||||||
.filter(local.eq(true))
|
.filter(local.eq(true))
|
||||||
.load::<PrivateMessage>(&mut *conn)
|
.load::<PrivateMessage>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
for cpm in &incorrect_pms {
|
for cpm in &incorrect_pms {
|
||||||
|
@ -223,7 +222,7 @@ async fn private_message_updates_2020_05_05(
|
||||||
protocol_and_hostname,
|
protocol_and_hostname,
|
||||||
)?;
|
)?;
|
||||||
PrivateMessage::update(
|
PrivateMessage::update(
|
||||||
&mut *conn,
|
conn,
|
||||||
cpm.id,
|
cpm.id,
|
||||||
&PrivateMessageUpdateForm::builder()
|
&PrivateMessageUpdateForm::builder()
|
||||||
.ap_id(Some(apub_id))
|
.ap_id(Some(apub_id))
|
||||||
|
@ -238,7 +237,7 @@ async fn private_message_updates_2020_05_05(
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn post_thumbnail_url_updates_2020_07_27(
|
async fn post_thumbnail_url_updates_2020_07_27(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
protocol_and_hostname: &str,
|
protocol_and_hostname: &str,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
use lemmy_db_schema::schema::post::dsl::{post, thumbnail_url};
|
use lemmy_db_schema::schema::post::dsl::{post, thumbnail_url};
|
||||||
|
@ -258,7 +257,7 @@ async fn post_thumbnail_url_updates_2020_07_27(
|
||||||
.concat(thumbnail_url),
|
.concat(thumbnail_url),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.get_results::<Post>(&mut *conn)
|
.get_results::<Post>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
info!("{} Post thumbnail_url rows updated.", res.len());
|
info!("{} Post thumbnail_url rows updated.", res.len());
|
||||||
|
@ -268,13 +267,13 @@ async fn post_thumbnail_url_updates_2020_07_27(
|
||||||
|
|
||||||
/// We are setting inbox and follower URLs for local and remote actors alike, because for now
|
/// We are setting inbox and follower URLs for local and remote actors alike, because for now
|
||||||
/// all federated instances are also Lemmy and use the same URL scheme.
|
/// all federated instances are also Lemmy and use the same URL scheme.
|
||||||
async fn apub_columns_2021_02_02(mut conn: impl DbConn) -> Result<(), LemmyError> {
|
async fn apub_columns_2021_02_02(mut conn: impl GetConn) -> Result<(), LemmyError> {
|
||||||
info!("Running apub_columns_2021_02_02");
|
info!("Running apub_columns_2021_02_02");
|
||||||
{
|
{
|
||||||
use lemmy_db_schema::schema::person::dsl::{inbox_url, person, shared_inbox_url};
|
use lemmy_db_schema::schema::person::dsl::{inbox_url, person, shared_inbox_url};
|
||||||
let persons = person
|
let persons = person
|
||||||
.filter(inbox_url.like("http://changeme%"))
|
.filter(inbox_url.like("http://changeme%"))
|
||||||
.load::<Person>(&mut *conn)
|
.load::<Person>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
for p in &persons {
|
for p in &persons {
|
||||||
|
@ -285,7 +284,7 @@ async fn apub_columns_2021_02_02(mut conn: impl DbConn) -> Result<(), LemmyError
|
||||||
inbox_url.eq(inbox_url_),
|
inbox_url.eq(inbox_url_),
|
||||||
shared_inbox_url.eq(shared_inbox_url_),
|
shared_inbox_url.eq(shared_inbox_url_),
|
||||||
))
|
))
|
||||||
.get_result::<Person>(&mut *conn)
|
.get_result::<Person>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -299,7 +298,7 @@ async fn apub_columns_2021_02_02(mut conn: impl DbConn) -> Result<(), LemmyError
|
||||||
};
|
};
|
||||||
let communities = community
|
let communities = community
|
||||||
.filter(inbox_url.like("http://changeme%"))
|
.filter(inbox_url.like("http://changeme%"))
|
||||||
.load::<Community>(&mut *conn)
|
.load::<Community>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
for c in &communities {
|
for c in &communities {
|
||||||
|
@ -312,7 +311,7 @@ async fn apub_columns_2021_02_02(mut conn: impl DbConn) -> Result<(), LemmyError
|
||||||
inbox_url.eq(inbox_url_),
|
inbox_url.eq(inbox_url_),
|
||||||
shared_inbox_url.eq(shared_inbox_url_),
|
shared_inbox_url.eq(shared_inbox_url_),
|
||||||
))
|
))
|
||||||
.get_result::<Community>(&mut *conn)
|
.get_result::<Community>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -325,11 +324,11 @@ async fn apub_columns_2021_02_02(mut conn: impl DbConn) -> Result<(), LemmyError
|
||||||
/// Before this point, there is only a single value in the site table which refers to the local
|
/// Before this point, there is only a single value in the site table which refers to the local
|
||||||
/// Lemmy instance, so thats all we need to update.
|
/// Lemmy instance, so thats all we need to update.
|
||||||
async fn instance_actor_2022_01_28(
|
async fn instance_actor_2022_01_28(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
protocol_and_hostname: &str,
|
protocol_and_hostname: &str,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
info!("Running instance_actor_2021_09_29");
|
info!("Running instance_actor_2021_09_29");
|
||||||
if let Ok(site_view) = SiteView::read_local(&mut *conn).await {
|
if let Ok(site_view) = SiteView::read_local(conn).await {
|
||||||
let site = site_view.site;
|
let site = site_view.site;
|
||||||
// if site already has public key, we dont need to do anything here
|
// if site already has public key, we dont need to do anything here
|
||||||
if !site.public_key.is_empty() {
|
if !site.public_key.is_empty() {
|
||||||
|
@ -344,7 +343,7 @@ async fn instance_actor_2022_01_28(
|
||||||
.private_key(Some(Some(key_pair.private_key)))
|
.private_key(Some(Some(key_pair.private_key)))
|
||||||
.public_key(Some(key_pair.public_key))
|
.public_key(Some(key_pair.public_key))
|
||||||
.build();
|
.build();
|
||||||
Site::update(&mut *conn, site.id, &site_form).await?;
|
Site::update(conn, site.id, &site_form).await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -354,7 +353,7 @@ async fn instance_actor_2022_01_28(
|
||||||
/// key field is empty, generate a new keypair. It would be possible to regenerate only the pubkey,
|
/// key field is empty, generate a new keypair. It would be possible to regenerate only the pubkey,
|
||||||
/// but thats more complicated and has no benefit, as federation is already broken for these actors.
|
/// but thats more complicated and has no benefit, as federation is already broken for these actors.
|
||||||
/// https://github.com/LemmyNet/lemmy/issues/2347
|
/// https://github.com/LemmyNet/lemmy/issues/2347
|
||||||
async fn regenerate_public_keys_2022_07_05(mut conn: impl DbConn) -> Result<(), LemmyError> {
|
async fn regenerate_public_keys_2022_07_05(mut conn: impl GetConn) -> Result<(), LemmyError> {
|
||||||
info!("Running regenerate_public_keys_2022_07_05");
|
info!("Running regenerate_public_keys_2022_07_05");
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -363,7 +362,7 @@ async fn regenerate_public_keys_2022_07_05(mut conn: impl DbConn) -> Result<(),
|
||||||
let communities: Vec<Community> = community
|
let communities: Vec<Community> = community
|
||||||
.filter(local.eq(true))
|
.filter(local.eq(true))
|
||||||
.filter(public_key.eq(""))
|
.filter(public_key.eq(""))
|
||||||
.load::<Community>(&mut *conn)
|
.load::<Community>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
for community_ in communities {
|
for community_ in communities {
|
||||||
info!(
|
info!(
|
||||||
|
@ -375,7 +374,7 @@ async fn regenerate_public_keys_2022_07_05(mut conn: impl DbConn) -> Result<(),
|
||||||
.public_key(Some(key_pair.public_key))
|
.public_key(Some(key_pair.public_key))
|
||||||
.private_key(Some(Some(key_pair.private_key)))
|
.private_key(Some(Some(key_pair.private_key)))
|
||||||
.build();
|
.build();
|
||||||
Community::update(&mut *conn, community_.id, &form).await?;
|
Community::update(conn, community_.id, &form).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,7 +384,7 @@ async fn regenerate_public_keys_2022_07_05(mut conn: impl DbConn) -> Result<(),
|
||||||
let persons = person
|
let persons = person
|
||||||
.filter(local.eq(true))
|
.filter(local.eq(true))
|
||||||
.filter(public_key.eq(""))
|
.filter(public_key.eq(""))
|
||||||
.load::<Person>(&mut *conn)
|
.load::<Person>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
for person_ in persons {
|
for person_ in persons {
|
||||||
info!(
|
info!(
|
||||||
|
@ -397,7 +396,7 @@ async fn regenerate_public_keys_2022_07_05(mut conn: impl DbConn) -> Result<(),
|
||||||
.public_key(Some(key_pair.public_key))
|
.public_key(Some(key_pair.public_key))
|
||||||
.private_key(Some(Some(key_pair.private_key)))
|
.private_key(Some(Some(key_pair.private_key)))
|
||||||
.build();
|
.build();
|
||||||
Person::update(&mut *conn, person_.id, &form).await?;
|
Person::update(conn, person_.id, &form).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -408,13 +407,13 @@ async fn regenerate_public_keys_2022_07_05(mut conn: impl DbConn) -> Result<(),
|
||||||
/// If a site already exists, the DB migration should generate a local_site row.
|
/// If a site already exists, the DB migration should generate a local_site row.
|
||||||
/// This will only be run for brand new sites.
|
/// This will only be run for brand new sites.
|
||||||
async fn initialize_local_site_2022_10_10(
|
async fn initialize_local_site_2022_10_10(
|
||||||
mut conn: impl DbConn,
|
mut conn: impl GetConn,
|
||||||
settings: &Settings,
|
settings: &Settings,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
info!("Running initialize_local_site_2022_10_10");
|
info!("Running initialize_local_site_2022_10_10");
|
||||||
|
|
||||||
// Check to see if local_site exists
|
// Check to see if local_site exists
|
||||||
if LocalSite::read(&mut *conn).await.is_ok() {
|
if LocalSite::read(conn).await.is_ok() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
info!("No Local Site found, creating it.");
|
info!("No Local Site found, creating it.");
|
||||||
|
@ -424,7 +423,7 @@ async fn initialize_local_site_2022_10_10(
|
||||||
.expect("must have domain");
|
.expect("must have domain");
|
||||||
|
|
||||||
// Upsert this to the instance table
|
// Upsert this to the instance table
|
||||||
let instance = Instance::read_or_create(&mut *conn, domain).await?;
|
let instance = Instance::read_or_create(conn, domain).await?;
|
||||||
|
|
||||||
if let Some(setup) = &settings.setup {
|
if let Some(setup) = &settings.setup {
|
||||||
let person_keypair = generate_actor_keypair()?;
|
let person_keypair = generate_actor_keypair()?;
|
||||||
|
@ -445,14 +444,14 @@ async fn initialize_local_site_2022_10_10(
|
||||||
.inbox_url(Some(generate_inbox_url(&person_actor_id)?))
|
.inbox_url(Some(generate_inbox_url(&person_actor_id)?))
|
||||||
.shared_inbox_url(Some(generate_shared_inbox_url(&person_actor_id)?))
|
.shared_inbox_url(Some(generate_shared_inbox_url(&person_actor_id)?))
|
||||||
.build();
|
.build();
|
||||||
let person_inserted = Person::create(&mut *conn, &person_form).await?;
|
let person_inserted = Person::create(conn, &person_form).await?;
|
||||||
|
|
||||||
let local_user_form = LocalUserInsertForm::builder()
|
let local_user_form = LocalUserInsertForm::builder()
|
||||||
.person_id(person_inserted.id)
|
.person_id(person_inserted.id)
|
||||||
.password_encrypted(setup.admin_password.clone())
|
.password_encrypted(setup.admin_password.clone())
|
||||||
.email(setup.admin_email.clone())
|
.email(setup.admin_email.clone())
|
||||||
.build();
|
.build();
|
||||||
LocalUser::create(&mut *conn, &local_user_form).await?;
|
LocalUser::create(conn, &local_user_form).await?;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add an entry for the site table
|
// Add an entry for the site table
|
||||||
|
@ -474,14 +473,14 @@ async fn initialize_local_site_2022_10_10(
|
||||||
.private_key(Some(site_key_pair.private_key))
|
.private_key(Some(site_key_pair.private_key))
|
||||||
.public_key(Some(site_key_pair.public_key))
|
.public_key(Some(site_key_pair.public_key))
|
||||||
.build();
|
.build();
|
||||||
let site = Site::create(&mut *conn, &site_form).await?;
|
let site = Site::create(conn, &site_form).await?;
|
||||||
|
|
||||||
// Finally create the local_site row
|
// Finally create the local_site row
|
||||||
let local_site_form = LocalSiteInsertForm::builder()
|
let local_site_form = LocalSiteInsertForm::builder()
|
||||||
.site_id(site.id)
|
.site_id(site.id)
|
||||||
.site_setup(Some(settings.setup.is_some()))
|
.site_setup(Some(settings.setup.is_some()))
|
||||||
.build();
|
.build();
|
||||||
let local_site = LocalSite::create(&mut *conn, &local_site_form).await?;
|
let local_site = LocalSite::create(conn, &local_site_form).await?;
|
||||||
|
|
||||||
// Create the rate limit table
|
// Create the rate limit table
|
||||||
let local_site_rate_limit_form = LocalSiteRateLimitInsertForm::builder()
|
let local_site_rate_limit_form = LocalSiteRateLimitInsertForm::builder()
|
||||||
|
@ -497,7 +496,7 @@ async fn initialize_local_site_2022_10_10(
|
||||||
.search(Some(999))
|
.search(Some(999))
|
||||||
.local_site_id(local_site.id)
|
.local_site_id(local_site.id)
|
||||||
.build();
|
.build();
|
||||||
LocalSiteRateLimit::create(&mut *conn, &local_site_rate_limit_form).await?;
|
LocalSiteRateLimit::create(conn, &local_site_rate_limit_form).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue