Diesel 2.0.0 upgrade (#2452)

* Initial commit to bump diesel to 2.0.0-rc.0 and see what happens

* Add chrono feature from diesel

* db_schema crate is close to building?

* Upgrade diesel-derive-newtype

* Mostly modifying references to connections to be mutable ones; also used
new way to do migrations as suggested by the migration guide; a lot more
compiles now, though I can't figure out this tricky ToSql issue at the
moment

* Running clippy --fix

* Trying to fix drone clippy 1

* Fix clippy

* Upgrade clux-musl

* Trying to fix drone clippy 2

* Trying to fix drone clippy 3

* Trying to fix drone clippy 5

* Adding diesel table aliases, removing sql view hack. Fixes #2101

Co-authored-by: Steven Chu <stevenc1@gmail.com>
Co-authored-by: Nutomic <me@nutomic.com>
pull/2447/head^2
Dessalines 2 years ago committed by GitHub
parent 4e6409f325
commit c9f1407429
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -10,7 +10,7 @@ steps:
# use minimum supported rust version for most steps
- name: prepare repo
image: clux/muslrust:1.57.0
image: clux/muslrust:1.59.0
user: root
commands:
- git fetch --tags
@ -27,12 +27,14 @@ steps:
- name: cargo clippy
image: rust:1.61-buster
commands:
- apt-get update
- apt-get -y install protobuf-compiler libprotobuf-dev
- rustup component add clippy
- cargo clippy --workspace --tests --all-targets --all-features -- -D warnings -D deprecated -D clippy::perf -D clippy::complexity -D clippy::dbg_macro
- cargo clippy --workspace --all-features -- -D clippy::unwrap_used
- name: cargo test
image: clux/muslrust:1.57.0
image: clux/muslrust:1.59.0
environment:
LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy
LEMMY_CONFIG_LOCATION: ../../config/config.hjson
@ -40,24 +42,24 @@ steps:
RUST_TEST_THREADS: 1
commands:
- apt-get update
- apt-get -y install --no-install-recommends postgresql-client
- apt-get -y install --no-install-recommends postgresql-client protobuf-compiler libprotobuf-dev
- cargo test --workspace --no-fail-fast --all-features
- name: check defaults.hjson updated
image: clux/muslrust:1.57.0
image: clux/muslrust:1.59.0
commands:
- ./scripts/update_config_defaults.sh config/defaults_current.hjson
- diff config/defaults.hjson config/defaults_current.hjson
- name: check with different features
image: clux/muslrust:1.57.0
image: clux/muslrust:1.59.0
commands:
- cargo install cargo-workspaces
- cargo workspaces exec cargo check --no-default-features
- cargo workspaces exec cargo check --all-features
- name: cargo build
image: clux/muslrust:1.57.0
image: clux/muslrust:1.59.0
commands:
- cargo build
- mv target/x86_64-unknown-linux-musl/debug/lemmy_server target/lemmy_server

1604
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -44,25 +44,25 @@ lemmy_api_common = { version = "=0.16.5", path = "crates/api_common" }
lemmy_websocket = { version = "=0.16.5", path = "./crates/websocket" }
lemmy_routes = { version = "=0.16.5", path = "./crates/routes" }
activitypub_federation = "0.2.0"
diesel = "1.4.8"
diesel_migrations = "1.4.0"
serde = { version = "1.0.136", features = ["derive"] }
diesel = "2.0.0"
diesel_migrations = "2.0.0"
serde = { version = "1.0.145", features = ["derive"] }
actix = "0.13.0"
actix-web = { version = "4.0.1", default-features = false, features = ["macros", "rustls"] }
tracing = "0.1.32"
tracing-actix-web = { version = "0.5.1", default-features = false }
actix-web = { version = "4.2.1", default-features = false, features = ["macros", "rustls"] }
tracing = "0.1.36"
tracing-actix-web = { version = "0.6.1", default-features = false }
tracing-error = "0.2.0"
tracing-log = "0.1.2"
tracing-subscriber = { version = "0.3.9", features = ["env-filter"] }
url = { version = "2.2.2", features = ["serde"] }
reqwest = { version = "0.11.10", features = ["json"] }
reqwest-middleware = "0.1.5"
reqwest-tracing = "0.2.1"
tracing-log = "0.1.3"
tracing-subscriber = { version = "0.3.15", features = ["env-filter"] }
url = { version = "2.3.1", features = ["serde"] }
reqwest = { version = "0.11.12", features = ["json"] }
reqwest-middleware = "0.1.6"
reqwest-tracing = "0.3.1"
clokwerk = "0.3.5"
doku = { version = "0.12.0", features = ["url-2"] }
parking_lot = "0.12.0"
parking_lot = "0.12.1"
reqwest-retry = "0.1.5"
console-subscriber = { version = "0.1.3", optional = true }
console-subscriber = { version = "0.1.8", optional = true }
opentelemetry = { version = "0.17.0", features = ["rt-tokio"], optional = true }
opentelemetry-otlp = { version = "0.10.0", optional = true }
tracing-opentelemetry = { version = "0.17.2", optional = true }

@ -23,15 +23,15 @@ lemmy_db_views_actor = { version = "=0.16.5", path = "../db_views_actor", featur
lemmy_api_common = { version = "=0.16.5", path = "../api_common", features = ["full"] }
lemmy_websocket = { version = "=0.16.5", path = "../websocket" }
activitypub_federation = "0.2.0"
diesel = "1.4.8"
bcrypt = "0.12.1"
chrono = { version = "0.4.19", features = ["serde"], default-features = false }
serde_json = { version = "1.0.79", features = ["preserve_order"] }
serde = { version = "1.0.136", features = ["derive"] }
actix-web = { version = "4.0.1", default-features = false }
diesel = "2.0.0"
bcrypt = "0.13.0"
chrono = { version = "0.4.22", features = ["serde"], default-features = false }
serde_json = { version = "1.0.85", features = ["preserve_order"] }
serde = { version = "1.0.145", features = ["derive"] }
actix-web = { version = "4.2.1", default-features = false }
base64 = "0.13.0"
uuid = { version = "0.8.2", features = ["serde", "v4"] }
async-trait = "0.1.53"
uuid = { version = "1.1.2", features = ["serde", "v4"] }
async-trait = "0.1.57"
captcha = "0.0.9"
anyhow = "1.0.56"
tracing = "0.1.32"
anyhow = "1.0.65"
tracing = "0.1.36"

@ -92,7 +92,7 @@ impl Perform for CreateCommentLike {
let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1);
if do_add {
let like_form2 = like_form.clone();
let like = move |conn: &'_ _| CommentLike::like(conn, &like_form2);
let like = move |conn: &mut _| CommentLike::like(conn, &like_form2);
blocking(context.pool(), like)
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_comment"))?;

@ -32,12 +32,12 @@ impl Perform for SaveComment {
};
if data.save {
let save_comment = move |conn: &'_ _| CommentSaved::save(conn, &comment_saved_form);
let save_comment = move |conn: &mut _| CommentSaved::save(conn, &comment_saved_form);
blocking(context.pool(), save_comment)
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_save_comment"))?;
} else {
let unsave_comment = move |conn: &'_ _| CommentSaved::unsave(conn, &comment_saved_form);
let unsave_comment = move |conn: &mut _| CommentSaved::unsave(conn, &comment_saved_form);
blocking(context.pool(), unsave_comment)
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_save_comment"))?;

@ -35,7 +35,7 @@ impl Perform for ResolveCommentReport {
is_mod_or_admin(context.pool(), person_id, report.community.id).await?;
let resolved = data.resolved;
let resolve_fun = move |conn: &'_ _| {
let resolve_fun = move |conn: &mut _| {
if resolved {
CommentReport::resolve(conn, report_id, person_id)
} else {

@ -52,12 +52,12 @@ impl Perform for AddModToCommunity {
person_id: data.person_id,
};
if data.added {
let join = move |conn: &'_ _| CommunityModerator::join(conn, &community_moderator_form);
let join = move |conn: &mut _| CommunityModerator::join(conn, &community_moderator_form);
blocking(context.pool(), join)
.await?
.map_err(|e| LemmyError::from_error_message(e, "community_moderator_already_exists"))?;
} else {
let leave = move |conn: &'_ _| CommunityModerator::leave(conn, &community_moderator_form);
let leave = move |conn: &mut _| CommunityModerator::leave(conn, &community_moderator_form);
blocking(context.pool(), leave)
.await?
.map_err(|e| LemmyError::from_error_message(e, "community_moderator_already_exists"))?;

@ -55,19 +55,19 @@ impl Perform for BanFromCommunity {
expires: Some(expires),
};
let community: ApubCommunity = blocking(context.pool(), move |conn: &'_ _| {
let community: ApubCommunity = blocking(context.pool(), move |conn: &mut _| {
Community::read(conn, community_id)
})
.await??
.into();
let banned_person: ApubPerson = blocking(context.pool(), move |conn: &'_ _| {
let banned_person: ApubPerson = blocking(context.pool(), move |conn: &mut _| {
Person::read(conn, banned_person_id)
})
.await??
.into();
if data.ban {
let ban = move |conn: &'_ _| CommunityPersonBan::ban(conn, &community_user_ban_form);
let ban = move |conn: &mut _| CommunityPersonBan::ban(conn, &community_user_ban_form);
blocking(context.pool(), ban)
.await?
.map_err(|e| LemmyError::from_error_message(e, "community_user_already_banned"))?;
@ -78,7 +78,7 @@ impl Perform for BanFromCommunity {
person_id: banned_person_id,
pending: false,
};
blocking(context.pool(), move |conn: &'_ _| {
blocking(context.pool(), move |conn: &mut _| {
CommunityFollower::unfollow(conn, &community_follower_form)
})
.await?
@ -95,7 +95,7 @@ impl Perform for BanFromCommunity {
)
.await?;
} else {
let unban = move |conn: &'_ _| CommunityPersonBan::unban(conn, &community_user_ban_form);
let unban = move |conn: &mut _| CommunityPersonBan::unban(conn, &community_user_ban_form);
blocking(context.pool(), unban)
.await?
.map_err(|e| LemmyError::from_error_message(e, "community_user_already_banned"))?;

@ -38,7 +38,7 @@ impl Perform for BlockCommunity {
};
if data.block {
let block = move |conn: &'_ _| CommunityBlock::block(conn, &community_block_form);
let block = move |conn: &mut _| CommunityBlock::block(conn, &community_block_form);
blocking(context.pool(), block)
.await?
.map_err(|e| LemmyError::from_error_message(e, "community_block_already_exists"))?;
@ -49,7 +49,7 @@ impl Perform for BlockCommunity {
person_id,
pending: false,
};
blocking(context.pool(), move |conn: &'_ _| {
blocking(context.pool(), move |conn: &mut _| {
CommunityFollower::unfollow(conn, &community_follower_form)
})
.await?
@ -60,7 +60,7 @@ impl Perform for BlockCommunity {
.await??;
UndoFollowCommunity::send(&local_user_view.person.into(), &community.into(), context).await?;
} else {
let unblock = move |conn: &'_ _| CommunityBlock::unblock(conn, &community_block_form);
let unblock = move |conn: &mut _| CommunityBlock::unblock(conn, &community_block_form);
blocking(context.pool(), unblock)
.await?
.map_err(|e| LemmyError::from_error_message(e, "community_block_already_exists"))?;

@ -55,13 +55,13 @@ impl Perform for FollowCommunity {
check_community_ban(local_user_view.person.id, community_id, context.pool()).await?;
check_community_deleted_or_removed(community_id, context.pool()).await?;
let follow = move |conn: &'_ _| CommunityFollower::follow(conn, &community_follower_form);
let follow = move |conn: &mut _| CommunityFollower::follow(conn, &community_follower_form);
blocking(context.pool(), follow)
.await?
.map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
} else {
let unfollow =
move |conn: &'_ _| CommunityFollower::unfollow(conn, &community_follower_form);
move |conn: &mut _| CommunityFollower::unfollow(conn, &community_follower_form);
blocking(context.pool(), unfollow)
.await?
.map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
@ -74,7 +74,8 @@ impl Perform for FollowCommunity {
} else {
UndoFollowCommunity::send(&local_user_view.person.clone().into(), &community, context)
.await?;
let unfollow = move |conn: &'_ _| CommunityFollower::unfollow(conn, &community_follower_form);
let unfollow =
move |conn: &mut _| CommunityFollower::unfollow(conn, &community_follower_form);
blocking(context.pool(), unfollow)
.await?
.map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;

@ -75,7 +75,7 @@ impl Perform for TransferCommunity {
person_id: cmod.moderator.id,
};
let join = move |conn: &'_ _| CommunityModerator::join(conn, &community_moderator_form);
let join = move |conn: &mut _| CommunityModerator::join(conn, &community_moderator_form);
blocking(context.pool(), join)
.await?
.map_err(|e| LemmyError::from_error_message(e, "community_moderator_already_exists"))?;

@ -254,8 +254,8 @@ mod tests {
#[test]
fn test_should_not_validate_user_token_after_password_change() {
let conn = establish_unpooled_connection();
let secret = Secret::init(&conn).unwrap();
let conn = &mut establish_unpooled_connection();
let secret = Secret::init(conn).unwrap();
let settings = &SETTINGS.to_owned();
let new_person = PersonForm {
@ -264,7 +264,7 @@ mod tests {
..PersonForm::default()
};
let inserted_person = Person::create(&conn, &new_person).unwrap();
let inserted_person = Person::create(conn, &new_person).unwrap();
let local_user_form = LocalUserForm {
person_id: Some(inserted_person.id),
@ -272,7 +272,7 @@ mod tests {
..LocalUserForm::default()
};
let inserted_local_user = LocalUser::create(&conn, &local_user_form).unwrap();
let inserted_local_user = LocalUser::create(conn, &local_user_form).unwrap();
let jwt = Claims::jwt(
inserted_local_user.id.0,
@ -286,11 +286,11 @@ mod tests {
// The check should fail, since the validator time is now newer than the jwt issue time
let updated_local_user =
LocalUser::update_password(&conn, inserted_local_user.id, "password111").unwrap();
LocalUser::update_password(conn, inserted_local_user.id, "password111").unwrap();
let check_after = check_validator_time(&updated_local_user.validator_time, &claims);
assert!(check_after.is_err());
let num_deleted = Person::delete(&conn, inserted_person.id).unwrap();
let num_deleted = Person::delete(conn, inserted_person.id).unwrap();
assert_eq!(1, num_deleted);
}
}

@ -41,7 +41,7 @@ impl Perform for BanPerson {
let banned_person_id = data.person_id;
let expires = data.expires.map(naive_from_unix);
let ban_person = move |conn: &'_ _| Person::ban_person(conn, banned_person_id, ban, expires);
let ban_person = move |conn: &mut _| Person::ban_person(conn, banned_person_id, ban, expires);
let person = blocking(context.pool(), ban_person)
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_user"))?;

@ -49,12 +49,12 @@ impl Perform for BlockPerson {
}
if data.block {
let block = move |conn: &'_ _| PersonBlock::block(conn, &person_block_form);
let block = move |conn: &mut _| PersonBlock::block(conn, &person_block_form);
blocking(context.pool(), block)
.await?
.map_err(|e| LemmyError::from_error_message(e, "person_block_already_exists"))?;
} else {
let unblock = move |conn: &'_ _| PersonBlock::unblock(conn, &person_block_form);
let unblock = move |conn: &mut _| PersonBlock::unblock(conn, &person_block_form);
blocking(context.pool(), unblock)
.await?
.map_err(|e| LemmyError::from_error_message(e, "person_block_already_exists"))?;

@ -36,7 +36,7 @@ impl Perform for MarkPersonMentionAsRead {
let person_mention_id = read_person_mention.id;
let read = data.read;
let update_mention =
move |conn: &'_ _| PersonMention::update_read(conn, person_mention_id, read);
move |conn: &mut _| PersonMention::update_read(conn, person_mention_id, read);
blocking(context.pool(), update_mention)
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;

@ -35,7 +35,7 @@ impl Perform for MarkCommentReplyAsRead {
let comment_reply_id = read_comment_reply.id;
let read = data.read;
let update_reply = move |conn: &'_ _| CommentReply::update_read(conn, comment_reply_id, read);
let update_reply = move |conn: &mut _| CommentReply::update_read(conn, comment_reply_id, read);
blocking(context.pool(), update_reply)
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;

@ -72,7 +72,7 @@ impl Perform for CreatePostLike {
let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1);
if do_add {
let like_form2 = like_form.clone();
let like = move |conn: &'_ _| PostLike::like(conn, &like_form2);
let like = move |conn: &mut _| PostLike::like(conn, &like_form2);
blocking(context.pool(), like)
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_post"))?;

@ -32,12 +32,12 @@ impl Perform for SavePost {
};
if data.save {
let save = move |conn: &'_ _| PostSaved::save(conn, &post_saved_form);
let save = move |conn: &mut _| PostSaved::save(conn, &post_saved_form);
blocking(context.pool(), save)
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_save_post"))?;
} else {
let unsave = move |conn: &'_ _| PostSaved::unsave(conn, &post_saved_form);
let unsave = move |conn: &mut _| PostSaved::unsave(conn, &post_saved_form);
blocking(context.pool(), unsave)
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_save_post"))?;

@ -35,7 +35,7 @@ impl Perform for ResolvePostReport {
is_mod_or_admin(context.pool(), person_id, report.community.id).await?;
let resolved = data.resolved;
let resolve_fun = move |conn: &'_ _| {
let resolve_fun = move |conn: &mut _| {
if resolved {
PostReport::resolve(conn, report_id, person_id)
} else {

@ -31,7 +31,7 @@ impl Perform for ResolvePrivateMessageReport {
let resolved = self.resolved;
let report_id = self.report_id;
let person_id = local_user_view.person.id;
let resolve_fn = move |conn: &'_ _| {
let resolve_fn = move |conn: &mut _| {
if resolved {
PrivateMessageReport::resolve(conn, report_id, person_id)
} else {

@ -24,18 +24,18 @@ lemmy_db_views_moderator = { version = "=0.16.5", path = "../db_views_moderator"
lemmy_db_views_actor = { version = "=0.16.5", path = "../db_views_actor" }
lemmy_db_schema = { version = "=0.16.5", path = "../db_schema", default-features = false }
lemmy_utils = { version = "=0.16.5", path = "../utils", optional = true }
serde = { version = "1.0.136", features = ["derive"] }
url = "2.2.2"
actix-web = { version = "4.0.1", default-features = false, features = ["cookies"], optional = true }
chrono = { version = "0.4.19", features = ["serde"], optional = true }
diesel = { version = "1.4.8", optional = true }
tracing = { version = "0.1.32", optional = true }
serde = { version = "1.0.145", features = ["derive"] }
url = "2.3.1"
actix-web = { version = "4.2.1", default-features = false, features = ["cookies"], optional = true }
chrono = { version = "0.4.22", features = ["serde"], optional = true }
diesel = { version = "2.0.0", optional = true }
tracing = { version = "0.1.36", optional = true }
rosetta-i18n = { version = "0.1.2", optional = true }
percent-encoding = { version = "2.1.0", optional = true }
percent-encoding = { version = "2.2.0", optional = true }
encoding = { version = "0.2.33", optional = true }
reqwest-middleware = { version = "0.1.5", optional = true }
reqwest-middleware = { version = "0.1.6", optional = true }
webpage = { version = "1.4.0", default-features = false, features = ["serde"], optional = true }
[dev-dependencies]
actix-rt = { version = "2.7.0", default-features = false }
reqwest = { version = "0.11.10", features = ["json"] }
reqwest = { version = "0.11.12", features = ["json"] }

@ -164,7 +164,7 @@ pub struct GetSiteMetadataResponse {
pub metadata: SiteMetadata,
}
#[derive(Debug, Deserialize, Serialize, PartialEq, Clone)]
#[derive(Debug, Deserialize, Serialize, PartialEq, Eq, Clone)]
pub struct SiteMetadata {
pub title: Option<String>,
pub description: Option<String>,

@ -42,15 +42,15 @@ use tracing::warn;
pub async fn blocking<F, T>(pool: &DbPool, f: F) -> Result<T, LemmyError>
where
F: FnOnce(&diesel::PgConnection) -> T + Send + 'static,
F: FnOnce(&mut diesel::PgConnection) -> T + Send + 'static,
T: Send + 'static,
{
let pool = pool.clone();
let blocking_span = tracing::info_span!("blocking operation");
actix_web::web::block(move || {
let entered = blocking_span.enter();
let conn = pool.get()?;
let res = (f)(&conn);
let mut conn = pool.get()?;
let res = (f)(&mut conn);
drop(entered);
Ok(res) as Result<T, LemmyError>
})
@ -219,7 +219,7 @@ pub async fn check_community_ban(
pool: &DbPool,
) -> Result<(), LemmyError> {
let is_banned =
move |conn: &'_ _| CommunityPersonBanView::get(conn, person_id, community_id).is_ok();
move |conn: &mut _| CommunityPersonBanView::get(conn, person_id, community_id).is_ok();
if blocking(pool, is_banned).await? {
Err(LemmyError::from_message("community_ban"))
} else {
@ -256,7 +256,7 @@ pub async fn check_person_block(
potential_blocker_id: PersonId,
pool: &DbPool,
) -> Result<(), LemmyError> {
let is_blocked = move |conn: &'_ _| PersonBlock::read(conn, potential_blocker_id, my_id).is_ok();
let is_blocked = move |conn: &mut _| PersonBlock::read(conn, potential_blocker_id, my_id).is_ok();
if blocking(pool, is_blocked).await? {
Err(LemmyError::from_message("person_block"))
} else {
@ -519,7 +519,7 @@ pub async fn purge_image_posts_for_person(
settings: &Settings,
client: &ClientWithMiddleware,
) -> Result<(), LemmyError> {
let posts = blocking(pool, move |conn: &'_ _| {
let posts = blocking(pool, move |conn: &mut _| {
Post::fetch_pictrs_posts_for_creator(conn, banned_person_id)
})
.await??;
@ -548,7 +548,7 @@ pub async fn purge_image_posts_for_community(
settings: &Settings,
client: &ClientWithMiddleware,
) -> Result<(), LemmyError> {
let posts = blocking(pool, move |conn: &'_ _| {
let posts = blocking(pool, move |conn: &mut _| {
Post::fetch_pictrs_posts_for_community(conn, banned_community_id)
})
.await??;
@ -597,7 +597,7 @@ pub async fn remove_user_data(
.await??;
// Posts
blocking(pool, move |conn: &'_ _| {
blocking(pool, move |conn: &mut _| {
Post::update_removed_for_creator(conn, banned_person_id, None, true)
})
.await??;
@ -608,7 +608,7 @@ pub async fn remove_user_data(
// Communities
// Remove all communities where they're the top mod
// for now, remove the communities manually
let first_mod_communities = blocking(pool, move |conn: &'_ _| {
let first_mod_communities = blocking(pool, move |conn: &mut _| {
CommunityModeratorView::get_community_first_mods(conn)
})
.await??;
@ -621,7 +621,7 @@ pub async fn remove_user_data(
for first_mod_community in banned_user_first_communities {
let community_id = first_mod_community.community.id;
blocking(pool, move |conn: &'_ _| {
blocking(pool, move |conn: &mut _| {
Community::update_removed(conn, community_id, true)
})
.await??;
@ -643,7 +643,7 @@ pub async fn remove_user_data(
}
// Comments
blocking(pool, move |conn: &'_ _| {
blocking(pool, move |conn: &mut _| {
Comment::update_removed_for_creator(conn, banned_person_id, true)
})
.await??;
@ -707,13 +707,13 @@ pub async fn delete_user_account(
// No need to update avatar and banner, those are handled in Person::delete_account
// Comments
let permadelete = move |conn: &'_ _| Comment::permadelete_for_creator(conn, person_id);
let permadelete = move |conn: &mut _| Comment::permadelete_for_creator(conn, person_id);
blocking(pool, permadelete)
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
// Posts
let permadelete = move |conn: &'_ _| Post::permadelete_for_creator(conn, person_id);
let permadelete = move |conn: &mut _| Post::permadelete_for_creator(conn, person_id);
blocking(pool, permadelete)
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_post"))?;

@ -17,11 +17,11 @@ lemmy_db_views_actor = { version = "=0.16.5", path = "../db_views_actor", featur
lemmy_api_common = { version = "=0.16.5", path = "../api_common", features = ["full"] }
lemmy_websocket = { version = "=0.16.5", path = "../websocket" }
activitypub_federation = "0.2.0"
bcrypt = "0.12.1"
serde_json = { version = "1.0.79", features = ["preserve_order"] }
serde = { version = "1.0.136", features = ["derive"] }
actix-web = { version = "4.0.1", default-features = false }
tracing = "0.1.32"
url = { version = "2.2.2", features = ["serde"] }
async-trait = "0.1.53"
bcrypt = "0.13.0"
serde_json = { version = "1.0.85", features = ["preserve_order"] }
serde = { version = "1.0.145", features = ["derive"] }
actix-web = { version = "4.2.1", default-features = false }
tracing = "0.1.36"
url = { version = "2.3.1", features = ["serde"] }
async-trait = "0.1.57"
webmention = "0.4.0"

@ -145,7 +145,7 @@ impl PerformCrud for CreateComment {
score: 1,
};
let like = move |conn: &'_ _| CommentLike::like(conn, &like_form);
let like = move |conn: &mut _| CommentLike::like(conn, &like_form);
blocking(context.pool(), like)
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_comment"))?;

@ -114,7 +114,7 @@ impl PerformCrud for CreateCommunity {
person_id: local_user_view.person.id,
};
let join = move |conn: &'_ _| CommunityModerator::join(conn, &community_moderator_form);
let join = move |conn: &mut _| CommunityModerator::join(conn, &community_moderator_form);
blocking(context.pool(), join)
.await?
.map_err(|e| LemmyError::from_error_message(e, "community_moderator_already_exists"))?;
@ -126,7 +126,7 @@ impl PerformCrud for CreateCommunity {
pending: false,
};
let follow = move |conn: &'_ _| CommunityFollower::follow(conn, &community_follower_form);
let follow = move |conn: &mut _| CommunityFollower::follow(conn, &community_follower_form);
blocking(context.pool(), follow)
.await?
.map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;

@ -150,7 +150,7 @@ impl PerformCrud for CreatePost {
score: 1,
};
let like = move |conn: &'_ _| PostLike::like(conn, &like_form);
let like = move |conn: &mut _| PostLike::like(conn, &like_form);
blocking(context.pool(), like)
.await?
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_post"))?;

@ -80,7 +80,7 @@ impl PerformCrud for CreateSite {
..SiteForm::default()
};
let create_site = move |conn: &'_ _| Site::create(conn, &site_form);
let create_site = move |conn: &mut _| Site::create(conn, &site_form);
blocking(context.pool(), create_site)
.await?
.map_err(|e| LemmyError::from_error_message(e, "site_already_exists"))?;

@ -62,20 +62,36 @@ impl PerformCrud for GetPersonDetails {
let saved_only = data.saved_only;
let show_deleted_and_removed = data.show_deleted_and_removed;
let community_id = data.community_id;
let local_user = local_user_view.map(|l| l.local_user);
let local_user_clone = local_user.to_owned();
let (posts, comments) = blocking(context.pool(), move |conn| {
let posts = blocking(context.pool(), move |conn| {
let posts_query = PostQuery::builder()
.conn(conn)
.local_user(local_user.as_ref())
.sort(sort)
.saved_only(saved_only)
.community_id(community_id)
.page(page)
.limit(limit);
let local_user = local_user_view.map(|l| l.local_user);
// If its saved only, you don't care what creator it was
// Or, if its not saved, then you only want it for that specific creator
if !saved_only.unwrap_or(false) {
posts_query
.creator_id(Some(person_details_id))
.build()
.list()
} else {
posts_query.build().list()
}
})
.await??;
let comments = blocking(context.pool(), move |conn| {
let comments_query = CommentQuery::builder()
.conn(conn)
.local_user(local_user.as_ref())
.local_user(local_user_clone.as_ref())
.sort(sort.map(post_to_comment_sort_type))
.saved_only(saved_only)
.show_deleted_and_removed(show_deleted_and_removed)
@ -85,22 +101,14 @@ impl PerformCrud for GetPersonDetails {
// If its saved only, you don't care what creator it was
// Or, if its not saved, then you only want it for that specific creator
let (posts, comments) = if !saved_only.unwrap_or(false) {
(
posts_query
.creator_id(Some(person_details_id))
.build()
.list()?,
comments_query
.creator_id(Some(person_details_id))
.build()
.list()?,
)
if !saved_only.unwrap_or(false) {
comments_query
.creator_id(Some(person_details_id))
.build()
.list()
} else {
(posts_query.build().list()?, comments_query.build().list()?)
};
Ok((posts, comments)) as Result<_, LemmyError>
comments_query.build().list()
}
})
.await??;

@ -21,32 +21,32 @@ lemmy_db_views_actor = { version = "=0.16.5", path = "../db_views_actor", featur
lemmy_api_common = { version = "=0.16.5", path = "../api_common", features = ["full"] }
lemmy_websocket = { version = "=0.16.5", path = "../websocket" }
activitypub_federation = "0.2.0"
diesel = "1.4.8"
diesel = "2.0.0"
activitystreams-kinds = "0.2.1"
chrono = { version = "0.4.19", features = ["serde"], default-features = false }
serde_json = { version = "1.0.79", features = ["preserve_order"] }
serde = { version = "1.0.136", features = ["derive"] }
serde_with = "1.12.0"
chrono = { version = "0.4.22", features = ["serde"], default-features = false }
serde_json = { version = "1.0.85", features = ["preserve_order"] }
serde = { version = "1.0.145", features = ["derive"] }
serde_with = "1.14.0"
actix = "0.13.0"
actix-web = { version = "4.0.1", default-features = false }
actix-web = { version = "4.2.1", default-features = false }
actix-rt = { version = "2.7.0", default-features = false }
tracing = "0.1.32"
strum_macros = "0.24.0"
url = { version = "2.2.2", features = ["serde"] }
http = "0.2.6"
tracing = "0.1.36"
strum_macros = "0.24.3"
url = { version = "2.3.1", features = ["serde"] }
http = "0.2.8"
http-signature-normalization-actix = { version = "0.6.1", default-features = false, features = ["server", "sha-2"] }
futures = "0.3.21"
itertools = "0.10.3"
uuid = { version = "0.8.2", features = ["serde", "v4"] }
sha2 = "0.10.2"
async-trait = "0.1.53"
anyhow = "1.0.56"
reqwest = { version = "0.11.10", features = ["json"] }
futures = "0.3.24"
itertools = "0.10.5"
uuid = { version = "1.1.2", features = ["serde", "v4"] }
sha2 = "0.10.6"
async-trait = "0.1.57"
anyhow = "1.0.65"
reqwest = { version = "0.11.12", features = ["json"] }
html2md = "0.2.13"
once_cell = "1.10.0"
once_cell = "1.15.0"
[dev-dependencies]
serial_test = "0.6.0"
assert-json-diff = "2.0.1"
reqwest-middleware = "0.1.5"
task-local-extensions = "0.1.1"
serial_test = "0.9.0"
assert-json-diff = "2.0.2"
reqwest-middleware = "0.1.6"
task-local-extensions = "0.1.3"

@ -217,7 +217,7 @@ impl ActivityHandler for BlockUser {
person_id: blocked_person.id,
pending: false,
};
blocking(context.pool(), move |conn: &'_ _| {
blocking(context.pool(), move |conn: &mut _| {
CommunityFollower::unfollow(conn, &community_follower_form)
})
.await?

@ -141,7 +141,7 @@ impl ActivityHandler for UndoBlockUser {
person_id: blocked_person.id,
expires: None,
};
blocking(context.pool(), move |conn: &'_ _| {
blocking(context.pool(), move |conn: &mut _| {
CommunityPersonBan::unban(conn, &community_user_ban_form)
})
.await??;

@ -143,7 +143,7 @@ impl ActivityHandler for CreateOrUpdateComment {
person_id: comment.creator_id,
score: 1,
};
blocking(context.pool(), move |conn: &'_ _| {
blocking(context.pool(), move |conn: &mut _| {
CommentLike::like(conn, &like_form)
})
.await??;

@ -149,7 +149,7 @@ impl ActivityHandler for CreateOrUpdatePost {
person_id: post.creator_id,
score: 1,
};
blocking(context.pool(), move |conn: &'_ _| {
blocking(context.pool(), move |conn: &mut _| {
PostLike::like(conn, &like_form)
})
.await??;

@ -67,7 +67,7 @@ pub(crate) async fn verify_person_in_community(
let person_id = person.id;
let community_id = community.id;
let is_banned =
move |conn: &'_ _| CommunityPersonBanView::get(conn, person_id, community_id).is_ok();
move |conn: &mut _| CommunityPersonBanView::get(conn, person_id, community_id).is_ok();
if blocking(context.pool(), is_banned).await? {
return Err(LemmyError::from_message("Person is banned from community"));
}

@ -163,6 +163,7 @@ mod tests {
#[serial]
async fn test_parse_lemmy_community_moderators() {
let context = init_context();
let conn = &mut context.pool().get().unwrap();
let (new_mod, site) = parse_lemmy_person(&context).await;
let community = parse_lemmy_community(&context).await;
let community_id = community.id;
@ -172,13 +173,13 @@ mod tests {
public_key: Some("pubkey".to_string()),
..PersonForm::default()
};
let old_mod = Person::create(&context.pool().get().unwrap(), &old_mod).unwrap();
let old_mod = Person::create(conn, &old_mod).unwrap();
let community_moderator_form = CommunityModeratorForm {
community_id: community.id,
person_id: old_mod.id,
};
CommunityModerator::join(&context.pool().get().unwrap(), &community_moderator_form).unwrap();
CommunityModerator::join(conn, &community_moderator_form).unwrap();
assert_eq!(site.actor_id.to_string(), "https://enterprise.lemmy.ml/");
@ -205,13 +206,9 @@ mod tests {
assert_eq!(current_moderators.len(), 1);
assert_eq!(current_moderators[0].moderator.id, new_mod.id);
Person::delete(&*community_context.1.pool().get().unwrap(), old_mod.id).unwrap();
Person::delete(&*community_context.1.pool().get().unwrap(), new_mod.id).unwrap();
Community::delete(
&*community_context.1.pool().get().unwrap(),
community_context.0.id,
)
.unwrap();
Site::delete(&*community_context.1.pool().get().unwrap(), site.id).unwrap();
Person::delete(conn, old_mod.id).unwrap();
Person::delete(conn, new_mod.id).unwrap();
Community::delete(conn, community_context.0.id).unwrap();
Site::delete(conn, site.id).unwrap();
}
}

@ -22,7 +22,7 @@ pub enum PersonOrGroup {
Group(Group),
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub enum PersonOrGroupType {
Person,
Group,

@ -249,16 +249,18 @@ pub(crate) mod tests {
}
fn cleanup(data: (ApubPerson, ApubCommunity, ApubPost, ApubSite), context: &LemmyContext) {
Post::delete(&*context.pool().get().unwrap(), data.2.id).unwrap();
Community::delete(&*context.pool().get().unwrap(), data.1.id).unwrap();
Person::delete(&*context.pool().get().unwrap(), data.0.id).unwrap();
Site::delete(&*context.pool().get().unwrap(), data.3.id).unwrap();
let conn = &mut context.pool().get().unwrap();
Post::delete(conn, data.2.id).unwrap();
Community::delete(conn, data.1.id).unwrap();
Person::delete(conn, data.0.id).unwrap();
Site::delete(conn, data.3.id).unwrap();
}
#[actix_rt::test]
#[serial]
pub(crate) async fn test_parse_lemmy_comment() {
let context = init_context();
let conn = &mut context.pool().get().unwrap();
let url = Url::parse("https://enterprise.lemmy.ml/comment/38741").unwrap();
let data = prepare_comment_test(&url, &context).await;
@ -280,7 +282,7 @@ pub(crate) mod tests {
let to_apub = comment.into_apub(&context).await.unwrap();
assert_json_include!(actual: json, expected: to_apub);
Comment::delete(&*context.pool().get().unwrap(), comment_id).unwrap();
Comment::delete(conn, comment_id).unwrap();
cleanup(data, &context);
}
@ -288,6 +290,7 @@ pub(crate) mod tests {
#[serial]
async fn test_parse_pleroma_comment() {
let context = init_context();
let conn = &mut context.pool().get().unwrap();
let url = Url::parse("https://enterprise.lemmy.ml/comment/38741").unwrap();
let data = prepare_comment_test(&url, &context).await;
@ -315,7 +318,7 @@ pub(crate) mod tests {
assert!(!comment.local);
assert_eq!(request_counter, 0);
Comment::delete(&*context.pool().get().unwrap(), comment.id).unwrap();
Comment::delete(conn, comment.id).unwrap();
cleanup(data, &context);
}

@ -247,6 +247,7 @@ pub(crate) mod tests {
#[serial]
async fn test_parse_lemmy_community() {
let context = init_context();
let conn = &mut context.pool().get().unwrap();
let site = parse_lemmy_instance(&context).await;
let community = parse_lemmy_community(&context).await;
@ -254,7 +255,7 @@ pub(crate) mod tests {
assert!(!community.local);
assert_eq!(community.description.as_ref().unwrap().len(), 132);
Community::delete(&*context.pool().get().unwrap(), community.id).unwrap();
Site::delete(&*context.pool().get().unwrap(), site.id).unwrap();
Community::delete(conn, community.id).unwrap();
Site::delete(conn, site.id).unwrap();
}
}

@ -219,11 +219,12 @@ pub(crate) mod tests {
#[serial]
async fn test_parse_lemmy_instance() {
let context = init_context();
let conn = &mut context.pool().get().unwrap();
let site = parse_lemmy_instance(&context).await;
assert_eq!(site.name, "Enterprise");
assert_eq!(site.description.as_ref().unwrap().len(), 15);
Site::delete(&*context.pool().get().unwrap(), site.id).unwrap();
Site::delete(conn, site.id).unwrap();
}
}

@ -32,7 +32,7 @@ use lemmy_websocket::LemmyContext;
use std::ops::Deref;
use url::Url;
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ApubPerson(DbPerson);
impl Deref for ApubPerson {
@ -230,20 +230,22 @@ pub(crate) mod tests {
#[serial]
async fn test_parse_lemmy_person() {
let context = init_context();
let conn = &mut context.pool().get().unwrap();
let (person, site) = parse_lemmy_person(&context).await;
assert_eq!(person.display_name, Some("Jean-Luc Picard".to_string()));
assert!(!person.local);
assert_eq!(person.bio.as_ref().unwrap().len(), 39);
DbPerson::delete(&*context.pool().get().unwrap(), person.id).unwrap();
Site::delete(&*context.pool().get().unwrap(), site.id).unwrap();
DbPerson::delete(conn, person.id).unwrap();
Site::delete(conn, site.id).unwrap();
}
#[actix_rt::test]
#[serial]
async fn test_parse_pleroma_person() {
let context = init_context();
let conn = &mut context.pool().get().unwrap();
// create and parse a fake pleroma instance actor, to avoid network request during test
let mut json: Instance = file_to_json_object("assets/lemmy/objects/instance.json").unwrap();
@ -270,7 +272,7 @@ pub(crate) mod tests {
assert_eq!(request_counter, 0);
assert_eq!(person.bio.as_ref().unwrap().len(), 873);
DbPerson::delete(&*context.pool().get().unwrap(), person.id).unwrap();
Site::delete(&*context.pool().get().unwrap(), site.id).unwrap();
DbPerson::delete(conn, person.id).unwrap();
Site::delete(conn, site.id).unwrap();
}
}

@ -283,6 +283,7 @@ mod tests {
#[serial]
async fn test_parse_lemmy_post() {
let context = init_context();
let conn = &mut context.pool().get().unwrap();
let (person, site) = parse_lemmy_person(&context).await;
let community = parse_lemmy_community(&context).await;
@ -304,9 +305,9 @@ mod tests {
assert!(post.stickied);
assert_eq!(request_counter, 0);
Post::delete(&*context.pool().get().unwrap(), post.id).unwrap();
Person::delete(&*context.pool().get().unwrap(), person.id).unwrap();
Community::delete(&*context.pool().get().unwrap(), community.id).unwrap();
Site::delete(&*context.pool().get().unwrap(), site.id).unwrap();
Post::delete(conn, post.id).unwrap();
Person::delete(conn, person.id).unwrap();
Community::delete(conn, community.id).unwrap();
Site::delete(conn, site.id).unwrap();
}
}

@ -192,15 +192,17 @@ mod tests {
}
fn cleanup(data: (ApubPerson, ApubPerson, ApubSite), context: &LemmyContext) {
Person::delete(&*context.pool().get().unwrap(), data.0.id).unwrap();
Person::delete(&*context.pool().get().unwrap(), data.1.id).unwrap();
Site::delete(&*context.pool().get().unwrap(), data.2.id).unwrap();
let conn = &mut context.pool().get().unwrap();
Person::delete(conn, data.0.id).unwrap();
Person::delete(conn, data.1.id).unwrap();
Site::delete(conn, data.2.id).unwrap();
}
#[actix_rt::test]
#[serial]
async fn test_parse_lemmy_pm() {
let context = init_context();
let conn = &mut context.pool().get().unwrap();
let url = Url::parse("https://enterprise.lemmy.ml/private_message/1621").unwrap();
let data = prepare_comment_test(&url, &context).await;
let json: ChatMessage = file_to_json_object("assets/lemmy/objects/chat_message.json").unwrap();
@ -220,7 +222,7 @@ mod tests {
let to_apub = pm.into_apub(&context).await.unwrap();
assert_json_include!(actual: json, expected: to_apub);
PrivateMessage::delete(&*context.pool().get().unwrap(), pm_id).unwrap();
PrivateMessage::delete(conn, pm_id).unwrap();
cleanup(data, &context);
}
@ -228,6 +230,7 @@ mod tests {
#[serial]
async fn test_parse_pleroma_pm() {
let context = init_context();
let conn = &mut context.pool().get().unwrap();
let url = Url::parse("https://enterprise.lemmy.ml/private_message/1621").unwrap();
let data = prepare_comment_test(&url, &context).await;
let pleroma_url = Url::parse("https://queer.hacktivis.me/objects/2").unwrap();
@ -244,7 +247,7 @@ mod tests {
assert_eq!(pm.content.len(), 3);
assert_eq!(request_counter, 0);
PrivateMessage::delete(&*context.pool().get().unwrap(), pm.id).unwrap();
PrivateMessage::delete(conn, pm.id).unwrap();
cleanup(data, &context);
}
}

@ -8,7 +8,7 @@ pub mod deletion;
pub mod following;
pub mod voting;
#[derive(Clone, Debug, Display, Deserialize, Serialize, PartialEq)]
#[derive(Clone, Debug, Display, Deserialize, Serialize, PartialEq, Eq)]
pub enum CreateOrUpdateType {
Create,
Update,

@ -25,7 +25,7 @@ pub struct Vote {
pub(crate) unparsed: Unparsed,
}
#[derive(Clone, Debug, Display, Deserialize, Serialize, PartialEq)]
#[derive(Clone, Debug, Display, Deserialize, Serialize, PartialEq, Eq)]
pub enum VoteType {
Like,
Dislike,

@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use url::Url;
#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq)]
#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq, Eq)]
pub enum InstanceType {
Application,
Service,

@ -23,7 +23,7 @@ use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use url::Url;
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
pub enum PageType {
Page,
Article,

@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use url::Url;
#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq)]
#[derive(Clone, Copy, Debug, Deserialize, Serialize, PartialEq, Eq)]
pub enum UserTypes {
Person,
Service,

@ -0,0 +1,31 @@
[package]
name = "lemmy_apub_lib"
version = "0.16.3"
edition = "2021"
description = "A link aggregator for the fediverse"
license = "AGPL-3.0"
homepage = "https://join-lemmy.org/"
documentation = "https://join-lemmy.org/docs/en/index.html"
[dependencies]
lemmy_utils = { version = "=0.16.3", path = "../utils" }
lemmy_apub_lib_derive = { version = "=0.16.3", path = "../apub_lib_derive" }
chrono = { version = "0.4.19", default-features = false }
serde = { version = "1.0.136", features = ["derive"] }
async-trait = "0.1.53"
url = { version = "2.2.2", features = ["serde"] }
serde_json = { version = "1.0.79", features = ["preserve_order"] }
anyhow = "1.0.56"
reqwest = { version = "0.11.10", features = ["json"] }
reqwest-middleware = "0.1.5"
tracing = "0.1.32"
base64 = "0.13.0"
openssl = "0.10.38"
once_cell = "1.10.0"
http = "0.2.6"
sha2 = "0.10.2"
actix-web = { version = "4.0.1", default-features = false }
http-signature-normalization-actix = { version = "0.6.1", default-features = false, features = ["server", "sha-2"] }
http-signature-normalization-reqwest = { version = "0.5.0", default-features = false, features = ["sha-2", "middleware"] }
background-jobs = "0.12.0"
diesel = { version = "2.0.0-rc.0", features = ["chrono"] }

@ -18,22 +18,22 @@ full = ["diesel", "diesel-derive-newtype", "diesel_migrations", "bcrypt", "lemmy
"activitypub_federation", "sha2", "regex", "once_cell", "serde_json"]
[dependencies]
chrono = { version = "0.4.19", features = ["serde"], default-features = false }
serde = { version = "1.0.136", features = ["derive"] }
url = { version = "2.2.2", features = ["serde"] }
strum = "0.24.0"
strum_macros = "0.24.0"
serde_json = { version = "1.0.79", features = ["preserve_order"], optional = true }
chrono = { version = "0.4.22", features = ["serde"], default-features = false }
serde = { version = "1.0.145", features = ["derive"] }
url = { version = "2.3.1", features = ["serde"] }
strum = "0.24.1"
strum_macros = "0.24.3"
serde_json = { version = "1.0.85", features = ["preserve_order"], optional = true }
activitypub_federation = { version = "0.2.0", optional = true }
lemmy_utils = { version = "=0.16.5", path = "../utils", optional = true }
bcrypt = { version = "0.12.1", optional = true }
diesel = { version = "1.4.8", features = ["postgres","chrono","r2d2","serde_json"], optional = true }
diesel-derive-newtype = { version = "0.1.2", optional = true }
diesel_migrations = { version = "1.4.0", optional = true }
sha2 = { version = "0.10.2", optional = true }
regex = { version = "1.5.5", optional = true }
once_cell = { version = "1.10.0", optional = true }
diesel_ltree = "0.2.7"
bcrypt = { version = "0.13.0", optional = true }
diesel = { version = "2.0.0", features = ["postgres","chrono","r2d2","serde_json"], optional = true }
diesel-derive-newtype = { version = "2.0.0-rc.0", optional = true }
diesel_migrations = { version = "2.0.0", optional = true }
sha2 = { version = "0.10.6", optional = true }
regex = { version = "1.6.0", optional = true }
once_cell = { version = "1.15.0", optional = true }
diesel_ltree = "0.3.0"
[dev-dependencies]
serial_test = "0.6.0"
serial_test = "0.9.0"

@ -6,7 +6,7 @@ use crate::{
use diesel::{result::Error, *};
impl CommentAggregates {
pub fn read(conn: &PgConnection, comment_id: CommentId) -> Result<Self, Error> {
pub fn read(conn: &mut PgConnection, comment_id: CommentId) -> Result<Self, Error> {
comment_aggregates::table
.filter(comment_aggregates::comment_id.eq(comment_id))
.first::<Self>(conn)
@ -31,7 +31,7 @@ mod tests {
#[test]
#[serial]
fn test_crud() {
let conn = establish_unpooled_connection();
let conn = &mut establish_unpooled_connection();
let new_person = PersonForm {
name: "thommy_comment_agg".into(),
@ -39,7 +39,7 @@ mod tests {
..PersonForm::default()
};
let inserted_person = Person::create(&conn, &new_person).unwrap();
let inserted_person = Person::create(conn, &new_person).unwrap();
let another_person = PersonForm {
name: "jerry_comment_agg".into(),
@ -47,7 +47,7 @@ mod tests {
..PersonForm::default()
};
let another_inserted_person = Person::create(&conn, &another_person).unwrap();
let another_inserted_person = Person::create(conn, &another_person).unwrap();
let new_community = CommunityForm {
name: "TIL_comment_agg".into(),
@ -56,7 +56,7 @@ mod tests {
..CommunityForm::default()
};
let inserted_community = Community::create(&conn, &new_community).unwrap();
let inserted_community = Community::create(conn, &new_community).unwrap();
let new_post = PostForm {
name: "A test post".into(),
@ -65,7 +65,7 @@ mod tests {
..PostForm::default()
};
let inserted_post = Post::create(&conn, &new_post).unwrap();
let inserted_post = Post::create(conn, &new_post).unwrap();
let comment_form = CommentForm {
content: "A test comment".into(),
@ -74,7 +74,7 @@ mod tests {
..CommentForm::default()
};
let inserted_comment = Comment::create(&conn, &comment_form, None).unwrap();
let inserted_comment = Comment::create(conn, &comment_form, None).unwrap();
let child_comment_form = CommentForm {
content: "A test comment".into(),
@ -84,7 +84,7 @@ mod tests {
};
let _inserted_child_comment =
Comment::create(&conn, &child_comment_form, Some(&inserted_comment.path)).unwrap();
Comment::create(conn, &child_comment_form, Some(&inserted_comment.path)).unwrap();
let comment_like = CommentLikeForm {
comment_id: inserted_comment.id,
@ -93,9 +93,9 @@ mod tests {
score: 1,
};
CommentLike::like(&conn, &comment_like).unwrap();
CommentLike::like(conn, &comment_like).unwrap();
let comment_aggs_before_delete = CommentAggregates::read(&conn, inserted_comment.id).unwrap();
let comment_aggs_before_delete = CommentAggregates::read(conn, inserted_comment.id).unwrap();
assert_eq!(1, comment_aggs_before_delete.score);
assert_eq!(1, comment_aggs_before_delete.upvotes);
@ -109,35 +109,35 @@ mod tests {
score: -1,
};
CommentLike::like(&conn, &comment_dislike).unwrap();
CommentLike::like(conn, &comment_dislike).unwrap();
let comment_aggs_after_dislike = CommentAggregates::read(&conn, inserted_comment.id).unwrap();
let comment_aggs_after_dislike = CommentAggregates::read(conn, inserted_comment.id).unwrap();
assert_eq!(0, comment_aggs_after_dislike.score);
assert_eq!(1, comment_aggs_after_dislike.upvotes);
assert_eq!(1, comment_aggs_after_dislike.downvotes);
// Remove the first comment like
CommentLike::remove(&conn, inserted_person.id, inserted_comment.id).unwrap();
let after_like_remove = CommentAggregates::read(&conn, inserted_comment.id).unwrap();
CommentLike::remove(conn, inserted_person.id, inserted_comment.id).unwrap();
let after_like_remove = CommentAggregates::read(conn, inserted_comment.id).unwrap();
assert_eq!(-1, after_like_remove.score);
assert_eq!(0, after_like_remove.upvotes);
assert_eq!(1, after_like_remove.downvotes);
// Remove the parent post
Post::delete(&conn, inserted_post.id).unwrap();
Post::delete(conn, inserted_post.id).unwrap();
// Should be none found, since the post was deleted
let after_delete = CommentAggregates::read(&conn, inserted_comment.id);
let after_delete = CommentAggregates::read(conn, inserted_comment.id);
assert!(after_delete.is_err());
// This should delete all the associated rows, and fire triggers
Person::delete(&conn, another_inserted_person.id).unwrap();
let person_num_deleted = Person::delete(&conn, inserted_person.id).unwrap();
Person::delete(conn, another_inserted_person.id).unwrap();
let person_num_deleted = Person::delete(conn, inserted_person.id).unwrap();
assert_eq!(1, person_num_deleted);
// Delete the community
let community_num_deleted = Community::delete(&conn, inserted_community.id).unwrap();
let community_num_deleted = Community::delete(conn, inserted_community.id).unwrap();
assert_eq!(1, community_num_deleted);
}
}

@ -6,7 +6,7 @@ use crate::{
use diesel::{result::Error, *};
impl CommunityAggregates {
pub fn read(conn: &PgConnection, community_id: CommunityId) -> Result<Self, Error> {
pub fn read(conn: &mut PgConnection, community_id: CommunityId) -> Result<Self, Error> {
community_aggregates::table
.filter(community_aggregates::community_id.eq(community_id))
.first::<Self>(conn)
@ -31,7 +31,7 @@ mod tests {
#[test]
#[serial]
fn test_crud() {
let conn = establish_unpooled_connection();
let conn = &mut establish_unpooled_connection();
let new_person = PersonForm {
name: "thommy_community_agg".into(),
@ -39,7 +39,7 @@ mod tests {
..PersonForm::default()
};
let inserted_person = Person::create(&conn, &new_person).unwrap();
let inserted_person = Person::create(conn, &new_person).unwrap();
let another_person = PersonForm {
name: "jerry_community_agg".into(),
@ -47,7 +47,7 @@ mod tests {
..PersonForm::default()
};
let another_inserted_person = Person::create(&conn, &another_person).unwrap();
let another_inserted_person = Person::create(conn, &another_person).unwrap();
let new_community = CommunityForm {
name: "TIL_community_agg".into(),
@ -56,7 +56,7 @@ mod tests {
..CommunityForm::default()
};
let inserted_community = Community::create(&conn, &new_community).unwrap();
let inserted_community = Community::create(conn, &new_community).unwrap();
let another_community = CommunityForm {
name: "TIL_community_agg_2".into(),
@ -65,7 +65,7 @@ mod tests {
..CommunityForm::default()
};
let another_inserted_community = Community::create(&conn, &another_community).unwrap();
let another_inserted_community = Community::create(conn, &another_community).unwrap();
let first_person_follow = CommunityFollowerForm {
community_id: inserted_community.id,
@ -73,7 +73,7 @@ mod tests {
pending: false,
};
CommunityFollower::follow(&conn, &first_person_follow).unwrap();
CommunityFollower::follow(conn, &first_person_follow).unwrap();
let second_person_follow = CommunityFollowerForm {
community_id: inserted_community.id,
@ -81,7 +81,7 @@ mod tests {
pending: false,
};
CommunityFollower::follow(&conn, &second_person_follow).unwrap();
CommunityFollower::follow(conn, &second_person_follow).unwrap();
let another_community_follow = CommunityFollowerForm {
community_id: another_inserted_community.id,
@ -89,7 +89,7 @@ mod tests {
pending: false,
};
CommunityFollower::follow(&conn, &another_community_follow).unwrap();
CommunityFollower::follow(conn, &another_community_follow).unwrap();
let new_post = PostForm {
name: "A test post".into(),
@ -98,7 +98,7 @@ mod tests {
..PostForm::default()
};
let inserted_post = Post::create(&conn, &new_post).unwrap();
let inserted_post = Post::create(conn, &new_post).unwrap();
let comment_form = CommentForm {
content: "A test comment".into(),
@ -107,7 +107,7 @@ mod tests {
..CommentForm::default()
};
let inserted_comment = Comment::create(&conn, &comment_form, None).unwrap();
let inserted_comment = Comment::create(conn, &comment_form, None).unwrap();
let child_comment_form = CommentForm {
content: "A test comment".into(),
@ -117,10 +117,10 @@ mod tests {
};
let _inserted_child_comment =
Comment::create(&conn, &child_comment_form, Some(&inserted_comment.path)).unwrap();
Comment::create(conn, &child_comment_form, Some(&inserted_comment.path)).unwrap();
let community_aggregates_before_delete =
CommunityAggregates::read(&conn, inserted_community.id).unwrap();
CommunityAggregates::read(conn, inserted_community.id).unwrap();
assert_eq!(2, community_aggregates_before_delete.subscribers);
assert_eq!(1, community_aggregates_before_delete.posts);
@ -128,46 +128,46 @@ mod tests {
// Test the other community
let another_community_aggs =
CommunityAggregates::read(&conn, another_inserted_community.id).unwrap();
CommunityAggregates::read(conn, another_inserted_community.id).unwrap();
assert_eq!(1, another_community_aggs.subscribers);
assert_eq!(0, another_community_aggs.posts);
assert_eq!(0, another_community_aggs.comments);
// Unfollow test
CommunityFollower::unfollow(&conn, &second_person_follow).unwrap();
let after_unfollow = CommunityAggregates::read(&conn, inserted_community.id).unwrap();
CommunityFollower::unfollow(conn, &second_person_follow).unwrap();
let after_unfollow = CommunityAggregates::read(conn, inserted_community.id).unwrap();
assert_eq!(1, after_unfollow.subscribers);
// Follow again just for the later tests
CommunityFollower::follow(&conn, &second_person_follow).unwrap();
let after_follow_again = CommunityAggregates::read(&conn, inserted_community.id).unwrap();
CommunityFollower::follow(conn, &second_person_follow).unwrap();
let after_follow_again = CommunityAggregates::read(conn, inserted_community.id).unwrap();
assert_eq!(2, after_follow_again.subscribers);
// Remove a parent comment (the comment count should also be 0)
Post::delete(&conn, inserted_post.id).unwrap();
let after_parent_post_delete = CommunityAggregates::read(&conn, inserted_community.id).unwrap();
Post::delete(conn, inserted_post.id).unwrap();
let after_parent_post_delete = CommunityAggregates::read(conn, inserted_community.id).unwrap();
assert_eq!(0, after_parent_post_delete.comments);
assert_eq!(0, after_parent_post_delete.posts);
// Remove the 2nd person
Person::delete(&conn, another_inserted_person.id).unwrap();
let after_person_delete = CommunityAggregates::read(&conn, inserted_community.id).unwrap();
Person::delete(conn, another_inserted_person.id).unwrap();
let after_person_delete = CommunityAggregates::read(conn, inserted_community.id).unwrap();
assert_eq!(1, after_person_delete.subscribers);
// This should delete all the associated rows, and fire triggers
let person_num_deleted = Person::delete(&conn, inserted_person.id).unwrap();
let person_num_deleted = Person::delete(conn, inserted_person.id).unwrap();
assert_eq!(1, person_num_deleted);
// Delete the community
let community_num_deleted = Community::delete(&conn, inserted_community.id).unwrap();
let community_num_deleted = Community::delete(conn, inserted_community.id).unwrap();
assert_eq!(1, community_num_deleted);
let another_community_num_deleted =
Community::delete(&conn, another_inserted_community.id).unwrap();
Community::delete(conn, another_inserted_community.id).unwrap();
assert_eq!(1, another_community_num_deleted);
// Should be none found, since the creator was deleted
let after_delete = CommunityAggregates::read(&conn, inserted_community.id);
let after_delete = CommunityAggregates::read(conn, inserted_community.id);
assert!(after_delete.is_err());
}
}

@ -2,7 +2,7 @@ use crate::{aggregates::structs::PersonAggregates, newtypes::PersonId, schema::p
use diesel::{result::Error, *};
impl PersonAggregates {
pub fn read(conn: &PgConnection, person_id: PersonId) -> Result<Self, Error> {
pub fn read(conn: &mut PgConnection, person_id: PersonId) -> Result<Self, Error> {
person_aggregates::table
.filter(person_aggregates::person_id.eq(person_id))
.first::<Self>(conn)
@ -27,7 +27,7 @@ mod tests {
#[test]
#[serial]
fn test_crud() {
let conn = establish_unpooled_connection();
let conn = &mut establish_unpooled_connection();
let new_person = PersonForm {
name: "thommy_user_agg".into(),
@ -35,7 +35,7 @@ mod tests {
..PersonForm::default()
};
let inserted_person = Person::create(&conn, &new_person).unwrap();
let inserted_person = Person::create(conn, &new_person).unwrap();
let another_person = PersonForm {
name: "jerry_user_agg".into(),
@ -43,7 +43,7 @@ mod tests {
..PersonForm::default()
};
let another_inserted_person = Person::create(&conn, &another_person).unwrap();
let another_inserted_person = Person::create(conn, &another_person).unwrap();
let new_community = CommunityForm {
name: "TIL_site_agg".into(),
@ -52,7 +52,7 @@ mod tests {
..CommunityForm::default()
};
let inserted_community = Community::create(&conn, &new_community).unwrap();
let inserted_community = Community::create(conn, &new_community).unwrap();
let new_post = PostForm {
name: "A test post".into(),
@ -61,7 +61,7 @@ mod tests {
..PostForm::default()
};
let inserted_post = Post::create(&conn, &new_post).unwrap();
let inserted_post = Post::create(conn, &new_post).unwrap();
let post_like = PostLikeForm {
post_id: inserted_post.id,
@ -69,7 +69,7 @@ mod tests {
score: 1,
};
let _inserted_post_like = PostLike::like(&conn, &post_like).unwrap();
let _inserted_post_like = PostLike::like(conn, &post_like).unwrap();
let comment_form = CommentForm {
content: "A test comment".into(),
@ -78,7 +78,7 @@ mod tests {
..CommentForm::default()
};
let inserted_comment = Comment::create(&conn, &comment_form, None).unwrap();
let inserted_comment = Comment::create(conn, &comment_form, None).unwrap();
let mut comment_like = CommentLikeForm {
comment_id: inserted_comment.id,
@ -87,7 +87,7 @@ mod tests {
score: 1,
};
let _inserted_comment_like = CommentLike::like(&conn, &comment_like).unwrap();
let _inserted_comment_like = CommentLike::like(conn, &comment_like).unwrap();
let child_comment_form = CommentForm {
content: "A test comment".into(),
@ -97,7 +97,7 @@ mod tests {
};
let inserted_child_comment =
Comment::create(&conn, &child_comment_form, Some(&inserted_comment.path)).unwrap();
Comment::create(conn, &child_comment_form, Some(&inserted_comment.path)).unwrap();
let child_comment_like = CommentLikeForm {
comment_id: inserted_child_comment.id,
@ -106,10 +106,9 @@ mod tests {
score: 1,
};
let _inserted_child_comment_like = CommentLike::like(&conn, &child_comment_like).unwrap();
let _inserted_child_comment_like = CommentLike::like(conn, &child_comment_like).unwrap();
let person_aggregates_before_delete =
PersonAggregates::read(&conn, inserted_person.id).unwrap();
let person_aggregates_before_delete = PersonAggregates::read(conn, inserted_person.id).unwrap();
assert_eq!(1, person_aggregates_before_delete.post_count);
assert_eq!(1, person_aggregates_before_delete.post_score);
@ -117,45 +116,45 @@ mod tests {
assert_eq!(2, person_aggregates_before_delete.comment_score);
// Remove a post like
PostLike::remove(&conn, inserted_person.id, inserted_post.id).unwrap();
let after_post_like_remove = PersonAggregates::read(&conn, inserted_person.id).unwrap();
PostLike::remove(conn, inserted_person.id, inserted_post.id).unwrap();
let after_post_like_remove = PersonAggregates::read(conn, inserted_person.id).unwrap();
assert_eq!(0, after_post_like_remove.post_score);
// Remove a parent comment (the scores should also be removed)
Comment::delete(&conn, inserted_comment.id).unwrap();
Comment::delete(&conn, inserted_child_comment.id).unwrap();
let after_parent_comment_delete = PersonAggregates::read(&conn, inserted_person.id).unwrap();
Comment::delete(conn, inserted_comment.id).unwrap();
Comment::delete(conn, inserted_child_comment.id).unwrap();
let after_parent_comment_delete = PersonAggregates::read(conn, inserted_person.id).unwrap();
assert_eq!(0, after_parent_comment_delete.comment_count);
assert_eq!(0, after_parent_comment_delete.comment_score);
// Add in the two comments again, then delete the post.
let new_parent_comment = Comment::create(&conn, &comment_form, None).unwrap();
let new_parent_comment = Comment::create(conn, &comment_form, None).unwrap();
let _new_child_comment =
Comment::create(&conn, &child_comment_form, Some(&new_parent_comment.path)).unwrap();
Comment::create(conn, &child_comment_form, Some(&new_parent_comment.path)).unwrap();
comment_like.comment_id = new_parent_comment.id;
CommentLike::like(&conn, &comment_like).unwrap();
let after_comment_add = PersonAggregates::read(&conn, inserted_person.id).unwrap();
CommentLike::like(conn, &comment_like).unwrap();
let after_comment_add = PersonAggregates::read(conn, inserted_person.id).unwrap();
assert_eq!(2, after_comment_add.comment_count);
assert_eq!(1, after_comment_add.comment_score);
Post::delete(&conn, inserted_post.id).unwrap();
let after_post_delete = PersonAggregates::read(&conn, inserted_person.id).unwrap();
Post::delete(conn, inserted_post.id).unwrap();
let after_post_delete = PersonAggregates::read(conn, inserted_person.id).unwrap();
assert_eq!(0, after_post_delete.comment_score);
assert_eq!(0, after_post_delete.comment_count);
assert_eq!(0, after_post_delete.post_score);
assert_eq!(0, after_post_delete.post_count);
// This should delete all the associated rows, and fire triggers
let person_num_deleted = Person::delete(&conn, inserted_person.id).unwrap();
let person_num_deleted = Person::delete(conn, inserted_person.id).unwrap();
assert_eq!(1, person_num_deleted);
Person::delete(&conn, another_inserted_person.id).unwrap();
Person::delete(conn, another_inserted_person.id).unwrap();
// Delete the community
let community_num_deleted = Community::delete(&conn, inserted_community.id).unwrap();
let community_num_deleted = Community::delete(conn, inserted_community.id).unwrap();
assert_eq!(1, community_num_deleted);
// Should be none found
let after_delete = PersonAggregates::read(&conn, inserted_person.id);
let after_delete = PersonAggregates::read(conn, inserted_person.id);
assert!(after_delete.is_err());
}
}

@ -2,7 +2,7 @@ use crate::{aggregates::structs::PostAggregates, newtypes::PostId, schema::post_
use diesel::{result::Error, *};
impl PostAggregates {
pub fn read(conn: &PgConnection, post_id: PostId) -> Result<Self, Error> {
pub fn read(conn: &mut PgConnection, post_id: PostId) -> Result<Self, Error> {
post_aggregates::table
.filter(post_aggregates::post_id.eq(post_id))
.first::<Self>(conn)
@ -27,7 +27,7 @@ mod tests {
#[test]
#[serial]
fn test_crud() {
let conn = establish_unpooled_connection();
let conn = &mut establish_unpooled_connection();
let new_person = PersonForm {
name: "thommy_community_agg".into(),
@ -35,7 +35,7 @@ mod tests {
..PersonForm::default()
};
let inserted_person = Person::create(&conn, &new_person).unwrap();
let inserted_person = Person::create(conn, &new_person).unwrap();
let another_person = PersonForm {
name: "jerry_community_agg".into(),
@ -43,7 +43,7 @@ mod tests {
..PersonForm::default()
};
let another_inserted_person = Person::create(&conn, &another_person).unwrap();
let another_inserted_person = Person::create(conn, &another_person).unwrap();
let new_community = CommunityForm {
name: "TIL_community_agg".into(),
@ -52,7 +52,7 @@ mod tests {
..CommunityForm::default()
};
let inserted_community = Community::create(&conn, &new_community).unwrap();
let inserted_community = Community::create(conn, &new_community).unwrap();
let new_post = PostForm {
name: "A test post".into(),
@ -61,7 +61,7 @@ mod tests {
..PostForm::default()
};
let inserted_post = Post::create(&conn, &new_post).unwrap();
let inserted_post = Post::create(conn, &new_post).unwrap();
let comment_form = CommentForm {
content: "A test comment".into(),
@ -70,7 +70,7 @@ mod tests {
..CommentForm::default()
};
let inserted_comment = Comment::create(&conn, &comment_form, None).unwrap();
let inserted_comment = Comment::create(conn, &comment_form, None).unwrap();
let child_comment_form = CommentForm {
content: "A test comment".into(),
@ -80,7 +80,7 @@ mod tests {
};
let inserted_child_comment =
Comment::create(&conn, &child_comment_form, Some(&inserted_comment.path)).unwrap();
Comment::create(conn, &child_comment_form, Some(&inserted_comment.path)).unwrap();
let post_like = PostLikeForm {
post_id: inserted_post.id,
@ -88,9 +88,9 @@ mod tests {
score: 1,
};
PostLike::like(&conn, &post_like).unwrap();
PostLike::like(conn, &post_like).unwrap();
let post_aggs_before_delete = PostAggregates::read(&conn, inserted_post.id).unwrap();
let post_aggs_before_delete = PostAggregates::read(conn, inserted_post.id).unwrap();
assert_eq!(2, post_aggs_before_delete.comments);
assert_eq!(1, post_aggs_before_delete.score);
@ -104,9 +104,9 @@ mod tests {
score: -1,
};
PostLike::like(&conn, &post_dislike).unwrap();
PostLike::like(conn, &post_dislike).unwrap();
let post_aggs_after_dislike = PostAggregates::read(&conn, inserted_post.id).unwrap();
let post_aggs_after_dislike = PostAggregates::read(conn, inserted_post.id).unwrap();
assert_eq!(2, post_aggs_after_dislike.comments);
assert_eq!(0, post_aggs_after_dislike.score);
@ -114,33 +114,33 @@ mod tests {
assert_eq!(1, post_aggs_after_dislike.downvotes);
// Remove the comments
Comment::delete(&conn, inserted_comment.id).unwrap();
Comment::delete(&conn, inserted_child_comment.id).unwrap();
let after_comment_delete = PostAggregates::read(&conn, inserted_post.id).unwrap();
Comment::delete(conn, inserted_comment.id).unwrap();
Comment::delete(conn, inserted_child_comment.id).unwrap();
let after_comment_delete = PostAggregates::read(conn, inserted_post.id).unwrap();
assert_eq!(0, after_comment_delete.comments);
assert_eq!(0, after_comment_delete.score);
assert_eq!(1, after_comment_delete.upvotes);
assert_eq!(1, after_comment_delete.downvotes);
// Remove the first post like
PostLike::remove(&conn, inserted_person.id, inserted_post.id).unwrap();
let after_like_remove = PostAggregates::read(&conn, inserted_post.id).unwrap();
PostLike::remove(conn, inserted_person.id, inserted_post.id).unwrap();
let after_like_remove = PostAggregates::read(conn, inserted_post.id).unwrap();
assert_eq!(0, after_like_remove.comments);
assert_eq!(-1, after_like_remove.score);
assert_eq!(0, after_like_remove.upvotes);
assert_eq!(1, after_like_remove.downvotes);
// This should delete all the associated rows, and fire triggers
Person::delete(&conn, another_inserted_person.id).unwrap();
let person_num_deleted = Person::delete(&conn, inserted_person.id).unwrap();
Person::delete(conn, another_inserted_person.id).unwrap();
let person_num_deleted = Person::delete(conn, inserted_person.id).unwrap();
assert_eq!(1, person_num_deleted);
// Delete the community
let community_num_deleted = Community::delete(&conn, inserted_community.id).unwrap();
let community_num_deleted = Community::delete(conn, inserted_community.id).unwrap();
assert_eq!(1, community_num_deleted);
// Should be none found, since the creator was deleted
let after_delete = PostAggregates::read(&conn, inserted_post.id);
let after_delete = PostAggregates::read(conn, inserted_post.id);
assert!(after_delete.is_err());
}
}

@ -2,7 +2,7 @@ use crate::{aggregates::structs::SiteAggregates, schema::site_aggregates};
use diesel::{result::Error, *};
impl SiteAggregates {
pub fn read(conn: &PgConnection) -> Result<Self, Error> {
pub fn read(conn: &mut PgConnection) -> Result<Self, Error> {
site_aggregates::table.first::<Self>(conn)
}
}
@ -26,7 +26,7 @@ mod tests {
#[test]
#[serial]
fn test_crud() {
let conn = establish_unpooled_connection();
let conn = &mut establish_unpooled_connection();
let new_person = PersonForm {
name: "thommy_site_agg".into(),
@ -34,7 +34,7 @@ mod tests {
..PersonForm::default()
};
let inserted_person = Person::create(&conn, &new_person).unwrap();
let inserted_person = Person::create(conn, &new_person).unwrap();
let site_form = SiteForm {
name: "test_site".into(),
@ -42,7 +42,7 @@ mod tests {
..Default::default()
};
let inserted_site = Site::create(&conn, &site_form).unwrap();
let inserted_site = Site::create(conn, &site_form).unwrap();
let new_community = CommunityForm {
name: "TIL_site_agg".into(),
@ -51,7 +51,7 @@ mod tests {
..CommunityForm::default()
};
let inserted_community = Community::create(&conn, &new_community).unwrap();
let inserted_community = Community::create(conn, &new_community).unwrap();
let new_post = PostForm {
name: "A test post".into(),
@ -61,8 +61,8 @@ mod tests {
};
// Insert two of those posts
let inserted_post = Post::create(&conn, &new_post).unwrap();
let _inserted_post_again = Post::create(&conn, &new_post).unwrap();
let inserted_post = Post::create(conn, &new_post).unwrap();
let _inserted_post_again = Post::create(conn, &new_post).unwrap();
let comment_form = CommentForm {
content: "A test comment".into(),
@ -72,7 +72,7 @@ mod tests {
};
// Insert two of those comments
let inserted_comment = Comment::create(&conn, &comment_form, None).unwrap();
let inserted_comment = Comment::create(conn, &comment_form, None).unwrap();
let child_comment_form = CommentForm {
content: "A test comment".into(),
@ -82,9 +82,9 @@ mod tests {
};
let _inserted_child_comment =
Comment::create(&conn, &child_comment_form, Some(&inserted_comment.path)).unwrap();
Comment::create(conn, &child_comment_form, Some(&inserted_comment.path)).unwrap();
let site_aggregates_before_delete = SiteAggregates::read(&conn).unwrap();
let site_aggregates_before_delete = SiteAggregates::read(conn).unwrap();
assert_eq!(1, site_aggregates_before_delete.users);
assert_eq!(1, site_aggregates_before_delete.communities);
@ -92,25 +92,25 @@ mod tests {
assert_eq!(2, site_aggregates_before_delete.comments);
// Try a post delete
Post::delete(&conn, inserted_post.id).unwrap();
let site_aggregates_after_post_delete = SiteAggregates::read(&conn).unwrap();
Post::delete(conn, inserted_post.id).unwrap();
let site_aggregates_after_post_delete = SiteAggregates::read(conn).unwrap();
assert_eq!(1, site_aggregates_after_post_delete.posts);
assert_eq!(0, site_aggregates_after_post_delete.comments);
// This shouuld delete all the associated rows, and fire triggers
let person_num_deleted = Person::delete(&conn, inserted_person.id).unwrap();
let person_num_deleted = Person::delete(conn, inserted_person.id).unwrap();
assert_eq!(1, person_num_deleted);
// Delete the community
let community_num_deleted = Community::delete(&conn, inserted_community.id).unwrap();
let community_num_deleted = Community::delete(conn, inserted_community.id).unwrap();
assert_eq!(1, community_num_deleted);
// Site should still exist, it can without a site creator.
let after_delete_creator = SiteAggregates::read(&conn);
let after_delete_creator = SiteAggregates::read(conn);
assert!(after_delete_creator.is_ok());
Site::delete(&conn, inserted_site.id).unwrap();
let after_delete_site = SiteAggregates::read(&conn);
Site::delete(conn, inserted_site.id).unwrap();
let after_delete_site = SiteAggregates::read(conn);
assert!(after_delete_site.is_err());
}
}

@ -10,9 +10,10 @@ use crate::schema::{
site_aggregates,
};
#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
#[cfg_attr(feature = "full", table_name = "comment_aggregates")]
#[cfg_attr(feature = "full", diesel(table_name = comment_aggregates))]
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))]
pub struct CommentAggregates {
pub id: i32,
pub comment_id: CommentId,
@ -23,9 +24,13 @@ pub struct CommentAggregates {
pub child_count: i32,
}
#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
#[cfg_attr(feature = "full", table_name = "community_aggregates")]
#[cfg_attr(feature = "full", diesel(table_name = community_aggregates))]
#[cfg_attr(
feature = "full",
diesel(belongs_to(crate::source::community::Community))
)]
pub struct CommunityAggregates {
pub id: i32,
pub community_id: CommunityId,
@ -39,9 +44,10 @@ pub struct CommunityAggregates {
pub users_active_half_year: i64,
}
#[derive(PartialEq, Debug, Serialize, Deserialize, Clone, Default)]
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
#[cfg_attr(feature = "full", table_name = "person_aggregates")]
#[cfg_attr(feature = "full", diesel(table_name = person_aggregates))]
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::person::Person)))]
pub struct PersonAggregates {
pub id: i32,
pub person_id: PersonId,
@ -51,9 +57,10 @@ pub struct PersonAggregates {
pub comment_score: i64,
}
#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
#[cfg_attr(feature = "full", table_name = "post_aggregates")]
#[cfg_attr(feature = "full", diesel(table_name = post_aggregates))]
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
pub struct PostAggregates {
pub id: i32,
pub post_id: PostId,
@ -67,9 +74,10 @@ pub struct PostAggregates {
pub newest_comment_time: chrono::NaiveDateTime,
}
#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
#[cfg_attr(feature = "full", table_name = "site_aggregates")]
#[cfg_attr(feature = "full", diesel(table_name = site_aggregates))]
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::site::Site)))]
pub struct SiteAggregates {
pub id: i32,
pub site_id: i32,

@ -9,12 +9,12 @@ use serde_json::Value;
impl Crud for Activity {
type Form = ActivityForm;
type IdType = i32;
fn read(conn: &PgConnection, activity_id: i32) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, activity_id: i32) -> Result<Self, Error> {
use crate::schema::activity::dsl::*;
activity.find(activity_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, new_activity: &ActivityForm) -> Result<Self, Error> {
fn create(conn: &mut PgConnection, new_activity: &ActivityForm) -> Result<Self, Error> {
use crate::schema::activity::dsl::*;
insert_into(activity)
.values(new_activity)
@ -22,7 +22,7 @@ impl Crud for Activity {
}
fn update(
conn: &PgConnection,
conn: &mut PgConnection,
activity_id: i32,
new_activity: &ActivityForm,
) -> Result<Self, Error> {
@ -31,7 +31,7 @@ impl Crud for Activity {
.set(new_activity)
.get_result::<Self>(conn)
}
fn delete(conn: &PgConnection, activity_id: i32) -> Result<usize, Error> {
fn delete(conn: &mut PgConnection, activity_id: i32) -> Result<usize, Error> {
use crate::schema::activity::dsl::*;
diesel::delete(activity.find(activity_id)).execute(conn)
}
@ -40,7 +40,7 @@ impl Crud for Activity {
impl Activity {
/// Returns true if the insert was successful
pub fn insert(
conn: &PgConnection,
conn: &mut PgConnection,
ap_id: DbUrl,
data: Value,
local: bool,
@ -64,12 +64,12 @@ impl Activity {
}
}
pub fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Activity, Error> {
pub fn read_from_apub_id(conn: &mut PgConnection, object_id: &DbUrl) -> Result<Activity, Error> {
use crate::schema::activity::dsl::*;
activity.filter(ap_id.eq(object_id)).first::<Self>(conn)
}
pub fn delete_olds(conn: &PgConnection) -> Result<usize, Error> {
pub fn delete_olds(conn: &mut PgConnection) -> Result<usize, Error> {
use crate::schema::activity::dsl::*;
diesel::delete(activity.filter(published.lt(now - 6.months()))).execute(conn)
}
@ -93,7 +93,7 @@ mod tests {
#[test]
#[serial]
fn test_crud() {
let conn = establish_unpooled_connection();
let conn = &mut establish_unpooled_connection();
let creator_form = PersonForm {
name: "activity_creator_pm".into(),
@ -101,7 +101,7 @@ mod tests {
..PersonForm::default()
};
let inserted_creator = Person::create(&conn, &creator_form).unwrap();
let inserted_creator = Person::create(conn, &creator_form).unwrap();
let ap_id: DbUrl = Url::parse(
"https://enterprise.lemmy.ml/activities/delete/f1b5d57c-80f8-4e03-a615-688d552e946c",
@ -130,7 +130,7 @@ mod tests {
updated: None,
};
let inserted_activity = Activity::create(&conn, &activity_form).unwrap();
let inserted_activity = Activity::create(conn, &activity_form).unwrap();
let expected_activity = Activity {
ap_id: ap_id.clone(),
@ -142,10 +142,10 @@ mod tests {
updated: None,
};
let read_activity = Activity::read(&conn, inserted_activity.id).unwrap();
let read_activity_by_apub_id = Activity::read_from_apub_id(&conn, &ap_id).unwrap();
Person::delete(&conn, inserted_creator.id).unwrap();
Activity::delete(&conn, inserted_activity.id).unwrap();
let read_activity = Activity::read(conn, inserted_activity.id).unwrap();
let read_activity_by_apub_id = Activity::read_from_apub_id(conn, &ap_id).unwrap();
Person::delete(conn, inserted_creator.id).unwrap();
Activity::delete(conn, inserted_activity.id).unwrap();
assert_eq!(expected_activity, read_activity);
assert_eq!(expected_activity, read_activity_by_apub_id);

@ -17,7 +17,7 @@ use url::Url;
impl Comment {
pub fn update_ap_id(
conn: &PgConnection,
conn: &mut PgConnection,
comment_id: CommentId,
apub_id: DbUrl,
) -> Result<Self, Error> {
@ -29,7 +29,7 @@ impl Comment {
}
pub fn permadelete_for_creator(
conn: &PgConnection,
conn: &mut PgConnection,
for_creator_id: PersonId,
) -> Result<Vec<Self>, Error> {
use crate::schema::comment::dsl::*;
@ -43,7 +43,7 @@ impl Comment {
}
pub fn update_deleted(
conn: &PgConnection,
conn: &mut PgConnection,
comment_id: CommentId,
new_deleted: bool,
) -> Result<Self, Error> {
@ -54,7 +54,7 @@ impl Comment {
}
pub fn update_removed(
conn: &PgConnection,
conn: &mut PgConnection,
comment_id: CommentId,
new_removed: bool,
) -> Result<Self, Error> {
@ -65,7 +65,7 @@ impl Comment {
}
pub fn update_removed_for_creator(
conn: &PgConnection,
conn: &mut PgConnection,
for_creator_id: PersonId,
new_removed: bool,
) -> Result<Vec<Self>, Error> {
@ -76,7 +76,7 @@ impl Comment {
}
pub fn create(
conn: &PgConnection,
conn: &mut PgConnection,
comment_form: &CommentForm,
parent_path: Option<&Ltree>,
) -> Result<Comment, Error> {
@ -141,7 +141,7 @@ where ca.comment_id = c.id",
inserted_comment
}
}
pub fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, Error> {
pub fn read_from_apub_id(conn: &mut PgConnection, object_id: Url) -> Result<Option<Self>, Error> {
use crate::schema::comment::dsl::*;
let object_id: DbUrl = object_id.into();
Ok(
@ -170,23 +170,23 @@ where ca.comment_id = c.id",
impl Crud for Comment {
type Form = CommentForm;
type IdType = CommentId;
fn read(conn: &PgConnection, comment_id: CommentId) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, comment_id: CommentId) -> Result<Self, Error> {
use crate::schema::comment::dsl::*;
comment.find(comment_id).first::<Self>(conn)
}
fn delete(conn: &PgConnection, comment_id: CommentId) -> Result<usize, Error> {
fn delete(conn: &mut PgConnection, comment_id: CommentId) -> Result<usize, Error> {
use crate::schema::comment::dsl::*;
diesel::delete(comment.find(comment_id)).execute(conn)
}
/// This is unimplemented, use [[Comment::create]]
fn create(_conn: &PgConnection, _comment_form: &CommentForm) -> Result<Self, Error> {
fn create(_conn: &mut PgConnection, _comment_form: &CommentForm) -> Result<Self, Error> {
unimplemented!();
}
fn update(
conn: &PgConnection,
conn: &mut PgConnection,
comment_id: CommentId,
comment_form: &CommentForm,
) -> Result<Self, Error> {
@ -200,7 +200,7 @@ impl Crud for Comment {
impl Likeable for CommentLike {
type Form = CommentLikeForm;
type IdType = CommentId;
fn like(conn: &PgConnection, comment_like_form: &CommentLikeForm) -> Result<Self, Error> {
fn like(conn: &mut PgConnection, comment_like_form: &CommentLikeForm) -> Result<Self, Error> {
use crate::schema::comment_like::dsl::*;
insert_into(comment_like)
.values(comment_like_form)
@ -210,7 +210,7 @@ impl Likeable for CommentLike {
.get_result::<Self>(conn)
}
fn remove(
conn: &PgConnection,
conn: &mut PgConnection,
person_id: PersonId,
comment_id: CommentId,
) -> Result<usize, Error> {
@ -226,7 +226,7 @@ impl Likeable for CommentLike {
impl Saveable for CommentSaved {
type Form = CommentSavedForm;
fn save(conn: &PgConnection, comment_saved_form: &CommentSavedForm) -> Result<Self, Error> {
fn save(conn: &mut PgConnection, comment_saved_form: &CommentSavedForm) -> Result<Self, Error> {
use crate::schema::comment_saved::dsl::*;
insert_into(comment_saved)
.values(comment_saved_form)
@ -235,7 +235,10 @@ impl Saveable for CommentSaved {
.set(comment_saved_form)
.get_result::<Self>(conn)
}
fn unsave(conn: &PgConnection, comment_saved_form: &CommentSavedForm) -> Result<usize, Error> {
fn unsave(
conn: &mut PgConnection,
comment_saved_form: &CommentSavedForm,
) -> Result<usize, Error> {
use crate::schema::comment_saved::dsl::*;
diesel::delete(
comment_saved
@ -272,7 +275,7 @@ mod tests {
#[test]
#[serial]
fn test_crud() {
let conn = establish_unpooled_connection();
let conn = &mut establish_unpooled_connection();
let new_person = PersonForm {
name: "terry".into(),
@ -280,7 +283,7 @@ mod tests {
..PersonForm::default()
};
let inserted_person = Person::create(&conn, &new_person).unwrap();
let inserted_person = Person::create(conn, &new_person).unwrap();
let new_community = CommunityForm {
name: "test community".to_string(),
@ -289,7 +292,7 @@ mod tests {
..CommunityForm::default()
};
let inserted_community = Community::create(&conn, &new_community).unwrap();
let inserted_community = Community::create(conn, &new_community).unwrap();
let new_post = PostForm {
name: "A test post".into(),
@ -298,7 +301,7 @@ mod tests {
..PostForm::default()
};
let inserted_post = Post::create(&conn, &new_post).unwrap();
let inserted_post = Post::create(conn, &new_post).unwrap();
let comment_form = CommentForm {
content: "A test comment".into(),
@ -307,7 +310,7 @@ mod tests {
..CommentForm::default()
};
let inserted_comment = Comment::create(&conn, &comment_form, None).unwrap();
let inserted_comment = Comment::create(conn, &comment_form, None).unwrap();
let expected_comment = Comment {
id: inserted_comment.id,
@ -334,7 +337,7 @@ mod tests {
};
let inserted_child_comment =
Comment::create(&conn, &child_comment_form, Some(&inserted_comment.path)).unwrap();
Comment::create(conn, &child_comment_form, Some(&inserted_comment.path)).unwrap();
// Comment Like
let comment_like_form = CommentLikeForm {
@ -344,7 +347,7 @@ mod tests {
score: 1,
};
let inserted_comment_like = CommentLike::like(&conn, &comment_like_form).unwrap();
let inserted_comment_like = CommentLike::like(conn, &comment_like_form).unwrap();
let expected_comment_like = CommentLike {
id: inserted_comment_like.id,
@ -361,7 +364,7 @@ mod tests {
person_id: inserted_person.id,
};
let inserted_comment_saved = CommentSaved::save(&conn, &comment_saved_form).unwrap();
let inserted_comment_saved = CommentSaved::save(conn, &comment_saved_form).unwrap();
let expected_comment_saved = CommentSaved {
id: inserted_comment_saved.id,
@ -370,15 +373,15 @@ mod tests {
published: inserted_comment_saved.published,
};
let read_comment = Comment::read(&conn, inserted_comment.id).unwrap();
let updated_comment = Comment::update(&conn, inserted_comment.id, &comment_form).unwrap();
let like_removed = CommentLike::remove(&conn, inserted_person.id, inserted_comment.id).unwrap();
let saved_removed = CommentSaved::unsave(&conn, &comment_saved_form).unwrap();
let num_deleted = Comment::delete(&conn, inserted_comment.id).unwrap();
Comment::delete(&conn, inserted_child_comment.id).unwrap();
Post::delete(&conn, inserted_post.id).unwrap();
Community::delete(&conn, inserted_community.id).unwrap();
Person::delete(&conn, inserted_person.id).unwrap();
let read_comment = Comment::read(conn, inserted_comment.id).unwrap();
let updated_comment = Comment::update(conn, inserted_comment.id, &comment_form).unwrap();
let like_removed = CommentLike::remove(conn, inserted_person.id, inserted_comment.id).unwrap();
let saved_removed = CommentSaved::unsave(conn, &comment_saved_form).unwrap();
let num_deleted = Comment::delete(conn, inserted_comment.id).unwrap();
Comment::delete(conn, inserted_child_comment.id).unwrap();
Post::delete(conn, inserted_post.id).unwrap();
Community::delete(conn, inserted_community.id).unwrap();
Person::delete(conn, inserted_person.id).unwrap();
assert_eq!(expected_comment, read_comment);
assert_eq!(expected_comment, inserted_comment);

@ -8,12 +8,12 @@ use diesel::{dsl::*, result::Error, *};
impl Crud for CommentReply {
type Form = CommentReplyForm;
type IdType = CommentReplyId;
fn read(conn: &PgConnection, comment_reply_id: CommentReplyId) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, comment_reply_id: CommentReplyId) -> Result<Self, Error> {
use crate::schema::comment_reply::dsl::*;
comment_reply.find(comment_reply_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, comment_reply_form: &CommentReplyForm) -> Result<Self, Error> {
fn create(conn: &mut PgConnection, comment_reply_form: &CommentReplyForm) -> Result<Self, Error> {
use crate::schema::comment_reply::dsl::*;
// since the return here isnt utilized, we dont need to do an update
// but get_result doesnt return the existing row here
@ -26,7 +26,7 @@ impl Crud for CommentReply {
}
fn update(
conn: &PgConnection,
conn: &mut PgConnection,
comment_reply_id: CommentReplyId,
comment_reply_form: &CommentReplyForm,
) -> Result<Self, Error> {
@ -39,7 +39,7 @@ impl Crud for CommentReply {
impl CommentReply {
pub fn update_read(
conn: &PgConnection,
conn: &mut PgConnection,
comment_reply_id: CommentReplyId,
new_read: bool,
) -> Result<CommentReply, Error> {
@ -50,7 +50,7 @@ impl CommentReply {
}
pub fn mark_all_as_read(
conn: &PgConnection,
conn: &mut PgConnection,
for_recipient_id: PersonId,
) -> Result<Vec<CommentReply>, Error> {
use crate::schema::comment_reply::dsl::*;
@ -63,7 +63,10 @@ impl CommentReply {
.get_results::<Self>(conn)
}
pub fn read_by_comment(conn: &PgConnection, for_comment_id: CommentId) -> Result<Self, Error> {
pub fn read_by_comment(
conn: &mut PgConnection,
for_comment_id: CommentId,
) -> Result<Self, Error> {
use crate::schema::comment_reply::dsl::*;
comment_reply
.filter(comment_id.eq(for_comment_id))
@ -89,7 +92,7 @@ mod tests {
#[test]
#[serial]
fn test_crud() {
let conn = establish_unpooled_connection();
let conn = &mut establish_unpooled_connection();
let new_person = PersonForm {
name: "terrylake".into(),
@ -97,7 +100,7 @@ mod tests {
..PersonForm::default()
};
let inserted_person = Person::create(&conn, &new_person).unwrap();
let inserted_person = Person::create(conn, &new_person).unwrap();
let recipient_form = PersonForm {
name: "terrylakes recipient".into(),
@ -105,7 +108,7 @@ mod tests {
..PersonForm::default()
};
let inserted_recipient = Person::create(&conn, &recipient_form).unwrap();
let inserted_recipient = Person::create(conn, &recipient_form).unwrap();
let new_community = CommunityForm {
name: "test community lake".to_string(),
@ -114,7 +117,7 @@ mod tests {
..CommunityForm::default()
};
let inserted_community = Community::create(&conn, &new_community).unwrap();
let inserted_community = Community::create(conn, &new_community).unwrap();
let new_post = PostForm {
name: "A test post".into(),
@ -123,7 +126,7 @@ mod tests {
..PostForm::default()
};
let inserted_post = Post::create(&conn, &new_post).unwrap();
let inserted_post = Post::create(conn, &new_post).unwrap();
let comment_form = CommentForm {
content: "A test comment".into(),
@ -132,7 +135,7 @@ mod tests {
..CommentForm::default()
};
let inserted_comment = Comment::create(&conn, &comment_form, None).unwrap();
let inserted_comment = Comment::create(conn, &comment_form, None).unwrap();
let comment_reply_form = CommentReplyForm {
recipient_id: inserted_recipient.id,
@ -140,7 +143,7 @@ mod tests {
read: None,
};
let inserted_reply = CommentReply::create(&conn, &comment_reply_form).unwrap();
let inserted_reply = CommentReply::create(conn, &comment_reply_form).unwrap();
let expected_reply = CommentReply {
id: inserted_reply.id,
@ -150,14 +153,13 @@ mod tests {
published: inserted_reply.published,
};
let read_reply = CommentReply::read(&conn, inserted_reply.id).unwrap();
let updated_reply =
CommentReply::update(&conn, inserted_reply.id, &comment_reply_form).unwrap();
Comment::delete(&conn, inserted_comment.id).unwrap();
Post::delete(&conn, inserted_post.id).unwrap();
Community::delete(&conn, inserted_community.id).unwrap();
Person::delete(&conn, inserted_person.id).unwrap();
Person::delete(&conn, inserted_recipient.id).unwrap();
let read_reply = CommentReply::read(conn, inserted_reply.id).unwrap();
let updated_reply = CommentReply::update(conn, inserted_reply.id, &comment_reply_form).unwrap();
Comment::delete(conn, inserted_comment.id).unwrap();
Post::delete(conn, inserted_post.id).unwrap();
Community::delete(conn, inserted_community.id).unwrap();
Person::delete(conn, inserted_person.id).unwrap();
Person::delete(conn, inserted_recipient.id).unwrap();
assert_eq!(expected_reply, read_reply);
assert_eq!(expected_reply, inserted_reply);

@ -13,7 +13,10 @@ impl Reportable for CommentReport {
///
/// * `conn` - the postgres connection
/// * `comment_report_form` - the filled CommentReportForm to insert
fn report(conn: &PgConnection, comment_report_form: &CommentReportForm) -> Result<Self, Error> {
fn report(
conn: &mut PgConnection,
comment_report_form: &CommentReportForm,
) -> Result<Self, Error> {
use crate::schema::comment_report::dsl::*;
insert_into(comment_report)
.values(comment_report_form)
@ -26,7 +29,7 @@ impl Reportable for CommentReport {
/// * `report_id` - the id of the report to resolve
/// * `by_resolver_id` - the id of the user resolving the report
fn resolve(
conn: &PgConnection,
conn: &mut PgConnection,
report_id: Self::IdType,
by_resolver_id: PersonId,
) -> Result<usize, Error> {
@ -46,7 +49,7 @@ impl Reportable for CommentReport {
/// * `report_id` - the id of the report to unresolve
/// * `by_resolver_id` - the id of the user unresolving the report
fn unresolve(
conn: &PgConnection,
conn: &mut PgConnection,
report_id: Self::IdType,
by_resolver_id: PersonId,
) -> Result<usize, Error> {

@ -73,17 +73,17 @@ mod safe_type {
impl Crud for Community {
type Form = CommunityForm;
type IdType = CommunityId;
fn read(conn: &PgConnection, community_id: CommunityId) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, community_id: CommunityId) -> Result<Self, Error> {
use crate::schema::community::dsl::*;
community.find(community_id).first::<Self>(conn)
}
fn delete(conn: &PgConnection, community_id: CommunityId) -> Result<usize, Error> {
fn delete(conn: &mut PgConnection, community_id: CommunityId) -> Result<usize, Error> {
use crate::schema::community::dsl::*;
diesel::delete(community.find(community_id)).execute(conn)
}
fn create(conn: &PgConnection, new_community: &CommunityForm) -> Result<Self, Error> {
fn create(conn: &mut PgConnection, new_community: &CommunityForm) -> Result<Self, Error> {
use crate::schema::community::dsl::*;
insert_into(community)
.values(new_community)
@ -91,7 +91,7 @@ impl Crud for Community {
}
fn update(
conn: &PgConnection,
conn: &mut PgConnection,
community_id: CommunityId,
new_community: &CommunityForm,
) -> Result<Self, Error> {
@ -104,7 +104,7 @@ impl Crud for Community {
impl Community {
pub fn update_deleted(
conn: &PgConnection,
conn: &mut PgConnection,
community_id: CommunityId,
new_deleted: bool,
) -> Result<Community, Error> {
@ -115,7 +115,7 @@ impl Community {
}
pub fn update_removed(
conn: &PgConnection,
conn: &mut PgConnection,
community_id: CommunityId,
new_removed: bool,
) -> Result<Community, Error> {
@ -125,12 +125,15 @@ impl Community {
.get_result::<Self>(conn)
}
pub fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<DbUrl>, Error> {
pub fn distinct_federated_communities(conn: &mut PgConnection) -> Result<Vec<DbUrl>, Error> {
use crate::schema::community::dsl::*;
community.select(actor_id).distinct().load::<DbUrl>(conn)
}
pub fn upsert(conn: &PgConnection, community_form: &CommunityForm) -> Result<Community, Error> {
pub fn upsert(
conn: &mut PgConnection,
community_form: &CommunityForm,
) -> Result<Community, Error> {
use crate::schema::community::dsl::*;
insert_into(community)
.values(community_form)
@ -141,7 +144,7 @@ impl Community {
}
pub fn remove_avatar_and_banner(
conn: &PgConnection,
conn: &mut PgConnection,
community_id: CommunityId,
) -> Result<Self, Error> {
use crate::schema::community::dsl::*;
@ -157,7 +160,7 @@ impl Community {
impl Joinable for CommunityModerator {
type Form = CommunityModeratorForm;
fn join(
conn: &PgConnection,
conn: &mut PgConnection,
community_moderator_form: &CommunityModeratorForm,
) -> Result<Self, Error> {
use crate::schema::community_moderator::dsl::*;
@ -167,7 +170,7 @@ impl Joinable for CommunityModerator {
}
fn leave(
conn: &PgConnection,
conn: &mut PgConnection,
community_moderator_form: &CommunityModeratorForm,
) -> Result<usize, Error> {
use crate::schema::community_moderator::dsl::*;
@ -202,7 +205,7 @@ impl DeleteableOrRemoveable for Community {
impl CommunityModerator {
pub fn delete_for_community(
conn: &PgConnection,
conn: &mut PgConnection,
for_community_id: CommunityId,
) -> Result<usize, Error> {
use crate::schema::community_moderator::dsl::*;
@ -210,7 +213,7 @@ impl CommunityModerator {
}
pub fn get_person_moderated_communities(
conn: &PgConnection,
conn: &mut PgConnection,
for_person_id: PersonId,
) -> Result<Vec<CommunityId>, Error> {
use crate::schema::community_moderator::dsl::*;
@ -224,7 +227,7 @@ impl CommunityModerator {
impl Bannable for CommunityPersonBan {
type Form = CommunityPersonBanForm;
fn ban(
conn: &PgConnection,
conn: &mut PgConnection,
community_person_ban_form: &CommunityPersonBanForm,
) -> Result<Self, Error> {
use crate::schema::community_person_ban::dsl::*;
@ -237,7 +240,7 @@ impl Bannable for CommunityPersonBan {
}
fn unban(
conn: &PgConnection,
conn: &mut PgConnection,
community_person_ban_form: &CommunityPersonBanForm,
) -> Result<usize, Error> {
use crate::schema::community_person_ban::dsl::*;
@ -269,7 +272,7 @@ impl CommunityFollower {
impl Followable for CommunityFollower {
type Form = CommunityFollowerForm;
fn follow(
conn: &PgConnection,
conn: &mut PgConnection,
community_follower_form: &CommunityFollowerForm,
) -> Result<Self, Error> {
use crate::schema::community_follower::dsl::*;
@ -281,7 +284,7 @@ impl Followable for CommunityFollower {
.get_result::<Self>(conn)
}
fn follow_accepted(
conn: &PgConnection,
conn: &mut PgConnection,
community_id_: CommunityId,
person_id_: PersonId,
) -> Result<Self, Error>
@ -298,7 +301,7 @@ impl Followable for CommunityFollower {
.get_result::<Self>(conn)
}
fn unfollow(
conn: &PgConnection,
conn: &mut PgConnection,
community_follower_form: &CommunityFollowerForm,
) -> Result<usize, Error> {
use crate::schema::community_follower::dsl::*;
@ -311,7 +314,10 @@ impl Followable for CommunityFollower {
}
// TODO: this function name only makes sense if you call it with a remote community. for a local
// community, it will also return true if only remote followers exist
fn has_local_followers(conn: &PgConnection, community_id_: CommunityId) -> Result<bool, Error> {
fn has_local_followers(
conn: &mut PgConnection,
community_id_: CommunityId,
) -> Result<bool, Error> {
use crate::schema::community_follower::dsl::*;
diesel::select(exists(
community_follower.filter(community_id.eq(community_id_)),
@ -321,7 +327,7 @@ impl Followable for CommunityFollower {
}
impl ApubActor for Community {
fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Option<Self>, Error> {
fn read_from_apub_id(conn: &mut PgConnection, object_id: &DbUrl) -> Result<Option<Self>, Error> {
use crate::schema::community::dsl::*;
Ok(
community
@ -333,7 +339,7 @@ impl ApubActor for Community {
}
fn read_from_name(
conn: &PgConnection,
conn: &mut PgConnection,
community_name: &str,
include_deleted: bool,
) -> Result<Community, Error> {
@ -349,7 +355,7 @@ impl ApubActor for Community {
}
fn read_from_name_and_domain(
conn: &PgConnection,
conn: &mut PgConnection,
community_name: &str,
protocol_domain: &str,
) -> Result<Community, Error> {
@ -373,7 +379,7 @@ mod tests {
#[test]
#[serial]
fn test_crud() {
let conn = establish_unpooled_connection();
let conn = &mut establish_unpooled_connection();
let new_person = PersonForm {
name: "bobbee".into(),
@ -381,7 +387,7 @@ mod tests {
..PersonForm::default()
};
let inserted_person = Person::create(&conn, &new_person).unwrap();
let inserted_person = Person::create(conn, &new_person).unwrap();
let new_community = CommunityForm {
name: "TIL".into(),
@ -390,7 +396,7 @@ mod tests {
..CommunityForm::default()
};
let inserted_community = Community::create(&conn, &new_community).unwrap();
let inserted_community = Community::create(conn, &new_community).unwrap();
let expected_community = Community {
id: inserted_community.id,
@ -423,7 +429,7 @@ mod tests {
};
let inserted_community_follower =
CommunityFollower::follow(&conn, &community_follower_form).unwrap();
CommunityFollower::follow(conn, &community_follower_form).unwrap();
let expected_community_follower = CommunityFollower {
id: inserted_community_follower.id,
@ -439,7 +445,7 @@ mod tests {
};
let inserted_community_moderator =
CommunityModerator::join(&conn, &community_moderator_form).unwrap();
CommunityModerator::join(conn, &community_moderator_form).unwrap();
let expected_community_moderator = CommunityModerator {
id: inserted_community_moderator.id,
@ -455,7 +461,7 @@ mod tests {
};
let inserted_community_person_ban =
CommunityPersonBan::ban(&conn, &community_person_ban_form).unwrap();
CommunityPersonBan::ban(conn, &community_person_ban_form).unwrap();
let expected_community_person_ban = CommunityPersonBan {
id: inserted_community_person_ban.id,
@ -465,14 +471,13 @@ mod tests {
expires: None,
};
let read_community = Community::read(&conn, inserted_community.id).unwrap();
let updated_community =
Community::update(&conn, inserted_community.id, &new_community).unwrap();
let ignored_community = CommunityFollower::unfollow(&conn, &community_follower_form).unwrap();
let left_community = CommunityModerator::leave(&conn, &community_moderator_form).unwrap();
let unban = CommunityPersonBan::unban(&conn, &community_person_ban_form).unwrap();
let num_deleted = Community::delete(&conn, inserted_community.id).unwrap();
Person::delete(&conn, inserted_person.id).unwrap();
let read_community = Community::read(conn, inserted_community.id).unwrap();
let updated_community = Community::update(conn, inserted_community.id, &new_community).unwrap();
let ignored_community = CommunityFollower::unfollow(conn, &community_follower_form).unwrap();
let left_community = CommunityModerator::leave(conn, &community_moderator_form).unwrap();
let unban = CommunityPersonBan::unban(conn, &community_person_ban_form).unwrap();
let num_deleted = Community::delete(conn, inserted_community.id).unwrap();
Person::delete(conn, inserted_person.id).unwrap();
assert_eq!(expected_community, read_community);
assert_eq!(expected_community, inserted_community);

@ -6,7 +6,7 @@ use diesel::{dsl::*, result::Error, *};
impl Blockable for CommunityBlock {
type Form = CommunityBlockForm;
fn block(conn: &PgConnection, community_block_form: &Self::Form) -> Result<Self, Error> {
fn block(conn: &mut PgConnection, community_block_form: &Self::Form) -> Result<Self, Error> {
use crate::schema::community_block::dsl::*;
insert_into(community_block)
.values(community_block_form)
@ -15,7 +15,7 @@ impl Blockable for CommunityBlock {
.set(community_block_form)
.get_result::<Self>(conn)
}
fn unblock(conn: &PgConnection, community_block_form: &Self::Form) -> Result<usize, Error> {
fn unblock(conn: &mut PgConnection, community_block_form: &Self::Form) -> Result<usize, Error> {
use crate::schema::community_block::dsl::*;
diesel::delete(
community_block

@ -12,33 +12,37 @@ use diesel::{
impl Crud for EmailVerification {
type Form = EmailVerificationForm;
type IdType = i32;
fn create(conn: &PgConnection, form: &EmailVerificationForm) -> Result<Self, Error> {
fn create(conn: &mut PgConnection, form: &EmailVerificationForm) -> Result<Self, Error> {
use crate::schema::email_verification::dsl::*;
insert_into(email_verification)
.values(form)
.get_result::<Self>(conn)
}
fn read(conn: &PgConnection, id_: i32) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, id_: i32) -> Result<Self, Error> {
use crate::schema::email_verification::dsl::*;
email_verification.find(id_).first::<Self>(conn)
}
fn update(conn: &PgConnection, id_: i32, form: &EmailVerificationForm) -> Result<Self, Error> {
fn update(
conn: &mut PgConnection,
id_: i32,
form: &EmailVerificationForm,
) -> Result<Self, Error> {
use crate::schema::email_verification::dsl::*;
diesel::update(email_verification.find(id_))
.set(form)
.get_result::<Self>(conn)
}
fn delete(conn: &PgConnection, id_: i32) -> Result<usize, Error> {
fn delete(conn: &mut PgConnection, id_: i32) -> Result<usize, Error> {
use crate::schema::email_verification::dsl::*;
diesel::delete(email_verification.find(id_)).execute(conn)
}
}
impl EmailVerification {
pub fn read_for_token(conn: &PgConnection, token: &str) -> Result<Self, Error> {
pub fn read_for_token(conn: &mut PgConnection, token: &str) -> Result<Self, Error> {
use crate::schema::email_verification::dsl::*;
email_verification
.filter(verification_token.eq(token))
@ -46,7 +50,7 @@ impl EmailVerification {
.first::<Self>(conn)
}
pub fn delete_old_tokens_for_local_user(
conn: &PgConnection,
conn: &mut PgConnection,
local_user_id_: LocalUserId,
) -> Result<usize, Error> {
use crate::schema::email_verification::dsl::*;

@ -2,23 +2,23 @@ use crate::{newtypes::LanguageId, source::language::Language};
use diesel::{result::Error, PgConnection, RunQueryDsl, *};
impl Language {
pub fn read_all(conn: &PgConnection) -> Result<Vec<Language>, Error> {
pub fn read_all(conn: &mut PgConnection) -> Result<Vec<Language>, Error> {
use crate::schema::language::dsl::*;
language.load::<Self>(conn)
}
pub fn read_from_id(conn: &PgConnection, id_: LanguageId) -> Result<Language, Error> {
pub fn read_from_id(conn: &mut PgConnection, id_: LanguageId) -> Result<Language, Error> {
use crate::schema::language::dsl::*;
language.filter(id.eq(id_)).first::<Self>(conn)
}
pub fn read_id_from_code(conn: &PgConnection, code_: &str) -> Result<LanguageId, Error> {
pub fn read_id_from_code(conn: &mut PgConnection, code_: &str) -> Result<LanguageId, Error> {
use crate::schema::language::dsl::*;
Ok(language.filter(code.eq(code_)).first::<Self>(conn)?.id)
}
pub fn read_id_from_code_opt(
conn: &PgConnection,
conn: &mut PgConnection,
code_: Option<&str>,
) -> Result<Option<LanguageId>, Error> {
if let Some(code_) = code_ {
@ -28,7 +28,7 @@ impl Language {
}
}
pub fn read_undetermined(conn: &PgConnection) -> Result<LanguageId, Error> {
pub fn read_undetermined(conn: &mut PgConnection) -> Result<LanguageId, Error> {
use crate::schema::language::dsl::*;
Ok(language.filter(code.eq("und")).first::<Self>(conn)?.id)
}
@ -42,9 +42,9 @@ mod tests {
#[test]
#[serial]
fn test_languages() {
let conn = establish_unpooled_connection();
let conn = &mut establish_unpooled_connection();
let all = Language::read_all(&conn).unwrap();
let all = Language::read_all(conn).unwrap();
assert_eq!(184, all.len());
assert_eq!("ak", all[5].code);

@ -67,7 +67,7 @@ mod safe_settings_type {
}
impl LocalUser {
pub fn register(conn: &PgConnection, form: &LocalUserForm) -> Result<Self, Error> {
pub fn register(conn: &mut PgConnection, form: &LocalUserForm) -> Result<Self, Error> {
let mut edited_user = form.clone();
let password_hash = form
.password_encrypted
@ -79,7 +79,7 @@ impl LocalUser {
}
pub fn update_password(
conn: &PgConnection,
conn: &mut PgConnection,
local_user_id: LocalUserId,
new_password: &str,
) -> Result<Self, Error> {
@ -93,14 +93,14 @@ impl LocalUser {
.get_result::<Self>(conn)
}
pub fn set_all_users_email_verified(conn: &PgConnection) -> Result<Vec<Self>, Error> {
pub fn set_all_users_email_verified(conn: &mut PgConnection) -> Result<Vec<Self>, Error> {
diesel::update(local_user)
.set(email_verified.eq(true))
.get_results::<Self>(conn)
}
pub fn set_all_users_registration_applications_accepted(
conn: &PgConnection,
conn: &mut PgConnection,
) -> Result<Vec<Self>, Error> {
diesel::update(local_user)
.set(accepted_application.eq(true))
@ -111,13 +111,13 @@ impl LocalUser {
impl Crud for LocalUser {
type Form = LocalUserForm;
type IdType = LocalUserId;
fn read(conn: &PgConnection, local_user_id: LocalUserId) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, local_user_id: LocalUserId) -> Result<Self, Error> {
local_user.find(local_user_id).first::<Self>(conn)
}
fn delete(conn: &PgConnection, local_user_id: LocalUserId) -> Result<usize, Error> {
fn delete(conn: &mut PgConnection, local_user_id: LocalUserId) -> Result<usize, Error> {
diesel::delete(local_user.find(local_user_id)).execute(conn)
}
fn create(conn: &PgConnection, form: &LocalUserForm) -> Result<Self, Error> {
fn create(conn: &mut PgConnection, form: &LocalUserForm) -> Result<Self, Error> {
let local_user_ = insert_into(local_user)
.values(form)
.get_result::<Self>(conn)?;
@ -126,7 +126,7 @@ impl Crud for LocalUser {
Ok(local_user_)
}
fn update(
conn: &PgConnection,
conn: &mut PgConnection,
local_user_id: LocalUserId,
form: &LocalUserForm,
) -> Result<Self, Error> {

@ -9,7 +9,7 @@ impl LocalUserLanguage {
///
/// If no language_id vector is given, it will show all languages
pub fn update_user_languages(
conn: &PgConnection,
conn: &mut PgConnection,
language_ids: Option<Vec<LanguageId>>,
for_local_user_id: LocalUserId,
) -> Result<(), Error> {
@ -23,7 +23,7 @@ impl LocalUserLanguage {
.collect(),
);
conn.build_transaction().read_write().run(|| {
conn.build_transaction().read_write().run(|conn| {
// Clear the current user languages
delete(local_user_language.filter(local_user_id.eq(for_local_user_id))).execute(conn)?;

@ -4,19 +4,23 @@ use diesel::{dsl::*, result::Error, *};
impl Crud for ModRemovePost {
type Form = ModRemovePostForm;
type IdType = i32;
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, from_id: i32) -> Result<Self, Error> {
use crate::schema::mod_remove_post::dsl::*;
mod_remove_post.find(from_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, form: &ModRemovePostForm) -> Result<Self, Error> {
fn create(conn: &mut PgConnection, form: &ModRemovePostForm) -> Result<Self, Error> {
use crate::schema::mod_remove_post::dsl::*;
insert_into(mod_remove_post)
.values(form)
.get_result::<Self>(conn)
}
fn update(conn: &PgConnection, from_id: i32, form: &ModRemovePostForm) -> Result<Self, Error> {
fn update(
conn: &mut PgConnection,
from_id: i32,
form: &ModRemovePostForm,
) -> Result<Self, Error> {
use crate::schema::mod_remove_post::dsl::*;
diesel::update(mod_remove_post.find(from_id))
.set(form)
@ -27,19 +31,19 @@ impl Crud for ModRemovePost {
impl Crud for ModLockPost {
type Form = ModLockPostForm;
type IdType = i32;
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, from_id: i32) -> Result<Self, Error> {
use crate::schema::mod_lock_post::dsl::*;
mod_lock_post.find(from_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, form: &ModLockPostForm) -> Result<Self, Error> {
fn create(conn: &mut PgConnection, form: &ModLockPostForm) -> Result<Self, Error> {
use crate::schema::mod_lock_post::dsl::*;
insert_into(mod_lock_post)
.values(form)
.get_result::<Self>(conn)
}
fn update(conn: &PgConnection, from_id: i32, form: &ModLockPostForm) -> Result<Self, Error> {
fn update(conn: &mut PgConnection, from_id: i32, form: &ModLockPostForm) -> Result<Self, Error> {
use crate::schema::mod_lock_post::dsl::*;
diesel::update(mod_lock_post.find(from_id))
.set(form)
@ -50,19 +54,23 @@ impl Crud for ModLockPost {
impl Crud for ModStickyPost {
type Form = ModStickyPostForm;
type IdType = i32;
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, from_id: i32) -> Result<Self, Error> {
use crate::schema::mod_sticky_post::dsl::*;
mod_sticky_post.find(from_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, form: &ModStickyPostForm) -> Result<Self, Error> {
fn create(conn: &mut PgConnection, form: &ModStickyPostForm) -> Result<Self, Error> {
use crate::schema::mod_sticky_post::dsl::*;
insert_into(mod_sticky_post)
.values(form)
.get_result::<Self>(conn)
}
fn update(conn: &PgConnection, from_id: i32, form: &ModStickyPostForm) -> Result<Self, Error> {
fn update(
conn: &mut PgConnection,
from_id: i32,
form: &ModStickyPostForm,
) -> Result<Self, Error> {
use crate::schema::mod_sticky_post::dsl::*;
diesel::update(mod_sticky_post.find(from_id))
.set(form)
@ -73,19 +81,23 @@ impl Crud for ModStickyPost {
impl Crud for ModRemoveComment {
type Form = ModRemoveCommentForm;
type IdType = i32;
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, from_id: i32) -> Result<Self, Error> {
use crate::schema::mod_remove_comment::dsl::*;
mod_remove_comment.find(from_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, form: &ModRemoveCommentForm) -> Result<Self, Error> {
fn create(conn: &mut PgConnection, form: &ModRemoveCommentForm) -> Result<Self, Error> {
use crate::schema::mod_remove_comment::dsl::*;
insert_into(mod_remove_comment)
.values(form)
.get_result::<Self>(conn)
}
fn update(conn: &PgConnection, from_id: i32, form: &ModRemoveCommentForm) -> Result<Self, Error> {
fn update(
conn: &mut PgConnection,
from_id: i32,
form: &ModRemoveCommentForm,
) -> Result<Self, Error> {
use crate::schema::mod_remove_comment::dsl::*;
diesel::update(mod_remove_comment.find(from_id))
.set(form)
@ -96,12 +108,12 @@ impl Crud for ModRemoveComment {
impl Crud for ModRemoveCommunity {
type Form = ModRemoveCommunityForm;
type IdType = i32;
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, from_id: i32) -> Result<Self, Error> {
use crate::schema::mod_remove_community::dsl::*;
mod_remove_community.find(from_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
fn create(conn: &mut PgConnection, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
use crate::schema::mod_remove_community::dsl::*;
insert_into(mod_remove_community)
.values(form)
@ -109,7 +121,7 @@ impl Crud for ModRemoveCommunity {
}
fn update(
conn: &PgConnection,
conn: &mut PgConnection,
from_id: i32,
form: &ModRemoveCommunityForm,
) -> Result<Self, Error> {
@ -123,12 +135,12 @@ impl Crud for ModRemoveCommunity {
impl Crud for ModBanFromCommunity {
type Form = ModBanFromCommunityForm;
type IdType = i32;
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, from_id: i32) -> Result<Self, Error> {
use crate::schema::mod_ban_from_community::dsl::*;
mod_ban_from_community.find(from_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
fn create(conn: &mut PgConnection, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
use crate::schema::mod_ban_from_community::dsl::*;
insert_into(mod_ban_from_community)
.values(form)
@ -136,7 +148,7 @@ impl Crud for ModBanFromCommunity {
}
fn update(
conn: &PgConnection,
conn: &mut PgConnection,
from_id: i32,
form: &ModBanFromCommunityForm,
) -> Result<Self, Error> {
@ -150,17 +162,17 @@ impl Crud for ModBanFromCommunity {
impl Crud for ModBan {
type Form = ModBanForm;
type IdType = i32;
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, from_id: i32) -> Result<Self, Error> {
use crate::schema::mod_ban::dsl::*;
mod_ban.find(from_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, form: &ModBanForm) -> Result<Self, Error> {
fn create(conn: &mut PgConnection, form: &ModBanForm) -> Result<Self, Error> {
use crate::schema::mod_ban::dsl::*;
insert_into(mod_ban).values(form).get_result::<Self>(conn)
}
fn update(conn: &PgConnection, from_id: i32, form: &ModBanForm) -> Result<Self, Error> {
fn update(conn: &mut PgConnection, from_id: i32, form: &ModBanForm) -> Result<Self, Error> {
use crate::schema::mod_ban::dsl::*;
diesel::update(mod_ban.find(from_id))
.set(form)
@ -172,19 +184,23 @@ impl Crud for ModHideCommunity {
type Form = ModHideCommunityForm;
type IdType = i32;
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, from_id: i32) -> Result<Self, Error> {
use crate::schema::mod_hide_community::dsl::*;
mod_hide_community.find(from_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, form: &ModHideCommunityForm) -> Result<Self, Error> {
fn create(conn: &mut PgConnection, form: &ModHideCommunityForm) -> Result<Self, Error> {
use crate::schema::mod_hide_community::dsl::*;
insert_into(mod_hide_community)
.values(form)
.get_result::<Self>(conn)
}
fn update(conn: &PgConnection, from_id: i32, form: &ModHideCommunityForm) -> Result<Self, Error> {
fn update(
conn: &mut PgConnection,
from_id: i32,
form: &ModHideCommunityForm,
) -> Result<Self, Error> {
use crate::schema::mod_hide_community::dsl::*;
diesel::update(mod_hide_community.find(from_id))
.set(form)
@ -195,19 +211,23 @@ impl Crud for ModHideCommunity {
impl Crud for ModAddCommunity {
type Form = ModAddCommunityForm;
type IdType = i32;
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, from_id: i32) -> Result<Self, Error> {
use crate::schema::mod_add_community::dsl::*;
mod_add_community.find(from_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, form: &ModAddCommunityForm) -> Result<Self, Error> {
fn create(conn: &mut PgConnection, form: &ModAddCommunityForm) -> Result<Self, Error> {
use crate::schema::mod_add_community::dsl::*;
insert_into(mod_add_community)
.values(form)
.get_result::<Self>(conn)
}
fn update(conn: &PgConnection, from_id: i32, form: &ModAddCommunityForm) -> Result<Self, Error> {
fn update(
conn: &mut PgConnection,
from_id: i32,
form: &ModAddCommunityForm,
) -> Result<Self, Error> {
use crate::schema::mod_add_community::dsl::*;
diesel::update(mod_add_community.find(from_id))
.set(form)
@ -218,12 +238,12 @@ impl Crud for ModAddCommunity {
impl Crud for ModTransferCommunity {
type Form = ModTransferCommunityForm;
type IdType = i32;
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, from_id: i32) -> Result<Self, Error> {
use crate::schema::mod_transfer_community::dsl::*;
mod_transfer_community.find(from_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, form: &ModTransferCommunityForm) -> Result<Self, Error> {
fn create(conn: &mut PgConnection, form: &ModTransferCommunityForm) -> Result<Self, Error> {
use crate::schema::mod_transfer_community::dsl::*;
insert_into(mod_transfer_community)
.values(form)
@ -231,7 +251,7 @@ impl Crud for ModTransferCommunity {
}
fn update(
conn: &PgConnection,
conn: &mut PgConnection,
from_id: i32,
form: &ModTransferCommunityForm,
) -> Result<Self, Error> {
@ -245,17 +265,17 @@ impl Crud for ModTransferCommunity {
impl Crud for ModAdd {
type Form = ModAddForm;
type IdType = i32;
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, from_id: i32) -> Result<Self, Error> {
use crate::schema::mod_add::dsl::*;
mod_add.find(from_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, form: &ModAddForm) -> Result<Self, Error> {
fn create(conn: &mut PgConnection, form: &ModAddForm) -> Result<Self, Error> {
use crate::schema::mod_add::dsl::*;
insert_into(mod_add).values(form).get_result::<Self>(conn)
}
fn update(conn: &PgConnection, from_id: i32, form: &ModAddForm) -> Result<Self, Error> {
fn update(conn: &mut PgConnection, from_id: i32, form: &ModAddForm) -> Result<Self, Error> {
use crate::schema::mod_add::dsl::*;
diesel::update(mod_add.find(from_id))
.set(form)
@ -266,19 +286,19 @@ impl Crud for ModAdd {
impl Crud for AdminPurgePerson {
type Form = AdminPurgePersonForm;
type IdType = i32;
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, from_id: i32) -> Result<Self, Error> {
use crate::schema::admin_purge_person::dsl::*;
admin_purge_person.find(from_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error> {
fn create(conn: &mut PgConnection, form: &Self::Form) -> Result<Self, Error> {
use crate::schema::admin_purge_person::dsl::*;
insert_into(admin_purge_person)
.values(form)
.get_result::<Self>(conn)
}
fn update(conn: &PgConnection, from_id: i32, form: &Self::Form) -> Result<Self, Error> {
fn update(conn: &mut PgConnection, from_id: i32, form: &Self::Form) -> Result<Self, Error> {
use crate::schema::admin_purge_person::dsl::*;
diesel::update(admin_purge_person.find(from_id))
.set(form)
@ -289,19 +309,19 @@ impl Crud for AdminPurgePerson {
impl Crud for AdminPurgeCommunity {
type Form = AdminPurgeCommunityForm;
type IdType = i32;
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, from_id: i32) -> Result<Self, Error> {
use crate::schema::admin_purge_community::dsl::*;
admin_purge_community.find(from_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error> {
fn create(conn: &mut PgConnection, form: &Self::Form) -> Result<Self, Error> {
use crate::schema::admin_purge_community::dsl::*;
insert_into(admin_purge_community)
.values(form)
.get_result::<Self>(conn)
}
fn update(conn: &PgConnection, from_id: i32, form: &Self::Form) -> Result<Self, Error> {
fn update(conn: &mut PgConnection, from_id: i32, form: &Self::Form) -> Result<Self, Error> {
use crate::schema::admin_purge_community::dsl::*;
diesel::update(admin_purge_community.find(from_id))
.set(form)
@ -312,19 +332,19 @@ impl Crud for AdminPurgeCommunity {
impl Crud for AdminPurgePost {
type Form = AdminPurgePostForm;
type IdType = i32;
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, from_id: i32) -> Result<Self, Error> {
use crate::schema::admin_purge_post::dsl::*;
admin_purge_post.find(from_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error> {
fn create(conn: &mut PgConnection, form: &Self::Form) -> Result<Self, Error> {
use crate::schema::admin_purge_post::dsl::*;
insert_into(admin_purge_post)
.values(form)
.get_result::<Self>(conn)
}
fn update(conn: &PgConnection, from_id: i32, form: &Self::Form) -> Result<Self, Error> {
fn update(conn: &mut PgConnection, from_id: i32, form: &Self::Form) -> Result<Self, Error> {
use crate::schema::admin_purge_post::dsl::*;
diesel::update(admin_purge_post.find(from_id))
.set(form)
@ -335,19 +355,19 @@ impl Crud for AdminPurgePost {
impl Crud for AdminPurgeComment {
type Form = AdminPurgeCommentForm;
type IdType = i32;
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, from_id: i32) -> Result<Self, Error> {
use crate::schema::admin_purge_comment::dsl::*;
admin_purge_comment.find(from_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error> {
fn create(conn: &mut PgConnection, form: &Self::Form) -> Result<Self, Error> {
use crate::schema::admin_purge_comment::dsl::*;
insert_into(admin_purge_comment)
.values(form)
.get_result::<Self>(conn)
}
fn update(conn: &PgConnection, from_id: i32, form: &Self::Form) -> Result<Self, Error> {
fn update(conn: &mut PgConnection, from_id: i32, form: &Self::Form) -> Result<Self, Error> {
use crate::schema::admin_purge_comment::dsl::*;
diesel::update(admin_purge_comment.find(from_id))
.set(form)
@ -368,7 +388,7 @@ mod tests {
#[test]
#[serial]
fn test_crud() {
let conn = establish_unpooled_connection();
let conn = &mut establish_unpooled_connection();
let new_mod = PersonForm {
name: "the mod".into(),
@ -376,7 +396,7 @@ mod tests {
..PersonForm::default()
};
let inserted_mod = Person::create(&conn, &new_mod).unwrap();
let inserted_mod = Person::create(conn, &new_mod).unwrap();
let new_person = PersonForm {
name: "jim2".into(),
@ -384,7 +404,7 @@ mod tests {
..PersonForm::default()
};
let inserted_person = Person::create(&conn, &new_person).unwrap();
let inserted_person = Person::create(conn, &new_person).unwrap();
let new_community = CommunityForm {
name: "mod_community".to_string(),
@ -393,7 +413,7 @@ mod tests {
..CommunityForm::default()
};
let inserted_community = Community::create(&conn, &new_community).unwrap();
let inserted_community = Community::create(conn, &new_community).unwrap();
let new_post = PostForm {
name: "A test post thweep".into(),
@ -402,7 +422,7 @@ mod tests {
..PostForm::default()
};
let inserted_post = Post::create(&conn, &new_post).unwrap();
let inserted_post = Post::create(conn, &new_post).unwrap();
let comment_form = CommentForm {
content: "A test comment".into(),
@ -411,7 +431,7 @@ mod tests {
..CommentForm::default()
};
let inserted_comment = Comment::create(&conn, &comment_form, None).unwrap();
let inserted_comment = Comment::create(conn, &comment_form, None).unwrap();
// Now the actual tests
@ -422,8 +442,8 @@ mod tests {
reason: None,
removed: None,
};
let inserted_mod_remove_post = ModRemovePost::create(&conn, &mod_remove_post_form).unwrap();
let read_mod_remove_post = ModRemovePost::read(&conn, inserted_mod_remove_post.id).unwrap();
let inserted_mod_remove_post = ModRemovePost::create(conn, &mod_remove_post_form).unwrap();
let read_mod_remove_post = ModRemovePost::read(conn, inserted_mod_remove_post.id).unwrap();
let expected_mod_remove_post = ModRemovePost {
id: inserted_mod_remove_post.id,
post_id: inserted_post.id,
@ -440,8 +460,8 @@ mod tests {
post_id: inserted_post.id,
locked: None,
};
let inserted_mod_lock_post = ModLockPost::create(&conn, &mod_lock_post_form).unwrap();
let read_mod_lock_post = ModLockPost::read(&conn, inserted_mod_lock_post.id).unwrap();
let inserted_mod_lock_post = ModLockPost::create(conn, &mod_lock_post_form).unwrap();
let read_mod_lock_post = ModLockPost::read(conn, inserted_mod_lock_post.id).unwrap();
let expected_mod_lock_post = ModLockPost {
id: inserted_mod_lock_post.id,
post_id: inserted_post.id,
@ -457,8 +477,8 @@ mod tests {
post_id: inserted_post.id,
stickied: None,
};
let inserted_mod_sticky_post = ModStickyPost::create(&conn, &mod_sticky_post_form).unwrap();
let read_mod_sticky_post = ModStickyPost::read(&conn, inserted_mod_sticky_post.id).unwrap();
let inserted_mod_sticky_post = ModStickyPost::create(conn, &mod_sticky_post_form).unwrap();
let read_mod_sticky_post = ModStickyPost::read(conn, inserted_mod_sticky_post.id).unwrap();
let expected_mod_sticky_post = ModStickyPost {
id: inserted_mod_sticky_post.id,
post_id: inserted_post.id,
@ -476,9 +496,9 @@ mod tests {
removed: None,
};
let inserted_mod_remove_comment =
ModRemoveComment::create(&conn, &mod_remove_comment_form).unwrap();
ModRemoveComment::create(conn, &mod_remove_comment_form).unwrap();
let read_mod_remove_comment =
ModRemoveComment::read(&conn, inserted_mod_remove_comment.id).unwrap();
ModRemoveComment::read(conn, inserted_mod_remove_comment.id).unwrap();
let expected_mod_remove_comment = ModRemoveComment {
id: inserted_mod_remove_comment.id,
comment_id: inserted_comment.id,
@ -498,9 +518,9 @@ mod tests {
expires: None,
};
let inserted_mod_remove_community =
ModRemoveCommunity::create(&conn, &mod_remove_community_form).unwrap();
ModRemoveCommunity::create(conn, &mod_remove_community_form).unwrap();
let read_mod_remove_community =
ModRemoveCommunity::read(&conn, inserted_mod_remove_community.id).unwrap();
ModRemoveCommunity::read(conn, inserted_mod_remove_community.id).unwrap();
let expected_mod_remove_community = ModRemoveCommunity {
id: inserted_mod_remove_community.id,
community_id: inserted_community.id,
@ -522,9 +542,9 @@ mod tests {
expires: None,
};
let inserted_mod_ban_from_community =
ModBanFromCommunity::create(&conn, &mod_ban_from_community_form).unwrap();
ModBanFromCommunity::create(conn, &mod_ban_from_community_form).unwrap();
let read_mod_ban_from_community =
ModBanFromCommunity::read(&conn, inserted_mod_ban_from_community.id).unwrap();
ModBanFromCommunity::read(conn, inserted_mod_ban_from_community.id).unwrap();
let expected_mod_ban_from_community = ModBanFromCommunity {
id: inserted_mod_ban_from_community.id,
community_id: inserted_community.id,
@ -545,8 +565,8 @@ mod tests {
banned: None,
expires: None,
};
let inserted_mod_ban = ModBan::create(&conn, &mod_ban_form).unwrap();
let read_mod_ban = ModBan::read(&conn, inserted_mod_ban.id).unwrap();
let inserted_mod_ban = ModBan::create(conn, &mod_ban_form).unwrap();
let read_mod_ban = ModBan::read(conn, inserted_mod_ban.id).unwrap();
let expected_mod_ban = ModBan {
id: inserted_mod_ban.id,
mod_person_id: inserted_mod.id,
@ -566,9 +586,9 @@ mod tests {
removed: None,
};
let inserted_mod_add_community =
ModAddCommunity::create(&conn, &mod_add_community_form).unwrap();
ModAddCommunity::create(conn, &mod_add_community_form).unwrap();
let read_mod_add_community =
ModAddCommunity::read(&conn, inserted_mod_add_community.id).unwrap();
ModAddCommunity::read(conn, inserted_mod_add_community.id).unwrap();
let expected_mod_add_community = ModAddCommunity {
id: inserted_mod_add_community.id,
community_id: inserted_community.id,
@ -585,8 +605,8 @@ mod tests {
other_person_id: inserted_person.id,
removed: None,
};
let inserted_mod_add = ModAdd::create(&conn, &mod_add_form).unwrap();
let read_mod_add = ModAdd::read(&conn, inserted_mod_add.id).unwrap();
let inserted_mod_add = ModAdd::create(conn, &mod_add_form).unwrap();
let read_mod_add = ModAdd::read(conn, inserted_mod_add.id).unwrap();
let expected_mod_add = ModAdd {
id: inserted_mod_add.id,
mod_person_id: inserted_mod.id,
@ -595,11 +615,11 @@ mod tests {
when_: inserted_mod_add.when_,
};
Comment::delete(&conn, inserted_comment.id).unwrap();
Post::delete(&conn, inserted_post.id).unwrap();
Community::delete(&conn, inserted_community.id).unwrap();
Person::delete(&conn, inserted_person.id).unwrap();
Person::delete(&conn, inserted_mod.id).unwrap();
Comment::delete(conn, inserted_comment.id).unwrap();
Post::delete(conn, inserted_post.id).unwrap();
Community::delete(conn, inserted_community.id).unwrap();
Person::delete(conn, inserted_person.id).unwrap();
Person::delete(conn, inserted_mod.id).unwrap();
assert_eq!(expected_mod_remove_post, read_mod_remove_post);
assert_eq!(expected_mod_lock_post, read_mod_lock_post);

@ -10,18 +10,18 @@ use sha2::{Digest, Sha256};
impl Crud for PasswordResetRequest {
type Form = PasswordResetRequestForm;
type IdType = i32;
fn read(conn: &PgConnection, password_reset_request_id: i32) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, password_reset_request_id: i32) -> Result<Self, Error> {
password_reset_request
.find(password_reset_request_id)
.first::<Self>(conn)
}
fn create(conn: &PgConnection, form: &PasswordResetRequestForm) -> Result<Self, Error> {
fn create(conn: &mut PgConnection, form: &PasswordResetRequestForm) -> Result<Self, Error> {
insert_into(password_reset_request)
.values(form)
.get_result::<Self>(conn)
}
fn update(
conn: &PgConnection,
conn: &mut PgConnection,
password_reset_request_id: i32,
form: &PasswordResetRequestForm,
) -> Result<Self, Error> {
@ -33,7 +33,7 @@ impl Crud for PasswordResetRequest {
impl PasswordResetRequest {
pub fn create_token(
conn: &PgConnection,
conn: &mut PgConnection,
from_local_user_id: LocalUserId,
token: &str,
) -> Result<PasswordResetRequest, Error> {
@ -48,7 +48,10 @@ impl PasswordResetRequest {
Self::create(conn, &form)
}
pub fn read_from_token(conn: &PgConnection, token: &str) -> Result<PasswordResetRequest, Error> {
pub fn read_from_token(
conn: &mut PgConnection,
token: &str,
) -> Result<PasswordResetRequest, Error> {
let mut hasher = Sha256::new();
hasher.update(token);
let token_hash: String = bytes_to_hex(hasher.finalize().to_vec());
@ -83,7 +86,7 @@ mod tests {
#[test]
#[serial]
fn test_crud() {
let conn = establish_unpooled_connection();
let conn = &mut establish_unpooled_connection();
let new_person = PersonForm {
name: "thommy prw".into(),
@ -91,7 +94,7 @@ mod tests {
..PersonForm::default()
};
let inserted_person = Person::create(&conn, &new_person).unwrap();
let inserted_person = Person::create(conn, &new_person).unwrap();
let new_local_user = LocalUserForm {
person_id: Some(inserted_person.id),
@ -99,13 +102,13 @@ mod tests {
..LocalUserForm::default()
};
let inserted_local_user = LocalUser::create(&conn, &new_local_user).unwrap();
let inserted_local_user = LocalUser::create(conn, &new_local_user).unwrap();
let token = "nope";
let token_encrypted_ = "ca3704aa0b06f5954c79ee837faa152d84d6b2d42838f0637a15eda8337dbdce";
let inserted_password_reset_request =
PasswordResetRequest::create_token(&conn, inserted_local_user.id, token).unwrap();
PasswordResetRequest::create_token(conn, inserted_local_user.id, token).unwrap();
let expected_password_reset_request = PasswordResetRequest {
id: inserted_password_reset_request.id,
@ -114,8 +117,8 @@ mod tests {
published: inserted_password_reset_request.published,
};
let read_password_reset_request = PasswordResetRequest::read_from_token(&conn, token).unwrap();
let num_deleted = Person::delete(&conn, inserted_person.id).unwrap();
let read_password_reset_request = PasswordResetRequest::read_from_token(conn, token).unwrap();
let num_deleted = Person::delete(conn, inserted_person.id).unwrap();
assert_eq!(expected_password_reset_request, read_password_reset_request);
assert_eq!(

@ -66,124 +66,26 @@ mod safe_type {
}
}
mod safe_type_alias_1 {
use crate::{schema::person_alias_1::columns::*, source::person::PersonAlias1, traits::ToSafe};
type Columns = (
id,
name,
display_name,
avatar,
banned,
published,
updated,
actor_id,
bio,
local,
banner,
deleted,
inbox_url,
shared_inbox_url,
matrix_user_id,
admin,
bot_account,
ban_expires,
);
impl ToSafe for PersonAlias1 {
type SafeColumns = Columns;
fn safe_columns_tuple() -> Self::SafeColumns {
(
id,
name,
display_name,
avatar,
banned,
published,
updated,
actor_id,
bio,
local,
banner,
deleted,
inbox_url,
shared_inbox_url,
matrix_user_id,
admin,
bot_account,
ban_expires,
)
}
}
}
mod safe_type_alias_2 {
use crate::{schema::person_alias_2::columns::*, source::person::PersonAlias2, traits::ToSafe};
type Columns = (
id,
name,
display_name,
avatar,
banned,
published,
updated,
actor_id,
bio,
local,
banner,
deleted,
inbox_url,
shared_inbox_url,
matrix_user_id,
admin,
bot_account,
ban_expires,
);
impl ToSafe for PersonAlias2 {
type SafeColumns = Columns;
fn safe_columns_tuple() -> Self::SafeColumns {
(
id,
name,
display_name,
avatar,
banned,
published,
updated,
actor_id,
bio,
local,
banner,
deleted,
inbox_url,
shared_inbox_url,
matrix_user_id,
admin,
bot_account,
ban_expires,
)
}
}
}
impl Crud for Person {
type Form = PersonForm;
type IdType = PersonId;
fn read(conn: &PgConnection, person_id: PersonId) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, person_id: PersonId) -> Result<Self, Error> {
person
.filter(deleted.eq(false))
.find(person_id)
.first::<Self>(conn)
}
fn delete(conn: &PgConnection, person_id: PersonId) -> Result<usize, Error> {
fn delete(conn: &mut PgConnection, person_id: PersonId) -> Result<usize, Error> {
diesel::delete(person.find(person_id)).execute(conn)
}
fn create(conn: &PgConnection, form: &PersonForm) -> Result<Self, Error> {
fn create(conn: &mut PgConnection, form: &PersonForm) -> Result<Self, Error> {
insert_into(person).values(form).get_result::<Self>(conn)
}
fn update(conn: &PgConnection, person_id: PersonId, form: &PersonForm) -> Result<Self, Error> {
fn update(
conn: &mut PgConnection,
person_id: PersonId,
form: &PersonForm,
) -> Result<Self, Error> {
diesel::update(person.find(person_id))
.set(form)
.get_result::<Self>(conn)
@ -192,7 +94,7 @@ impl Crud for Person {
impl Person {
pub fn ban_person(
conn: &PgConnection,
conn: &mut PgConnection,
person_id: PersonId,
ban: bool,
expires: Option<chrono::NaiveDateTime>,
@ -202,19 +104,23 @@ impl Person {
.get_result::<Self>(conn)
}
pub fn add_admin(conn: &PgConnection, person_id: PersonId, added: bool) -> Result<Self, Error> {
pub fn add_admin(
conn: &mut PgConnection,
person_id: PersonId,
added: bool,
) -> Result<Self, Error> {
diesel::update(person.find(person_id))
.set(admin.eq(added))
.get_result::<Self>(conn)
}
pub fn mark_as_updated(conn: &PgConnection, person_id: PersonId) -> Result<Person, Error> {
pub fn mark_as_updated(conn: &mut PgConnection, person_id: PersonId) -> Result<Person, Error> {
diesel::update(person.find(person_id))
.set((last_refreshed_at.eq(naive_now()),))
.get_result::<Self>(conn)
}
pub fn delete_account(conn: &PgConnection, person_id: PersonId) -> Result<Person, Error> {
pub fn delete_account(conn: &mut PgConnection, person_id: PersonId) -> Result<Person, Error> {
use crate::schema::local_user;
// Set the local user info to none
@ -238,7 +144,7 @@ impl Person {
.get_result::<Self>(conn)
}
pub fn upsert(conn: &PgConnection, person_form: &PersonForm) -> Result<Person, Error> {
pub fn upsert(conn: &mut PgConnection, person_form: &PersonForm) -> Result<Person, Error> {
insert_into(person)
.values(person_form)
.on_conflict(actor_id)
@ -248,7 +154,7 @@ impl Person {
}
pub fn update_deleted(
conn: &PgConnection,
conn: &mut PgConnection,
person_id: PersonId,
new_deleted: bool,
) -> Result<Person, Error> {
@ -258,13 +164,16 @@ impl Person {
.get_result::<Self>(conn)
}
pub fn leave_admin(conn: &PgConnection, person_id: PersonId) -> Result<Self, Error> {
pub fn leave_admin(conn: &mut PgConnection, person_id: PersonId) -> Result<Self, Error> {
diesel::update(person.find(person_id))
.set(admin.eq(false))
.get_result::<Self>(conn)
}
pub fn remove_avatar_and_banner(conn: &PgConnection, person_id: PersonId) -> Result<Self, Error> {
pub fn remove_avatar_and_banner(
conn: &mut PgConnection,
person_id: PersonId,
) -> Result<Self, Error> {
diesel::update(person.find(person_id))
.set((
avatar.eq::<Option<String>>(None),
@ -283,7 +192,7 @@ pub fn is_banned(banned_: bool, expires: Option<chrono::NaiveDateTime>) -> bool
}
impl ApubActor for Person {
fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Option<Self>, Error> {
fn read_from_apub_id(conn: &mut PgConnection, object_id: &DbUrl) -> Result<Option<Self>, Error> {
use crate::schema::person::dsl::*;
Ok(
person
@ -296,7 +205,7 @@ impl ApubActor for Person {
}
fn read_from_name(
conn: &PgConnection,
conn: &mut PgConnection,
from_name: &str,
include_deleted: bool,
) -> Result<Person, Error> {
@ -311,7 +220,7 @@ impl ApubActor for Person {
}
fn read_from_name_and_domain(
conn: &PgConnection,
conn: &mut PgConnection,
person_name: &str,
protocol_domain: &str,
) -> Result<Person, Error> {
@ -329,7 +238,7 @@ mod tests {
#[test]
fn test_crud() {
let conn = establish_unpooled_connection();
let conn = &mut establish_unpooled_connection();
let new_person = PersonForm {
name: "holly".into(),
@ -337,7 +246,7 @@ mod tests {
..PersonForm::default()
};
let inserted_person = Person::create(&conn, &new_person).unwrap();
let inserted_person = Person::create(conn, &new_person).unwrap();
let expected_person = Person {
id: inserted_person.id,
@ -363,9 +272,9 @@ mod tests {
ban_expires: None,
};
let read_person = Person::read(&conn, inserted_person.id).unwrap();
let updated_person = Person::update(&conn, inserted_person.id, &new_person).unwrap();
let num_deleted = Person::delete(&conn, inserted_person.id).unwrap();
let read_person = Person::read(conn, inserted_person.id).unwrap();
let updated_person = Person::update(conn, inserted_person.id, &new_person).unwrap();
let num_deleted = Person::delete(conn, inserted_person.id).unwrap();
assert_eq!(expected_person, read_person);
assert_eq!(expected_person, inserted_person);

@ -7,7 +7,7 @@ use diesel::{dsl::*, result::Error, *};
impl PersonBlock {
pub fn read(
conn: &PgConnection,
conn: &mut PgConnection,
for_person_id: PersonId,
for_recipient_id: PersonId,
) -> Result<Self, Error> {
@ -21,7 +21,7 @@ impl PersonBlock {
impl Blockable for PersonBlock {
type Form = PersonBlockForm;
fn block(conn: &PgConnection, person_block_form: &PersonBlockForm) -> Result<Self, Error> {
fn block(conn: &mut PgConnection, person_block_form: &PersonBlockForm) -> Result<Self, Error> {
use crate::schema::person_block::dsl::*;
insert_into(person_block)
.values(person_block_form)
@ -30,7 +30,7 @@ impl Blockable for PersonBlock {
.set(person_block_form)
.get_result::<Self>(conn)
}
fn unblock(conn: &PgConnection, person_block_form: &Self::Form) -> Result<usize, Error> {
fn unblock(conn: &mut PgConnection, person_block_form: &Self::Form) -> Result<usize, Error> {
use crate::schema::person_block::dsl::*;
diesel::delete(
person_block

@ -8,12 +8,15 @@ use diesel::{dsl::*, result::Error, *};
impl Crud for PersonMention {
type Form = PersonMentionForm;
type IdType = PersonMentionId;
fn read(conn: &PgConnection, person_mention_id: PersonMentionId) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, person_mention_id: PersonMentionId) -> Result<Self, Error> {
use crate::schema::person_mention::dsl::*;
person_mention.find(person_mention_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, person_mention_form: &PersonMentionForm) -> Result<Self, Error> {
fn create(
conn: &mut PgConnection,
person_mention_form: &PersonMentionForm,
) -> Result<Self, Error> {
use crate::schema::person_mention::dsl::*;
// since the return here isnt utilized, we dont need to do an update
// but get_result doesnt return the existing row here
@ -26,7 +29,7 @@ impl Crud for PersonMention {
}
fn update(
conn: &PgConnection,
conn: &mut PgConnection,
person_mention_id: PersonMentionId,
person_mention_form: &PersonMentionForm,
) -> Result<Self, Error> {
@ -39,7 +42,7 @@ impl Crud for PersonMention {
impl PersonMention {
pub fn update_read(
conn: &PgConnection,
conn: &mut PgConnection,
person_mention_id: PersonMentionId,
new_read: bool,
) -> Result<PersonMention, Error> {
@ -50,7 +53,7 @@ impl PersonMention {
}
pub fn mark_all_as_read(
conn: &PgConnection,
conn: &mut PgConnection,
for_recipient_id: PersonId,
) -> Result<Vec<PersonMention>, Error> {
use crate::schema::person_mention::dsl::*;
@ -63,7 +66,7 @@ impl PersonMention {
.get_results::<Self>(conn)
}
pub fn read_by_comment_and_person(
conn: &PgConnection,
conn: &mut PgConnection,
for_comment_id: CommentId,
for_recipient_id: PersonId,
) -> Result<Self, Error> {
@ -93,7 +96,7 @@ mod tests {
#[test]
#[serial]
fn test_crud() {
let conn = establish_unpooled_connection();
let conn = &mut establish_unpooled_connection();
let new_person = PersonForm {
name: "terrylake".into(),
@ -101,7 +104,7 @@ mod tests {
..PersonForm::default()
};
let inserted_person = Person::create(&conn, &new_person).unwrap();
let inserted_person = Person::create(conn, &new_person).unwrap();
let recipient_form = PersonForm {
name: "terrylakes recipient".into(),
@ -109,7 +112,7 @@ mod tests {
..PersonForm::default()
};
let inserted_recipient = Person::create(&conn, &recipient_form).unwrap();
let inserted_recipient = Person::create(conn, &recipient_form).unwrap();
let new_community = CommunityForm {
name: "test community lake".to_string(),
@ -118,7 +121,7 @@ mod tests {
..CommunityForm::default()
};
let inserted_community = Community::create(&conn, &new_community).unwrap();
let inserted_community = Community::create(conn, &new_community).unwrap();
let new_post = PostForm {
name: "A test post".into(),
@ -127,7 +130,7 @@ mod tests {
..PostForm::default()
};
let inserted_post = Post::create(&conn, &new_post).unwrap();
let inserted_post = Post::create(conn, &new_post).unwrap();
let comment_form = CommentForm {
content: "A test comment".into(),
@ -136,7 +139,7 @@ mod tests {
..CommentForm::default()
};
let inserted_comment = Comment::create(&conn, &comment_form, None).unwrap();
let inserted_comment = Comment::create(conn, &comment_form, None).unwrap();
let person_mention_form = PersonMentionForm {
recipient_id: inserted_recipient.id,
@ -144,7 +147,7 @@ mod tests {
read: None,
};
let inserted_mention = PersonMention::create(&conn, &person_mention_form).unwrap();
let inserted_mention = PersonMention::create(conn, &person_mention_form).unwrap();
let expected_mention = PersonMention {
id: inserted_mention.id,
@ -154,14 +157,14 @@ mod tests {
published: inserted_mention.published,
};
let read_mention = PersonMention::read(&conn, inserted_mention.id).unwrap();
let read_mention = PersonMention::read(conn, inserted_mention.id).unwrap();
let updated_mention =
PersonMention::update(&conn, inserted_mention.id, &person_mention_form).unwrap();
Comment::delete(&conn, inserted_comment.id).unwrap();
Post::delete(&conn, inserted_post.id).unwrap();
Community::delete(&conn, inserted_community.id).unwrap();
Person::delete(&conn, inserted_person.id).unwrap();
Person::delete(&conn, inserted_recipient.id).unwrap();
PersonMention::update(conn, inserted_mention.id, &person_mention_form).unwrap();
Comment::delete(conn, inserted_comment.id).unwrap();
Post::delete(conn, inserted_post.id).unwrap();
Community::delete(conn, inserted_community.id).unwrap();
Person::delete(conn, inserted_person.id).unwrap();
Person::delete(conn, inserted_recipient.id).unwrap();
assert_eq!(expected_mention, read_mention);
assert_eq!(expected_mention, inserted_mention);

@ -19,22 +19,22 @@ use url::Url;
impl Crud for Post {
type Form = PostForm;
type IdType = PostId;
fn read(conn: &PgConnection, post_id: PostId) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, post_id: PostId) -> Result<Self, Error> {
use crate::schema::post::dsl::*;
post.find(post_id).first::<Self>(conn)
}
fn delete(conn: &PgConnection, post_id: PostId) -> Result<usize, Error> {
fn delete(conn: &mut PgConnection, post_id: PostId) -> Result<usize, Error> {
use crate::schema::post::dsl::*;
diesel::delete(post.find(post_id)).execute(conn)
}
fn create(conn: &PgConnection, new_post: &PostForm) -> Result<Self, Error> {
fn create(conn: &mut PgConnection, new_post: &PostForm) -> Result<Self, Error> {
use crate::schema::post::dsl::*;
insert_into(post).values(new_post).get_result::<Self>(conn)
}
fn update(conn: &PgConnection, post_id: PostId, new_post: &PostForm) -> Result<Self, Error> {
fn update(conn: &mut PgConnection, post_id: PostId, new_post: &PostForm) -> Result<Self, Error> {
use crate::schema::post::dsl::*;
diesel::update(post.find(post_id))
.set(new_post)
@ -44,7 +44,7 @@ impl Crud for Post {
impl Post {
pub fn list_for_community(
conn: &PgConnection,
conn: &mut PgConnection,
the_community_id: CommunityId,
) -> Result<Vec<Self>, Error> {
use crate::schema::post::dsl::*;
@ -58,7 +58,11 @@ impl Post {
.load::<Self>(conn)
}
pub fn update_ap_id(conn: &PgConnection, post_id: PostId, apub_id: DbUrl) -> Result<Self, Error> {
pub fn update_ap_id(
conn: &mut PgConnection,
post_id: PostId,
apub_id: DbUrl,
) -> Result<Self, Error> {
use crate::schema::post::dsl::*;
diesel::update(post.find(post_id))
@ -67,7 +71,7 @@ impl Post {
}
pub fn permadelete_for_creator(
conn: &PgConnection,
conn: &mut PgConnection,
for_creator_id: PersonId,
) -> Result<Vec<Self>, Error> {
use crate::schema::post::dsl::*;
@ -87,7 +91,7 @@ impl Post {
}
pub fn update_deleted(
conn: &PgConnection,
conn: &mut PgConnection,
post_id: PostId,
new_deleted: bool,
) -> Result<Self, Error> {
@ -98,7 +102,7 @@ impl Post {
}
pub fn update_removed(
conn: &PgConnection,
conn: &mut PgConnection,
post_id: PostId,
new_removed: bool,
) -> Result<Self, Error> {
@ -109,7 +113,7 @@ impl Post {
}
pub fn update_removed_for_creator(
conn: &PgConnection,
conn: &mut PgConnection,
for_creator_id: PersonId,
for_community_id: Option<CommunityId>,
new_removed: bool,
@ -129,7 +133,7 @@ impl Post {
}
pub fn update_locked(
conn: &PgConnection,
conn: &mut PgConnection,
post_id: PostId,
new_locked: bool,
) -> Result<Self, Error> {
@ -140,7 +144,7 @@ impl Post {
}
pub fn update_stickied(
conn: &PgConnection,
conn: &mut PgConnection,
post_id: PostId,
new_stickied: bool,
) -> Result<Self, Error> {
@ -154,7 +158,7 @@ impl Post {
person_id == post_creator_id
}
pub fn upsert(conn: &PgConnection, post_form: &PostForm) -> Result<Post, Error> {
pub fn upsert(conn: &mut PgConnection, post_form: &PostForm) -> Result<Post, Error> {
use crate::schema::post::dsl::*;
insert_into(post)
.values(post_form)
@ -163,7 +167,7 @@ impl Post {
.set(post_form)
.get_result::<Self>(conn)
}
pub fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, Error> {
pub fn read_from_apub_id(conn: &mut PgConnection, object_id: Url) -> Result<Option<Self>, Error> {
use crate::schema::post::dsl::*;
let object_id: DbUrl = object_id.into();
Ok(
@ -176,7 +180,7 @@ impl Post {
}
pub fn fetch_pictrs_posts_for_creator(
conn: &PgConnection,
conn: &mut PgConnection,
for_creator_id: PersonId,
) -> Result<Vec<Self>, Error> {
use crate::schema::post::dsl::*;
@ -190,7 +194,7 @@ impl Post {
/// Sets the url and thumbnails fields to None
pub fn remove_pictrs_post_images_and_thumbnails_for_creator(
conn: &PgConnection,
conn: &mut PgConnection,
for_creator_id: PersonId,
) -> Result<Vec<Self>, Error> {
use crate::schema::post::dsl::*;
@ -209,7 +213,7 @@ impl Post {
}
pub fn fetch_pictrs_posts_for_community(
conn: &PgConnection,
conn: &mut PgConnection,
for_community_id: CommunityId,
) -> Result<Vec<Self>, Error> {
use crate::schema::post::dsl::*;
@ -222,7 +226,7 @@ impl Post {
/// Sets the url and thumbnails fields to None
pub fn remove_pictrs_post_images_and_thumbnails_for_community(
conn: &PgConnection,
conn: &mut PgConnection,
for_community_id: CommunityId,
) -> Result<Vec<Self>, Error> {
use crate::schema::post::dsl::*;
@ -244,7 +248,7 @@ impl Post {
impl Likeable for PostLike {
type Form = PostLikeForm;
type IdType = PostId;
fn like(conn: &PgConnection, post_like_form: &PostLikeForm) -> Result<Self, Error> {
fn like(conn: &mut PgConnection, post_like_form: &PostLikeForm) -> Result<Self, Error> {
use crate::schema::post_like::dsl::*;
insert_into(post_like)
.values(post_like_form)
@ -253,7 +257,7 @@ impl Likeable for PostLike {
.set(post_like_form)
.get_result::<Self>(conn)
}
fn remove(conn: &PgConnection, person_id: PersonId, post_id: PostId) -> Result<usize, Error> {
fn remove(conn: &mut PgConnection, person_id: PersonId, post_id: PostId) -> Result<usize, Error> {
use crate::schema::post_like::dsl;
diesel::delete(
dsl::post_like
@ -266,7 +270,7 @@ impl Likeable for PostLike {
impl Saveable for PostSaved {
type Form = PostSavedForm;
fn save(conn: &PgConnection, post_saved_form: &PostSavedForm) -> Result<Self, Error> {
fn save(conn: &mut PgConnection, post_saved_form: &PostSavedForm) -> Result<Self, Error> {
use crate::schema::post_saved::dsl::*;
insert_into(post_saved)
.values(post_saved_form)
@ -275,7 +279,7 @@ impl Saveable for PostSaved {
.set(post_saved_form)
.get_result::<Self>(conn)
}
fn unsave(conn: &PgConnection, post_saved_form: &PostSavedForm) -> Result<usize, Error> {
fn unsave(conn: &mut PgConnection, post_saved_form: &PostSavedForm) -> Result<usize, Error> {
use crate::schema::post_saved::dsl::*;
diesel::delete(
post_saved
@ -288,7 +292,7 @@ impl Saveable for PostSaved {
impl Readable for PostRead {
type Form = PostReadForm;
fn mark_as_read(conn: &PgConnection, post_read_form: &PostReadForm) -> Result<Self, Error> {
fn mark_as_read(conn: &mut PgConnection, post_read_form: &PostReadForm) -> Result<Self, Error> {
use crate::schema::post_read::dsl::*;
insert_into(post_read)
.values(post_read_form)
@ -298,7 +302,10 @@ impl Readable for PostRead {
.get_result::<Self>(conn)
}
fn mark_as_unread(conn: &PgConnection, post_read_form: &PostReadForm) -> Result<usize, Error> {
fn mark_as_unread(
conn: &mut PgConnection,
post_read_form: &PostReadForm,
) -> Result<usize, Error> {
use crate::schema::post_read::dsl::*;
diesel::delete(
post_read
@ -339,7 +346,7 @@ mod tests {
#[test]
#[serial]
fn test_crud() {
let conn = establish_unpooled_connection();
let conn = &mut establish_unpooled_connection();
let new_person = PersonForm {
name: "jim".into(),
@ -347,7 +354,7 @@ mod tests {
..PersonForm::default()
};
let inserted_person = Person::create(&conn, &new_person).unwrap();
let inserted_person = Person::create(conn, &new_person).unwrap();
let new_community = CommunityForm {
name: "test community_3".to_string(),
@ -356,7 +363,7 @@ mod tests {
..CommunityForm::default()
};
let inserted_community = Community::create(&conn, &new_community).unwrap();
let inserted_community = Community::create(conn, &new_community).unwrap();
let new_post = PostForm {
name: "A test post".into(),
@ -365,7 +372,7 @@ mod tests {
..PostForm::default()
};
let inserted_post = Post::create(&conn, &new_post).unwrap();
let inserted_post = Post::create(conn, &new_post).unwrap();
let expected_post = Post {
id: inserted_post.id,
@ -397,7 +404,7 @@ mod tests {
score: 1,
};
let inserted_post_like = PostLike::like(&conn, &post_like_form).unwrap();
let inserted_post_like = PostLike::like(conn, &post_like_form).unwrap();
let expected_post_like = PostLike {
id: inserted_post_like.id,
@ -413,7 +420,7 @@ mod tests {
person_id: inserted_person.id,
};
let inserted_post_saved = PostSaved::save(&conn, &post_saved_form).unwrap();
let inserted_post_saved = PostSaved::save(conn, &post_saved_form).unwrap();
let expected_post_saved = PostSaved {
id: inserted_post_saved.id,
@ -428,7 +435,7 @@ mod tests {
person_id: inserted_person.id,
};
let inserted_post_read = PostRead::mark_as_read(&conn, &post_read_form).unwrap();
let inserted_post_read = PostRead::mark_as_read(conn, &post_read_form).unwrap();
let expected_post_read = PostRead {
id: inserted_post_read.id,
@ -437,14 +444,14 @@ mod tests {
published: inserted_post_read.published,
};
let read_post = Post::read(&conn, inserted_post.id).unwrap();
let updated_post = Post::update(&conn, inserted_post.id, &new_post).unwrap();
let like_removed = PostLike::remove(&conn, inserted_person.id, inserted_post.id).unwrap();
let saved_removed = PostSaved::unsave(&conn, &post_saved_form).unwrap();
let read_removed = PostRead::mark_as_unread(&conn, &post_read_form).unwrap();
let num_deleted = Post::delete(&conn, inserted_post.id).unwrap();
Community::delete(&conn, inserted_community.id).unwrap();
Person::delete(&conn, inserted_person.id).unwrap();
let read_post = Post::read(conn, inserted_post.id).unwrap();
let updated_post = Post::update(conn, inserted_post.id, &new_post).unwrap();
let like_removed = PostLike::remove(conn, inserted_person.id, inserted_post.id).unwrap();
let saved_removed = PostSaved::unsave(conn, &post_saved_form).unwrap();
let read_removed = PostRead::mark_as_unread(conn, &post_read_form).unwrap();
let num_deleted = Post::delete(conn, inserted_post.id).unwrap();
Community::delete(conn, inserted_community.id).unwrap();
Person::delete(conn, inserted_person.id).unwrap();
assert_eq!(expected_post, read_post);
assert_eq!(expected_post, inserted_post);

@ -14,7 +14,7 @@ impl Reportable for PostReport {
///
/// * `conn` - the postgres connection
/// * `post_report_form` - the filled CommentReportForm to insert
fn report(conn: &PgConnection, post_report_form: &PostReportForm) -> Result<Self, Error> {
fn report(conn: &mut PgConnection, post_report_form: &PostReportForm) -> Result<Self, Error> {
use crate::schema::post_report::dsl::*;
insert_into(post_report)
.values(post_report_form)
@ -27,7 +27,7 @@ impl Reportable for PostReport {
/// * `report_id` - the id of the report to resolve
/// * `by_resolver_id` - the id of the user resolving the report
fn resolve(
conn: &PgConnection,
conn: &mut PgConnection,
report_id: Self::IdType,
by_resolver_id: PersonId,
) -> Result<usize, Error> {
@ -47,7 +47,7 @@ impl Reportable for PostReport {
/// * `report_id` - the id of the report to unresolve
/// * `by_resolver_id` - the id of the user unresolving the report
fn unresolve(
conn: &PgConnection,
conn: &mut PgConnection,
report_id: Self::IdType,
by_resolver_id: PersonId,
) -> Result<usize, Error> {

@ -11,12 +11,15 @@ use url::Url;
impl Crud for PrivateMessage {
type Form = PrivateMessageForm;
type IdType = PrivateMessageId;
fn read(conn: &PgConnection, private_message_id: PrivateMessageId) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, private_message_id: PrivateMessageId) -> Result<Self, Error> {
use crate::schema::private_message::dsl::*;
private_message.find(private_message_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, private_message_form: &PrivateMessageForm) -> Result<Self, Error> {
fn create(
conn: &mut PgConnection,
private_message_form: &PrivateMessageForm,
) -> Result<Self, Error> {
use crate::schema::private_message::dsl::*;
insert_into(private_message)
.values(private_message_form)
@ -24,7 +27,7 @@ impl Crud for PrivateMessage {
}
fn update(
conn: &PgConnection,
conn: &mut PgConnection,
private_message_id: PrivateMessageId,
private_message_form: &PrivateMessageForm,
) -> Result<Self, Error> {
@ -33,7 +36,7 @@ impl Crud for PrivateMessage {
.set(private_message_form)
.get_result::<Self>(conn)
}
fn delete(conn: &PgConnection, pm_id: Self::IdType) -> Result<usize, Error> {
fn delete(conn: &mut PgConnection, pm_id: Self::IdType) -> Result<usize, Error> {
use crate::schema::private_message::dsl::*;
diesel::delete(private_message.find(pm_id)).execute(conn)
}
@ -41,7 +44,7 @@ impl Crud for PrivateMessage {
impl PrivateMessage {
pub fn update_ap_id(
conn: &PgConnection,
conn: &mut PgConnection,
private_message_id: PrivateMessageId,
apub_id: DbUrl,
) -> Result<PrivateMessage, Error> {
@ -53,7 +56,7 @@ impl PrivateMessage {
}
pub fn update_content(
conn: &PgConnection,
conn: &mut PgConnection,
private_message_id: PrivateMessageId,
new_content: &str,
) -> Result<PrivateMessage, Error> {
@ -64,7 +67,7 @@ impl PrivateMessage {
}
pub fn update_deleted(
conn: &PgConnection,
conn: &mut PgConnection,
private_message_id: PrivateMessageId,
new_deleted: bool,
) -> Result<PrivateMessage, Error> {
@ -75,7 +78,7 @@ impl PrivateMessage {
}
pub fn update_read(
conn: &PgConnection,
conn: &mut PgConnection,
private_message_id: PrivateMessageId,
new_read: bool,
) -> Result<PrivateMessage, Error> {
@ -86,7 +89,7 @@ impl PrivateMessage {
}
pub fn mark_all_as_read(
conn: &PgConnection,
conn: &mut PgConnection,
for_recipient_id: PersonId,
) -> Result<Vec<PrivateMessage>, Error> {
use crate::schema::private_message::dsl::*;
@ -100,7 +103,7 @@ impl PrivateMessage {
}
pub fn upsert(
conn: &PgConnection,
conn: &mut PgConnection,
private_message_form: &PrivateMessageForm,
) -> Result<PrivateMessage, Error> {
use crate::schema::private_message::dsl::*;
@ -113,7 +116,7 @@ impl PrivateMessage {
}
pub fn read_from_apub_id(
conn: &PgConnection,
conn: &mut PgConnection,
object_id: Url,
) -> Result<Option<Self>, LemmyError> {
use crate::schema::private_message::dsl::*;
@ -147,7 +150,7 @@ mod tests {
#[test]
#[serial]
fn test_crud() {
let conn = establish_unpooled_connection();
let conn = &mut establish_unpooled_connection();
let creator_form = PersonForm {
name: "creator_pm".into(),
@ -155,7 +158,7 @@ mod tests {
..PersonForm::default()
};
let inserted_creator = Person::create(&conn, &creator_form).unwrap();
let inserted_creator = Person::create(conn, &creator_form).unwrap();
let recipient_form = PersonForm {
name: "recipient_pm".into(),
@ -163,7 +166,7 @@ mod tests {
..PersonForm::default()
};
let inserted_recipient = Person::create(&conn, &recipient_form).unwrap();
let inserted_recipient = Person::create(conn, &recipient_form).unwrap();
let private_message_form = PrivateMessageForm {
content: "A test private message".into(),
@ -172,7 +175,7 @@ mod tests {
..PrivateMessageForm::default()
};
let inserted_private_message = PrivateMessage::create(&conn, &private_message_form).unwrap();
let inserted_private_message = PrivateMessage::create(conn, &private_message_form).unwrap();
let expected_private_message = PrivateMessage {
id: inserted_private_message.id,
@ -187,15 +190,15 @@ mod tests {
local: true,
};
let read_private_message = PrivateMessage::read(&conn, inserted_private_message.id).unwrap();
let read_private_message = PrivateMessage::read(conn, inserted_private_message.id).unwrap();
let updated_private_message =
PrivateMessage::update(&conn, inserted_private_message.id, &private_message_form).unwrap();
PrivateMessage::update(conn, inserted_private_message.id, &private_message_form).unwrap();
let deleted_private_message =
PrivateMessage::update_deleted(&conn, inserted_private_message.id, true).unwrap();
PrivateMessage::update_deleted(conn, inserted_private_message.id, true).unwrap();
let marked_read_private_message =
PrivateMessage::update_read(&conn, inserted_private_message.id, true).unwrap();
Person::delete(&conn, inserted_creator.id).unwrap();
Person::delete(&conn, inserted_recipient.id).unwrap();
PrivateMessage::update_read(conn, inserted_private_message.id, true).unwrap();
Person::delete(conn, inserted_creator.id).unwrap();
Person::delete(conn, inserted_recipient.id).unwrap();
assert_eq!(expected_private_message, read_private_message);
assert_eq!(expected_private_message, updated_private_message);

@ -13,7 +13,10 @@ impl Reportable for PrivateMessageReport {
///
/// * `conn` - the postgres connection
/// * `comment_report_form` - the filled CommentReportForm to insert
fn report(conn: &PgConnection, pm_report_form: &PrivateMessageReportForm) -> Result<Self, Error> {
fn report(
conn: &mut PgConnection,
pm_report_form: &PrivateMessageReportForm,
) -> Result<Self, Error> {
use crate::schema::private_message_report::dsl::*;
insert_into(private_message_report)
.values(pm_report_form)
@ -26,7 +29,7 @@ impl Reportable for PrivateMessageReport {
/// * `report_id` - the id of the report to resolve
/// * `by_resolver_id` - the id of the user resolving the report
fn resolve(
conn: &PgConnection,
conn: &mut PgConnection,
report_id: Self::IdType,
by_resolver_id: PersonId,
) -> Result<usize, Error> {
@ -46,7 +49,7 @@ impl Reportable for PrivateMessageReport {
/// * `report_id` - the id of the report to unresolve
/// * `by_resolver_id` - the id of the user unresolving the report
fn unresolve(
conn: &PgConnection,
conn: &mut PgConnection,
report_id: Self::IdType,
by_resolver_id: PersonId,
) -> Result<usize, Error> {

@ -4,26 +4,26 @@ use diesel::{insert_into, result::Error, ExpressionMethods, PgConnection, QueryD
impl Crud for RegistrationApplication {
type Form = RegistrationApplicationForm;
type IdType = i32;
fn create(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error> {
fn create(conn: &mut PgConnection, form: &Self::Form) -> Result<Self, Error> {
use crate::schema::registration_application::dsl::*;
insert_into(registration_application)
.values(form)
.get_result::<Self>(conn)
}
fn read(conn: &PgConnection, id_: Self::IdType) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, id_: Self::IdType) -> Result<Self, Error> {
use crate::schema::registration_application::dsl::*;
registration_application.find(id_).first::<Self>(conn)
}
fn update(conn: &PgConnection, id_: Self::IdType, form: &Self::Form) -> Result<Self, Error> {
fn update(conn: &mut PgConnection, id_: Self::IdType, form: &Self::Form) -> Result<Self, Error> {
use crate::schema::registration_application::dsl::*;
diesel::update(registration_application.find(id_))
.set(form)
.get_result::<Self>(conn)
}
fn delete(conn: &PgConnection, id_: Self::IdType) -> Result<usize, Error> {
fn delete(conn: &mut PgConnection, id_: Self::IdType) -> Result<usize, Error> {
use crate::schema::registration_application::dsl::*;
diesel::delete(registration_application.find(id_)).execute(conn)
}
@ -31,7 +31,7 @@ impl Crud for RegistrationApplication {
impl RegistrationApplication {
pub fn find_by_local_user_id(
conn: &PgConnection,
conn: &mut PgConnection,
local_user_id_: LocalUserId,
) -> Result<Self, Error> {
use crate::schema::registration_application::dsl::*;

@ -4,12 +4,12 @@ use diesel::{result::Error, *};
impl Secret {
/// Initialize the Secrets from the DB.
/// Warning: You should only call this once.
pub fn init(conn: &PgConnection) -> Result<Secret, Error> {
pub fn init(conn: &mut PgConnection) -> Result<Secret, Error> {
read_secrets(conn)
}
}
fn read_secrets(conn: &PgConnection) -> Result<Secret, Error> {
fn read_secrets(conn: &mut PgConnection) -> Result<Secret, Error> {
use crate::schema::secret::dsl::*;
secret.first::<Secret>(conn)
}

@ -5,35 +5,35 @@ use url::Url;
impl Crud for Site {
type Form = SiteForm;
type IdType = i32;
fn read(conn: &PgConnection, _site_id: i32) -> Result<Self, Error> {
fn read(conn: &mut PgConnection, _site_id: i32) -> Result<Self, Error> {
use crate::schema::site::dsl::*;
site.first::<Self>(conn)
}
fn create(conn: &PgConnection, new_site: &SiteForm) -> Result<Self, Error> {
fn create(conn: &mut PgConnection, new_site: &SiteForm) -> Result<Self, Error> {
use crate::schema::site::dsl::*;
insert_into(site).values(new_site).get_result::<Self>(conn)
}
fn update(conn: &PgConnection, site_id: i32, new_site: &SiteForm) -> Result<Self, Error> {
fn update(conn: &mut PgConnection, site_id: i32, new_site: &SiteForm) -> Result<Self, Error> {
use crate::schema::site::dsl::*;
diesel::update(site.find(site_id))
.set(new_site)
.get_result::<Self>(conn)
}
fn delete(conn: &PgConnection, site_id: i32) -> Result<usize, Error> {
fn delete(conn: &mut PgConnection, site_id: i32) -> Result<usize, Error> {
use crate::schema::site::dsl::*;
diesel::delete(site.find(site_id)).execute(conn)
}
}
impl Site {
pub fn read_local_site(conn: &PgConnection) -> Result<Self, Error> {
pub fn read_local_site(conn: &mut PgConnection) -> Result<Self, Error> {
use crate::schema::site::dsl::*;
site.order_by(id).first::<Self>(conn)
}
pub fn upsert(conn: &PgConnection, site_form: &SiteForm) -> Result<Site, Error> {
pub fn upsert(conn: &mut PgConnection, site_form: &SiteForm) -> Result<Site, Error> {
use crate::schema::site::dsl::*;
insert_into(site)
.values(site_form)
@ -43,7 +43,7 @@ impl Site {
.get_result::<Self>(conn)
}
pub fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, Error> {
pub fn read_from_apub_id(conn: &mut PgConnection, object_id: Url) -> Result<Option<Self>, Error> {
use crate::schema::site::dsl::*;
let object_id: DbUrl = object_id.into();
Ok(
@ -55,7 +55,7 @@ impl Site {
)
}
pub fn read_remote_sites(conn: &PgConnection) -> Result<Vec<Self>, Error> {
pub fn read_remote_sites(conn: &mut PgConnection) -> Result<Vec<Self>, Error> {
use crate::schema::site::dsl::*;
site.order_by(id).offset(1).get_results::<Self>(conn)
}

@ -48,7 +48,7 @@ pub enum CommentSortType {
Old,
}
#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
pub enum ListingType {
All,
Local,
@ -65,14 +65,14 @@ pub enum SearchType {
Url,
}
#[derive(EnumString, Display, Debug, PartialEq, Serialize, Deserialize, Clone, Copy)]
#[derive(EnumString, Display, Debug, PartialEq, Eq, Serialize, Deserialize, Clone, Copy)]
pub enum SubscribedType {
Subscribed,
NotSubscribed,
Pending,
}
#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
pub enum ModlogActionType {
All,
ModRemovePost,

@ -86,9 +86,9 @@ pub struct LocalUserLanguageId(pub i32);
pub struct CommentReplyId(i32);
#[repr(transparent)]
#[derive(Clone, PartialEq, Serialize, Deserialize, Debug)]
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
#[cfg_attr(feature = "full", derive(AsExpression, FromSqlRow))]
#[cfg_attr(feature = "full", sql_type = "diesel::sql_types::Text")]
#[cfg_attr(feature = "full", diesel(sql_type = diesel::sql_types::Text))]
pub struct DbUrl(pub(crate) Url);
#[derive(Serialize, Deserialize)]

@ -531,59 +531,6 @@ table! {
}
}
// These are necessary since diesel doesn't have self joins / aliases
table! {
person_alias_1 (id) {
id -> Int4,
name -> Varchar,
display_name -> Nullable<Varchar>,
avatar -> Nullable<Varchar>,
banned -> Bool,
published -> Timestamp,
updated -> Nullable<Timestamp>,
actor_id -> Varchar,
bio -> Nullable<Text>,
local -> Bool,
private_key -> Nullable<Text>,
public_key -> Text,
last_refreshed_at -> Timestamp,
banner -> Nullable<Varchar>,
deleted -> Bool,
inbox_url -> Varchar,
shared_inbox_url -> Nullable<Varchar>,
matrix_user_id -> Nullable<Text>,
admin -> Bool,
bot_account -> Bool,
ban_expires -> Nullable<Timestamp>,
}
}
table! {
person_alias_2 (id) {
id -> Int4,
name -> Varchar,
display_name -> Nullable<Varchar>,
avatar -> Nullable<Varchar>,
banned -> Bool,
published -> Timestamp,
updated -> Nullable<Timestamp>,
actor_id -> Varchar,
bio -> Nullable<Text>,
local -> Bool,
private_key -> Nullable<Text>,
public_key -> Text,
last_refreshed_at -> Timestamp,
banner -> Nullable<Varchar>,
deleted -> Bool,
inbox_url -> Varchar,
shared_inbox_url -> Nullable<Varchar>,
matrix_user_id -> Nullable<Text>,
admin -> Bool,
bot_account -> Bool,
ban_expires -> Nullable<Timestamp>,
}
}
table! {
secret(id) {
id -> Int4,
@ -677,18 +624,7 @@ table! {
}
}
joinable!(person_mention -> person_alias_1 (recipient_id));
joinable!(comment_reply -> person_alias_1 (recipient_id));
joinable!(post -> person_alias_1 (creator_id));
joinable!(comment -> person_alias_1 (creator_id));
joinable!(private_message_report -> person_alias_1 (resolver_id));
joinable!(post_report -> person_alias_2 (resolver_id));
joinable!(comment_report -> person_alias_2 (resolver_id));
joinable!(private_message_report -> person_alias_2 (resolver_id));
joinable!(person_block -> person (person_id));
joinable!(person_block -> person_alias_1 (target_id));
joinable!(comment -> person (creator_id));
joinable!(comment -> post (post_id));
@ -800,8 +736,6 @@ allow_tables_to_appear_in_same_query!(
private_message_report,
site,
site_aggregates,
person_alias_1,
person_alias_2,
admin_purge_comment,
admin_purge_community,
admin_purge_person,

@ -2,8 +2,8 @@ use crate::{newtypes::DbUrl, schema::activity};
use serde_json::Value;
use std::fmt::Debug;
#[derive(PartialEq, Debug, Queryable, Identifiable)]
#[table_name = "activity"]
#[derive(PartialEq, Eq, Debug, Queryable, Identifiable)]
#[diesel(table_name = activity)]
pub struct Activity {
pub id: i32,
pub data: Value,
@ -15,7 +15,7 @@ pub struct Activity {
}
#[derive(Insertable, AsChangeset)]
#[table_name = "activity"]
#[diesel(table_name = activity)]
pub struct ActivityForm {
pub data: Value,
pub local: Option<bool>,

@ -5,10 +5,10 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "full")]
use crate::schema::{comment, comment_like, comment_saved};
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
#[cfg_attr(feature = "full", belongs_to(crate::source::post::Post))]
#[cfg_attr(feature = "full", table_name = "comment")]
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
#[cfg_attr(feature = "full", diesel(table_name = comment))]
pub struct Comment {
pub id: CommentId,
pub creator_id: PersonId,
@ -28,7 +28,7 @@ pub struct Comment {
#[derive(Clone, Default)]
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "comment")]
#[cfg_attr(feature = "full", diesel(table_name = comment))]
pub struct CommentForm {
pub creator_id: PersonId,
pub post_id: PostId,
@ -43,10 +43,10 @@ pub struct CommentForm {
pub language_id: Option<LanguageId>,
}
#[derive(PartialEq, Debug, Clone)]
#[derive(PartialEq, Eq, Debug, Clone)]
#[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
#[cfg_attr(feature = "full", belongs_to(Comment))]
#[cfg_attr(feature = "full", table_name = "comment_like")]
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))]
#[cfg_attr(feature = "full", diesel(table_name = comment_like))]
pub struct CommentLike {
pub id: i32,
pub person_id: PersonId,
@ -58,7 +58,7 @@ pub struct CommentLike {
#[derive(Clone)]
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "comment_like")]
#[cfg_attr(feature = "full", diesel(table_name = comment_like))]
pub struct CommentLikeForm {
pub person_id: PersonId,
pub comment_id: CommentId,
@ -66,10 +66,10 @@ pub struct CommentLikeForm {
pub score: i16,
}
#[derive(PartialEq, Debug)]
#[derive(PartialEq, Eq, Debug)]
#[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
#[cfg_attr(feature = "full", belongs_to(Comment))]
#[cfg_attr(feature = "full", table_name = "comment_saved")]
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))]
#[cfg_attr(feature = "full", diesel(table_name = comment_saved))]
pub struct CommentSaved {
pub id: i32,
pub comment_id: CommentId,
@ -78,7 +78,7 @@ pub struct CommentSaved {
}
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "comment_saved")]
#[cfg_attr(feature = "full", diesel(table_name = comment_saved))]
pub struct CommentSavedForm {
pub comment_id: CommentId,
pub person_id: PersonId,

@ -4,10 +4,10 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "full")]
use crate::schema::comment_reply;
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
#[cfg_attr(feature = "full", belongs_to(crate::source::comment::Comment))]
#[cfg_attr(feature = "full", table_name = "comment_reply")]
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))]
#[cfg_attr(feature = "full", diesel(table_name = comment_reply))]
/// This table keeps a list of replies to comments and posts.
pub struct CommentReply {
pub id: CommentReplyId,
@ -18,7 +18,7 @@ pub struct CommentReply {
}
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "comment_reply")]
#[cfg_attr(feature = "full", diesel(table_name = comment_reply))]
pub struct CommentReplyForm {
pub recipient_id: PersonId,
pub comment_id: CommentId,

@ -4,10 +4,10 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "full")]
use crate::schema::comment_report;
#[derive(PartialEq, Serialize, Deserialize, Debug, Clone)]
#[derive(PartialEq, Eq, Serialize, Deserialize, Debug, Clone)]
#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
#[cfg_attr(feature = "full", belongs_to(crate::source::comment::Comment))]
#[cfg_attr(feature = "full", table_name = "comment_report")]
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))]
#[cfg_attr(feature = "full", diesel(table_name = comment_report))]
pub struct CommentReport {
pub id: CommentReportId,
pub creator_id: PersonId,
@ -22,7 +22,7 @@ pub struct CommentReport {
#[derive(Clone)]
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "comment_report")]
#[cfg_attr(feature = "full", diesel(table_name = comment_report))]
pub struct CommentReportForm {
pub creator_id: PersonId,
pub comment_id: CommentId,

@ -4,9 +4,9 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "full")]
use crate::schema::{community, community_follower, community_moderator, community_person_ban};
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "community")]
#[cfg_attr(feature = "full", diesel(table_name = community))]
pub struct Community {
pub id: CommunityId,
pub name: String,
@ -32,9 +32,9 @@ pub struct Community {
}
/// A safe representation of community, without the sensitive info
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "community")]
#[cfg_attr(feature = "full", diesel(table_name = community))]
pub struct CommunitySafe {
pub id: CommunityId,
pub name: String,
@ -55,7 +55,7 @@ pub struct CommunitySafe {
#[derive(Debug, Default)]
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "community")]
#[cfg_attr(feature = "full", diesel(table_name = community))]
pub struct CommunityForm {
pub name: String,
pub title: String,
@ -79,10 +79,13 @@ pub struct CommunityForm {
pub posting_restricted_to_mods: Option<bool>,
}
#[derive(PartialEq, Debug)]
#[derive(PartialEq, Eq, Debug)]
#[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
#[cfg_attr(feature = "full", belongs_to(Community))]
#[cfg_attr(feature = "full", table_name = "community_moderator")]
#[cfg_attr(
feature = "full",
diesel(belongs_to(crate::source::community::Community))
)]
#[cfg_attr(feature = "full", diesel(table_name = community_moderator))]
pub struct CommunityModerator {
pub id: i32,
pub community_id: CommunityId,
@ -92,16 +95,19 @@ pub struct CommunityModerator {
#[derive(Clone)]
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "community_moderator")]
#[cfg_attr(feature = "full", diesel(table_name = community_moderator))]
pub struct CommunityModeratorForm {
pub community_id: CommunityId,
pub person_id: PersonId,
}
#[derive(PartialEq, Debug)]
#[derive(PartialEq, Eq, Debug)]
#[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
#[cfg_attr(feature = "full", belongs_to(Community))]
#[cfg_attr(feature = "full", table_name = "community_person_ban")]
#[cfg_attr(
feature = "full",
diesel(belongs_to(crate::source::community::Community))
)]
#[cfg_attr(feature = "full", diesel(table_name = community_person_ban))]
pub struct CommunityPersonBan {
pub id: i32,
pub community_id: CommunityId,
@ -112,17 +118,20 @@ pub struct CommunityPersonBan {
#[derive(Clone)]
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "community_person_ban")]
#[cfg_attr(feature = "full", diesel(table_name = community_person_ban))]
pub struct CommunityPersonBanForm {
pub community_id: CommunityId,
pub person_id: PersonId,
pub expires: Option<Option<chrono::NaiveDateTime>>,
}
#[derive(PartialEq, Debug)]
#[derive(PartialEq, Eq, Debug)]
#[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
#[cfg_attr(feature = "full", belongs_to(Community))]
#[cfg_attr(feature = "full", table_name = "community_follower")]
#[cfg_attr(
feature = "full",
diesel(belongs_to(crate::source::community::Community))
)]
#[cfg_attr(feature = "full", diesel(table_name = community_follower))]
pub struct CommunityFollower {
pub id: i32,
pub community_id: CommunityId,
@ -133,7 +142,7 @@ pub struct CommunityFollower {
#[derive(Clone)]
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "community_follower")]
#[cfg_attr(feature = "full", diesel(table_name = community_follower))]
pub struct CommunityFollowerForm {
pub community_id: CommunityId,
pub person_id: PersonId,

@ -4,10 +4,13 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "full")]
use crate::schema::community_block;
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
#[cfg_attr(feature = "full", belongs_to(crate::source::community::Community))]
#[cfg_attr(feature = "full", table_name = "community_block")]
#[cfg_attr(
feature = "full",
diesel(belongs_to(crate::source::community::Community))
)]
#[cfg_attr(feature = "full", diesel(table_name = community_block))]
pub struct CommunityBlock {
pub id: CommunityBlockId,
pub person_id: PersonId,
@ -16,7 +19,7 @@ pub struct CommunityBlock {
}
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "community_block")]
#[cfg_attr(feature = "full", diesel(table_name = community_block))]
pub struct CommunityBlockForm {
pub person_id: PersonId,
pub community_id: CommunityId,

@ -5,7 +5,7 @@ use crate::schema::email_verification;
#[derive(Clone)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "email_verification")]
#[cfg_attr(feature = "full", diesel(table_name = email_verification))]
pub struct EmailVerification {
pub id: i32,
pub local_user_id: LocalUserId,
@ -15,7 +15,7 @@ pub struct EmailVerification {
}
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "email_verification")]
#[cfg_attr(feature = "full", diesel(table_name = email_verification))]
pub struct EmailVerificationForm {
pub local_user_id: LocalUserId,
pub email: String,

@ -4,9 +4,9 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "full")]
use crate::schema::language;
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "language")]
#[cfg_attr(feature = "full", diesel(table_name = language))]
pub struct Language {
pub id: LanguageId,
pub code: String,

@ -4,9 +4,9 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "full")]
use crate::schema::local_user;
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "local_user")]
#[cfg_attr(feature = "full", diesel(table_name = local_user))]
pub struct LocalUser {
pub id: LocalUserId,
pub person_id: PersonId,
@ -31,7 +31,7 @@ pub struct LocalUser {
// TODO redo these, check table defaults
#[derive(Clone, Default)]
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "local_user")]
#[cfg_attr(feature = "full", diesel(table_name = local_user))]
pub struct LocalUserForm {
pub person_id: Option<PersonId>,
pub password_encrypted: Option<String>,
@ -52,9 +52,9 @@ pub struct LocalUserForm {
}
/// A local user view that removes password encrypted
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "local_user")]
#[cfg_attr(feature = "full", diesel(table_name = local_user))]
pub struct LocalUserSettings {
pub id: LocalUserId,
pub person_id: PersonId,

@ -4,9 +4,9 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "full")]
use crate::schema::local_user_language;
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "local_user_language")]
#[cfg_attr(feature = "full", diesel(table_name = local_user_language))]
pub struct LocalUserLanguage {
#[serde(skip)]
pub id: LocalUserLanguageId,
@ -16,7 +16,7 @@ pub struct LocalUserLanguage {
#[derive(Clone)]
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "local_user_language")]
#[cfg_attr(feature = "full", diesel(table_name = local_user_language))]
pub struct LocalUserLanguageForm {
pub local_user_id: LocalUserId,
pub language_id: LanguageId,

@ -20,9 +20,9 @@ use crate::schema::{
mod_transfer_community,
};
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "mod_remove_post")]
#[cfg_attr(feature = "full", diesel(table_name = mod_remove_post))]
pub struct ModRemovePost {
pub id: i32,
pub mod_person_id: PersonId,
@ -33,7 +33,7 @@ pub struct ModRemovePost {
}
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "mod_remove_post")]
#[cfg_attr(feature = "full", diesel(table_name = mod_remove_post))]
pub struct ModRemovePostForm {
pub mod_person_id: PersonId,
pub post_id: PostId,
@ -41,9 +41,9 @@ pub struct ModRemovePostForm {
pub removed: Option<bool>,
}
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "mod_lock_post")]
#[cfg_attr(feature = "full", diesel(table_name = mod_lock_post))]
pub struct ModLockPost {
pub id: i32,
pub mod_person_id: PersonId,
@ -53,16 +53,16 @@ pub struct ModLockPost {
}
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "mod_lock_post")]
#[cfg_attr(feature = "full", diesel(table_name = mod_lock_post))]
pub struct ModLockPostForm {
pub mod_person_id: PersonId,
pub post_id: PostId,
pub locked: Option<bool>,
}
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "mod_sticky_post")]
#[cfg_attr(feature = "full", diesel(table_name = mod_sticky_post))]
pub struct ModStickyPost {
pub id: i32,
pub mod_person_id: PersonId,
@ -72,16 +72,16 @@ pub struct ModStickyPost {
}
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "mod_sticky_post")]
#[cfg_attr(feature = "full", diesel(table_name = mod_sticky_post))]
pub struct ModStickyPostForm {
pub mod_person_id: PersonId,
pub post_id: PostId,
pub stickied: Option<bool>,
}
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "mod_remove_comment")]
#[cfg_attr(feature = "full", diesel(table_name = mod_remove_comment))]
pub struct ModRemoveComment {
pub id: i32,
pub mod_person_id: PersonId,
@ -92,7 +92,7 @@ pub struct ModRemoveComment {
}
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "mod_remove_comment")]
#[cfg_attr(feature = "full", diesel(table_name = mod_remove_comment))]
pub struct ModRemoveCommentForm {
pub mod_person_id: PersonId,
pub comment_id: CommentId,
@ -100,9 +100,9 @@ pub struct ModRemoveCommentForm {
pub removed: Option<bool>,
}
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "mod_remove_community")]
#[cfg_attr(feature = "full", diesel(table_name = mod_remove_community))]
pub struct ModRemoveCommunity {
pub id: i32,
pub mod_person_id: PersonId,
@ -114,7 +114,7 @@ pub struct ModRemoveCommunity {
}
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "mod_remove_community")]
#[cfg_attr(feature = "full", diesel(table_name = mod_remove_community))]
pub struct ModRemoveCommunityForm {
pub mod_person_id: PersonId,
pub community_id: CommunityId,
@ -123,9 +123,9 @@ pub struct ModRemoveCommunityForm {
pub expires: Option<chrono::NaiveDateTime>,
}
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "mod_ban_from_community")]
#[cfg_attr(feature = "full", diesel(table_name = mod_ban_from_community))]
pub struct ModBanFromCommunity {
pub id: i32,
pub mod_person_id: PersonId,
@ -138,7 +138,7 @@ pub struct ModBanFromCommunity {
}
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "mod_ban_from_community")]
#[cfg_attr(feature = "full", diesel(table_name = mod_ban_from_community))]
pub struct ModBanFromCommunityForm {
pub mod_person_id: PersonId,
pub other_person_id: PersonId,
@ -148,9 +148,9 @@ pub struct ModBanFromCommunityForm {
pub expires: Option<chrono::NaiveDateTime>,
}
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "mod_ban")]
#[cfg_attr(feature = "full", diesel(table_name = mod_ban))]
pub struct ModBan {
pub id: i32,
pub mod_person_id: PersonId,
@ -162,16 +162,16 @@ pub struct ModBan {
}
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "mod_hide_community")]
#[cfg_attr(feature = "full", diesel(table_name = mod_hide_community))]
pub struct ModHideCommunityForm {
pub community_id: CommunityId,
pub mod_person_id: PersonId,
pub hidden: Option<bool>,
pub reason: Option<String>,
}
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "mod_hide_community")]
#[cfg_attr(feature = "full", diesel(table_name = mod_hide_community))]
pub struct ModHideCommunity {
pub id: i32,
pub community_id: CommunityId,
@ -182,7 +182,7 @@ pub struct ModHideCommunity {
}
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "mod_ban")]
#[cfg_attr(feature = "full", diesel(table_name = mod_ban))]
pub struct ModBanForm {
pub mod_person_id: PersonId,
pub other_person_id: PersonId,
@ -191,9 +191,9 @@ pub struct ModBanForm {
pub expires: Option<chrono::NaiveDateTime>,
}
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "mod_add_community")]
#[cfg_attr(feature = "full", diesel(table_name = mod_add_community))]
pub struct ModAddCommunity {
pub id: i32,
pub mod_person_id: PersonId,
@ -204,7 +204,7 @@ pub struct ModAddCommunity {
}
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "mod_add_community")]
#[cfg_attr(feature = "full", diesel(table_name = mod_add_community))]
pub struct ModAddCommunityForm {
pub mod_person_id: PersonId,
pub other_person_id: PersonId,
@ -212,9 +212,9 @@ pub struct ModAddCommunityForm {
pub removed: Option<bool>,
}
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "mod_transfer_community")]
#[cfg_attr(feature = "full", diesel(table_name = mod_transfer_community))]
pub struct ModTransferCommunity {
pub id: i32,
pub mod_person_id: PersonId,
@ -225,7 +225,7 @@ pub struct ModTransferCommunity {
}
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "mod_transfer_community")]
#[cfg_attr(feature = "full", diesel(table_name = mod_transfer_community))]
pub struct ModTransferCommunityForm {
pub mod_person_id: PersonId,
pub other_person_id: PersonId,
@ -233,9 +233,9 @@ pub struct ModTransferCommunityForm {
pub removed: Option<bool>,
}
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "mod_add")]
#[cfg_attr(feature = "full", diesel(table_name = mod_add))]
pub struct ModAdd {
pub id: i32,
pub mod_person_id: PersonId,
@ -245,16 +245,16 @@ pub struct ModAdd {
}
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "mod_add")]
#[cfg_attr(feature = "full", diesel(table_name = mod_add))]
pub struct ModAddForm {
pub mod_person_id: PersonId,
pub other_person_id: PersonId,
pub removed: Option<bool>,
}
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "admin_purge_person")]
#[cfg_attr(feature = "full", diesel(table_name = admin_purge_person))]
pub struct AdminPurgePerson {
pub id: i32,
pub admin_person_id: PersonId,
@ -263,15 +263,15 @@ pub struct AdminPurgePerson {
}
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "admin_purge_person")]
#[cfg_attr(feature = "full", diesel(table_name = admin_purge_person))]
pub struct AdminPurgePersonForm {
pub admin_person_id: PersonId,
pub reason: Option<String>,
}
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "admin_purge_community")]
#[cfg_attr(feature = "full", diesel(table_name = admin_purge_community))]
pub struct AdminPurgeCommunity {
pub id: i32,
pub admin_person_id: PersonId,
@ -280,15 +280,15 @@ pub struct AdminPurgeCommunity {
}
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "admin_purge_community")]
#[cfg_attr(feature = "full", diesel(table_name = admin_purge_community))]
pub struct AdminPurgeCommunityForm {
pub admin_person_id: PersonId,
pub reason: Option<String>,
}
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "admin_purge_post")]
#[cfg_attr(feature = "full", diesel(table_name = admin_purge_post))]
pub struct AdminPurgePost {
pub id: i32,
pub admin_person_id: PersonId,
@ -298,16 +298,16 @@ pub struct AdminPurgePost {
}
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "admin_purge_post")]
#[cfg_attr(feature = "full", diesel(table_name = admin_purge_post))]
pub struct AdminPurgePostForm {
pub admin_person_id: PersonId,
pub community_id: CommunityId,
pub reason: Option<String>,
}
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "admin_purge_comment")]
#[cfg_attr(feature = "full", diesel(table_name = admin_purge_comment))]
pub struct AdminPurgeComment {
pub id: i32,
pub admin_person_id: PersonId,
@ -317,7 +317,7 @@ pub struct AdminPurgeComment {
}
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "admin_purge_comment")]
#[cfg_attr(feature = "full", diesel(table_name = admin_purge_comment))]
pub struct AdminPurgeCommentForm {
pub admin_person_id: PersonId,
pub post_id: PostId,

@ -3,9 +3,9 @@ use crate::newtypes::LocalUserId;
#[cfg(feature = "full")]
use crate::schema::password_reset_request;
#[derive(PartialEq, Debug)]
#[derive(PartialEq, Eq, Debug)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "password_reset_request")]
#[cfg_attr(feature = "full", diesel(table_name = password_reset_request))]
pub struct PasswordResetRequest {
pub id: i32,
pub token_encrypted: String,
@ -14,7 +14,7 @@ pub struct PasswordResetRequest {
}
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "password_reset_request")]
#[cfg_attr(feature = "full", diesel(table_name = password_reset_request))]
pub struct PasswordResetRequestForm {
pub local_user_id: LocalUserId,
pub token_encrypted: String,

@ -2,11 +2,11 @@ use crate::newtypes::{DbUrl, PersonId};
use serde::{Deserialize, Serialize};
#[cfg(feature = "full")]
use crate::schema::{person, person_alias_1, person_alias_2};
use crate::schema::person;
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "person")]
#[cfg_attr(feature = "full", diesel(table_name = person))]
pub struct Person {
pub id: PersonId,
pub name: String,
@ -32,9 +32,9 @@ pub struct Person {
}
/// A safe representation of person, without the sensitive info
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "person")]
#[cfg_attr(feature = "full", diesel(table_name = person))]
pub struct PersonSafe {
pub id: PersonId,
pub name: String,
@ -56,111 +56,9 @@ pub struct PersonSafe {
pub ban_expires: Option<chrono::NaiveDateTime>,
}
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "person_alias_1")]
pub struct PersonAlias1 {
pub id: PersonId,
pub name: String,
pub display_name: Option<String>,
pub avatar: Option<DbUrl>,
pub banned: bool,
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub actor_id: DbUrl,
pub bio: Option<String>,
pub local: bool,
pub private_key: Option<String>,
pub public_key: String,
pub last_refreshed_at: chrono::NaiveDateTime,
pub banner: Option<DbUrl>,
pub deleted: bool,
pub inbox_url: DbUrl,
pub shared_inbox_url: Option<DbUrl>,
pub matrix_user_id: Option<String>,
pub admin: bool,
pub bot_account: bool,
pub ban_expires: Option<chrono::NaiveDateTime>,
}
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "person_alias_1")]
pub struct PersonSafeAlias1 {
pub id: PersonId,
pub name: String,
pub display_name: Option<String>,
pub avatar: Option<DbUrl>,
pub banned: bool,
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub actor_id: DbUrl,
pub bio: Option<String>,
pub local: bool,
pub banner: Option<DbUrl>,
pub deleted: bool,
pub inbox_url: DbUrl,
pub shared_inbox_url: Option<DbUrl>,
pub matrix_user_id: Option<String>,
pub admin: bool,
pub bot_account: bool,
pub ban_expires: Option<chrono::NaiveDateTime>,
}
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "person_alias_2")]
pub struct PersonAlias2 {
pub id: PersonId,
pub name: String,
pub display_name: Option<String>,
pub avatar: Option<DbUrl>,
pub banned: bool,
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub actor_id: DbUrl,
pub bio: Option<String>,
pub local: bool,
pub private_key: Option<String>,
pub public_key: String,
pub last_refreshed_at: chrono::NaiveDateTime,
pub banner: Option<DbUrl>,
pub deleted: bool,
pub inbox_url: DbUrl,
pub shared_inbox_url: Option<DbUrl>,
pub matrix_user_id: Option<String>,
pub admin: bool,
pub bot_account: bool,
pub ban_expires: Option<chrono::NaiveDateTime>,
}
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "person_alias_1")]
pub struct PersonSafeAlias2 {
pub id: PersonId,
pub name: String,
pub display_name: Option<String>,
pub avatar: Option<DbUrl>,
pub banned: bool,
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub actor_id: DbUrl,
pub bio: Option<String>,
pub local: bool,
pub banner: Option<DbUrl>,
pub deleted: bool,
pub inbox_url: DbUrl,
pub shared_inbox_url: Option<DbUrl>,
pub matrix_user_id: Option<String>,
pub admin: bool,
pub bot_account: bool,
pub ban_expires: Option<chrono::NaiveDateTime>,
}
#[derive(Clone, Default)]
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "person")]
#[cfg_attr(feature = "full", diesel(table_name = person))]
pub struct PersonForm {
pub name: String,
pub display_name: Option<Option<String>>,

@ -4,9 +4,10 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "full")]
use crate::schema::person_block;
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
#[cfg_attr(feature = "full", table_name = "person_block")]
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::person::Person)))]
#[cfg_attr(feature = "full", diesel(table_name = person_block))]
pub struct PersonBlock {
pub id: PersonBlockId,
pub person_id: PersonId,
@ -15,7 +16,7 @@ pub struct PersonBlock {
}
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "person_block")]
#[cfg_attr(feature = "full", diesel(table_name = person_block))]
pub struct PersonBlockForm {
pub person_id: PersonId,
pub target_id: PersonId,

@ -4,10 +4,10 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "full")]
use crate::schema::person_mention;
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
#[cfg_attr(feature = "full", belongs_to(crate::source::comment::Comment))]
#[cfg_attr(feature = "full", table_name = "person_mention")]
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::comment::Comment)))]
#[cfg_attr(feature = "full", diesel(table_name = person_mention))]
pub struct PersonMention {
pub id: PersonMentionId,
pub recipient_id: PersonId,
@ -17,7 +17,7 @@ pub struct PersonMention {
}
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "person_mention")]
#[cfg_attr(feature = "full", diesel(table_name = person_mention))]
pub struct PersonMentionForm {
pub recipient_id: PersonId,
pub comment_id: CommentId,

@ -4,9 +4,9 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "full")]
use crate::schema::{post, post_like, post_read, post_saved};
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
#[cfg_attr(feature = "full", table_name = "post")]
#[cfg_attr(feature = "full", diesel(table_name = post))]
pub struct Post {
pub id: PostId,
pub name: String,
@ -32,7 +32,7 @@ pub struct Post {
#[derive(Default)]
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "post")]
#[cfg_attr(feature = "full", diesel(table_name = post))]
pub struct PostForm {
pub name: String,
pub creator_id: PersonId,
@ -55,10 +55,10 @@ pub struct PostForm {
pub language_id: Option<LanguageId>,
}
#[derive(PartialEq, Debug)]
#[derive(PartialEq, Eq, Debug)]
#[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
#[cfg_attr(feature = "full", belongs_to(Post))]
#[cfg_attr(feature = "full", table_name = "post_like")]
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
#[cfg_attr(feature = "full", diesel(table_name = post_like))]
pub struct PostLike {
pub id: i32,
pub post_id: PostId,
@ -69,17 +69,17 @@ pub struct PostLike {
#[derive(Clone)]
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "post_like")]
#[cfg_attr(feature = "full", diesel(table_name = post_like))]
pub struct PostLikeForm {
pub post_id: PostId,
pub person_id: PersonId,
pub score: i16,
}
#[derive(PartialEq, Debug)]
#[derive(PartialEq, Eq, Debug)]
#[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
#[cfg_attr(feature = "full", belongs_to(Post))]
#[cfg_attr(feature = "full", table_name = "post_saved")]
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
#[cfg_attr(feature = "full", diesel(table_name = post_saved))]
pub struct PostSaved {
pub id: i32,
pub post_id: PostId,
@ -88,16 +88,16 @@ pub struct PostSaved {
}
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "post_saved")]
#[cfg_attr(feature = "full", diesel(table_name = post_saved))]
pub struct PostSavedForm {
pub post_id: PostId,
pub person_id: PersonId,
}
#[derive(PartialEq, Debug)]
#[derive(PartialEq, Eq, Debug)]
#[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
#[cfg_attr(feature = "full", belongs_to(Post))]
#[cfg_attr(feature = "full", table_name = "post_read")]
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))]
#[cfg_attr(feature = "full", diesel(table_name = post_read))]
pub struct PostRead {
pub id: i32,
pub post_id: PostId,
@ -106,7 +106,7 @@ pub struct PostRead {
}
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "post_read")]
#[cfg_attr(feature = "full", diesel(table_name = post_read))]
pub struct PostReadForm {
pub post_id: PostId,
pub person_id: PersonId,

@ -4,10 +4,10 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "full")]
use crate::schema::post_report;
#[derive(PartialEq, Serialize, Deserialize, Debug, Clone)]
#[derive(PartialEq, Eq, Serialize, Deserialize, Debug, Clone)]
#[cfg_attr(feature = "full", derive(Identifiable, Queryable, Associations))]
#[cfg_attr(feature = "full", belongs_to(crate::source::post::Post))]
#[cfg_attr(feature = "full", table_name = "post_report")]
#[cfg_attr(feature = "full", diesel(belongs_to(crate::source::post::Post)))] // Is this the right assoc?
#[cfg_attr(feature = "full", diesel(table_name = post_report))]
pub struct PostReport {
pub id: PostReportId,
pub creator_id: PersonId,
@ -24,7 +24,7 @@ pub struct PostReport {
#[derive(Clone)]
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "post_report")]
#[cfg_attr(feature = "full", diesel(table_name = post_report))]
pub struct PostReportForm {
pub creator_id: PersonId,
pub post_id: PostId,

@ -4,9 +4,13 @@ use serde::{Deserialize, Serialize};
#[cfg(feature = "full")]
use crate::schema::private_message;
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable))]
#[cfg_attr(feature = "full", table_name = "private_message")]
#[cfg_attr(
feature = "full",
diesel(belongs_to(crate::source::person::Person, foreign_key = creator_id)
))] // Is this the right assoc?
#[cfg_attr(feature = "full", diesel(table_name = private_message))]
pub struct PrivateMessage {
pub id: PrivateMessageId,
pub creator_id: PersonId,
@ -22,7 +26,7 @@ pub struct PrivateMessage {
#[derive(Default)]
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", table_name = "private_message")]
#[cfg_attr(feature = "full", diesel(table_name = private_message))]
pub struct PrivateMessageForm {
pub creator_id: PersonId,
pub recipient_id: PersonId,

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save