mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-22 19:01:32 +00:00
Still continuing on....
This commit is contained in:
parent
efc9047f87
commit
a869a2823b
43 changed files with 1232 additions and 1470 deletions
|
@ -134,7 +134,7 @@ impl Perform for CreateComment {
|
||||||
let like_form = CommentLikeForm {
|
let like_form = CommentLikeForm {
|
||||||
comment_id: inserted_comment.id,
|
comment_id: inserted_comment.id,
|
||||||
post_id,
|
post_id,
|
||||||
user_id: user.id,
|
person_id: user.id,
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -375,7 +375,7 @@ impl Perform for RemoveComment {
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
let form = ModRemoveCommentForm {
|
let form = ModRemoveCommentForm {
|
||||||
mod_user_id: user.id,
|
mod_person_id: user.id,
|
||||||
comment_id: data.comment_id,
|
comment_id: data.comment_id,
|
||||||
removed: Some(removed),
|
removed: Some(removed),
|
||||||
reason: data.reason.to_owned(),
|
reason: data.reason.to_owned(),
|
||||||
|
@ -498,7 +498,7 @@ impl Perform for SaveComment {
|
||||||
|
|
||||||
let comment_saved_form = CommentSavedForm {
|
let comment_saved_form = CommentSavedForm {
|
||||||
comment_id: data.comment_id,
|
comment_id: data.comment_id,
|
||||||
user_id: user.id,
|
person_id: user.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
if data.save {
|
if data.save {
|
||||||
|
@ -559,7 +559,7 @@ impl Perform for CreateCommentLike {
|
||||||
let like_form = CommentLikeForm {
|
let like_form = CommentLikeForm {
|
||||||
comment_id: data.comment_id,
|
comment_id: data.comment_id,
|
||||||
post_id: orig_comment.post.id,
|
post_id: orig_comment.post.id,
|
||||||
user_id: user.id,
|
person_id: user.id,
|
||||||
score: data.score,
|
score: data.score,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -198,7 +198,7 @@ impl Perform for CreateCommunity {
|
||||||
// The community creator becomes a moderator
|
// The community creator becomes a moderator
|
||||||
let community_moderator_form = CommunityModeratorForm {
|
let community_moderator_form = CommunityModeratorForm {
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
user_id: user.id,
|
person_id: user.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
let join = move |conn: &'_ _| CommunityModerator::join(conn, &community_moderator_form);
|
let join = move |conn: &'_ _| CommunityModerator::join(conn, &community_moderator_form);
|
||||||
|
@ -209,7 +209,7 @@ impl Perform for CreateCommunity {
|
||||||
// Follow your own community
|
// Follow your own community
|
||||||
let community_follower_form = CommunityFollowerForm {
|
let community_follower_form = CommunityFollowerForm {
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
user_id: user.id,
|
person_id: user.id,
|
||||||
pending: false,
|
pending: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -405,7 +405,7 @@ impl Perform for RemoveCommunity {
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
let form = ModRemoveCommunityForm {
|
let form = ModRemoveCommunityForm {
|
||||||
mod_user_id: user.id,
|
mod_person_id: user.id,
|
||||||
community_id: data.community_id,
|
community_id: data.community_id,
|
||||||
removed: Some(removed),
|
removed: Some(removed),
|
||||||
reason: data.reason.to_owned(),
|
reason: data.reason.to_owned(),
|
||||||
|
@ -501,7 +501,7 @@ impl Perform for FollowCommunity {
|
||||||
.await??;
|
.await??;
|
||||||
let community_follower_form = CommunityFollowerForm {
|
let community_follower_form = CommunityFollowerForm {
|
||||||
community_id: data.community_id,
|
community_id: data.community_id,
|
||||||
user_id: user.id,
|
person_id: user.id,
|
||||||
pending: false,
|
pending: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -595,13 +595,13 @@ impl Perform for BanFromCommunity {
|
||||||
// Verify that only mods or admins can ban
|
// Verify that only mods or admins can ban
|
||||||
is_mod_or_admin(context.pool(), user.id, community_id).await?;
|
is_mod_or_admin(context.pool(), user.id, community_id).await?;
|
||||||
|
|
||||||
let community_user_ban_form = CommunityUserBanForm {
|
let community_user_ban_form = CommunityPersonBanForm {
|
||||||
community_id: data.community_id,
|
community_id: data.community_id,
|
||||||
user_id: data.user_id,
|
person_id: data.user_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
if data.ban {
|
if data.ban {
|
||||||
let ban = move |conn: &'_ _| CommunityUserBan::ban(conn, &community_user_ban_form);
|
let ban = move |conn: &'_ _| CommunityPersonBan::ban(conn, &community_user_ban_form);
|
||||||
if blocking(context.pool(), ban).await?.is_err() {
|
if blocking(context.pool(), ban).await?.is_err() {
|
||||||
return Err(ApiError::err("community_user_already_banned").into());
|
return Err(ApiError::err("community_user_already_banned").into());
|
||||||
}
|
}
|
||||||
|
@ -609,7 +609,7 @@ impl Perform for BanFromCommunity {
|
||||||
// Also unsubscribe them from the community, if they are subscribed
|
// Also unsubscribe them from the community, if they are subscribed
|
||||||
let community_follower_form = CommunityFollowerForm {
|
let community_follower_form = CommunityFollowerForm {
|
||||||
community_id: data.community_id,
|
community_id: data.community_id,
|
||||||
user_id: banned_user_id,
|
person_id: banned_user_id,
|
||||||
pending: false,
|
pending: false,
|
||||||
};
|
};
|
||||||
blocking(context.pool(), move |conn: &'_ _| {
|
blocking(context.pool(), move |conn: &'_ _| {
|
||||||
|
@ -618,7 +618,7 @@ impl Perform for BanFromCommunity {
|
||||||
.await?
|
.await?
|
||||||
.ok();
|
.ok();
|
||||||
} else {
|
} else {
|
||||||
let unban = move |conn: &'_ _| CommunityUserBan::unban(conn, &community_user_ban_form);
|
let unban = move |conn: &'_ _| CommunityPersonBan::unban(conn, &community_user_ban_form);
|
||||||
if blocking(context.pool(), unban).await?.is_err() {
|
if blocking(context.pool(), unban).await?.is_err() {
|
||||||
return Err(ApiError::err("community_user_already_banned").into());
|
return Err(ApiError::err("community_user_already_banned").into());
|
||||||
}
|
}
|
||||||
|
@ -660,8 +660,8 @@ impl Perform for BanFromCommunity {
|
||||||
};
|
};
|
||||||
|
|
||||||
let form = ModBanFromCommunityForm {
|
let form = ModBanFromCommunityForm {
|
||||||
mod_user_id: user.id,
|
mod_person_id: user.id,
|
||||||
other_user_id: data.user_id,
|
other_person_id: data.user_id,
|
||||||
community_id: data.community_id,
|
community_id: data.community_id,
|
||||||
reason: data.reason.to_owned(),
|
reason: data.reason.to_owned(),
|
||||||
banned: Some(data.ban),
|
banned: Some(data.ban),
|
||||||
|
@ -708,7 +708,7 @@ impl Perform for AddModToCommunity {
|
||||||
|
|
||||||
let community_moderator_form = CommunityModeratorForm {
|
let community_moderator_form = CommunityModeratorForm {
|
||||||
community_id: data.community_id,
|
community_id: data.community_id,
|
||||||
user_id: data.user_id,
|
person_id: data.user_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
|
@ -730,8 +730,8 @@ impl Perform for AddModToCommunity {
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
let form = ModAddCommunityForm {
|
let form = ModAddCommunityForm {
|
||||||
mod_user_id: user.id,
|
mod_person_id: user.id,
|
||||||
other_user_id: data.user_id,
|
other_person_id: data.user_id,
|
||||||
community_id: data.community_id,
|
community_id: data.community_id,
|
||||||
removed: Some(!data.added),
|
removed: Some(!data.added),
|
||||||
};
|
};
|
||||||
|
@ -829,7 +829,7 @@ impl Perform for TransferCommunity {
|
||||||
for cmod in &community_mods {
|
for cmod in &community_mods {
|
||||||
let community_moderator_form = CommunityModeratorForm {
|
let community_moderator_form = CommunityModeratorForm {
|
||||||
community_id: cmod.community.id,
|
community_id: cmod.community.id,
|
||||||
user_id: cmod.moderator.id,
|
person_id: cmod.moderator.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
let join = move |conn: &'_ _| CommunityModerator::join(conn, &community_moderator_form);
|
let join = move |conn: &'_ _| CommunityModerator::join(conn, &community_moderator_form);
|
||||||
|
@ -840,8 +840,8 @@ impl Perform for TransferCommunity {
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
let form = ModAddCommunityForm {
|
let form = ModAddCommunityForm {
|
||||||
mod_user_id: user.id,
|
mod_person_id: user.id,
|
||||||
other_user_id: data.user_id,
|
other_person_id: data.user_id,
|
||||||
community_id: data.community_id,
|
community_id: data.community_id,
|
||||||
removed: Some(false),
|
removed: Some(false),
|
||||||
};
|
};
|
||||||
|
|
|
@ -165,7 +165,7 @@ pub(crate) async fn collect_moderated_communities(
|
||||||
Ok(vec![community_id])
|
Ok(vec![community_id])
|
||||||
} else {
|
} else {
|
||||||
let ids = blocking(pool, move |conn: &'_ _| {
|
let ids = blocking(pool, move |conn: &'_ _| {
|
||||||
CommunityModerator::get_user_moderated_communities(conn, user_id)
|
CommunityModerator::get_person_moderated_communities(conn, user_id)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
Ok(ids)
|
Ok(ids)
|
||||||
|
|
|
@ -129,7 +129,7 @@ impl Perform for CreatePost {
|
||||||
// They like their own post by default
|
// They like their own post by default
|
||||||
let like_form = PostLikeForm {
|
let like_form = PostLikeForm {
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
user_id: user.id,
|
person_id: user.id,
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -303,7 +303,7 @@ impl Perform for CreatePostLike {
|
||||||
|
|
||||||
let like_form = PostLikeForm {
|
let like_form = PostLikeForm {
|
||||||
post_id: data.post_id,
|
post_id: data.post_id,
|
||||||
user_id: user.id,
|
person_id: user.id,
|
||||||
score: data.score,
|
score: data.score,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -534,7 +534,7 @@ impl Perform for RemovePost {
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
let form = ModRemovePostForm {
|
let form = ModRemovePostForm {
|
||||||
mod_user_id: user.id,
|
mod_person_id: user.id,
|
||||||
post_id: data.post_id,
|
post_id: data.post_id,
|
||||||
removed: Some(removed),
|
removed: Some(removed),
|
||||||
reason: data.reason.to_owned(),
|
reason: data.reason.to_owned(),
|
||||||
|
@ -601,7 +601,7 @@ impl Perform for LockPost {
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
let form = ModLockPostForm {
|
let form = ModLockPostForm {
|
||||||
mod_user_id: user.id,
|
mod_person_id: user.id,
|
||||||
post_id: data.post_id,
|
post_id: data.post_id,
|
||||||
locked: Some(locked),
|
locked: Some(locked),
|
||||||
};
|
};
|
||||||
|
@ -659,7 +659,7 @@ impl Perform for StickyPost {
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
let form = ModStickyPostForm {
|
let form = ModStickyPostForm {
|
||||||
mod_user_id: user.id,
|
mod_person_id: user.id,
|
||||||
post_id: data.post_id,
|
post_id: data.post_id,
|
||||||
stickied: Some(stickied),
|
stickied: Some(stickied),
|
||||||
};
|
};
|
||||||
|
@ -705,7 +705,7 @@ impl Perform for SavePost {
|
||||||
|
|
||||||
let post_saved_form = PostSavedForm {
|
let post_saved_form = PostSavedForm {
|
||||||
post_id: data.post_id,
|
post_id: data.post_id,
|
||||||
user_id: user.id,
|
person_id: user.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
if data.save {
|
if data.save {
|
||||||
|
|
|
@ -511,8 +511,8 @@ impl Perform for TransferSite {
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
let form = ModAddForm {
|
let form = ModAddForm {
|
||||||
mod_user_id: user.id,
|
mod_person_id: user.id,
|
||||||
other_user_id: data.user_id,
|
other_person_id: data.user_id,
|
||||||
removed: Some(false),
|
removed: Some(false),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -278,7 +278,7 @@ impl Perform for Register {
|
||||||
// Sign them up for main community no matter what
|
// Sign them up for main community no matter what
|
||||||
let community_follower_form = CommunityFollowerForm {
|
let community_follower_form = CommunityFollowerForm {
|
||||||
community_id: main_community.id,
|
community_id: main_community.id,
|
||||||
user_id: inserted_user.id,
|
person_id: inserted_user.id,
|
||||||
pending: false,
|
pending: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -291,7 +291,7 @@ impl Perform for Register {
|
||||||
if no_admins {
|
if no_admins {
|
||||||
let community_moderator_form = CommunityModeratorForm {
|
let community_moderator_form = CommunityModeratorForm {
|
||||||
community_id: main_community.id,
|
community_id: main_community.id,
|
||||||
user_id: inserted_user.id,
|
person_id: inserted_user.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
let join = move |conn: &'_ _| CommunityModerator::join(conn, &community_moderator_form);
|
let join = move |conn: &'_ _| CommunityModerator::join(conn, &community_moderator_form);
|
||||||
|
@ -611,8 +611,8 @@ impl Perform for AddAdmin {
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
let form = ModAddForm {
|
let form = ModAddForm {
|
||||||
mod_user_id: user.id,
|
mod_person_id: user.id,
|
||||||
other_user_id: data.user_id,
|
other_person_id: data.user_id,
|
||||||
removed: Some(!data.added),
|
removed: Some(!data.added),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -693,8 +693,8 @@ impl Perform for BanUser {
|
||||||
};
|
};
|
||||||
|
|
||||||
let form = ModBanForm {
|
let form = ModBanForm {
|
||||||
mod_user_id: user.id,
|
mod_person_id: user.id,
|
||||||
other_user_id: data.user_id,
|
other_person_id: data.user_id,
|
||||||
reason: data.reason.to_owned(),
|
reason: data.reason.to_owned(),
|
||||||
banned: Some(data.ban),
|
banned: Some(data.ban),
|
||||||
expires,
|
expires,
|
||||||
|
@ -989,7 +989,7 @@ impl Perform for PasswordChange {
|
||||||
// Fetch the user_id from the token
|
// Fetch the user_id from the token
|
||||||
let token = data.token.clone();
|
let token = data.token.clone();
|
||||||
let user_id = blocking(context.pool(), move |conn| {
|
let user_id = blocking(context.pool(), move |conn| {
|
||||||
PasswordResetRequest::read_from_token(conn, &token).map(|p| p.user_id)
|
PasswordResetRequest::read_from_token(conn, &token).map(|p| p.local_user_id)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,7 @@ pub(crate) async fn receive_like_comment(
|
||||||
let like_form = CommentLikeForm {
|
let like_form = CommentLikeForm {
|
||||||
comment_id,
|
comment_id,
|
||||||
post_id: comment.post_id,
|
post_id: comment.post_id,
|
||||||
user_id: user.id,
|
person_id: user.id,
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
let user_id = user.id;
|
let user_id = user.id;
|
||||||
|
@ -154,7 +154,7 @@ pub(crate) async fn receive_dislike_comment(
|
||||||
let like_form = CommentLikeForm {
|
let like_form = CommentLikeForm {
|
||||||
comment_id,
|
comment_id,
|
||||||
post_id: comment.post_id,
|
post_id: comment.post_id,
|
||||||
user_id: user.id,
|
person_id: user.id,
|
||||||
score: -1,
|
score: -1,
|
||||||
};
|
};
|
||||||
let user_id = user.id;
|
let user_id = user.id;
|
||||||
|
|
|
@ -80,7 +80,7 @@ pub(crate) async fn receive_like_post(
|
||||||
let post_id = post.id;
|
let post_id = post.id;
|
||||||
let like_form = PostLikeForm {
|
let like_form = PostLikeForm {
|
||||||
post_id,
|
post_id,
|
||||||
user_id: user.id,
|
person_id: user.id,
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
let user_id = user.id;
|
let user_id = user.id;
|
||||||
|
@ -118,7 +118,7 @@ pub(crate) async fn receive_dislike_post(
|
||||||
let post_id = post.id;
|
let post_id = post.id;
|
||||||
let like_form = PostLikeForm {
|
let like_form = PostLikeForm {
|
||||||
post_id,
|
post_id,
|
||||||
user_id: user.id,
|
person_id: user.id,
|
||||||
score: -1,
|
score: -1,
|
||||||
};
|
};
|
||||||
let user_id = user.id;
|
let user_id = user.id;
|
||||||
|
|
|
@ -62,7 +62,7 @@ impl ActorType for User_ {
|
||||||
|
|
||||||
let community_follower_form = CommunityFollowerForm {
|
let community_follower_form = CommunityFollowerForm {
|
||||||
community_id: community.id,
|
community_id: community.id,
|
||||||
user_id: self.id,
|
person_id: self.id,
|
||||||
pending: true,
|
pending: true,
|
||||||
};
|
};
|
||||||
blocking(&context.pool(), move |conn| {
|
blocking(&context.pool(), move |conn| {
|
||||||
|
|
|
@ -104,7 +104,7 @@ async fn fetch_remote_community(
|
||||||
for mod_ in creator_and_moderators {
|
for mod_ in creator_and_moderators {
|
||||||
let community_moderator_form = CommunityModeratorForm {
|
let community_moderator_form = CommunityModeratorForm {
|
||||||
community_id,
|
community_id,
|
||||||
user_id: mod_.id,
|
person_id: mod_.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
CommunityModerator::join(conn, &community_moderator_form)?;
|
CommunityModerator::join(conn, &community_moderator_form)?;
|
||||||
|
|
|
@ -191,7 +191,7 @@ async fn handle_follow(
|
||||||
|
|
||||||
let community_follower_form = CommunityFollowerForm {
|
let community_follower_form = CommunityFollowerForm {
|
||||||
community_id: community.id,
|
community_id: community.id,
|
||||||
user_id: user.id,
|
person_id: user.id,
|
||||||
pending: false,
|
pending: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ async fn handle_undo_follow(
|
||||||
.await??;
|
.await??;
|
||||||
let community_follower_form = CommunityFollowerForm {
|
let community_follower_form = CommunityFollowerForm {
|
||||||
community_id: community.id,
|
community_id: community.id,
|
||||||
user_id: user.id,
|
person_id: user.id,
|
||||||
pending: false,
|
pending: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -35,35 +35,25 @@ mod tests {
|
||||||
comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
|
comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
|
||||||
community::{Community, CommunityForm},
|
community::{Community, CommunityForm},
|
||||||
post::{Post, PostForm},
|
post::{Post, PostForm},
|
||||||
user::{UserForm, User_},
|
person::{PersonForm, Person},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_crud() {
|
fn test_crud() {
|
||||||
let conn = establish_unpooled_connection();
|
let conn = establish_unpooled_connection();
|
||||||
|
|
||||||
let new_user = UserForm {
|
let new_person = PersonForm {
|
||||||
name: "thommy_comment_agg".into(),
|
name: "thommy_comment_agg".into(),
|
||||||
preferred_username: None,
|
preferred_username: None,
|
||||||
password_encrypted: "nope".into(),
|
|
||||||
email: None,
|
|
||||||
matrix_user_id: None,
|
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
banned: None,
|
||||||
banned: Some(false),
|
deleted: None,
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
|
||||||
theme: "browser".into(),
|
|
||||||
default_sort_type: SortType::Hot as i16,
|
|
||||||
default_listing_type: ListingType::Subscribed as i16,
|
|
||||||
lang: "browser".into(),
|
|
||||||
show_avatars: true,
|
|
||||||
send_notifications_to_email: false,
|
|
||||||
actor_id: None,
|
actor_id: None,
|
||||||
bio: None,
|
bio: None,
|
||||||
local: true,
|
local: None,
|
||||||
private_key: None,
|
private_key: None,
|
||||||
public_key: None,
|
public_key: None,
|
||||||
last_refreshed_at: None,
|
last_refreshed_at: None,
|
||||||
|
@ -71,30 +61,20 @@ mod tests {
|
||||||
shared_inbox_url: None,
|
shared_inbox_url: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_user = User_::create(&conn, &new_user).unwrap();
|
let inserted_person = Person::create(&conn, &new_person).unwrap();
|
||||||
|
|
||||||
let another_user = UserForm {
|
let another_person = PersonForm {
|
||||||
name: "jerry_comment_agg".into(),
|
name: "jerry_comment_agg".into(),
|
||||||
preferred_username: None,
|
preferred_username: None,
|
||||||
password_encrypted: "nope".into(),
|
|
||||||
email: None,
|
|
||||||
matrix_user_id: None,
|
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
banned: None,
|
||||||
banned: Some(false),
|
deleted: None,
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
|
||||||
theme: "browser".into(),
|
|
||||||
default_sort_type: SortType::Hot as i16,
|
|
||||||
default_listing_type: ListingType::Subscribed as i16,
|
|
||||||
lang: "browser".into(),
|
|
||||||
show_avatars: true,
|
|
||||||
send_notifications_to_email: false,
|
|
||||||
actor_id: None,
|
actor_id: None,
|
||||||
bio: None,
|
bio: None,
|
||||||
local: true,
|
local: None,
|
||||||
private_key: None,
|
private_key: None,
|
||||||
public_key: None,
|
public_key: None,
|
||||||
last_refreshed_at: None,
|
last_refreshed_at: None,
|
||||||
|
@ -102,11 +82,11 @@ mod tests {
|
||||||
shared_inbox_url: None,
|
shared_inbox_url: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let another_inserted_user = User_::create(&conn, &another_user).unwrap();
|
let another_inserted_person = Person::create(&conn, &another_person).unwrap();
|
||||||
|
|
||||||
let new_community = CommunityForm {
|
let new_community = CommunityForm {
|
||||||
name: "TIL_comment_agg".into(),
|
name: "TIL_comment_agg".into(),
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
description: None,
|
description: None,
|
||||||
nsfw: false,
|
nsfw: false,
|
||||||
|
@ -132,7 +112,7 @@ mod tests {
|
||||||
name: "A test post".into(),
|
name: "A test post".into(),
|
||||||
url: None,
|
url: None,
|
||||||
body: None,
|
body: None,
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
|
@ -153,7 +133,7 @@ mod tests {
|
||||||
|
|
||||||
let comment_form = CommentForm {
|
let comment_form = CommentForm {
|
||||||
content: "A test comment".into(),
|
content: "A test comment".into(),
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
|
@ -169,7 +149,7 @@ mod tests {
|
||||||
|
|
||||||
let child_comment_form = CommentForm {
|
let child_comment_form = CommentForm {
|
||||||
content: "A test comment".into(),
|
content: "A test comment".into(),
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
|
@ -186,7 +166,7 @@ mod tests {
|
||||||
let comment_like = CommentLikeForm {
|
let comment_like = CommentLikeForm {
|
||||||
comment_id: inserted_comment.id,
|
comment_id: inserted_comment.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
user_id: inserted_user.id,
|
person_id: inserted_person.id,
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -198,11 +178,11 @@ mod tests {
|
||||||
assert_eq!(1, comment_aggs_before_delete.upvotes);
|
assert_eq!(1, comment_aggs_before_delete.upvotes);
|
||||||
assert_eq!(0, comment_aggs_before_delete.downvotes);
|
assert_eq!(0, comment_aggs_before_delete.downvotes);
|
||||||
|
|
||||||
// Add a post dislike from the other user
|
// Add a post dislike from the other person
|
||||||
let comment_dislike = CommentLikeForm {
|
let comment_dislike = CommentLikeForm {
|
||||||
comment_id: inserted_comment.id,
|
comment_id: inserted_comment.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
user_id: another_inserted_user.id,
|
person_id: another_inserted_person.id,
|
||||||
score: -1,
|
score: -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -215,7 +195,7 @@ mod tests {
|
||||||
assert_eq!(1, comment_aggs_after_dislike.downvotes);
|
assert_eq!(1, comment_aggs_after_dislike.downvotes);
|
||||||
|
|
||||||
// Remove the first comment like
|
// Remove the first comment like
|
||||||
CommentLike::remove(&conn, inserted_user.id, 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();
|
let after_like_remove = CommentAggregates::read(&conn, inserted_comment.id).unwrap();
|
||||||
assert_eq!(-1, after_like_remove.score);
|
assert_eq!(-1, after_like_remove.score);
|
||||||
assert_eq!(0, after_like_remove.upvotes);
|
assert_eq!(0, after_like_remove.upvotes);
|
||||||
|
@ -229,8 +209,8 @@ mod tests {
|
||||||
assert!(after_delete.is_err());
|
assert!(after_delete.is_err());
|
||||||
|
|
||||||
// This should delete all the associated rows, and fire triggers
|
// This should delete all the associated rows, and fire triggers
|
||||||
User_::delete(&conn, another_inserted_user.id).unwrap();
|
Person::delete(&conn, another_inserted_person.id).unwrap();
|
||||||
let user_num_deleted = User_::delete(&conn, inserted_user.id).unwrap();
|
let person_num_deleted = Person::delete(&conn, inserted_person.id).unwrap();
|
||||||
assert_eq!(1, user_num_deleted);
|
assert_eq!(1, person_num_deleted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,32 +39,22 @@ mod tests {
|
||||||
comment::{Comment, CommentForm},
|
comment::{Comment, CommentForm},
|
||||||
community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm},
|
community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm},
|
||||||
post::{Post, PostForm},
|
post::{Post, PostForm},
|
||||||
user::{UserForm, User_},
|
person::{PersonForm, Person},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_crud() {
|
fn test_crud() {
|
||||||
let conn = establish_unpooled_connection();
|
let conn = establish_unpooled_connection();
|
||||||
|
|
||||||
let new_user = UserForm {
|
let new_person = PersonForm {
|
||||||
name: "thommy_community_agg".into(),
|
name: "thommy_community_agg".into(),
|
||||||
preferred_username: None,
|
preferred_username: None,
|
||||||
password_encrypted: "nope".into(),
|
|
||||||
email: None,
|
|
||||||
matrix_user_id: None,
|
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
|
||||||
banned: Some(false),
|
banned: Some(false),
|
||||||
|
deleted: false,
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
|
||||||
theme: "browser".into(),
|
|
||||||
default_sort_type: SortType::Hot as i16,
|
|
||||||
default_listing_type: ListingType::Subscribed as i16,
|
|
||||||
lang: "browser".into(),
|
|
||||||
show_avatars: true,
|
|
||||||
send_notifications_to_email: false,
|
|
||||||
actor_id: None,
|
actor_id: None,
|
||||||
bio: None,
|
bio: None,
|
||||||
local: true,
|
local: true,
|
||||||
|
@ -75,27 +65,17 @@ mod tests {
|
||||||
shared_inbox_url: None,
|
shared_inbox_url: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_user = User_::create(&conn, &new_user).unwrap();
|
let inserted_person = Person::create(&conn, &new_person).unwrap();
|
||||||
|
|
||||||
let another_user = UserForm {
|
let another_person = PersonForm {
|
||||||
name: "jerry_community_agg".into(),
|
name: "jerry_community_agg".into(),
|
||||||
preferred_username: None,
|
preferred_username: None,
|
||||||
password_encrypted: "nope".into(),
|
|
||||||
email: None,
|
|
||||||
matrix_user_id: None,
|
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
|
||||||
banned: Some(false),
|
banned: Some(false),
|
||||||
|
deleted: false,
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
|
||||||
theme: "browser".into(),
|
|
||||||
default_sort_type: SortType::Hot as i16,
|
|
||||||
default_listing_type: ListingType::Subscribed as i16,
|
|
||||||
lang: "browser".into(),
|
|
||||||
show_avatars: true,
|
|
||||||
send_notifications_to_email: false,
|
|
||||||
actor_id: None,
|
actor_id: None,
|
||||||
bio: None,
|
bio: None,
|
||||||
local: true,
|
local: true,
|
||||||
|
@ -106,11 +86,11 @@ mod tests {
|
||||||
shared_inbox_url: None,
|
shared_inbox_url: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let another_inserted_user = User_::create(&conn, &another_user).unwrap();
|
let another_inserted_person = Person::create(&conn, &another_person).unwrap();
|
||||||
|
|
||||||
let new_community = CommunityForm {
|
let new_community = CommunityForm {
|
||||||
name: "TIL_community_agg".into(),
|
name: "TIL_community_agg".into(),
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
description: None,
|
description: None,
|
||||||
nsfw: false,
|
nsfw: false,
|
||||||
|
@ -134,7 +114,7 @@ mod tests {
|
||||||
|
|
||||||
let another_community = CommunityForm {
|
let another_community = CommunityForm {
|
||||||
name: "TIL_community_agg_2".into(),
|
name: "TIL_community_agg_2".into(),
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
description: None,
|
description: None,
|
||||||
nsfw: false,
|
nsfw: false,
|
||||||
|
@ -156,25 +136,25 @@ mod tests {
|
||||||
|
|
||||||
let another_inserted_community = Community::create(&conn, &another_community).unwrap();
|
let another_inserted_community = Community::create(&conn, &another_community).unwrap();
|
||||||
|
|
||||||
let first_user_follow = CommunityFollowerForm {
|
let first_person_follow = CommunityFollowerForm {
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
user_id: inserted_user.id,
|
person_id: inserted_person.id,
|
||||||
pending: false,
|
pending: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
CommunityFollower::follow(&conn, &first_user_follow).unwrap();
|
CommunityFollower::follow(&conn, &first_person_follow).unwrap();
|
||||||
|
|
||||||
let second_user_follow = CommunityFollowerForm {
|
let second_person_follow = CommunityFollowerForm {
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
user_id: another_inserted_user.id,
|
person_id: another_inserted_person.id,
|
||||||
pending: false,
|
pending: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
CommunityFollower::follow(&conn, &second_user_follow).unwrap();
|
CommunityFollower::follow(&conn, &second_person_follow).unwrap();
|
||||||
|
|
||||||
let another_community_follow = CommunityFollowerForm {
|
let another_community_follow = CommunityFollowerForm {
|
||||||
community_id: another_inserted_community.id,
|
community_id: another_inserted_community.id,
|
||||||
user_id: inserted_user.id,
|
person_id: inserted_person.id,
|
||||||
pending: false,
|
pending: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -184,7 +164,7 @@ mod tests {
|
||||||
name: "A test post".into(),
|
name: "A test post".into(),
|
||||||
url: None,
|
url: None,
|
||||||
body: None,
|
body: None,
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
|
@ -205,7 +185,7 @@ mod tests {
|
||||||
|
|
||||||
let comment_form = CommentForm {
|
let comment_form = CommentForm {
|
||||||
content: "A test comment".into(),
|
content: "A test comment".into(),
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
|
@ -221,7 +201,7 @@ mod tests {
|
||||||
|
|
||||||
let child_comment_form = CommentForm {
|
let child_comment_form = CommentForm {
|
||||||
content: "A test comment".into(),
|
content: "A test comment".into(),
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
|
@ -250,12 +230,12 @@ mod tests {
|
||||||
assert_eq!(0, another_community_aggs.comments);
|
assert_eq!(0, another_community_aggs.comments);
|
||||||
|
|
||||||
// Unfollow test
|
// Unfollow test
|
||||||
CommunityFollower::unfollow(&conn, &second_user_follow).unwrap();
|
CommunityFollower::unfollow(&conn, &second_person_follow).unwrap();
|
||||||
let after_unfollow = CommunityAggregates::read(&conn, inserted_community.id).unwrap();
|
let after_unfollow = CommunityAggregates::read(&conn, inserted_community.id).unwrap();
|
||||||
assert_eq!(1, after_unfollow.subscribers);
|
assert_eq!(1, after_unfollow.subscribers);
|
||||||
|
|
||||||
// Follow again just for the later tests
|
// Follow again just for the later tests
|
||||||
CommunityFollower::follow(&conn, &second_user_follow).unwrap();
|
CommunityFollower::follow(&conn, &second_person_follow).unwrap();
|
||||||
let after_follow_again = CommunityAggregates::read(&conn, inserted_community.id).unwrap();
|
let after_follow_again = CommunityAggregates::read(&conn, inserted_community.id).unwrap();
|
||||||
assert_eq!(2, after_follow_again.subscribers);
|
assert_eq!(2, after_follow_again.subscribers);
|
||||||
|
|
||||||
|
@ -265,14 +245,14 @@ mod tests {
|
||||||
assert_eq!(0, after_parent_post_delete.comments);
|
assert_eq!(0, after_parent_post_delete.comments);
|
||||||
assert_eq!(0, after_parent_post_delete.posts);
|
assert_eq!(0, after_parent_post_delete.posts);
|
||||||
|
|
||||||
// Remove the 2nd user
|
// Remove the 2nd person
|
||||||
User_::delete(&conn, another_inserted_user.id).unwrap();
|
Person::delete(&conn, another_inserted_person.id).unwrap();
|
||||||
let after_user_delete = CommunityAggregates::read(&conn, inserted_community.id).unwrap();
|
let after_person_delete = CommunityAggregates::read(&conn, inserted_community.id).unwrap();
|
||||||
assert_eq!(1, after_user_delete.subscribers);
|
assert_eq!(1, after_person_delete.subscribers);
|
||||||
|
|
||||||
// This should delete all the associated rows, and fire triggers
|
// This should delete all the associated rows, and fire triggers
|
||||||
let user_num_deleted = User_::delete(&conn, inserted_user.id).unwrap();
|
let person_num_deleted = Person::delete(&conn, inserted_person.id).unwrap();
|
||||||
assert_eq!(1, user_num_deleted);
|
assert_eq!(1, person_num_deleted);
|
||||||
|
|
||||||
// Should be none found, since the creator was deleted
|
// Should be none found, since the creator was deleted
|
||||||
let after_delete = CommunityAggregates::read(&conn, inserted_community.id);
|
let after_delete = CommunityAggregates::read(&conn, inserted_community.id);
|
||||||
|
|
|
@ -2,4 +2,4 @@ pub mod comment_aggregates;
|
||||||
pub mod community_aggregates;
|
pub mod community_aggregates;
|
||||||
pub mod post_aggregates;
|
pub mod post_aggregates;
|
||||||
pub mod site_aggregates;
|
pub mod site_aggregates;
|
||||||
pub mod user_aggregates;
|
pub mod person_aggregates;
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::schema::user_aggregates;
|
use lemmy_db_schema::schema::person_aggregates;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
#[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Clone)]
|
#[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Clone)]
|
||||||
#[table_name = "user_aggregates"]
|
#[table_name = "person_aggregates"]
|
||||||
pub struct UserAggregates {
|
pub struct PersonAggregates {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub user_id: i32,
|
pub person_id: i32,
|
||||||
pub post_count: i64,
|
pub post_count: i64,
|
||||||
pub post_score: i64,
|
pub post_score: i64,
|
||||||
pub comment_count: i64,
|
pub comment_count: i64,
|
||||||
pub comment_score: i64,
|
pub comment_score: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UserAggregates {
|
impl PersonAggregates {
|
||||||
pub fn read(conn: &PgConnection, user_id: i32) -> Result<Self, Error> {
|
pub fn read(conn: &PgConnection, person_id: i32) -> Result<Self, Error> {
|
||||||
user_aggregates::table
|
person_aggregates::table
|
||||||
.filter(user_aggregates::user_id.eq(user_id))
|
.filter(person_aggregates::person_id.eq(person_id))
|
||||||
.first::<Self>(conn)
|
.first::<Self>(conn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ impl UserAggregates {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
aggregates::user_aggregates::UserAggregates,
|
aggregates::person_aggregates::PersonAggregates,
|
||||||
establish_unpooled_connection,
|
establish_unpooled_connection,
|
||||||
Crud,
|
Crud,
|
||||||
Likeable,
|
Likeable,
|
||||||
|
@ -35,32 +35,22 @@ mod tests {
|
||||||
comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
|
comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
|
||||||
community::{Community, CommunityForm},
|
community::{Community, CommunityForm},
|
||||||
post::{Post, PostForm, PostLike, PostLikeForm},
|
post::{Post, PostForm, PostLike, PostLikeForm},
|
||||||
user::{UserForm, User_},
|
person::{PersonForm, Person},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_crud() {
|
fn test_crud() {
|
||||||
let conn = establish_unpooled_connection();
|
let conn = establish_unpooled_connection();
|
||||||
|
|
||||||
let new_user = UserForm {
|
let new_person = PersonForm {
|
||||||
name: "thommy_user_agg".into(),
|
name: "thommy_user_agg".into(),
|
||||||
preferred_username: None,
|
preferred_username: None,
|
||||||
password_encrypted: "nope".into(),
|
|
||||||
email: None,
|
|
||||||
matrix_user_id: None,
|
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
|
||||||
banned: Some(false),
|
banned: Some(false),
|
||||||
|
deleted: false,
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
|
||||||
theme: "browser".into(),
|
|
||||||
default_sort_type: SortType::Hot as i16,
|
|
||||||
default_listing_type: ListingType::Subscribed as i16,
|
|
||||||
lang: "browser".into(),
|
|
||||||
show_avatars: true,
|
|
||||||
send_notifications_to_email: false,
|
|
||||||
actor_id: None,
|
actor_id: None,
|
||||||
bio: None,
|
bio: None,
|
||||||
local: true,
|
local: true,
|
||||||
|
@ -71,27 +61,17 @@ mod tests {
|
||||||
shared_inbox_url: None,
|
shared_inbox_url: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_user = User_::create(&conn, &new_user).unwrap();
|
let inserted_person = Person::create(&conn, &new_person).unwrap();
|
||||||
|
|
||||||
let another_user = UserForm {
|
let another_person = PersonForm {
|
||||||
name: "jerry_user_agg".into(),
|
name: "jerry_user_agg".into(),
|
||||||
preferred_username: None,
|
preferred_username: None,
|
||||||
password_encrypted: "nope".into(),
|
|
||||||
email: None,
|
|
||||||
matrix_user_id: None,
|
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
|
||||||
banned: Some(false),
|
banned: Some(false),
|
||||||
|
deleted: false,
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
|
||||||
theme: "browser".into(),
|
|
||||||
default_sort_type: SortType::Hot as i16,
|
|
||||||
default_listing_type: ListingType::Subscribed as i16,
|
|
||||||
lang: "browser".into(),
|
|
||||||
show_avatars: true,
|
|
||||||
send_notifications_to_email: false,
|
|
||||||
actor_id: None,
|
actor_id: None,
|
||||||
bio: None,
|
bio: None,
|
||||||
local: true,
|
local: true,
|
||||||
|
@ -102,11 +82,11 @@ mod tests {
|
||||||
shared_inbox_url: None,
|
shared_inbox_url: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let another_inserted_user = User_::create(&conn, &another_user).unwrap();
|
let another_inserted_person = Person::create(&conn, &another_person).unwrap();
|
||||||
|
|
||||||
let new_community = CommunityForm {
|
let new_community = CommunityForm {
|
||||||
name: "TIL_site_agg".into(),
|
name: "TIL_site_agg".into(),
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
description: None,
|
description: None,
|
||||||
nsfw: false,
|
nsfw: false,
|
||||||
|
@ -132,7 +112,7 @@ mod tests {
|
||||||
name: "A test post".into(),
|
name: "A test post".into(),
|
||||||
url: None,
|
url: None,
|
||||||
body: None,
|
body: None,
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
|
@ -153,7 +133,7 @@ mod tests {
|
||||||
|
|
||||||
let post_like = PostLikeForm {
|
let post_like = PostLikeForm {
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
user_id: inserted_user.id,
|
person_id: inserted_person.id,
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -161,7 +141,7 @@ mod tests {
|
||||||
|
|
||||||
let comment_form = CommentForm {
|
let comment_form = CommentForm {
|
||||||
content: "A test comment".into(),
|
content: "A test comment".into(),
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
|
@ -177,7 +157,7 @@ mod tests {
|
||||||
|
|
||||||
let mut comment_like = CommentLikeForm {
|
let mut comment_like = CommentLikeForm {
|
||||||
comment_id: inserted_comment.id,
|
comment_id: inserted_comment.id,
|
||||||
user_id: inserted_user.id,
|
person_id: inserted_person.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
@ -186,7 +166,7 @@ mod tests {
|
||||||
|
|
||||||
let mut child_comment_form = CommentForm {
|
let mut child_comment_form = CommentForm {
|
||||||
content: "A test comment".into(),
|
content: "A test comment".into(),
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
|
@ -202,28 +182,28 @@ mod tests {
|
||||||
|
|
||||||
let child_comment_like = CommentLikeForm {
|
let child_comment_like = CommentLikeForm {
|
||||||
comment_id: inserted_child_comment.id,
|
comment_id: inserted_child_comment.id,
|
||||||
user_id: another_inserted_user.id,
|
person_id: another_inserted_person.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
score: 1,
|
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 user_aggregates_before_delete = UserAggregates::read(&conn, inserted_user.id).unwrap();
|
let person_aggregates_before_delete = PersonAggregates::read(&conn, inserted_person.id).unwrap();
|
||||||
|
|
||||||
assert_eq!(1, user_aggregates_before_delete.post_count);
|
assert_eq!(1, person_aggregates_before_delete.post_count);
|
||||||
assert_eq!(1, user_aggregates_before_delete.post_score);
|
assert_eq!(1, person_aggregates_before_delete.post_score);
|
||||||
assert_eq!(2, user_aggregates_before_delete.comment_count);
|
assert_eq!(2, person_aggregates_before_delete.comment_count);
|
||||||
assert_eq!(2, user_aggregates_before_delete.comment_score);
|
assert_eq!(2, person_aggregates_before_delete.comment_score);
|
||||||
|
|
||||||
// Remove a post like
|
// Remove a post like
|
||||||
PostLike::remove(&conn, inserted_user.id, inserted_post.id).unwrap();
|
PostLike::remove(&conn, inserted_person.id, inserted_post.id).unwrap();
|
||||||
let after_post_like_remove = UserAggregates::read(&conn, inserted_user.id).unwrap();
|
let after_post_like_remove = PersonAggregates::read(&conn, inserted_person.id).unwrap();
|
||||||
assert_eq!(0, after_post_like_remove.post_score);
|
assert_eq!(0, after_post_like_remove.post_score);
|
||||||
|
|
||||||
// Remove a parent comment (the scores should also be removed)
|
// Remove a parent comment (the scores should also be removed)
|
||||||
Comment::delete(&conn, inserted_comment.id).unwrap();
|
Comment::delete(&conn, inserted_comment.id).unwrap();
|
||||||
let after_parent_comment_delete = UserAggregates::read(&conn, inserted_user.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_count);
|
||||||
assert_eq!(0, after_parent_comment_delete.comment_score);
|
assert_eq!(0, after_parent_comment_delete.comment_score);
|
||||||
|
|
||||||
|
@ -233,24 +213,24 @@ mod tests {
|
||||||
Comment::create(&conn, &child_comment_form).unwrap();
|
Comment::create(&conn, &child_comment_form).unwrap();
|
||||||
comment_like.comment_id = new_parent_comment.id;
|
comment_like.comment_id = new_parent_comment.id;
|
||||||
CommentLike::like(&conn, &comment_like).unwrap();
|
CommentLike::like(&conn, &comment_like).unwrap();
|
||||||
let after_comment_add = UserAggregates::read(&conn, inserted_user.id).unwrap();
|
let after_comment_add = PersonAggregates::read(&conn, inserted_person.id).unwrap();
|
||||||
assert_eq!(2, after_comment_add.comment_count);
|
assert_eq!(2, after_comment_add.comment_count);
|
||||||
assert_eq!(1, after_comment_add.comment_score);
|
assert_eq!(1, after_comment_add.comment_score);
|
||||||
|
|
||||||
Post::delete(&conn, inserted_post.id).unwrap();
|
Post::delete(&conn, inserted_post.id).unwrap();
|
||||||
let after_post_delete = UserAggregates::read(&conn, inserted_user.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_score);
|
||||||
assert_eq!(0, after_post_delete.comment_count);
|
assert_eq!(0, after_post_delete.comment_count);
|
||||||
assert_eq!(0, after_post_delete.post_score);
|
assert_eq!(0, after_post_delete.post_score);
|
||||||
assert_eq!(0, after_post_delete.post_count);
|
assert_eq!(0, after_post_delete.post_count);
|
||||||
|
|
||||||
// This should delete all the associated rows, and fire triggers
|
// This should delete all the associated rows, and fire triggers
|
||||||
let user_num_deleted = User_::delete(&conn, inserted_user.id).unwrap();
|
let person_num_deleted = Person::delete(&conn, inserted_person.id).unwrap();
|
||||||
assert_eq!(1, user_num_deleted);
|
assert_eq!(1, person_num_deleted);
|
||||||
User_::delete(&conn, another_inserted_user.id).unwrap();
|
Person::delete(&conn, another_inserted_person.id).unwrap();
|
||||||
|
|
||||||
// Should be none found
|
// Should be none found
|
||||||
let after_delete = UserAggregates::read(&conn, inserted_user.id);
|
let after_delete = PersonAggregates::read(&conn, inserted_person.id);
|
||||||
assert!(after_delete.is_err());
|
assert!(after_delete.is_err());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -31,40 +31,27 @@ mod tests {
|
||||||
aggregates::post_aggregates::PostAggregates,
|
aggregates::post_aggregates::PostAggregates,
|
||||||
establish_unpooled_connection,
|
establish_unpooled_connection,
|
||||||
Crud,
|
Crud,
|
||||||
Likeable,
|
|
||||||
ListingType,
|
|
||||||
SortType,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::source::{
|
use lemmy_db_schema::source::{
|
||||||
comment::{Comment, CommentForm},
|
comment::{Comment, CommentForm},
|
||||||
community::{Community, CommunityForm},
|
community::{Community, CommunityForm},
|
||||||
post::{Post, PostForm, PostLike, PostLikeForm},
|
post::{Post, PostForm, PostLike, PostLikeForm},
|
||||||
user::{UserForm, User_},
|
person::{PersonForm, Person},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_crud() {
|
fn test_crud() {
|
||||||
let conn = establish_unpooled_connection();
|
let conn = establish_unpooled_connection();
|
||||||
|
|
||||||
let new_user = UserForm {
|
let new_person = PersonForm {
|
||||||
name: "thommy_community_agg".into(),
|
name: "thommy_community_agg".into(),
|
||||||
preferred_username: None,
|
preferred_username: None,
|
||||||
password_encrypted: "nope".into(),
|
|
||||||
email: None,
|
|
||||||
matrix_user_id: None,
|
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
|
||||||
banned: Some(false),
|
banned: Some(false),
|
||||||
|
deleted: false,
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
|
||||||
theme: "browser".into(),
|
|
||||||
default_sort_type: SortType::Hot as i16,
|
|
||||||
default_listing_type: ListingType::Subscribed as i16,
|
|
||||||
lang: "browser".into(),
|
|
||||||
show_avatars: true,
|
|
||||||
send_notifications_to_email: false,
|
|
||||||
actor_id: None,
|
actor_id: None,
|
||||||
bio: None,
|
bio: None,
|
||||||
local: true,
|
local: true,
|
||||||
|
@ -75,27 +62,17 @@ mod tests {
|
||||||
shared_inbox_url: None,
|
shared_inbox_url: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_user = User_::create(&conn, &new_user).unwrap();
|
let inserted_person = Person::create(&conn, &new_person).unwrap();
|
||||||
|
|
||||||
let another_user = UserForm {
|
let another_person = PersonForm {
|
||||||
name: "jerry_community_agg".into(),
|
name: "jerry_community_agg".into(),
|
||||||
preferred_username: None,
|
preferred_username: None,
|
||||||
password_encrypted: "nope".into(),
|
|
||||||
email: None,
|
|
||||||
matrix_user_id: None,
|
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
|
||||||
banned: Some(false),
|
banned: Some(false),
|
||||||
|
deleted: false,
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
|
||||||
theme: "browser".into(),
|
|
||||||
default_sort_type: SortType::Hot as i16,
|
|
||||||
default_listing_type: ListingType::Subscribed as i16,
|
|
||||||
lang: "browser".into(),
|
|
||||||
show_avatars: true,
|
|
||||||
send_notifications_to_email: false,
|
|
||||||
actor_id: None,
|
actor_id: None,
|
||||||
bio: None,
|
bio: None,
|
||||||
local: true,
|
local: true,
|
||||||
|
@ -106,11 +83,11 @@ mod tests {
|
||||||
shared_inbox_url: None,
|
shared_inbox_url: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let another_inserted_user = User_::create(&conn, &another_user).unwrap();
|
let another_inserted_person = Person::create(&conn, &another_person).unwrap();
|
||||||
|
|
||||||
let new_community = CommunityForm {
|
let new_community = CommunityForm {
|
||||||
name: "TIL_community_agg".into(),
|
name: "TIL_community_agg".into(),
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
description: None,
|
description: None,
|
||||||
nsfw: false,
|
nsfw: false,
|
||||||
|
@ -136,7 +113,7 @@ mod tests {
|
||||||
name: "A test post".into(),
|
name: "A test post".into(),
|
||||||
url: None,
|
url: None,
|
||||||
body: None,
|
body: None,
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
|
@ -157,7 +134,7 @@ mod tests {
|
||||||
|
|
||||||
let comment_form = CommentForm {
|
let comment_form = CommentForm {
|
||||||
content: "A test comment".into(),
|
content: "A test comment".into(),
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
|
@ -173,7 +150,7 @@ mod tests {
|
||||||
|
|
||||||
let child_comment_form = CommentForm {
|
let child_comment_form = CommentForm {
|
||||||
content: "A test comment".into(),
|
content: "A test comment".into(),
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
|
@ -189,7 +166,7 @@ mod tests {
|
||||||
|
|
||||||
let post_like = PostLikeForm {
|
let post_like = PostLikeForm {
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
user_id: inserted_user.id,
|
person_id: inserted_person.id,
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -202,10 +179,10 @@ mod tests {
|
||||||
assert_eq!(1, post_aggs_before_delete.upvotes);
|
assert_eq!(1, post_aggs_before_delete.upvotes);
|
||||||
assert_eq!(0, post_aggs_before_delete.downvotes);
|
assert_eq!(0, post_aggs_before_delete.downvotes);
|
||||||
|
|
||||||
// Add a post dislike from the other user
|
// Add a post dislike from the other person
|
||||||
let post_dislike = PostLikeForm {
|
let post_dislike = PostLikeForm {
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
user_id: another_inserted_user.id,
|
person_id: another_inserted_person.id,
|
||||||
score: -1,
|
score: -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -227,7 +204,7 @@ mod tests {
|
||||||
assert_eq!(1, after_comment_delete.downvotes);
|
assert_eq!(1, after_comment_delete.downvotes);
|
||||||
|
|
||||||
// Remove the first post like
|
// Remove the first post like
|
||||||
PostLike::remove(&conn, inserted_user.id, 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();
|
let after_like_remove = PostAggregates::read(&conn, inserted_post.id).unwrap();
|
||||||
assert_eq!(0, after_like_remove.comments);
|
assert_eq!(0, after_like_remove.comments);
|
||||||
assert_eq!(-1, after_like_remove.score);
|
assert_eq!(-1, after_like_remove.score);
|
||||||
|
@ -235,9 +212,9 @@ mod tests {
|
||||||
assert_eq!(1, after_like_remove.downvotes);
|
assert_eq!(1, after_like_remove.downvotes);
|
||||||
|
|
||||||
// This should delete all the associated rows, and fire triggers
|
// This should delete all the associated rows, and fire triggers
|
||||||
User_::delete(&conn, another_inserted_user.id).unwrap();
|
Person::delete(&conn, another_inserted_person.id).unwrap();
|
||||||
let user_num_deleted = User_::delete(&conn, inserted_user.id).unwrap();
|
let person_num_deleted = Person::delete(&conn, inserted_person.id).unwrap();
|
||||||
assert_eq!(1, user_num_deleted);
|
assert_eq!(1, person_num_deleted);
|
||||||
|
|
||||||
// Should be none found, since the creator was deleted
|
// Should be none found, since the creator was deleted
|
||||||
let after_delete = PostAggregates::read(&conn, inserted_post.id);
|
let after_delete = PostAggregates::read(&conn, inserted_post.id);
|
||||||
|
|
|
@ -28,41 +28,28 @@ mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
aggregates::site_aggregates::SiteAggregates,
|
aggregates::site_aggregates::SiteAggregates,
|
||||||
establish_unpooled_connection,
|
establish_unpooled_connection,
|
||||||
Crud,
|
|
||||||
ListingType,
|
|
||||||
SortType,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::source::{
|
use lemmy_db_schema::source::{
|
||||||
comment::{Comment, CommentForm},
|
comment::{Comment, CommentForm},
|
||||||
community::{Community, CommunityForm},
|
community::{Community, CommunityForm},
|
||||||
post::{Post, PostForm},
|
post::{Post, PostForm},
|
||||||
site::{Site, SiteForm},
|
site::{Site, SiteForm},
|
||||||
user::{UserForm, User_},
|
person::{PersonForm, Person},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_crud() {
|
fn test_crud() {
|
||||||
let conn = establish_unpooled_connection();
|
let conn = establish_unpooled_connection();
|
||||||
|
|
||||||
let new_user = UserForm {
|
let new_person = PersonForm {
|
||||||
name: "thommy_site_agg".into(),
|
name: "thommy_site_agg".into(),
|
||||||
preferred_username: None,
|
preferred_username: None,
|
||||||
password_encrypted: "nope".into(),
|
|
||||||
email: None,
|
|
||||||
matrix_user_id: None,
|
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
|
||||||
banned: Some(false),
|
banned: Some(false),
|
||||||
|
deleted: false,
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
|
||||||
theme: "browser".into(),
|
|
||||||
default_sort_type: SortType::Hot as i16,
|
|
||||||
default_listing_type: ListingType::Subscribed as i16,
|
|
||||||
lang: "browser".into(),
|
|
||||||
show_avatars: true,
|
|
||||||
send_notifications_to_email: false,
|
|
||||||
actor_id: None,
|
actor_id: None,
|
||||||
bio: None,
|
bio: None,
|
||||||
local: true,
|
local: true,
|
||||||
|
@ -73,14 +60,14 @@ mod tests {
|
||||||
shared_inbox_url: None,
|
shared_inbox_url: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_user = User_::create(&conn, &new_user).unwrap();
|
let inserted_person = Person::create(&conn, &new_person).unwrap();
|
||||||
|
|
||||||
let site_form = SiteForm {
|
let site_form = SiteForm {
|
||||||
name: "test_site".into(),
|
name: "test_site".into(),
|
||||||
description: None,
|
description: None,
|
||||||
icon: None,
|
icon: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
enable_downvotes: true,
|
enable_downvotes: true,
|
||||||
open_registration: true,
|
open_registration: true,
|
||||||
enable_nsfw: true,
|
enable_nsfw: true,
|
||||||
|
@ -91,7 +78,7 @@ mod tests {
|
||||||
|
|
||||||
let new_community = CommunityForm {
|
let new_community = CommunityForm {
|
||||||
name: "TIL_site_agg".into(),
|
name: "TIL_site_agg".into(),
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
description: None,
|
description: None,
|
||||||
nsfw: false,
|
nsfw: false,
|
||||||
|
@ -117,7 +104,7 @@ mod tests {
|
||||||
name: "A test post".into(),
|
name: "A test post".into(),
|
||||||
url: None,
|
url: None,
|
||||||
body: None,
|
body: None,
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
|
@ -140,7 +127,7 @@ mod tests {
|
||||||
|
|
||||||
let comment_form = CommentForm {
|
let comment_form = CommentForm {
|
||||||
content: "A test comment".into(),
|
content: "A test comment".into(),
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
|
@ -157,7 +144,7 @@ mod tests {
|
||||||
|
|
||||||
let child_comment_form = CommentForm {
|
let child_comment_form = CommentForm {
|
||||||
content: "A test comment".into(),
|
content: "A test comment".into(),
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
|
@ -185,8 +172,8 @@ mod tests {
|
||||||
assert_eq!(0, site_aggregates_after_post_delete.comments);
|
assert_eq!(0, site_aggregates_after_post_delete.comments);
|
||||||
|
|
||||||
// This shouuld delete all the associated rows, and fire triggers
|
// This shouuld delete all the associated rows, and fire triggers
|
||||||
let user_num_deleted = User_::delete(&conn, inserted_user.id).unwrap();
|
let person_num_deleted = Person::delete(&conn, inserted_person.id).unwrap();
|
||||||
assert_eq!(1, user_num_deleted);
|
assert_eq!(1, person_num_deleted);
|
||||||
|
|
||||||
let after_delete = SiteAggregates::read(&conn);
|
let after_delete = SiteAggregates::read(&conn);
|
||||||
assert!(after_delete.is_err());
|
assert!(after_delete.is_err());
|
||||||
|
|
|
@ -124,13 +124,10 @@ mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
establish_unpooled_connection,
|
establish_unpooled_connection,
|
||||||
source::activity::Activity_,
|
source::activity::Activity_,
|
||||||
Crud,
|
|
||||||
ListingType,
|
|
||||||
SortType,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::source::{
|
use lemmy_db_schema::source::{
|
||||||
activity::{Activity, ActivityForm},
|
activity::{Activity, ActivityForm},
|
||||||
user::{UserForm, User_},
|
person::{PersonForm, Person},
|
||||||
};
|
};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
|
@ -138,28 +135,18 @@ mod tests {
|
||||||
fn test_crud() {
|
fn test_crud() {
|
||||||
let conn = establish_unpooled_connection();
|
let conn = establish_unpooled_connection();
|
||||||
|
|
||||||
let creator_form = UserForm {
|
let creator_form = PersonForm {
|
||||||
name: "activity_creator_pm".into(),
|
name: "activity_creator_pm".into(),
|
||||||
preferred_username: None,
|
preferred_username: None,
|
||||||
password_encrypted: "nope".into(),
|
|
||||||
email: None,
|
|
||||||
matrix_user_id: None,
|
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
banned: None,
|
||||||
banned: Some(false),
|
deleted: None,
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
|
||||||
theme: "browser".into(),
|
|
||||||
default_sort_type: SortType::Hot as i16,
|
|
||||||
default_listing_type: ListingType::Subscribed as i16,
|
|
||||||
lang: "browser".into(),
|
|
||||||
show_avatars: true,
|
|
||||||
send_notifications_to_email: false,
|
|
||||||
actor_id: None,
|
actor_id: None,
|
||||||
bio: None,
|
bio: None,
|
||||||
local: true,
|
local: None,
|
||||||
private_key: None,
|
private_key: None,
|
||||||
public_key: None,
|
public_key: None,
|
||||||
last_refreshed_at: None,
|
last_refreshed_at: None,
|
||||||
|
@ -167,7 +154,7 @@ mod tests {
|
||||||
shared_inbox_url: None,
|
shared_inbox_url: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_creator = User_::create(&conn, &creator_form).unwrap();
|
let inserted_creator = Person::create(&conn, &creator_form).unwrap();
|
||||||
|
|
||||||
let ap_id =
|
let ap_id =
|
||||||
"https://enterprise.lemmy.ml/activities/delete/f1b5d57c-80f8-4e03-a615-688d552e946c";
|
"https://enterprise.lemmy.ml/activities/delete/f1b5d57c-80f8-4e03-a615-688d552e946c";
|
||||||
|
@ -207,7 +194,7 @@ mod tests {
|
||||||
|
|
||||||
let read_activity = Activity::read(&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();
|
let read_activity_by_apub_id = Activity::read_from_apub_id(&conn, ap_id).unwrap();
|
||||||
User_::delete(&conn, inserted_creator.id).unwrap();
|
Person::delete(&conn, inserted_creator.id).unwrap();
|
||||||
Activity::delete(&conn, inserted_activity.id).unwrap();
|
Activity::delete(&conn, inserted_activity.id).unwrap();
|
||||||
|
|
||||||
assert_eq!(expected_activity, read_activity);
|
assert_eq!(expected_activity, read_activity);
|
||||||
|
|
|
@ -166,17 +166,17 @@ impl Likeable<CommentLikeForm> for CommentLike {
|
||||||
use lemmy_db_schema::schema::comment_like::dsl::*;
|
use lemmy_db_schema::schema::comment_like::dsl::*;
|
||||||
insert_into(comment_like)
|
insert_into(comment_like)
|
||||||
.values(comment_like_form)
|
.values(comment_like_form)
|
||||||
.on_conflict((comment_id, user_id))
|
.on_conflict((comment_id, person_id))
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(comment_like_form)
|
.set(comment_like_form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
}
|
}
|
||||||
fn remove(conn: &PgConnection, user_id: i32, comment_id: i32) -> Result<usize, Error> {
|
fn remove(conn: &PgConnection, person_id: i32, comment_id: i32) -> Result<usize, Error> {
|
||||||
use lemmy_db_schema::schema::comment_like::dsl;
|
use lemmy_db_schema::schema::comment_like::dsl;
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
dsl::comment_like
|
dsl::comment_like
|
||||||
.filter(dsl::comment_id.eq(comment_id))
|
.filter(dsl::comment_id.eq(comment_id))
|
||||||
.filter(dsl::user_id.eq(user_id)),
|
.filter(dsl::person_id.eq(person_id)),
|
||||||
)
|
)
|
||||||
.execute(conn)
|
.execute(conn)
|
||||||
}
|
}
|
||||||
|
@ -197,7 +197,7 @@ impl Saveable<CommentSavedForm> for CommentSaved {
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
comment_saved
|
comment_saved
|
||||||
.filter(comment_id.eq(comment_saved_form.comment_id))
|
.filter(comment_id.eq(comment_saved_form.comment_id))
|
||||||
.filter(user_id.eq(comment_saved_form.user_id)),
|
.filter(user_id.eq(comment_saved_form.person_id)),
|
||||||
)
|
)
|
||||||
.execute(conn)
|
.execute(conn)
|
||||||
}
|
}
|
||||||
|
@ -210,32 +210,22 @@ mod tests {
|
||||||
comment::*,
|
comment::*,
|
||||||
community::{Community, CommunityForm},
|
community::{Community, CommunityForm},
|
||||||
post::*,
|
post::*,
|
||||||
user::{UserForm, User_},
|
person::{PersonForm, Person},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_crud() {
|
fn test_crud() {
|
||||||
let conn = establish_unpooled_connection();
|
let conn = establish_unpooled_connection();
|
||||||
|
|
||||||
let new_user = UserForm {
|
let new_person = PersonForm {
|
||||||
name: "terry".into(),
|
name: "terry".into(),
|
||||||
preferred_username: None,
|
preferred_username: None,
|
||||||
password_encrypted: "nope".into(),
|
|
||||||
email: None,
|
|
||||||
matrix_user_id: None,
|
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
|
||||||
banned: Some(false),
|
banned: Some(false),
|
||||||
|
deleted: false,
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
|
||||||
theme: "browser".into(),
|
|
||||||
default_sort_type: SortType::Hot as i16,
|
|
||||||
default_listing_type: ListingType::Subscribed as i16,
|
|
||||||
lang: "browser".into(),
|
|
||||||
show_avatars: true,
|
|
||||||
send_notifications_to_email: false,
|
|
||||||
actor_id: None,
|
actor_id: None,
|
||||||
bio: None,
|
bio: None,
|
||||||
local: true,
|
local: true,
|
||||||
|
@ -246,13 +236,13 @@ mod tests {
|
||||||
shared_inbox_url: None,
|
shared_inbox_url: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_user = User_::create(&conn, &new_user).unwrap();
|
let inserted_persod = Person::create(&conn, &new_person).unwrap();
|
||||||
|
|
||||||
let new_community = CommunityForm {
|
let new_community = CommunityForm {
|
||||||
name: "test community".to_string(),
|
name: "test community".to_string(),
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
description: None,
|
description: None,
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_persod.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
|
@ -274,7 +264,7 @@ mod tests {
|
||||||
|
|
||||||
let new_post = PostForm {
|
let new_post = PostForm {
|
||||||
name: "A test post".into(),
|
name: "A test post".into(),
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_persod.id,
|
||||||
url: None,
|
url: None,
|
||||||
body: None,
|
body: None,
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
|
@ -297,7 +287,7 @@ mod tests {
|
||||||
|
|
||||||
let comment_form = CommentForm {
|
let comment_form = CommentForm {
|
||||||
content: "A test comment".into(),
|
content: "A test comment".into(),
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_persod.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
|
@ -314,7 +304,7 @@ mod tests {
|
||||||
let expected_comment = Comment {
|
let expected_comment = Comment {
|
||||||
id: inserted_comment.id,
|
id: inserted_comment.id,
|
||||||
content: "A test comment".into(),
|
content: "A test comment".into(),
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_persod.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
removed: false,
|
removed: false,
|
||||||
deleted: false,
|
deleted: false,
|
||||||
|
@ -328,7 +318,7 @@ mod tests {
|
||||||
|
|
||||||
let child_comment_form = CommentForm {
|
let child_comment_form = CommentForm {
|
||||||
content: "A child comment".into(),
|
content: "A child comment".into(),
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_persod.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
parent_id: Some(inserted_comment.id),
|
parent_id: Some(inserted_comment.id),
|
||||||
removed: None,
|
removed: None,
|
||||||
|
@ -346,7 +336,7 @@ mod tests {
|
||||||
let comment_like_form = CommentLikeForm {
|
let comment_like_form = CommentLikeForm {
|
||||||
comment_id: inserted_comment.id,
|
comment_id: inserted_comment.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
user_id: inserted_user.id,
|
person_id: inserted_persod.id,
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -356,7 +346,7 @@ mod tests {
|
||||||
id: inserted_comment_like.id,
|
id: inserted_comment_like.id,
|
||||||
comment_id: inserted_comment.id,
|
comment_id: inserted_comment.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
user_id: inserted_user.id,
|
person_id: inserted_persod.id,
|
||||||
published: inserted_comment_like.published,
|
published: inserted_comment_like.published,
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
@ -364,7 +354,7 @@ mod tests {
|
||||||
// Comment Saved
|
// Comment Saved
|
||||||
let comment_saved_form = CommentSavedForm {
|
let comment_saved_form = CommentSavedForm {
|
||||||
comment_id: inserted_comment.id,
|
comment_id: inserted_comment.id,
|
||||||
user_id: inserted_user.id,
|
person_id: inserted_persod.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_comment_saved = CommentSaved::save(&conn, &comment_saved_form).unwrap();
|
let inserted_comment_saved = CommentSaved::save(&conn, &comment_saved_form).unwrap();
|
||||||
|
@ -372,19 +362,19 @@ mod tests {
|
||||||
let expected_comment_saved = CommentSaved {
|
let expected_comment_saved = CommentSaved {
|
||||||
id: inserted_comment_saved.id,
|
id: inserted_comment_saved.id,
|
||||||
comment_id: inserted_comment.id,
|
comment_id: inserted_comment.id,
|
||||||
user_id: inserted_user.id,
|
person_id: inserted_persod.id,
|
||||||
published: inserted_comment_saved.published,
|
published: inserted_comment_saved.published,
|
||||||
};
|
};
|
||||||
|
|
||||||
let read_comment = Comment::read(&conn, inserted_comment.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 updated_comment = Comment::update(&conn, inserted_comment.id, &comment_form).unwrap();
|
||||||
let like_removed = CommentLike::remove(&conn, inserted_user.id, inserted_comment.id).unwrap();
|
let like_removed = CommentLike::remove(&conn, inserted_persod.id, inserted_comment.id).unwrap();
|
||||||
let saved_removed = CommentSaved::unsave(&conn, &comment_saved_form).unwrap();
|
let saved_removed = CommentSaved::unsave(&conn, &comment_saved_form).unwrap();
|
||||||
let num_deleted = Comment::delete(&conn, inserted_comment.id).unwrap();
|
let num_deleted = Comment::delete(&conn, inserted_comment.id).unwrap();
|
||||||
Comment::delete(&conn, inserted_child_comment.id).unwrap();
|
Comment::delete(&conn, inserted_child_comment.id).unwrap();
|
||||||
Post::delete(&conn, inserted_post.id).unwrap();
|
Post::delete(&conn, inserted_post.id).unwrap();
|
||||||
Community::delete(&conn, inserted_community.id).unwrap();
|
Community::delete(&conn, inserted_community.id).unwrap();
|
||||||
User_::delete(&conn, inserted_user.id).unwrap();
|
Person::delete(&conn, inserted_persod.id).unwrap();
|
||||||
|
|
||||||
assert_eq!(expected_comment, read_comment);
|
assert_eq!(expected_comment, read_comment);
|
||||||
assert_eq!(expected_comment, inserted_comment);
|
assert_eq!(expected_comment, inserted_comment);
|
||||||
|
|
|
@ -9,8 +9,8 @@ use lemmy_db_schema::{
|
||||||
CommunityForm,
|
CommunityForm,
|
||||||
CommunityModerator,
|
CommunityModerator,
|
||||||
CommunityModeratorForm,
|
CommunityModeratorForm,
|
||||||
CommunityUserBan,
|
CommunityPersonBan,
|
||||||
CommunityUserBanForm,
|
CommunityPersonBanForm,
|
||||||
},
|
},
|
||||||
Url,
|
Url,
|
||||||
};
|
};
|
||||||
|
@ -206,23 +206,23 @@ impl Community_ for Community {
|
||||||
impl Joinable<CommunityModeratorForm> for CommunityModerator {
|
impl Joinable<CommunityModeratorForm> for CommunityModerator {
|
||||||
fn join(
|
fn join(
|
||||||
conn: &PgConnection,
|
conn: &PgConnection,
|
||||||
community_user_form: &CommunityModeratorForm,
|
community_moderator_form: &CommunityModeratorForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use lemmy_db_schema::schema::community_moderator::dsl::*;
|
use lemmy_db_schema::schema::community_moderator::dsl::*;
|
||||||
insert_into(community_moderator)
|
insert_into(community_moderator)
|
||||||
.values(community_user_form)
|
.values(community_moderator_form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn leave(
|
fn leave(
|
||||||
conn: &PgConnection,
|
conn: &PgConnection,
|
||||||
community_user_form: &CommunityModeratorForm,
|
community_moderator_form: &CommunityModeratorForm,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
use lemmy_db_schema::schema::community_moderator::dsl::*;
|
use lemmy_db_schema::schema::community_moderator::dsl::*;
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
community_moderator
|
community_moderator
|
||||||
.filter(community_id.eq(community_user_form.community_id))
|
.filter(community_id.eq(community_moderator_form.community_id))
|
||||||
.filter(user_id.eq(community_user_form.user_id)),
|
.filter(person_id.eq(community_moderator_form.person_id)),
|
||||||
)
|
)
|
||||||
.execute(conn)
|
.execute(conn)
|
||||||
}
|
}
|
||||||
|
@ -230,9 +230,9 @@ impl Joinable<CommunityModeratorForm> for CommunityModerator {
|
||||||
|
|
||||||
pub trait CommunityModerator_ {
|
pub trait CommunityModerator_ {
|
||||||
fn delete_for_community(conn: &PgConnection, for_community_id: i32) -> Result<usize, Error>;
|
fn delete_for_community(conn: &PgConnection, for_community_id: i32) -> Result<usize, Error>;
|
||||||
fn get_user_moderated_communities(
|
fn get_person_moderated_communities(
|
||||||
conn: &PgConnection,
|
conn: &PgConnection,
|
||||||
for_user_id: i32,
|
for_person_id: i32,
|
||||||
) -> Result<Vec<i32>, Error>;
|
) -> Result<Vec<i32>, Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,38 +242,38 @@ impl CommunityModerator_ for CommunityModerator {
|
||||||
diesel::delete(community_moderator.filter(community_id.eq(for_community_id))).execute(conn)
|
diesel::delete(community_moderator.filter(community_id.eq(for_community_id))).execute(conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_user_moderated_communities(
|
fn get_person_moderated_communities(
|
||||||
conn: &PgConnection,
|
conn: &PgConnection,
|
||||||
for_user_id: i32,
|
for_person_id: i32,
|
||||||
) -> Result<Vec<i32>, Error> {
|
) -> Result<Vec<i32>, Error> {
|
||||||
use lemmy_db_schema::schema::community_moderator::dsl::*;
|
use lemmy_db_schema::schema::community_moderator::dsl::*;
|
||||||
community_moderator
|
community_moderator
|
||||||
.filter(user_id.eq(for_user_id))
|
.filter(person_id.eq(for_person_id))
|
||||||
.select(community_id)
|
.select(community_id)
|
||||||
.load::<i32>(conn)
|
.load::<i32>(conn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Bannable<CommunityUserBanForm> for CommunityUserBan {
|
impl Bannable<CommunityPersonBanForm> for CommunityPersonBan {
|
||||||
fn ban(
|
fn ban(
|
||||||
conn: &PgConnection,
|
conn: &PgConnection,
|
||||||
community_user_ban_form: &CommunityUserBanForm,
|
community_person_ban_form: &CommunityPersonBanForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use lemmy_db_schema::schema::community_user_ban::dsl::*;
|
use lemmy_db_schema::schema::community_person_ban::dsl::*;
|
||||||
insert_into(community_user_ban)
|
insert_into(community_person_ban)
|
||||||
.values(community_user_ban_form)
|
.values(community_person_ban_form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unban(
|
fn unban(
|
||||||
conn: &PgConnection,
|
conn: &PgConnection,
|
||||||
community_user_ban_form: &CommunityUserBanForm,
|
community_person_ban_form: &CommunityPersonBanForm,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
use lemmy_db_schema::schema::community_user_ban::dsl::*;
|
use lemmy_db_schema::schema::community_person_ban::dsl::*;
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
community_user_ban
|
community_person_ban
|
||||||
.filter(community_id.eq(community_user_ban_form.community_id))
|
.filter(community_id.eq(community_person_ban_form.community_id))
|
||||||
.filter(user_id.eq(community_user_ban_form.user_id)),
|
.filter(person_id.eq(community_person_ban_form.person_id)),
|
||||||
)
|
)
|
||||||
.execute(conn)
|
.execute(conn)
|
||||||
}
|
}
|
||||||
|
@ -313,7 +313,7 @@ impl Followable<CommunityFollowerForm> for CommunityFollower {
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
community_follower
|
community_follower
|
||||||
.filter(community_id.eq(&community_follower_form.community_id))
|
.filter(community_id.eq(&community_follower_form.community_id))
|
||||||
.filter(user_id.eq(&community_follower_form.user_id)),
|
.filter(user_id.eq(&community_follower_form.person_id)),
|
||||||
)
|
)
|
||||||
.execute(conn)
|
.execute(conn)
|
||||||
}
|
}
|
||||||
|
@ -339,31 +339,21 @@ mod tests {
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::source::{community::*, user::*};
|
use lemmy_db_schema::source::{community::*, person::*};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_crud() {
|
fn test_crud() {
|
||||||
let conn = establish_unpooled_connection();
|
let conn = establish_unpooled_connection();
|
||||||
|
|
||||||
let new_user = UserForm {
|
let new_person = PersonForm {
|
||||||
name: "bobbee".into(),
|
name: "bobbee".into(),
|
||||||
preferred_username: None,
|
preferred_username: None,
|
||||||
password_encrypted: "nope".into(),
|
|
||||||
email: None,
|
|
||||||
matrix_user_id: None,
|
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
|
||||||
banned: Some(false),
|
banned: Some(false),
|
||||||
|
deleted: false,
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
|
||||||
theme: "browser".into(),
|
|
||||||
default_sort_type: SortType::Hot as i16,
|
|
||||||
default_listing_type: ListingType::Subscribed as i16,
|
|
||||||
lang: "browser".into(),
|
|
||||||
show_avatars: true,
|
|
||||||
send_notifications_to_email: false,
|
|
||||||
actor_id: None,
|
actor_id: None,
|
||||||
bio: None,
|
bio: None,
|
||||||
local: true,
|
local: true,
|
||||||
|
@ -374,11 +364,11 @@ mod tests {
|
||||||
shared_inbox_url: None,
|
shared_inbox_url: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_user = User_::create(&conn, &new_user).unwrap();
|
let inserted_person = Person::create(&conn, &new_person).unwrap();
|
||||||
|
|
||||||
let new_community = CommunityForm {
|
let new_community = CommunityForm {
|
||||||
name: "TIL".into(),
|
name: "TIL".into(),
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
description: None,
|
description: None,
|
||||||
nsfw: false,
|
nsfw: false,
|
||||||
|
@ -402,7 +392,7 @@ mod tests {
|
||||||
|
|
||||||
let expected_community = Community {
|
let expected_community = Community {
|
||||||
id: inserted_community.id,
|
id: inserted_community.id,
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
name: "TIL".into(),
|
name: "TIL".into(),
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
description: None,
|
description: None,
|
||||||
|
@ -425,7 +415,7 @@ mod tests {
|
||||||
|
|
||||||
let community_follower_form = CommunityFollowerForm {
|
let community_follower_form = CommunityFollowerForm {
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
user_id: inserted_user.id,
|
person_id: inserted_person.id,
|
||||||
pending: false,
|
pending: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -435,55 +425,55 @@ mod tests {
|
||||||
let expected_community_follower = CommunityFollower {
|
let expected_community_follower = CommunityFollower {
|
||||||
id: inserted_community_follower.id,
|
id: inserted_community_follower.id,
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
user_id: inserted_user.id,
|
person_id: inserted_person.id,
|
||||||
pending: Some(false),
|
pending: Some(false),
|
||||||
published: inserted_community_follower.published,
|
published: inserted_community_follower.published,
|
||||||
};
|
};
|
||||||
|
|
||||||
let community_user_form = CommunityModeratorForm {
|
let community_moderator_form = CommunityModeratorForm {
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
user_id: inserted_user.id,
|
person_id: inserted_person.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_community_user = CommunityModerator::join(&conn, &community_user_form).unwrap();
|
let inserted_community_moderator = CommunityModerator::join(&conn, &community_moderator_form).unwrap();
|
||||||
|
|
||||||
let expected_community_user = CommunityModerator {
|
let expected_community_moderator = CommunityModerator {
|
||||||
id: inserted_community_user.id,
|
id: inserted_community_moderator.id,
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
user_id: inserted_user.id,
|
person_id: inserted_person.id,
|
||||||
published: inserted_community_user.published,
|
published: inserted_community_moderator.published,
|
||||||
};
|
};
|
||||||
|
|
||||||
let community_user_ban_form = CommunityUserBanForm {
|
let community_person_ban_form = CommunityPersonBanForm {
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
user_id: inserted_user.id,
|
person_id: inserted_person.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_community_user_ban =
|
let inserted_community_person_ban =
|
||||||
CommunityUserBan::ban(&conn, &community_user_ban_form).unwrap();
|
CommunityPersonBan::ban(&conn, &community_person_ban_form).unwrap();
|
||||||
|
|
||||||
let expected_community_user_ban = CommunityUserBan {
|
let expected_community_person_ban = CommunityPersonBan {
|
||||||
id: inserted_community_user_ban.id,
|
id: inserted_community_person_ban.id,
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
user_id: inserted_user.id,
|
person_id: inserted_person.id,
|
||||||
published: inserted_community_user_ban.published,
|
published: inserted_community_person_ban.published,
|
||||||
};
|
};
|
||||||
|
|
||||||
let read_community = Community::read(&conn, inserted_community.id).unwrap();
|
let read_community = Community::read(&conn, inserted_community.id).unwrap();
|
||||||
let updated_community =
|
let updated_community =
|
||||||
Community::update(&conn, inserted_community.id, &new_community).unwrap();
|
Community::update(&conn, inserted_community.id, &new_community).unwrap();
|
||||||
let ignored_community = CommunityFollower::unfollow(&conn, &community_follower_form).unwrap();
|
let ignored_community = CommunityFollower::unfollow(&conn, &community_follower_form).unwrap();
|
||||||
let left_community = CommunityModerator::leave(&conn, &community_user_form).unwrap();
|
let left_community = CommunityModerator::leave(&conn, &community_moderator_form).unwrap();
|
||||||
let unban = CommunityUserBan::unban(&conn, &community_user_ban_form).unwrap();
|
let unban = CommunityPersonBan::unban(&conn, &community_person_ban_form).unwrap();
|
||||||
let num_deleted = Community::delete(&conn, inserted_community.id).unwrap();
|
let num_deleted = Community::delete(&conn, inserted_community.id).unwrap();
|
||||||
User_::delete(&conn, inserted_user.id).unwrap();
|
Person::delete(&conn, inserted_person.id).unwrap();
|
||||||
|
|
||||||
assert_eq!(expected_community, read_community);
|
assert_eq!(expected_community, read_community);
|
||||||
assert_eq!(expected_community, inserted_community);
|
assert_eq!(expected_community, inserted_community);
|
||||||
assert_eq!(expected_community, updated_community);
|
assert_eq!(expected_community, updated_community);
|
||||||
assert_eq!(expected_community_follower, inserted_community_follower);
|
assert_eq!(expected_community_follower, inserted_community_follower);
|
||||||
assert_eq!(expected_community_user, inserted_community_user);
|
assert_eq!(expected_community_moderator, inserted_community_moderator);
|
||||||
assert_eq!(expected_community_user_ban, inserted_community_user_ban);
|
assert_eq!(expected_community_person_ban, inserted_community_person_ban);
|
||||||
assert_eq!(1, ignored_community);
|
assert_eq!(1, ignored_community);
|
||||||
assert_eq!(1, left_community);
|
assert_eq!(1, left_community);
|
||||||
assert_eq!(1, unban);
|
assert_eq!(1, unban);
|
||||||
|
|
76
crates/db_queries/src/source/local_user.rs
Normal file
76
crates/db_queries/src/source/local_user.rs
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
use crate::{is_email_regex, ApubObject, Crud, ToSafeSettings};
|
||||||
|
mod safe_settings_type {
|
||||||
|
use crate::ToSafeSettings;
|
||||||
|
use lemmy_db_schema::{schema::user_::columns::*, source::user::User_};
|
||||||
|
|
||||||
|
type Columns = (
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
preferred_username,
|
||||||
|
email,
|
||||||
|
avatar,
|
||||||
|
admin,
|
||||||
|
banned,
|
||||||
|
published,
|
||||||
|
updated,
|
||||||
|
show_nsfw,
|
||||||
|
theme,
|
||||||
|
default_sort_type,
|
||||||
|
default_listing_type,
|
||||||
|
lang,
|
||||||
|
show_avatars,
|
||||||
|
send_notifications_to_email,
|
||||||
|
matrix_user_id,
|
||||||
|
actor_id,
|
||||||
|
bio,
|
||||||
|
local,
|
||||||
|
last_refreshed_at,
|
||||||
|
banner,
|
||||||
|
deleted,
|
||||||
|
);
|
||||||
|
|
||||||
|
impl ToSafeSettings for User_ {
|
||||||
|
type SafeSettingsColumns = Columns;
|
||||||
|
fn safe_settings_columns_tuple() -> Self::SafeSettingsColumns {
|
||||||
|
(
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
preferred_username,
|
||||||
|
email,
|
||||||
|
avatar,
|
||||||
|
admin,
|
||||||
|
banned,
|
||||||
|
published,
|
||||||
|
updated,
|
||||||
|
show_nsfw,
|
||||||
|
theme,
|
||||||
|
default_sort_type,
|
||||||
|
default_listing_type,
|
||||||
|
lang,
|
||||||
|
show_avatars,
|
||||||
|
send_notifications_to_email,
|
||||||
|
matrix_user_id,
|
||||||
|
actor_id,
|
||||||
|
bio,
|
||||||
|
local,
|
||||||
|
last_refreshed_at,
|
||||||
|
banner,
|
||||||
|
deleted,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait UserSafeSettings_ {
|
||||||
|
fn read(conn: &PgConnection, user_id: i32) -> Result<UserSafeSettings, Error>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UserSafeSettings_ for UserSafeSettings {
|
||||||
|
fn read(conn: &PgConnection, user_id: i32) -> Result<Self, Error> {
|
||||||
|
user_
|
||||||
|
.select(User_::safe_settings_columns_tuple())
|
||||||
|
.filter(deleted.eq(false))
|
||||||
|
.find(user_id)
|
||||||
|
.first::<Self>(conn)
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,5 +8,6 @@ pub mod post;
|
||||||
pub mod post_report;
|
pub mod post_report;
|
||||||
pub mod private_message;
|
pub mod private_message;
|
||||||
pub mod site;
|
pub mod site;
|
||||||
pub mod user;
|
pub mod person;
|
||||||
pub mod user_mention;
|
pub mod person_mention;
|
||||||
|
pub mod local_user;
|
||||||
|
|
|
@ -198,32 +198,22 @@ impl Crud<ModAddForm> for ModAdd {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{establish_unpooled_connection, Crud, ListingType, SortType};
|
use crate::{establish_unpooled_connection, Crud, ListingType, SortType};
|
||||||
use lemmy_db_schema::source::{comment::*, community::*, moderator::*, post::*, user::*};
|
use lemmy_db_schema::source::{comment::*, community::*, moderator::*, post::*, person::*};
|
||||||
|
|
||||||
// use Crud;
|
// use Crud;
|
||||||
#[test]
|
#[test]
|
||||||
fn test_crud() {
|
fn test_crud() {
|
||||||
let conn = establish_unpooled_connection();
|
let conn = establish_unpooled_connection();
|
||||||
|
|
||||||
let new_mod = UserForm {
|
let new_mod = PersonForm {
|
||||||
name: "the mod".into(),
|
name: "the mod".into(),
|
||||||
preferred_username: None,
|
preferred_username: None,
|
||||||
password_encrypted: "nope".into(),
|
|
||||||
email: None,
|
|
||||||
matrix_user_id: None,
|
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
|
||||||
banned: Some(false),
|
banned: Some(false),
|
||||||
|
deleted: false,
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
|
||||||
theme: "browser".into(),
|
|
||||||
default_sort_type: SortType::Hot as i16,
|
|
||||||
default_listing_type: ListingType::Subscribed as i16,
|
|
||||||
lang: "browser".into(),
|
|
||||||
show_avatars: true,
|
|
||||||
send_notifications_to_email: false,
|
|
||||||
actor_id: None,
|
actor_id: None,
|
||||||
bio: None,
|
bio: None,
|
||||||
local: true,
|
local: true,
|
||||||
|
@ -234,27 +224,17 @@ mod tests {
|
||||||
shared_inbox_url: None,
|
shared_inbox_url: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_mod = User_::create(&conn, &new_mod).unwrap();
|
let inserted_mod = Person::create(&conn, &new_mod).unwrap();
|
||||||
|
|
||||||
let new_user = UserForm {
|
let new_person = PersonForm {
|
||||||
name: "jim2".into(),
|
name: "jim2".into(),
|
||||||
preferred_username: None,
|
preferred_username: None,
|
||||||
password_encrypted: "nope".into(),
|
|
||||||
email: None,
|
|
||||||
matrix_user_id: None,
|
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
|
||||||
banned: Some(false),
|
banned: Some(false),
|
||||||
|
deleted: false,
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
|
||||||
theme: "browser".into(),
|
|
||||||
default_sort_type: SortType::Hot as i16,
|
|
||||||
default_listing_type: ListingType::Subscribed as i16,
|
|
||||||
lang: "browser".into(),
|
|
||||||
show_avatars: true,
|
|
||||||
send_notifications_to_email: false,
|
|
||||||
actor_id: None,
|
actor_id: None,
|
||||||
bio: None,
|
bio: None,
|
||||||
local: true,
|
local: true,
|
||||||
|
@ -265,13 +245,13 @@ mod tests {
|
||||||
shared_inbox_url: None,
|
shared_inbox_url: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_user = User_::create(&conn, &new_user).unwrap();
|
let inserted_person = Person::create(&conn, &new_person).unwrap();
|
||||||
|
|
||||||
let new_community = CommunityForm {
|
let new_community = CommunityForm {
|
||||||
name: "mod_community".to_string(),
|
name: "mod_community".to_string(),
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
description: None,
|
description: None,
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
|
@ -295,7 +275,7 @@ mod tests {
|
||||||
name: "A test post thweep".into(),
|
name: "A test post thweep".into(),
|
||||||
url: None,
|
url: None,
|
||||||
body: None,
|
body: None,
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
|
@ -316,7 +296,7 @@ mod tests {
|
||||||
|
|
||||||
let comment_form = CommentForm {
|
let comment_form = CommentForm {
|
||||||
content: "A test comment".into(),
|
content: "A test comment".into(),
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
|
@ -334,7 +314,7 @@ mod tests {
|
||||||
|
|
||||||
// remove post
|
// remove post
|
||||||
let mod_remove_post_form = ModRemovePostForm {
|
let mod_remove_post_form = ModRemovePostForm {
|
||||||
mod_user_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
reason: None,
|
reason: None,
|
||||||
removed: None,
|
removed: None,
|
||||||
|
@ -344,7 +324,7 @@ mod tests {
|
||||||
let expected_mod_remove_post = ModRemovePost {
|
let expected_mod_remove_post = ModRemovePost {
|
||||||
id: inserted_mod_remove_post.id,
|
id: inserted_mod_remove_post.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
mod_user_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
reason: None,
|
reason: None,
|
||||||
removed: Some(true),
|
removed: Some(true),
|
||||||
when_: inserted_mod_remove_post.when_,
|
when_: inserted_mod_remove_post.when_,
|
||||||
|
@ -353,7 +333,7 @@ mod tests {
|
||||||
// lock post
|
// lock post
|
||||||
|
|
||||||
let mod_lock_post_form = ModLockPostForm {
|
let mod_lock_post_form = ModLockPostForm {
|
||||||
mod_user_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
locked: None,
|
locked: None,
|
||||||
};
|
};
|
||||||
|
@ -362,7 +342,7 @@ mod tests {
|
||||||
let expected_mod_lock_post = ModLockPost {
|
let expected_mod_lock_post = ModLockPost {
|
||||||
id: inserted_mod_lock_post.id,
|
id: inserted_mod_lock_post.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
mod_user_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
locked: Some(true),
|
locked: Some(true),
|
||||||
when_: inserted_mod_lock_post.when_,
|
when_: inserted_mod_lock_post.when_,
|
||||||
};
|
};
|
||||||
|
@ -370,7 +350,7 @@ mod tests {
|
||||||
// sticky post
|
// sticky post
|
||||||
|
|
||||||
let mod_sticky_post_form = ModStickyPostForm {
|
let mod_sticky_post_form = ModStickyPostForm {
|
||||||
mod_user_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
stickied: None,
|
stickied: None,
|
||||||
};
|
};
|
||||||
|
@ -379,7 +359,7 @@ mod tests {
|
||||||
let expected_mod_sticky_post = ModStickyPost {
|
let expected_mod_sticky_post = ModStickyPost {
|
||||||
id: inserted_mod_sticky_post.id,
|
id: inserted_mod_sticky_post.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
mod_user_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
stickied: Some(true),
|
stickied: Some(true),
|
||||||
when_: inserted_mod_sticky_post.when_,
|
when_: inserted_mod_sticky_post.when_,
|
||||||
};
|
};
|
||||||
|
@ -387,7 +367,7 @@ mod tests {
|
||||||
// comment
|
// comment
|
||||||
|
|
||||||
let mod_remove_comment_form = ModRemoveCommentForm {
|
let mod_remove_comment_form = ModRemoveCommentForm {
|
||||||
mod_user_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
comment_id: inserted_comment.id,
|
comment_id: inserted_comment.id,
|
||||||
reason: None,
|
reason: None,
|
||||||
removed: None,
|
removed: None,
|
||||||
|
@ -399,7 +379,7 @@ mod tests {
|
||||||
let expected_mod_remove_comment = ModRemoveComment {
|
let expected_mod_remove_comment = ModRemoveComment {
|
||||||
id: inserted_mod_remove_comment.id,
|
id: inserted_mod_remove_comment.id,
|
||||||
comment_id: inserted_comment.id,
|
comment_id: inserted_comment.id,
|
||||||
mod_user_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
reason: None,
|
reason: None,
|
||||||
removed: Some(true),
|
removed: Some(true),
|
||||||
when_: inserted_mod_remove_comment.when_,
|
when_: inserted_mod_remove_comment.when_,
|
||||||
|
@ -408,7 +388,7 @@ mod tests {
|
||||||
// community
|
// community
|
||||||
|
|
||||||
let mod_remove_community_form = ModRemoveCommunityForm {
|
let mod_remove_community_form = ModRemoveCommunityForm {
|
||||||
mod_user_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
reason: None,
|
reason: None,
|
||||||
removed: None,
|
removed: None,
|
||||||
|
@ -421,7 +401,7 @@ mod tests {
|
||||||
let expected_mod_remove_community = ModRemoveCommunity {
|
let expected_mod_remove_community = ModRemoveCommunity {
|
||||||
id: inserted_mod_remove_community.id,
|
id: inserted_mod_remove_community.id,
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
mod_user_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
reason: None,
|
reason: None,
|
||||||
removed: Some(true),
|
removed: Some(true),
|
||||||
expires: None,
|
expires: None,
|
||||||
|
@ -431,8 +411,8 @@ mod tests {
|
||||||
// ban from community
|
// ban from community
|
||||||
|
|
||||||
let mod_ban_from_community_form = ModBanFromCommunityForm {
|
let mod_ban_from_community_form = ModBanFromCommunityForm {
|
||||||
mod_user_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
other_user_id: inserted_user.id,
|
other_person_id: inserted_person.id,
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
reason: None,
|
reason: None,
|
||||||
banned: None,
|
banned: None,
|
||||||
|
@ -445,8 +425,8 @@ mod tests {
|
||||||
let expected_mod_ban_from_community = ModBanFromCommunity {
|
let expected_mod_ban_from_community = ModBanFromCommunity {
|
||||||
id: inserted_mod_ban_from_community.id,
|
id: inserted_mod_ban_from_community.id,
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
mod_user_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
other_user_id: inserted_user.id,
|
other_person_id: inserted_person.id,
|
||||||
reason: None,
|
reason: None,
|
||||||
banned: Some(true),
|
banned: Some(true),
|
||||||
expires: None,
|
expires: None,
|
||||||
|
@ -456,8 +436,8 @@ mod tests {
|
||||||
// ban
|
// ban
|
||||||
|
|
||||||
let mod_ban_form = ModBanForm {
|
let mod_ban_form = ModBanForm {
|
||||||
mod_user_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
other_user_id: inserted_user.id,
|
other_person_id: inserted_person.id,
|
||||||
reason: None,
|
reason: None,
|
||||||
banned: None,
|
banned: None,
|
||||||
expires: None,
|
expires: None,
|
||||||
|
@ -466,8 +446,8 @@ mod tests {
|
||||||
let read_mod_ban = ModBan::read(&conn, inserted_mod_ban.id).unwrap();
|
let read_mod_ban = ModBan::read(&conn, inserted_mod_ban.id).unwrap();
|
||||||
let expected_mod_ban = ModBan {
|
let expected_mod_ban = ModBan {
|
||||||
id: inserted_mod_ban.id,
|
id: inserted_mod_ban.id,
|
||||||
mod_user_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
other_user_id: inserted_user.id,
|
other_person_id: inserted_person.id,
|
||||||
reason: None,
|
reason: None,
|
||||||
banned: Some(true),
|
banned: Some(true),
|
||||||
expires: None,
|
expires: None,
|
||||||
|
@ -477,8 +457,8 @@ mod tests {
|
||||||
// mod add community
|
// mod add community
|
||||||
|
|
||||||
let mod_add_community_form = ModAddCommunityForm {
|
let mod_add_community_form = ModAddCommunityForm {
|
||||||
mod_user_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
other_user_id: inserted_user.id,
|
other_person_id: inserted_person.id,
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
};
|
};
|
||||||
|
@ -489,8 +469,8 @@ mod tests {
|
||||||
let expected_mod_add_community = ModAddCommunity {
|
let expected_mod_add_community = ModAddCommunity {
|
||||||
id: inserted_mod_add_community.id,
|
id: inserted_mod_add_community.id,
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
mod_user_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
other_user_id: inserted_user.id,
|
other_person_id: inserted_person.id,
|
||||||
removed: Some(false),
|
removed: Some(false),
|
||||||
when_: inserted_mod_add_community.when_,
|
when_: inserted_mod_add_community.when_,
|
||||||
};
|
};
|
||||||
|
@ -498,16 +478,16 @@ mod tests {
|
||||||
// mod add
|
// mod add
|
||||||
|
|
||||||
let mod_add_form = ModAddForm {
|
let mod_add_form = ModAddForm {
|
||||||
mod_user_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
other_user_id: inserted_user.id,
|
other_person_id: inserted_person.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
};
|
};
|
||||||
let inserted_mod_add = ModAdd::create(&conn, &mod_add_form).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 read_mod_add = ModAdd::read(&conn, inserted_mod_add.id).unwrap();
|
||||||
let expected_mod_add = ModAdd {
|
let expected_mod_add = ModAdd {
|
||||||
id: inserted_mod_add.id,
|
id: inserted_mod_add.id,
|
||||||
mod_user_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
other_user_id: inserted_user.id,
|
other_person_id: inserted_person.id,
|
||||||
removed: Some(false),
|
removed: Some(false),
|
||||||
when_: inserted_mod_add.when_,
|
when_: inserted_mod_add.when_,
|
||||||
};
|
};
|
||||||
|
@ -515,8 +495,8 @@ mod tests {
|
||||||
Comment::delete(&conn, inserted_comment.id).unwrap();
|
Comment::delete(&conn, inserted_comment.id).unwrap();
|
||||||
Post::delete(&conn, inserted_post.id).unwrap();
|
Post::delete(&conn, inserted_post.id).unwrap();
|
||||||
Community::delete(&conn, inserted_community.id).unwrap();
|
Community::delete(&conn, inserted_community.id).unwrap();
|
||||||
User_::delete(&conn, inserted_user.id).unwrap();
|
Person::delete(&conn, inserted_person.id).unwrap();
|
||||||
User_::delete(&conn, inserted_mod.id).unwrap();
|
Person::delete(&conn, inserted_mod.id).unwrap();
|
||||||
|
|
||||||
assert_eq!(expected_mod_remove_post, read_mod_remove_post);
|
assert_eq!(expected_mod_remove_post, read_mod_remove_post);
|
||||||
assert_eq!(expected_mod_lock_post, read_mod_lock_post);
|
assert_eq!(expected_mod_lock_post, read_mod_lock_post);
|
||||||
|
|
|
@ -28,7 +28,7 @@ impl Crud<PasswordResetRequestForm> for PasswordResetRequest {
|
||||||
pub trait PasswordResetRequest_ {
|
pub trait PasswordResetRequest_ {
|
||||||
fn create_token(
|
fn create_token(
|
||||||
conn: &PgConnection,
|
conn: &PgConnection,
|
||||||
from_user_id: i32,
|
from_local_user_id: i32,
|
||||||
token: &str,
|
token: &str,
|
||||||
) -> Result<PasswordResetRequest, Error>;
|
) -> Result<PasswordResetRequest, Error>;
|
||||||
fn read_from_token(conn: &PgConnection, token: &str) -> Result<PasswordResetRequest, Error>;
|
fn read_from_token(conn: &PgConnection, token: &str) -> Result<PasswordResetRequest, Error>;
|
||||||
|
@ -37,7 +37,7 @@ pub trait PasswordResetRequest_ {
|
||||||
impl PasswordResetRequest_ for PasswordResetRequest {
|
impl PasswordResetRequest_ for PasswordResetRequest {
|
||||||
fn create_token(
|
fn create_token(
|
||||||
conn: &PgConnection,
|
conn: &PgConnection,
|
||||||
from_user_id: i32,
|
from_local_user_id: i32,
|
||||||
token: &str,
|
token: &str,
|
||||||
) -> Result<PasswordResetRequest, Error> {
|
) -> Result<PasswordResetRequest, Error> {
|
||||||
let mut hasher = Sha256::new();
|
let mut hasher = Sha256::new();
|
||||||
|
@ -45,7 +45,7 @@ impl PasswordResetRequest_ for PasswordResetRequest {
|
||||||
let token_hash: String = bytes_to_hex(hasher.finalize().to_vec());
|
let token_hash: String = bytes_to_hex(hasher.finalize().to_vec());
|
||||||
|
|
||||||
let form = PasswordResetRequestForm {
|
let form = PasswordResetRequestForm {
|
||||||
user_id: from_user_id,
|
local_user_id: from_local_user_id,
|
||||||
token_encrypted: token_hash,
|
token_encrypted: token_hash,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -79,31 +79,21 @@ mod tests {
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::source::{password_reset_request::PasswordResetRequest, user::*};
|
use lemmy_db_schema::source::{password_reset_request::PasswordResetRequest, person::*};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_crud() {
|
fn test_crud() {
|
||||||
let conn = establish_unpooled_connection();
|
let conn = establish_unpooled_connection();
|
||||||
|
|
||||||
let new_user = UserForm {
|
let new_person = PersonForm {
|
||||||
name: "thommy prw".into(),
|
name: "thommy prw".into(),
|
||||||
preferred_username: None,
|
preferred_username: None,
|
||||||
password_encrypted: "nope".into(),
|
|
||||||
email: None,
|
|
||||||
matrix_user_id: None,
|
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
|
||||||
banned: Some(false),
|
banned: Some(false),
|
||||||
|
deleted: false,
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
|
||||||
theme: "browser".into(),
|
|
||||||
default_sort_type: SortType::Hot as i16,
|
|
||||||
default_listing_type: ListingType::Subscribed as i16,
|
|
||||||
lang: "browser".into(),
|
|
||||||
show_avatars: true,
|
|
||||||
send_notifications_to_email: false,
|
|
||||||
actor_id: None,
|
actor_id: None,
|
||||||
bio: None,
|
bio: None,
|
||||||
local: true,
|
local: true,
|
||||||
|
@ -114,23 +104,23 @@ mod tests {
|
||||||
shared_inbox_url: None,
|
shared_inbox_url: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_user = User_::create(&conn, &new_user).unwrap();
|
let inserted_person = Person::create(&conn, &new_person).unwrap();
|
||||||
|
|
||||||
let token = "nope";
|
let token = "nope";
|
||||||
let token_encrypted_ = "ca3704aa0b06f5954c79ee837faa152d84d6b2d42838f0637a15eda8337dbdce";
|
let token_encrypted_ = "ca3704aa0b06f5954c79ee837faa152d84d6b2d42838f0637a15eda8337dbdce";
|
||||||
|
|
||||||
let inserted_password_reset_request =
|
let inserted_password_reset_request =
|
||||||
PasswordResetRequest::create_token(&conn, inserted_user.id, token).unwrap();
|
PasswordResetRequest::create_token(&conn, inserted_person.id, token).unwrap();
|
||||||
|
|
||||||
let expected_password_reset_request = PasswordResetRequest {
|
let expected_password_reset_request = PasswordResetRequest {
|
||||||
id: inserted_password_reset_request.id,
|
id: inserted_password_reset_request.id,
|
||||||
user_id: inserted_user.id,
|
local_user_id: inserted_person.id,
|
||||||
token_encrypted: token_encrypted_.to_string(),
|
token_encrypted: token_encrypted_.to_string(),
|
||||||
published: inserted_password_reset_request.published,
|
published: inserted_password_reset_request.published,
|
||||||
};
|
};
|
||||||
|
|
||||||
let read_password_reset_request = PasswordResetRequest::read_from_token(&conn, token).unwrap();
|
let read_password_reset_request = PasswordResetRequest::read_from_token(&conn, token).unwrap();
|
||||||
let num_deleted = User_::delete(&conn, inserted_user.id).unwrap();
|
let num_deleted = Person::delete(&conn, inserted_person.id).unwrap();
|
||||||
|
|
||||||
assert_eq!(expected_password_reset_request, read_password_reset_request);
|
assert_eq!(expected_password_reset_request, read_password_reset_request);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
364
crates/db_queries/src/source/person.rs
Normal file
364
crates/db_queries/src/source/person.rs
Normal file
|
@ -0,0 +1,364 @@
|
||||||
|
use crate::{is_email_regex, ApubObject, Crud, ToSafeSettings};
|
||||||
|
use bcrypt::{hash, DEFAULT_COST};
|
||||||
|
use diesel::{dsl::*, result::Error, *};
|
||||||
|
use lemmy_db_schema::{
|
||||||
|
naive_now,
|
||||||
|
schema::person::dsl::*,
|
||||||
|
source::person::{PersonForm, Person},
|
||||||
|
Url,
|
||||||
|
};
|
||||||
|
use lemmy_utils::settings::Settings;
|
||||||
|
|
||||||
|
mod safe_type {
|
||||||
|
use crate::ToSafe;
|
||||||
|
use lemmy_db_schema::{schema::person::columns::*, source::person::Person};
|
||||||
|
|
||||||
|
type Columns = (
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
preferred_username,
|
||||||
|
avatar,
|
||||||
|
banned,
|
||||||
|
published,
|
||||||
|
updated,
|
||||||
|
actor_id,
|
||||||
|
bio,
|
||||||
|
local,
|
||||||
|
last_refreshed_at,
|
||||||
|
banner,
|
||||||
|
deleted,
|
||||||
|
inbox_url,
|
||||||
|
shared_inbox_url,
|
||||||
|
);
|
||||||
|
|
||||||
|
impl ToSafe for Person {
|
||||||
|
type SafeColumns = Columns;
|
||||||
|
fn safe_columns_tuple() -> Self::SafeColumns {
|
||||||
|
(
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
preferred_username,
|
||||||
|
avatar,
|
||||||
|
banned,
|
||||||
|
published,
|
||||||
|
updated,
|
||||||
|
actor_id,
|
||||||
|
bio,
|
||||||
|
local,
|
||||||
|
last_refreshed_at,
|
||||||
|
banner,
|
||||||
|
deleted,
|
||||||
|
inbox_url,
|
||||||
|
shared_inbox_url,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod safe_type_alias_1 {
|
||||||
|
use crate::ToSafe;
|
||||||
|
use lemmy_db_schema::{schema::person_alias_1::columns::*, source::person::PersonAlias1};
|
||||||
|
|
||||||
|
type Columns = (
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
preferred_username,
|
||||||
|
avatar,
|
||||||
|
banned,
|
||||||
|
published,
|
||||||
|
updated,
|
||||||
|
actor_id,
|
||||||
|
bio,
|
||||||
|
local,
|
||||||
|
last_refreshed_at,
|
||||||
|
banner,
|
||||||
|
deleted,
|
||||||
|
inbox_url,
|
||||||
|
shared_inbox_url,
|
||||||
|
);
|
||||||
|
|
||||||
|
impl ToSafe for PersonAlias1 {
|
||||||
|
type SafeColumns = Columns;
|
||||||
|
fn safe_columns_tuple() -> Self::SafeColumns {
|
||||||
|
(
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
preferred_username,
|
||||||
|
avatar,
|
||||||
|
banned,
|
||||||
|
published,
|
||||||
|
updated,
|
||||||
|
actor_id,
|
||||||
|
bio,
|
||||||
|
local,
|
||||||
|
last_refreshed_at,
|
||||||
|
banner,
|
||||||
|
deleted,
|
||||||
|
inbox_url,
|
||||||
|
shared_inbox_url,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mod safe_type_alias_2 {
|
||||||
|
use crate::ToSafe;
|
||||||
|
use lemmy_db_schema::{schema::person_alias_2::columns::*, source::person::PersonAlias2};
|
||||||
|
|
||||||
|
type Columns = (
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
preferred_username,
|
||||||
|
avatar,
|
||||||
|
banned,
|
||||||
|
published,
|
||||||
|
updated,
|
||||||
|
actor_id,
|
||||||
|
bio,
|
||||||
|
local,
|
||||||
|
last_refreshed_at,
|
||||||
|
banner,
|
||||||
|
deleted,
|
||||||
|
inbox_url,
|
||||||
|
shared_inbox_url,
|
||||||
|
);
|
||||||
|
|
||||||
|
impl ToSafe for PersonAlias2 {
|
||||||
|
type SafeColumns = Columns;
|
||||||
|
fn safe_columns_tuple() -> Self::SafeColumns {
|
||||||
|
(
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
preferred_username,
|
||||||
|
avatar,
|
||||||
|
banned,
|
||||||
|
published,
|
||||||
|
updated,
|
||||||
|
actor_id,
|
||||||
|
bio,
|
||||||
|
local,
|
||||||
|
last_refreshed_at,
|
||||||
|
banner,
|
||||||
|
deleted,
|
||||||
|
inbox_url,
|
||||||
|
shared_inbox_url,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Crud<PersonForm> for Person {
|
||||||
|
fn read(conn: &PgConnection, person_id: i32) -> Result<Self, Error> {
|
||||||
|
person
|
||||||
|
.filter(deleted.eq(false))
|
||||||
|
.find(person_id)
|
||||||
|
.first::<Self>(conn)
|
||||||
|
}
|
||||||
|
fn delete(conn: &PgConnection, person_id: i32) -> Result<usize, Error> {
|
||||||
|
diesel::delete(person.find(person_id)).execute(conn)
|
||||||
|
}
|
||||||
|
fn create(conn: &PgConnection, form: &PersonForm) -> Result<Self, Error> {
|
||||||
|
insert_into(person).values(form).get_result::<Self>(conn)
|
||||||
|
}
|
||||||
|
fn update(conn: &PgConnection, person_id: i32, form: &PersonForm) -> Result<Self, Error> {
|
||||||
|
diesel::update(person.find(person_id))
|
||||||
|
.set(form)
|
||||||
|
.get_result::<Self>(conn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ApubObject<PersonForm> for Person {
|
||||||
|
fn read_from_apub_id(conn: &PgConnection, object_id: &Url) -> Result<Self, Error> {
|
||||||
|
use lemmy_db_schema::schema::person::dsl::*;
|
||||||
|
person
|
||||||
|
.filter(deleted.eq(false))
|
||||||
|
.filter(actor_id.eq(object_id))
|
||||||
|
.first::<Self>(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn upsert(conn: &PgConnection, person_form: &PersonForm) -> Result<Person, Error> {
|
||||||
|
insert_into(person)
|
||||||
|
.values(person_form)
|
||||||
|
.on_conflict(actor_id)
|
||||||
|
.do_update()
|
||||||
|
.set(person_form)
|
||||||
|
.get_result::<Self>(conn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait Person_ {
|
||||||
|
fn register(conn: &PgConnection, form: &PersonForm) -> Result<Person, Error>;
|
||||||
|
fn update_password(conn: &PgConnection, person_id: i32, new_password: &str)
|
||||||
|
-> Result<Person, Error>;
|
||||||
|
fn read_from_name(conn: &PgConnection, from_name: &str) -> Result<Person, Error>;
|
||||||
|
fn add_admin(conn: &PgConnection, person_id: i32, added: bool) -> Result<Person, Error>;
|
||||||
|
fn ban_person(conn: &PgConnection, person_id: i32, ban: bool) -> Result<Person, Error>;
|
||||||
|
fn find_by_email_or_name(
|
||||||
|
conn: &PgConnection,
|
||||||
|
name_or_email: &str,
|
||||||
|
) -> Result<Person, Error>;
|
||||||
|
fn find_by_name(conn: &PgConnection, name: &str) -> Result<Person, Error>;
|
||||||
|
fn find_by_email(conn: &PgConnection, from_email: &str) -> Result<Person, Error>;
|
||||||
|
fn get_profile_url(&self, hostname: &str) -> String;
|
||||||
|
fn mark_as_updated(conn: &PgConnection, person_id: i32) -> Result<Person, Error>;
|
||||||
|
fn delete_account(conn: &PgConnection, person_id: i32) -> Result<Person, Error>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Person_ for Person {
|
||||||
|
fn register(conn: &PgConnection, form: &PersonForm) -> Result<Self, Error> {
|
||||||
|
let mut edited_person = form.clone();
|
||||||
|
let password_hash =
|
||||||
|
hash(&form.password_encrypted, DEFAULT_COST).expect("Couldn't hash password");
|
||||||
|
edited_person.password_encrypted = password_hash;
|
||||||
|
|
||||||
|
Self::create(&conn, &edited_person)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO do more individual updates like these
|
||||||
|
fn update_password(conn: &PgConnection, person_id: i32, new_password: &str) -> Result<Self, Error> {
|
||||||
|
let password_hash = hash(new_password, DEFAULT_COST).expect("Couldn't hash password");
|
||||||
|
|
||||||
|
diesel::update(person.find(person_id))
|
||||||
|
.set((
|
||||||
|
password_encrypted.eq(password_hash),
|
||||||
|
updated.eq(naive_now()),
|
||||||
|
))
|
||||||
|
.get_result::<Self>(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_from_name(conn: &PgConnection, from_name: &str) -> Result<Self, Error> {
|
||||||
|
person
|
||||||
|
.filter(local.eq(true))
|
||||||
|
.filter(deleted.eq(false))
|
||||||
|
.filter(name.eq(from_name))
|
||||||
|
.first::<Self>(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_admin(conn: &PgConnection, person_id: i32, added: bool) -> Result<Self, Error> {
|
||||||
|
diesel::update(person.find(person_id))
|
||||||
|
.set(admin.eq(added))
|
||||||
|
.get_result::<Self>(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ban_person(conn: &PgConnection, person_id: i32, ban: bool) -> Result<Self, Error> {
|
||||||
|
diesel::update(person.find(person_id))
|
||||||
|
.set(banned.eq(ban))
|
||||||
|
.get_result::<Self>(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn find_by_email_or_name(
|
||||||
|
conn: &PgConnection,
|
||||||
|
name_or_email: &str,
|
||||||
|
) -> Result<Self, Error> {
|
||||||
|
if is_email_regex(name_or_email) {
|
||||||
|
Self::find_by_email(conn, name_or_email)
|
||||||
|
} else {
|
||||||
|
Self::find_by_name(conn, name_or_email)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn find_by_name(conn: &PgConnection, name: &str) -> Result<Person, Error> {
|
||||||
|
person
|
||||||
|
.filter(deleted.eq(false))
|
||||||
|
.filter(local.eq(true))
|
||||||
|
.filter(name.ilike(name))
|
||||||
|
.first::<Person>(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn find_by_email(conn: &PgConnection, from_email: &str) -> Result<Person, Error> {
|
||||||
|
person
|
||||||
|
.filter(deleted.eq(false))
|
||||||
|
.filter(local.eq(true))
|
||||||
|
.filter(email.eq(from_email))
|
||||||
|
.first::<Person>(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_profile_url(&self, hostname: &str) -> String {
|
||||||
|
format!(
|
||||||
|
"{}://{}/u/{}",
|
||||||
|
Settings::get().get_protocol_string(),
|
||||||
|
hostname,
|
||||||
|
self.name
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn mark_as_updated(conn: &PgConnection, person_id: i32) -> Result<Person, Error> {
|
||||||
|
diesel::update(person.find(person_id))
|
||||||
|
.set((last_refreshed_at.eq(naive_now()),))
|
||||||
|
.get_result::<Self>(conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_account(conn: &PgConnection, person_id: i32) -> Result<Person, Error> {
|
||||||
|
diesel::update(person.find(person_id))
|
||||||
|
.set((
|
||||||
|
preferred_username.eq::<Option<String>>(None),
|
||||||
|
email.eq::<Option<String>>(None),
|
||||||
|
matrix_user_id.eq::<Option<String>>(None),
|
||||||
|
bio.eq::<Option<String>>(None),
|
||||||
|
deleted.eq(true),
|
||||||
|
updated.eq(naive_now()),
|
||||||
|
))
|
||||||
|
.get_result::<Self>(conn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::{establish_unpooled_connection, source::person::*, ListingType, SortType};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_crud() {
|
||||||
|
let conn = establish_unpooled_connection();
|
||||||
|
|
||||||
|
let new_person = PersonForm {
|
||||||
|
name: "thommy".into(),
|
||||||
|
preferred_username: None,
|
||||||
|
avatar: None,
|
||||||
|
banner: None,
|
||||||
|
banned: Some(false),
|
||||||
|
deleted: false,
|
||||||
|
published: None,
|
||||||
|
updated: None,
|
||||||
|
actor_id: None,
|
||||||
|
bio: None,
|
||||||
|
local: true,
|
||||||
|
private_key: None,
|
||||||
|
public_key: None,
|
||||||
|
last_refreshed_at: None,
|
||||||
|
inbox_url: None,
|
||||||
|
shared_inbox_url: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let inserted_person = Person::create(&conn, &new_person).unwrap();
|
||||||
|
|
||||||
|
let expected_person = Person {
|
||||||
|
id: inserted_person.id,
|
||||||
|
name: "thommy".into(),
|
||||||
|
preferred_username: None,
|
||||||
|
avatar: None,
|
||||||
|
banner: None,
|
||||||
|
banned: false,
|
||||||
|
deleted: false,
|
||||||
|
published: inserted_person.published,
|
||||||
|
updated: None,
|
||||||
|
actor_id: inserted_person.actor_id.to_owned(),
|
||||||
|
bio: None,
|
||||||
|
local: true,
|
||||||
|
private_key: None,
|
||||||
|
public_key: None,
|
||||||
|
last_refreshed_at: inserted_person.published,
|
||||||
|
deleted: false,
|
||||||
|
inbox_url: inserted_person.inbox_url.to_owned(),
|
||||||
|
shared_inbox_url: 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();
|
||||||
|
|
||||||
|
assert_eq!(expected_person, read_person);
|
||||||
|
assert_eq!(expected_person, inserted_person);
|
||||||
|
assert_eq!(expected_person, updated_person);
|
||||||
|
assert_eq!(1, num_deleted);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,57 +1,57 @@
|
||||||
use crate::Crud;
|
use crate::Crud;
|
||||||
use diesel::{dsl::*, result::Error, *};
|
use diesel::{dsl::*, result::Error, *};
|
||||||
use lemmy_db_schema::source::user_mention::*;
|
use lemmy_db_schema::source::person_mention::*;
|
||||||
|
|
||||||
impl Crud<UserMentionForm> for UserMention {
|
impl Crud<PersonMentionForm> for PersonMention {
|
||||||
fn read(conn: &PgConnection, user_mention_id: i32) -> Result<Self, Error> {
|
fn read(conn: &PgConnection, person_mention_id: i32) -> Result<Self, Error> {
|
||||||
use lemmy_db_schema::schema::user_mention::dsl::*;
|
use lemmy_db_schema::schema::person_mention::dsl::*;
|
||||||
user_mention.find(user_mention_id).first::<Self>(conn)
|
person_mention.find(person_mention_id).first::<Self>(conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create(conn: &PgConnection, user_mention_form: &UserMentionForm) -> Result<Self, Error> {
|
fn create(conn: &PgConnection, person_mention_form: &PersonMentionForm) -> Result<Self, Error> {
|
||||||
use lemmy_db_schema::schema::user_mention::dsl::*;
|
use lemmy_db_schema::schema::person_mention::dsl::*;
|
||||||
// since the return here isnt utilized, we dont need to do an update
|
// since the return here isnt utilized, we dont need to do an update
|
||||||
// but get_result doesnt return the existing row here
|
// but get_result doesnt return the existing row here
|
||||||
insert_into(user_mention)
|
insert_into(person_mention)
|
||||||
.values(user_mention_form)
|
.values(person_mention_form)
|
||||||
.on_conflict((recipient_id, comment_id))
|
.on_conflict((recipient_id, comment_id))
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(user_mention_form)
|
.set(person_mention_form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(
|
fn update(
|
||||||
conn: &PgConnection,
|
conn: &PgConnection,
|
||||||
user_mention_id: i32,
|
person_mention_id: i32,
|
||||||
user_mention_form: &UserMentionForm,
|
person_mention_form: &PersonMentionForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use lemmy_db_schema::schema::user_mention::dsl::*;
|
use lemmy_db_schema::schema::person_mention::dsl::*;
|
||||||
diesel::update(user_mention.find(user_mention_id))
|
diesel::update(person_mention.find(person_mention_id))
|
||||||
.set(user_mention_form)
|
.set(person_mention_form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait UserMention_ {
|
pub trait PersonMention_ {
|
||||||
fn update_read(
|
fn update_read(
|
||||||
conn: &PgConnection,
|
conn: &PgConnection,
|
||||||
user_mention_id: i32,
|
person_mention_id: i32,
|
||||||
new_read: bool,
|
new_read: bool,
|
||||||
) -> Result<UserMention, Error>;
|
) -> Result<PersonMention, Error>;
|
||||||
fn mark_all_as_read(
|
fn mark_all_as_read(
|
||||||
conn: &PgConnection,
|
conn: &PgConnection,
|
||||||
for_recipient_id: i32,
|
for_recipient_id: i32,
|
||||||
) -> Result<Vec<UserMention>, Error>;
|
) -> Result<Vec<PersonMention>, Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UserMention_ for UserMention {
|
impl PersonMention_ for PersonMention {
|
||||||
fn update_read(
|
fn update_read(
|
||||||
conn: &PgConnection,
|
conn: &PgConnection,
|
||||||
user_mention_id: i32,
|
person_mention_id: i32,
|
||||||
new_read: bool,
|
new_read: bool,
|
||||||
) -> Result<UserMention, Error> {
|
) -> Result<PersonMention, Error> {
|
||||||
use lemmy_db_schema::schema::user_mention::dsl::*;
|
use lemmy_db_schema::schema::person_mention::dsl::*;
|
||||||
diesel::update(user_mention.find(user_mention_id))
|
diesel::update(person_mention.find(person_mention_id))
|
||||||
.set(read.eq(new_read))
|
.set(read.eq(new_read))
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
}
|
}
|
||||||
|
@ -59,10 +59,10 @@ impl UserMention_ for UserMention {
|
||||||
fn mark_all_as_read(
|
fn mark_all_as_read(
|
||||||
conn: &PgConnection,
|
conn: &PgConnection,
|
||||||
for_recipient_id: i32,
|
for_recipient_id: i32,
|
||||||
) -> Result<Vec<UserMention>, Error> {
|
) -> Result<Vec<PersonMention>, Error> {
|
||||||
use lemmy_db_schema::schema::user_mention::dsl::*;
|
use lemmy_db_schema::schema::person_mention::dsl::*;
|
||||||
diesel::update(
|
diesel::update(
|
||||||
user_mention
|
person_mention
|
||||||
.filter(recipient_id.eq(for_recipient_id))
|
.filter(recipient_id.eq(for_recipient_id))
|
||||||
.filter(read.eq(false)),
|
.filter(read.eq(false)),
|
||||||
)
|
)
|
||||||
|
@ -78,33 +78,23 @@ mod tests {
|
||||||
comment::*,
|
comment::*,
|
||||||
community::{Community, CommunityForm},
|
community::{Community, CommunityForm},
|
||||||
post::*,
|
post::*,
|
||||||
user::*,
|
person::*,
|
||||||
user_mention::*,
|
person_mention::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_crud() {
|
fn test_crud() {
|
||||||
let conn = establish_unpooled_connection();
|
let conn = establish_unpooled_connection();
|
||||||
|
|
||||||
let new_user = UserForm {
|
let new_person = PersonForm {
|
||||||
name: "terrylake".into(),
|
name: "terrylake".into(),
|
||||||
preferred_username: None,
|
preferred_username: None,
|
||||||
password_encrypted: "nope".into(),
|
|
||||||
email: None,
|
|
||||||
matrix_user_id: None,
|
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
|
||||||
banned: Some(false),
|
banned: Some(false),
|
||||||
|
deleted: false,
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
|
||||||
theme: "browser".into(),
|
|
||||||
default_sort_type: SortType::Hot as i16,
|
|
||||||
default_listing_type: ListingType::Subscribed as i16,
|
|
||||||
lang: "browser".into(),
|
|
||||||
show_avatars: true,
|
|
||||||
send_notifications_to_email: false,
|
|
||||||
actor_id: None,
|
actor_id: None,
|
||||||
bio: None,
|
bio: None,
|
||||||
local: true,
|
local: true,
|
||||||
|
@ -115,27 +105,17 @@ mod tests {
|
||||||
shared_inbox_url: None,
|
shared_inbox_url: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_user = User_::create(&conn, &new_user).unwrap();
|
let inserted_person = Person::create(&conn, &new_person).unwrap();
|
||||||
|
|
||||||
let recipient_form = UserForm {
|
let recipient_form = PersonForm {
|
||||||
name: "terrylakes recipient".into(),
|
name: "terrylakes recipient".into(),
|
||||||
preferred_username: None,
|
preferred_username: None,
|
||||||
password_encrypted: "nope".into(),
|
|
||||||
email: None,
|
|
||||||
matrix_user_id: None,
|
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
|
||||||
banned: Some(false),
|
banned: Some(false),
|
||||||
|
deleted: false,
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
|
||||||
theme: "browser".into(),
|
|
||||||
default_sort_type: SortType::Hot as i16,
|
|
||||||
default_listing_type: ListingType::Subscribed as i16,
|
|
||||||
lang: "browser".into(),
|
|
||||||
show_avatars: true,
|
|
||||||
send_notifications_to_email: false,
|
|
||||||
actor_id: None,
|
actor_id: None,
|
||||||
bio: None,
|
bio: None,
|
||||||
local: true,
|
local: true,
|
||||||
|
@ -146,13 +126,13 @@ mod tests {
|
||||||
shared_inbox_url: None,
|
shared_inbox_url: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_recipient = User_::create(&conn, &recipient_form).unwrap();
|
let inserted_recipient = Person::create(&conn, &recipient_form).unwrap();
|
||||||
|
|
||||||
let new_community = CommunityForm {
|
let new_community = CommunityForm {
|
||||||
name: "test community lake".to_string(),
|
name: "test community lake".to_string(),
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
description: None,
|
description: None,
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
|
@ -174,7 +154,7 @@ mod tests {
|
||||||
|
|
||||||
let new_post = PostForm {
|
let new_post = PostForm {
|
||||||
name: "A test post".into(),
|
name: "A test post".into(),
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
url: None,
|
url: None,
|
||||||
body: None,
|
body: None,
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
|
@ -197,7 +177,7 @@ mod tests {
|
||||||
|
|
||||||
let comment_form = CommentForm {
|
let comment_form = CommentForm {
|
||||||
content: "A test comment".into(),
|
content: "A test comment".into(),
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
|
@ -211,15 +191,15 @@ mod tests {
|
||||||
|
|
||||||
let inserted_comment = Comment::create(&conn, &comment_form).unwrap();
|
let inserted_comment = Comment::create(&conn, &comment_form).unwrap();
|
||||||
|
|
||||||
let user_mention_form = UserMentionForm {
|
let person_mention_form = PersonMentionForm {
|
||||||
recipient_id: inserted_recipient.id,
|
recipient_id: inserted_recipient.id,
|
||||||
comment_id: inserted_comment.id,
|
comment_id: inserted_comment.id,
|
||||||
read: None,
|
read: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_mention = UserMention::create(&conn, &user_mention_form).unwrap();
|
let inserted_mention = PersonMention::create(&conn, &person_mention_form).unwrap();
|
||||||
|
|
||||||
let expected_mention = UserMention {
|
let expected_mention = PersonMention {
|
||||||
id: inserted_mention.id,
|
id: inserted_mention.id,
|
||||||
recipient_id: inserted_mention.recipient_id,
|
recipient_id: inserted_mention.recipient_id,
|
||||||
comment_id: inserted_mention.comment_id,
|
comment_id: inserted_mention.comment_id,
|
||||||
|
@ -227,14 +207,14 @@ mod tests {
|
||||||
published: inserted_mention.published,
|
published: inserted_mention.published,
|
||||||
};
|
};
|
||||||
|
|
||||||
let read_mention = UserMention::read(&conn, inserted_mention.id).unwrap();
|
let read_mention = PersonMention::read(&conn, inserted_mention.id).unwrap();
|
||||||
let updated_mention =
|
let updated_mention =
|
||||||
UserMention::update(&conn, inserted_mention.id, &user_mention_form).unwrap();
|
PersonMention::update(&conn, inserted_mention.id, &person_mention_form).unwrap();
|
||||||
Comment::delete(&conn, inserted_comment.id).unwrap();
|
Comment::delete(&conn, inserted_comment.id).unwrap();
|
||||||
Post::delete(&conn, inserted_post.id).unwrap();
|
Post::delete(&conn, inserted_post.id).unwrap();
|
||||||
Community::delete(&conn, inserted_community.id).unwrap();
|
Community::delete(&conn, inserted_community.id).unwrap();
|
||||||
User_::delete(&conn, inserted_user.id).unwrap();
|
Person::delete(&conn, inserted_person.id).unwrap();
|
||||||
User_::delete(&conn, inserted_recipient.id).unwrap();
|
Person::delete(&conn, inserted_recipient.id).unwrap();
|
||||||
|
|
||||||
assert_eq!(expected_mention, read_mention);
|
assert_eq!(expected_mention, read_mention);
|
||||||
assert_eq!(expected_mention, inserted_mention);
|
assert_eq!(expected_mention, inserted_mention);
|
|
@ -54,7 +54,7 @@ pub trait Post_ {
|
||||||
) -> Result<Vec<Post>, Error>;
|
) -> Result<Vec<Post>, Error>;
|
||||||
fn update_locked(conn: &PgConnection, post_id: i32, new_locked: bool) -> Result<Post, Error>;
|
fn update_locked(conn: &PgConnection, post_id: i32, new_locked: bool) -> Result<Post, Error>;
|
||||||
fn update_stickied(conn: &PgConnection, post_id: i32, new_stickied: bool) -> Result<Post, Error>;
|
fn update_stickied(conn: &PgConnection, post_id: i32, new_stickied: bool) -> Result<Post, Error>;
|
||||||
fn is_post_creator(user_id: i32, post_creator_id: i32) -> bool;
|
fn is_post_creator(person_id: i32, post_creator_id: i32) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Post_ for Post {
|
impl Post_ for Post {
|
||||||
|
@ -141,8 +141,8 @@ impl Post_ for Post {
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_post_creator(user_id: i32, post_creator_id: i32) -> bool {
|
fn is_post_creator(person_id: i32, post_creator_id: i32) -> bool {
|
||||||
user_id == post_creator_id
|
person_id == post_creator_id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,17 +168,17 @@ impl Likeable<PostLikeForm> for PostLike {
|
||||||
use lemmy_db_schema::schema::post_like::dsl::*;
|
use lemmy_db_schema::schema::post_like::dsl::*;
|
||||||
insert_into(post_like)
|
insert_into(post_like)
|
||||||
.values(post_like_form)
|
.values(post_like_form)
|
||||||
.on_conflict((post_id, user_id))
|
.on_conflict((post_id, person_id))
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(post_like_form)
|
.set(post_like_form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
}
|
}
|
||||||
fn remove(conn: &PgConnection, user_id: i32, post_id: i32) -> Result<usize, Error> {
|
fn remove(conn: &PgConnection, person_id: i32, post_id: i32) -> Result<usize, Error> {
|
||||||
use lemmy_db_schema::schema::post_like::dsl;
|
use lemmy_db_schema::schema::post_like::dsl;
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
dsl::post_like
|
dsl::post_like
|
||||||
.filter(dsl::post_id.eq(post_id))
|
.filter(dsl::post_id.eq(post_id))
|
||||||
.filter(dsl::user_id.eq(user_id)),
|
.filter(dsl::person_id.eq(person_id)),
|
||||||
)
|
)
|
||||||
.execute(conn)
|
.execute(conn)
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,7 @@ impl Saveable<PostSavedForm> for PostSaved {
|
||||||
use lemmy_db_schema::schema::post_saved::dsl::*;
|
use lemmy_db_schema::schema::post_saved::dsl::*;
|
||||||
insert_into(post_saved)
|
insert_into(post_saved)
|
||||||
.values(post_saved_form)
|
.values(post_saved_form)
|
||||||
.on_conflict((post_id, user_id))
|
.on_conflict((post_id, person_id))
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(post_saved_form)
|
.set(post_saved_form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -199,7 +199,7 @@ impl Saveable<PostSavedForm> for PostSaved {
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
post_saved
|
post_saved
|
||||||
.filter(post_id.eq(post_saved_form.post_id))
|
.filter(post_id.eq(post_saved_form.post_id))
|
||||||
.filter(user_id.eq(post_saved_form.user_id)),
|
.filter(person_id.eq(post_saved_form.person_id)),
|
||||||
)
|
)
|
||||||
.execute(conn)
|
.execute(conn)
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ impl Readable<PostReadForm> for PostRead {
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
post_read
|
post_read
|
||||||
.filter(post_id.eq(post_read_form.post_id))
|
.filter(post_id.eq(post_read_form.post_id))
|
||||||
.filter(user_id.eq(post_read_form.user_id)),
|
.filter(person_id.eq(post_read_form.person_id)),
|
||||||
)
|
)
|
||||||
.execute(conn)
|
.execute(conn)
|
||||||
}
|
}
|
||||||
|
@ -229,32 +229,22 @@ mod tests {
|
||||||
use crate::{establish_unpooled_connection, source::post::*, ListingType, SortType};
|
use crate::{establish_unpooled_connection, source::post::*, ListingType, SortType};
|
||||||
use lemmy_db_schema::source::{
|
use lemmy_db_schema::source::{
|
||||||
community::{Community, CommunityForm},
|
community::{Community, CommunityForm},
|
||||||
user::*,
|
person::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_crud() {
|
fn test_crud() {
|
||||||
let conn = establish_unpooled_connection();
|
let conn = establish_unpooled_connection();
|
||||||
|
|
||||||
let new_user = UserForm {
|
let new_person = PersonForm {
|
||||||
name: "jim".into(),
|
name: "jim".into(),
|
||||||
preferred_username: None,
|
preferred_username: None,
|
||||||
password_encrypted: "nope".into(),
|
|
||||||
email: None,
|
|
||||||
matrix_user_id: None,
|
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
|
||||||
banned: Some(false),
|
banned: Some(false),
|
||||||
|
deleted: false,
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
|
||||||
theme: "browser".into(),
|
|
||||||
default_sort_type: SortType::Hot as i16,
|
|
||||||
default_listing_type: ListingType::Subscribed as i16,
|
|
||||||
lang: "browser".into(),
|
|
||||||
show_avatars: true,
|
|
||||||
send_notifications_to_email: false,
|
|
||||||
actor_id: None,
|
actor_id: None,
|
||||||
bio: None,
|
bio: None,
|
||||||
local: true,
|
local: true,
|
||||||
|
@ -265,13 +255,13 @@ mod tests {
|
||||||
shared_inbox_url: None,
|
shared_inbox_url: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_user = User_::create(&conn, &new_user).unwrap();
|
let inserted_person = Person::create(&conn, &new_person).unwrap();
|
||||||
|
|
||||||
let new_community = CommunityForm {
|
let new_community = CommunityForm {
|
||||||
name: "test community_3".to_string(),
|
name: "test community_3".to_string(),
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
description: None,
|
description: None,
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
|
@ -295,7 +285,7 @@ mod tests {
|
||||||
name: "A test post".into(),
|
name: "A test post".into(),
|
||||||
url: None,
|
url: None,
|
||||||
body: None,
|
body: None,
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
|
@ -319,7 +309,7 @@ mod tests {
|
||||||
name: "A test post".into(),
|
name: "A test post".into(),
|
||||||
url: None,
|
url: None,
|
||||||
body: None,
|
body: None,
|
||||||
creator_id: inserted_user.id,
|
creator_id: inserted_person.id,
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
published: inserted_post.published,
|
published: inserted_post.published,
|
||||||
removed: false,
|
removed: false,
|
||||||
|
@ -339,7 +329,7 @@ mod tests {
|
||||||
// Post Like
|
// Post Like
|
||||||
let post_like_form = PostLikeForm {
|
let post_like_form = PostLikeForm {
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
user_id: inserted_user.id,
|
person_id: inserted_person.id,
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -348,7 +338,7 @@ mod tests {
|
||||||
let expected_post_like = PostLike {
|
let expected_post_like = PostLike {
|
||||||
id: inserted_post_like.id,
|
id: inserted_post_like.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
user_id: inserted_user.id,
|
person_id: inserted_person.id,
|
||||||
published: inserted_post_like.published,
|
published: inserted_post_like.published,
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
@ -356,7 +346,7 @@ mod tests {
|
||||||
// Post Save
|
// Post Save
|
||||||
let post_saved_form = PostSavedForm {
|
let post_saved_form = PostSavedForm {
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
user_id: inserted_user.id,
|
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();
|
||||||
|
@ -364,14 +354,14 @@ mod tests {
|
||||||
let expected_post_saved = PostSaved {
|
let expected_post_saved = PostSaved {
|
||||||
id: inserted_post_saved.id,
|
id: inserted_post_saved.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
user_id: inserted_user.id,
|
person_id: inserted_person.id,
|
||||||
published: inserted_post_saved.published,
|
published: inserted_post_saved.published,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Post Read
|
// Post Read
|
||||||
let post_read_form = PostReadForm {
|
let post_read_form = PostReadForm {
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
user_id: inserted_user.id,
|
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();
|
||||||
|
@ -379,18 +369,18 @@ mod tests {
|
||||||
let expected_post_read = PostRead {
|
let expected_post_read = PostRead {
|
||||||
id: inserted_post_read.id,
|
id: inserted_post_read.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
user_id: inserted_user.id,
|
person_id: inserted_person.id,
|
||||||
published: inserted_post_read.published,
|
published: inserted_post_read.published,
|
||||||
};
|
};
|
||||||
|
|
||||||
let read_post = Post::read(&conn, inserted_post.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 updated_post = Post::update(&conn, inserted_post.id, &new_post).unwrap();
|
||||||
let like_removed = PostLike::remove(&conn, inserted_user.id, inserted_post.id).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 saved_removed = PostSaved::unsave(&conn, &post_saved_form).unwrap();
|
||||||
let read_removed = PostRead::mark_as_unread(&conn, &post_read_form).unwrap();
|
let read_removed = PostRead::mark_as_unread(&conn, &post_read_form).unwrap();
|
||||||
let num_deleted = Post::delete(&conn, inserted_post.id).unwrap();
|
let num_deleted = Post::delete(&conn, inserted_post.id).unwrap();
|
||||||
Community::delete(&conn, inserted_community.id).unwrap();
|
Community::delete(&conn, inserted_community.id).unwrap();
|
||||||
User_::delete(&conn, inserted_user.id).unwrap();
|
Person::delete(&conn, inserted_person.id).unwrap();
|
||||||
|
|
||||||
assert_eq!(expected_post, read_post);
|
assert_eq!(expected_post, read_post);
|
||||||
assert_eq!(expected_post, inserted_post);
|
assert_eq!(expected_post, inserted_post);
|
||||||
|
|
|
@ -146,31 +146,21 @@ mod tests {
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::source::{private_message::*, user::*};
|
use lemmy_db_schema::source::{private_message::*, person::*};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_crud() {
|
fn test_crud() {
|
||||||
let conn = establish_unpooled_connection();
|
let conn = establish_unpooled_connection();
|
||||||
|
|
||||||
let creator_form = UserForm {
|
let creator_form = PersonForm {
|
||||||
name: "creator_pm".into(),
|
name: "creator_pm".into(),
|
||||||
preferred_username: None,
|
preferred_username: None,
|
||||||
password_encrypted: "nope".into(),
|
|
||||||
email: None,
|
|
||||||
matrix_user_id: None,
|
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
|
||||||
banned: Some(false),
|
banned: Some(false),
|
||||||
|
deleted: false,
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
|
||||||
theme: "browser".into(),
|
|
||||||
default_sort_type: SortType::Hot as i16,
|
|
||||||
default_listing_type: ListingType::Subscribed as i16,
|
|
||||||
lang: "browser".into(),
|
|
||||||
show_avatars: true,
|
|
||||||
send_notifications_to_email: false,
|
|
||||||
actor_id: None,
|
actor_id: None,
|
||||||
bio: None,
|
bio: None,
|
||||||
local: true,
|
local: true,
|
||||||
|
@ -181,27 +171,17 @@ mod tests {
|
||||||
shared_inbox_url: None,
|
shared_inbox_url: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_creator = User_::create(&conn, &creator_form).unwrap();
|
let inserted_creator = Person::create(&conn, &creator_form).unwrap();
|
||||||
|
|
||||||
let recipient_form = UserForm {
|
let recipient_form = PersonForm {
|
||||||
name: "recipient_pm".into(),
|
name: "recipient_pm".into(),
|
||||||
preferred_username: None,
|
preferred_username: None,
|
||||||
password_encrypted: "nope".into(),
|
|
||||||
email: None,
|
|
||||||
matrix_user_id: None,
|
|
||||||
avatar: None,
|
avatar: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
admin: false,
|
|
||||||
banned: Some(false),
|
banned: Some(false),
|
||||||
|
deleted: false,
|
||||||
published: None,
|
published: None,
|
||||||
updated: None,
|
updated: None,
|
||||||
show_nsfw: false,
|
|
||||||
theme: "browser".into(),
|
|
||||||
default_sort_type: SortType::Hot as i16,
|
|
||||||
default_listing_type: ListingType::Subscribed as i16,
|
|
||||||
lang: "browser".into(),
|
|
||||||
show_avatars: true,
|
|
||||||
send_notifications_to_email: false,
|
|
||||||
actor_id: None,
|
actor_id: None,
|
||||||
bio: None,
|
bio: None,
|
||||||
local: true,
|
local: true,
|
||||||
|
@ -212,7 +192,7 @@ mod tests {
|
||||||
shared_inbox_url: None,
|
shared_inbox_url: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_recipient = User_::create(&conn, &recipient_form).unwrap();
|
let inserted_recipient = Person::create(&conn, &recipient_form).unwrap();
|
||||||
|
|
||||||
let private_message_form = PrivateMessageForm {
|
let private_message_form = PrivateMessageForm {
|
||||||
content: "A test private message".into(),
|
content: "A test private message".into(),
|
||||||
|
@ -248,8 +228,8 @@ mod tests {
|
||||||
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 =
|
let marked_read_private_message =
|
||||||
PrivateMessage::update_read(&conn, inserted_private_message.id, true).unwrap();
|
PrivateMessage::update_read(&conn, inserted_private_message.id, true).unwrap();
|
||||||
User_::delete(&conn, inserted_creator.id).unwrap();
|
Person::delete(&conn, inserted_creator.id).unwrap();
|
||||||
User_::delete(&conn, inserted_recipient.id).unwrap();
|
Person::delete(&conn, inserted_recipient.id).unwrap();
|
||||||
|
|
||||||
assert_eq!(expected_private_message, read_private_message);
|
assert_eq!(expected_private_message, read_private_message);
|
||||||
assert_eq!(expected_private_message, updated_private_message);
|
assert_eq!(expected_private_message, updated_private_message);
|
||||||
|
|
|
@ -1,458 +0,0 @@
|
||||||
use crate::{is_email_regex, ApubObject, Crud, ToSafeSettings};
|
|
||||||
use bcrypt::{hash, DEFAULT_COST};
|
|
||||||
use diesel::{dsl::*, result::Error, *};
|
|
||||||
use lemmy_db_schema::{
|
|
||||||
naive_now,
|
|
||||||
schema::user_::dsl::*,
|
|
||||||
source::user::{UserForm, UserSafeSettings, User_},
|
|
||||||
Url,
|
|
||||||
};
|
|
||||||
use lemmy_utils::settings::Settings;
|
|
||||||
|
|
||||||
mod safe_type {
|
|
||||||
use crate::ToSafe;
|
|
||||||
use lemmy_db_schema::{schema::user_::columns::*, source::user::User_};
|
|
||||||
|
|
||||||
type Columns = (
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
preferred_username,
|
|
||||||
avatar,
|
|
||||||
admin,
|
|
||||||
banned,
|
|
||||||
published,
|
|
||||||
updated,
|
|
||||||
matrix_user_id,
|
|
||||||
actor_id,
|
|
||||||
bio,
|
|
||||||
local,
|
|
||||||
banner,
|
|
||||||
deleted,
|
|
||||||
inbox_url,
|
|
||||||
shared_inbox_url,
|
|
||||||
);
|
|
||||||
|
|
||||||
impl ToSafe for User_ {
|
|
||||||
type SafeColumns = Columns;
|
|
||||||
fn safe_columns_tuple() -> Self::SafeColumns {
|
|
||||||
(
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
preferred_username,
|
|
||||||
avatar,
|
|
||||||
admin,
|
|
||||||
banned,
|
|
||||||
published,
|
|
||||||
updated,
|
|
||||||
matrix_user_id,
|
|
||||||
actor_id,
|
|
||||||
bio,
|
|
||||||
local,
|
|
||||||
banner,
|
|
||||||
deleted,
|
|
||||||
inbox_url,
|
|
||||||
shared_inbox_url,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mod safe_type_alias_1 {
|
|
||||||
use crate::ToSafe;
|
|
||||||
use lemmy_db_schema::{schema::user_alias_1::columns::*, source::user::UserAlias1};
|
|
||||||
|
|
||||||
type Columns = (
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
preferred_username,
|
|
||||||
avatar,
|
|
||||||
admin,
|
|
||||||
banned,
|
|
||||||
published,
|
|
||||||
updated,
|
|
||||||
matrix_user_id,
|
|
||||||
actor_id,
|
|
||||||
bio,
|
|
||||||
local,
|
|
||||||
banner,
|
|
||||||
deleted,
|
|
||||||
);
|
|
||||||
|
|
||||||
impl ToSafe for UserAlias1 {
|
|
||||||
type SafeColumns = Columns;
|
|
||||||
fn safe_columns_tuple() -> Self::SafeColumns {
|
|
||||||
(
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
preferred_username,
|
|
||||||
avatar,
|
|
||||||
admin,
|
|
||||||
banned,
|
|
||||||
published,
|
|
||||||
updated,
|
|
||||||
matrix_user_id,
|
|
||||||
actor_id,
|
|
||||||
bio,
|
|
||||||
local,
|
|
||||||
banner,
|
|
||||||
deleted,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mod safe_type_alias_2 {
|
|
||||||
use crate::ToSafe;
|
|
||||||
use lemmy_db_schema::{schema::user_alias_2::columns::*, source::user::UserAlias2};
|
|
||||||
|
|
||||||
type Columns = (
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
preferred_username,
|
|
||||||
avatar,
|
|
||||||
admin,
|
|
||||||
banned,
|
|
||||||
published,
|
|
||||||
updated,
|
|
||||||
matrix_user_id,
|
|
||||||
actor_id,
|
|
||||||
bio,
|
|
||||||
local,
|
|
||||||
banner,
|
|
||||||
deleted,
|
|
||||||
);
|
|
||||||
|
|
||||||
impl ToSafe for UserAlias2 {
|
|
||||||
type SafeColumns = Columns;
|
|
||||||
fn safe_columns_tuple() -> Self::SafeColumns {
|
|
||||||
(
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
preferred_username,
|
|
||||||
avatar,
|
|
||||||
admin,
|
|
||||||
banned,
|
|
||||||
published,
|
|
||||||
updated,
|
|
||||||
matrix_user_id,
|
|
||||||
actor_id,
|
|
||||||
bio,
|
|
||||||
local,
|
|
||||||
banner,
|
|
||||||
deleted,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mod safe_settings_type {
|
|
||||||
use crate::ToSafeSettings;
|
|
||||||
use lemmy_db_schema::{schema::user_::columns::*, source::user::User_};
|
|
||||||
|
|
||||||
type Columns = (
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
preferred_username,
|
|
||||||
email,
|
|
||||||
avatar,
|
|
||||||
admin,
|
|
||||||
banned,
|
|
||||||
published,
|
|
||||||
updated,
|
|
||||||
show_nsfw,
|
|
||||||
theme,
|
|
||||||
default_sort_type,
|
|
||||||
default_listing_type,
|
|
||||||
lang,
|
|
||||||
show_avatars,
|
|
||||||
send_notifications_to_email,
|
|
||||||
matrix_user_id,
|
|
||||||
actor_id,
|
|
||||||
bio,
|
|
||||||
local,
|
|
||||||
last_refreshed_at,
|
|
||||||
banner,
|
|
||||||
deleted,
|
|
||||||
);
|
|
||||||
|
|
||||||
impl ToSafeSettings for User_ {
|
|
||||||
type SafeSettingsColumns = Columns;
|
|
||||||
fn safe_settings_columns_tuple() -> Self::SafeSettingsColumns {
|
|
||||||
(
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
preferred_username,
|
|
||||||
email,
|
|
||||||
avatar,
|
|
||||||
admin,
|
|
||||||
banned,
|
|
||||||
published,
|
|
||||||
updated,
|
|
||||||
show_nsfw,
|
|
||||||
theme,
|
|
||||||
default_sort_type,
|
|
||||||
default_listing_type,
|
|
||||||
lang,
|
|
||||||
show_avatars,
|
|
||||||
send_notifications_to_email,
|
|
||||||
matrix_user_id,
|
|
||||||
actor_id,
|
|
||||||
bio,
|
|
||||||
local,
|
|
||||||
last_refreshed_at,
|
|
||||||
banner,
|
|
||||||
deleted,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait UserSafeSettings_ {
|
|
||||||
fn read(conn: &PgConnection, user_id: i32) -> Result<UserSafeSettings, Error>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl UserSafeSettings_ for UserSafeSettings {
|
|
||||||
fn read(conn: &PgConnection, user_id: i32) -> Result<Self, Error> {
|
|
||||||
user_
|
|
||||||
.select(User_::safe_settings_columns_tuple())
|
|
||||||
.filter(deleted.eq(false))
|
|
||||||
.find(user_id)
|
|
||||||
.first::<Self>(conn)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Crud<UserForm> for User_ {
|
|
||||||
fn read(conn: &PgConnection, user_id: i32) -> Result<Self, Error> {
|
|
||||||
user_
|
|
||||||
.filter(deleted.eq(false))
|
|
||||||
.find(user_id)
|
|
||||||
.first::<Self>(conn)
|
|
||||||
}
|
|
||||||
fn delete(conn: &PgConnection, user_id: i32) -> Result<usize, Error> {
|
|
||||||
diesel::delete(user_.find(user_id)).execute(conn)
|
|
||||||
}
|
|
||||||
fn create(conn: &PgConnection, form: &UserForm) -> Result<Self, Error> {
|
|
||||||
insert_into(user_).values(form).get_result::<Self>(conn)
|
|
||||||
}
|
|
||||||
fn update(conn: &PgConnection, user_id: i32, form: &UserForm) -> Result<Self, Error> {
|
|
||||||
diesel::update(user_.find(user_id))
|
|
||||||
.set(form)
|
|
||||||
.get_result::<Self>(conn)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ApubObject<UserForm> for User_ {
|
|
||||||
fn read_from_apub_id(conn: &PgConnection, object_id: &Url) -> Result<Self, Error> {
|
|
||||||
use lemmy_db_schema::schema::user_::dsl::*;
|
|
||||||
user_
|
|
||||||
.filter(deleted.eq(false))
|
|
||||||
.filter(actor_id.eq(object_id))
|
|
||||||
.first::<Self>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn upsert(conn: &PgConnection, user_form: &UserForm) -> Result<User_, Error> {
|
|
||||||
insert_into(user_)
|
|
||||||
.values(user_form)
|
|
||||||
.on_conflict(actor_id)
|
|
||||||
.do_update()
|
|
||||||
.set(user_form)
|
|
||||||
.get_result::<Self>(conn)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait User {
|
|
||||||
fn register(conn: &PgConnection, form: &UserForm) -> Result<User_, Error>;
|
|
||||||
fn update_password(conn: &PgConnection, user_id: i32, new_password: &str)
|
|
||||||
-> Result<User_, Error>;
|
|
||||||
fn read_from_name(conn: &PgConnection, from_user_name: &str) -> Result<User_, Error>;
|
|
||||||
fn add_admin(conn: &PgConnection, user_id: i32, added: bool) -> Result<User_, Error>;
|
|
||||||
fn ban_user(conn: &PgConnection, user_id: i32, ban: bool) -> Result<User_, Error>;
|
|
||||||
fn find_by_email_or_username(
|
|
||||||
conn: &PgConnection,
|
|
||||||
username_or_email: &str,
|
|
||||||
) -> Result<User_, Error>;
|
|
||||||
fn find_by_username(conn: &PgConnection, username: &str) -> Result<User_, Error>;
|
|
||||||
fn find_by_email(conn: &PgConnection, from_email: &str) -> Result<User_, Error>;
|
|
||||||
fn get_profile_url(&self, hostname: &str) -> String;
|
|
||||||
fn mark_as_updated(conn: &PgConnection, user_id: i32) -> Result<User_, Error>;
|
|
||||||
fn delete_account(conn: &PgConnection, user_id: i32) -> Result<User_, Error>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl User for User_ {
|
|
||||||
fn register(conn: &PgConnection, form: &UserForm) -> Result<Self, Error> {
|
|
||||||
let mut edited_user = form.clone();
|
|
||||||
let password_hash =
|
|
||||||
hash(&form.password_encrypted, DEFAULT_COST).expect("Couldn't hash password");
|
|
||||||
edited_user.password_encrypted = password_hash;
|
|
||||||
|
|
||||||
Self::create(&conn, &edited_user)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO do more individual updates like these
|
|
||||||
fn update_password(conn: &PgConnection, user_id: i32, new_password: &str) -> Result<Self, Error> {
|
|
||||||
let password_hash = hash(new_password, DEFAULT_COST).expect("Couldn't hash password");
|
|
||||||
|
|
||||||
diesel::update(user_.find(user_id))
|
|
||||||
.set((
|
|
||||||
password_encrypted.eq(password_hash),
|
|
||||||
updated.eq(naive_now()),
|
|
||||||
))
|
|
||||||
.get_result::<Self>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn read_from_name(conn: &PgConnection, from_user_name: &str) -> Result<Self, Error> {
|
|
||||||
user_
|
|
||||||
.filter(local.eq(true))
|
|
||||||
.filter(deleted.eq(false))
|
|
||||||
.filter(name.eq(from_user_name))
|
|
||||||
.first::<Self>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn add_admin(conn: &PgConnection, user_id: i32, added: bool) -> Result<Self, Error> {
|
|
||||||
diesel::update(user_.find(user_id))
|
|
||||||
.set(admin.eq(added))
|
|
||||||
.get_result::<Self>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn ban_user(conn: &PgConnection, user_id: i32, ban: bool) -> Result<Self, Error> {
|
|
||||||
diesel::update(user_.find(user_id))
|
|
||||||
.set(banned.eq(ban))
|
|
||||||
.get_result::<Self>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_by_email_or_username(
|
|
||||||
conn: &PgConnection,
|
|
||||||
username_or_email: &str,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
if is_email_regex(username_or_email) {
|
|
||||||
Self::find_by_email(conn, username_or_email)
|
|
||||||
} else {
|
|
||||||
Self::find_by_username(conn, username_or_email)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_by_username(conn: &PgConnection, username: &str) -> Result<User_, Error> {
|
|
||||||
user_
|
|
||||||
.filter(deleted.eq(false))
|
|
||||||
.filter(local.eq(true))
|
|
||||||
.filter(name.ilike(username))
|
|
||||||
.first::<User_>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn find_by_email(conn: &PgConnection, from_email: &str) -> Result<User_, Error> {
|
|
||||||
user_
|
|
||||||
.filter(deleted.eq(false))
|
|
||||||
.filter(local.eq(true))
|
|
||||||
.filter(email.eq(from_email))
|
|
||||||
.first::<User_>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_profile_url(&self, hostname: &str) -> String {
|
|
||||||
format!(
|
|
||||||
"{}://{}/u/{}",
|
|
||||||
Settings::get().get_protocol_string(),
|
|
||||||
hostname,
|
|
||||||
self.name
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn mark_as_updated(conn: &PgConnection, user_id: i32) -> Result<User_, Error> {
|
|
||||||
diesel::update(user_.find(user_id))
|
|
||||||
.set((last_refreshed_at.eq(naive_now()),))
|
|
||||||
.get_result::<Self>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn delete_account(conn: &PgConnection, user_id: i32) -> Result<User_, Error> {
|
|
||||||
diesel::update(user_.find(user_id))
|
|
||||||
.set((
|
|
||||||
preferred_username.eq::<Option<String>>(None),
|
|
||||||
email.eq::<Option<String>>(None),
|
|
||||||
matrix_user_id.eq::<Option<String>>(None),
|
|
||||||
bio.eq::<Option<String>>(None),
|
|
||||||
deleted.eq(true),
|
|
||||||
updated.eq(naive_now()),
|
|
||||||
))
|
|
||||||
.get_result::<Self>(conn)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use crate::{establish_unpooled_connection, source::user::*, ListingType, SortType};
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_crud() {
|
|
||||||
let conn = establish_unpooled_connection();
|
|
||||||
|
|
||||||
let new_user = UserForm {
|
|
||||||
name: "thommy".into(),
|
|
||||||
preferred_username: None,
|
|
||||||
password_encrypted: "nope".into(),
|
|
||||||
email: None,
|
|
||||||
matrix_user_id: None,
|
|
||||||
avatar: None,
|
|
||||||
banner: None,
|
|
||||||
admin: false,
|
|
||||||
banned: Some(false),
|
|
||||||
published: None,
|
|
||||||
updated: None,
|
|
||||||
show_nsfw: false,
|
|
||||||
theme: "browser".into(),
|
|
||||||
default_sort_type: SortType::Hot as i16,
|
|
||||||
default_listing_type: ListingType::Subscribed as i16,
|
|
||||||
lang: "browser".into(),
|
|
||||||
show_avatars: true,
|
|
||||||
send_notifications_to_email: false,
|
|
||||||
actor_id: None,
|
|
||||||
bio: None,
|
|
||||||
local: true,
|
|
||||||
private_key: None,
|
|
||||||
public_key: None,
|
|
||||||
last_refreshed_at: None,
|
|
||||||
inbox_url: None,
|
|
||||||
shared_inbox_url: None,
|
|
||||||
};
|
|
||||||
|
|
||||||
let inserted_user = User_::create(&conn, &new_user).unwrap();
|
|
||||||
|
|
||||||
let expected_user = User_ {
|
|
||||||
id: inserted_user.id,
|
|
||||||
name: "thommy".into(),
|
|
||||||
preferred_username: None,
|
|
||||||
password_encrypted: "nope".into(),
|
|
||||||
email: None,
|
|
||||||
matrix_user_id: None,
|
|
||||||
avatar: None,
|
|
||||||
banner: None,
|
|
||||||
admin: false,
|
|
||||||
banned: false,
|
|
||||||
published: inserted_user.published,
|
|
||||||
updated: None,
|
|
||||||
show_nsfw: false,
|
|
||||||
theme: "browser".into(),
|
|
||||||
default_sort_type: SortType::Hot as i16,
|
|
||||||
default_listing_type: ListingType::Subscribed as i16,
|
|
||||||
lang: "browser".into(),
|
|
||||||
show_avatars: true,
|
|
||||||
send_notifications_to_email: false,
|
|
||||||
actor_id: inserted_user.actor_id.to_owned(),
|
|
||||||
bio: None,
|
|
||||||
local: true,
|
|
||||||
private_key: None,
|
|
||||||
public_key: None,
|
|
||||||
last_refreshed_at: inserted_user.published,
|
|
||||||
deleted: false,
|
|
||||||
inbox_url: inserted_user.inbox_url.to_owned(),
|
|
||||||
shared_inbox_url: None,
|
|
||||||
};
|
|
||||||
|
|
||||||
let read_user = User_::read(&conn, inserted_user.id).unwrap();
|
|
||||||
let updated_user = User_::update(&conn, inserted_user.id, &new_user).unwrap();
|
|
||||||
let num_deleted = User_::delete(&conn, inserted_user.id).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(expected_user, read_user);
|
|
||||||
assert_eq!(expected_user, inserted_user);
|
|
||||||
assert_eq!(expected_user, updated_user);
|
|
||||||
assert_eq!(1, num_deleted);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -41,7 +41,7 @@ table! {
|
||||||
table! {
|
table! {
|
||||||
comment_like (id) {
|
comment_like (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
user_id -> Int4,
|
person_id -> Int4,
|
||||||
comment_id -> Int4,
|
comment_id -> Int4,
|
||||||
post_id -> Int4,
|
post_id -> Int4,
|
||||||
score -> Int2,
|
score -> Int2,
|
||||||
|
@ -67,7 +67,7 @@ table! {
|
||||||
comment_saved (id) {
|
comment_saved (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
comment_id -> Int4,
|
comment_id -> Int4,
|
||||||
user_id -> Int4,
|
person_id -> Int4,
|
||||||
published -> Timestamp,
|
published -> Timestamp,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,9 +91,9 @@ table! {
|
||||||
last_refreshed_at -> Timestamp,
|
last_refreshed_at -> Timestamp,
|
||||||
icon -> Nullable<Text>,
|
icon -> Nullable<Text>,
|
||||||
banner -> Nullable<Text>,
|
banner -> Nullable<Text>,
|
||||||
followers_url -> Text,
|
followers_url -> Varchar,
|
||||||
inbox_url -> Text,
|
inbox_url -> Varchar,
|
||||||
shared_inbox_url -> Nullable<Text>,
|
shared_inbox_url -> Nullable<Varchar>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ table! {
|
||||||
community_follower (id) {
|
community_follower (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
community_id -> Int4,
|
community_id -> Int4,
|
||||||
user_id -> Int4,
|
person_id -> Int4,
|
||||||
published -> Timestamp,
|
published -> Timestamp,
|
||||||
pending -> Nullable<Bool>,
|
pending -> Nullable<Bool>,
|
||||||
}
|
}
|
||||||
|
@ -126,25 +126,43 @@ table! {
|
||||||
community_moderator (id) {
|
community_moderator (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
community_id -> Int4,
|
community_id -> Int4,
|
||||||
user_id -> Int4,
|
person_id -> Int4,
|
||||||
published -> Timestamp,
|
published -> Timestamp,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
community_user_ban (id) {
|
community_person_ban (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
community_id -> Int4,
|
community_id -> Int4,
|
||||||
user_id -> Int4,
|
person_id -> Int4,
|
||||||
published -> Timestamp,
|
published -> Timestamp,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table! {
|
||||||
|
local_user (id) {
|
||||||
|
id -> Int4,
|
||||||
|
person_id -> Int4,
|
||||||
|
password_encrypted -> Text,
|
||||||
|
email -> Nullable<Text>,
|
||||||
|
admin -> Bool,
|
||||||
|
show_nsfw -> Bool,
|
||||||
|
theme -> Varchar,
|
||||||
|
default_sort_type -> Int2,
|
||||||
|
default_listing_type -> Int2,
|
||||||
|
lang -> Varchar,
|
||||||
|
show_avatars -> Bool,
|
||||||
|
send_notifications_to_email -> Bool,
|
||||||
|
matrix_user_id -> Nullable<Text>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
mod_add (id) {
|
mod_add (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
mod_user_id -> Int4,
|
mod_person_id -> Int4,
|
||||||
other_user_id -> Int4,
|
other_person_id -> Int4,
|
||||||
removed -> Nullable<Bool>,
|
removed -> Nullable<Bool>,
|
||||||
when_ -> Timestamp,
|
when_ -> Timestamp,
|
||||||
}
|
}
|
||||||
|
@ -153,8 +171,8 @@ table! {
|
||||||
table! {
|
table! {
|
||||||
mod_add_community (id) {
|
mod_add_community (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
mod_user_id -> Int4,
|
mod_person_id -> Int4,
|
||||||
other_user_id -> Int4,
|
other_person_id -> Int4,
|
||||||
community_id -> Int4,
|
community_id -> Int4,
|
||||||
removed -> Nullable<Bool>,
|
removed -> Nullable<Bool>,
|
||||||
when_ -> Timestamp,
|
when_ -> Timestamp,
|
||||||
|
@ -164,8 +182,8 @@ table! {
|
||||||
table! {
|
table! {
|
||||||
mod_ban (id) {
|
mod_ban (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
mod_user_id -> Int4,
|
mod_person_id -> Int4,
|
||||||
other_user_id -> Int4,
|
other_person_id -> Int4,
|
||||||
reason -> Nullable<Text>,
|
reason -> Nullable<Text>,
|
||||||
banned -> Nullable<Bool>,
|
banned -> Nullable<Bool>,
|
||||||
expires -> Nullable<Timestamp>,
|
expires -> Nullable<Timestamp>,
|
||||||
|
@ -176,8 +194,8 @@ table! {
|
||||||
table! {
|
table! {
|
||||||
mod_ban_from_community (id) {
|
mod_ban_from_community (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
mod_user_id -> Int4,
|
mod_person_id -> Int4,
|
||||||
other_user_id -> Int4,
|
other_person_id -> Int4,
|
||||||
community_id -> Int4,
|
community_id -> Int4,
|
||||||
reason -> Nullable<Text>,
|
reason -> Nullable<Text>,
|
||||||
banned -> Nullable<Bool>,
|
banned -> Nullable<Bool>,
|
||||||
|
@ -189,7 +207,7 @@ table! {
|
||||||
table! {
|
table! {
|
||||||
mod_lock_post (id) {
|
mod_lock_post (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
mod_user_id -> Int4,
|
mod_person_id -> Int4,
|
||||||
post_id -> Int4,
|
post_id -> Int4,
|
||||||
locked -> Nullable<Bool>,
|
locked -> Nullable<Bool>,
|
||||||
when_ -> Timestamp,
|
when_ -> Timestamp,
|
||||||
|
@ -199,7 +217,7 @@ table! {
|
||||||
table! {
|
table! {
|
||||||
mod_remove_comment (id) {
|
mod_remove_comment (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
mod_user_id -> Int4,
|
mod_person_id -> Int4,
|
||||||
comment_id -> Int4,
|
comment_id -> Int4,
|
||||||
reason -> Nullable<Text>,
|
reason -> Nullable<Text>,
|
||||||
removed -> Nullable<Bool>,
|
removed -> Nullable<Bool>,
|
||||||
|
@ -210,7 +228,7 @@ table! {
|
||||||
table! {
|
table! {
|
||||||
mod_remove_community (id) {
|
mod_remove_community (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
mod_user_id -> Int4,
|
mod_person_id -> Int4,
|
||||||
community_id -> Int4,
|
community_id -> Int4,
|
||||||
reason -> Nullable<Text>,
|
reason -> Nullable<Text>,
|
||||||
removed -> Nullable<Bool>,
|
removed -> Nullable<Bool>,
|
||||||
|
@ -222,7 +240,7 @@ table! {
|
||||||
table! {
|
table! {
|
||||||
mod_remove_post (id) {
|
mod_remove_post (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
mod_user_id -> Int4,
|
mod_person_id -> Int4,
|
||||||
post_id -> Int4,
|
post_id -> Int4,
|
||||||
reason -> Nullable<Text>,
|
reason -> Nullable<Text>,
|
||||||
removed -> Nullable<Bool>,
|
removed -> Nullable<Bool>,
|
||||||
|
@ -233,7 +251,7 @@ table! {
|
||||||
table! {
|
table! {
|
||||||
mod_sticky_post (id) {
|
mod_sticky_post (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
mod_user_id -> Int4,
|
mod_person_id -> Int4,
|
||||||
post_id -> Int4,
|
post_id -> Int4,
|
||||||
stickied -> Nullable<Bool>,
|
stickied -> Nullable<Bool>,
|
||||||
when_ -> Timestamp,
|
when_ -> Timestamp,
|
||||||
|
@ -243,9 +261,60 @@ table! {
|
||||||
table! {
|
table! {
|
||||||
password_reset_request (id) {
|
password_reset_request (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
user_id -> Int4,
|
|
||||||
token_encrypted -> Text,
|
token_encrypted -> Text,
|
||||||
published -> Timestamp,
|
published -> Timestamp,
|
||||||
|
local_user_id -> Int4,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
table! {
|
||||||
|
person (id) {
|
||||||
|
id -> Int4,
|
||||||
|
name -> Varchar,
|
||||||
|
preferred_username -> Nullable<Varchar>,
|
||||||
|
avatar -> Nullable<Text>,
|
||||||
|
banned -> Bool,
|
||||||
|
published -> Timestamp,
|
||||||
|
updated -> Nullable<Timestamp>,
|
||||||
|
actor_id -> Varchar,
|
||||||
|
bio -> Nullable<Text>,
|
||||||
|
local -> Bool,
|
||||||
|
private_key -> Nullable<Text>,
|
||||||
|
public_key -> Nullable<Text>,
|
||||||
|
last_refreshed_at -> Timestamp,
|
||||||
|
banner -> Nullable<Text>,
|
||||||
|
deleted -> Bool,
|
||||||
|
inbox_url -> Varchar,
|
||||||
|
shared_inbox_url -> Nullable<Varchar>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
table! {
|
||||||
|
person_aggregates (id) {
|
||||||
|
id -> Int4,
|
||||||
|
person_id -> Int4,
|
||||||
|
post_count -> Int8,
|
||||||
|
post_score -> Int8,
|
||||||
|
comment_count -> Int8,
|
||||||
|
comment_score -> Int8,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
table! {
|
||||||
|
person_ban (id) {
|
||||||
|
id -> Int4,
|
||||||
|
person_id -> Int4,
|
||||||
|
published -> Timestamp,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
table! {
|
||||||
|
person_mention (id) {
|
||||||
|
id -> Int4,
|
||||||
|
recipient_id -> Int4,
|
||||||
|
comment_id -> Int4,
|
||||||
|
read -> Bool,
|
||||||
|
published -> Timestamp,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,7 +361,7 @@ table! {
|
||||||
post_like (id) {
|
post_like (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
post_id -> Int4,
|
post_id -> Int4,
|
||||||
user_id -> Int4,
|
person_id -> Int4,
|
||||||
score -> Int2,
|
score -> Int2,
|
||||||
published -> Timestamp,
|
published -> Timestamp,
|
||||||
}
|
}
|
||||||
|
@ -302,7 +371,7 @@ table! {
|
||||||
post_read (id) {
|
post_read (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
post_id -> Int4,
|
post_id -> Int4,
|
||||||
user_id -> Int4,
|
person_id -> Int4,
|
||||||
published -> Timestamp,
|
published -> Timestamp,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -327,7 +396,7 @@ table! {
|
||||||
post_saved (id) {
|
post_saved (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
post_id -> Int4,
|
post_id -> Int4,
|
||||||
user_id -> Int4,
|
person_id -> Int4,
|
||||||
published -> Timestamp,
|
published -> Timestamp,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -378,68 +447,6 @@ table! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table! {
|
|
||||||
user_ (id) {
|
|
||||||
id -> Int4,
|
|
||||||
name -> Varchar,
|
|
||||||
preferred_username -> Nullable<Varchar>,
|
|
||||||
password_encrypted -> Text,
|
|
||||||
email -> Nullable<Text>,
|
|
||||||
avatar -> Nullable<Text>,
|
|
||||||
admin -> Bool,
|
|
||||||
banned -> Bool,
|
|
||||||
published -> Timestamp,
|
|
||||||
updated -> Nullable<Timestamp>,
|
|
||||||
show_nsfw -> Bool,
|
|
||||||
theme -> Varchar,
|
|
||||||
default_sort_type -> Int2,
|
|
||||||
default_listing_type -> Int2,
|
|
||||||
lang -> Varchar,
|
|
||||||
show_avatars -> Bool,
|
|
||||||
send_notifications_to_email -> Bool,
|
|
||||||
matrix_user_id -> Nullable<Text>,
|
|
||||||
actor_id -> Varchar,
|
|
||||||
bio -> Nullable<Text>,
|
|
||||||
local -> Bool,
|
|
||||||
private_key -> Nullable<Text>,
|
|
||||||
public_key -> Nullable<Text>,
|
|
||||||
last_refreshed_at -> Timestamp,
|
|
||||||
banner -> Nullable<Text>,
|
|
||||||
deleted -> Bool,
|
|
||||||
inbox_url -> Text,
|
|
||||||
shared_inbox_url -> Nullable<Text>,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
table! {
|
|
||||||
user_aggregates (id) {
|
|
||||||
id -> Int4,
|
|
||||||
user_id -> Int4,
|
|
||||||
post_count -> Int8,
|
|
||||||
post_score -> Int8,
|
|
||||||
comment_count -> Int8,
|
|
||||||
comment_score -> Int8,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
table! {
|
|
||||||
user_ban (id) {
|
|
||||||
id -> Int4,
|
|
||||||
user_id -> Int4,
|
|
||||||
published -> Timestamp,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
table! {
|
|
||||||
user_mention (id) {
|
|
||||||
id -> Int4,
|
|
||||||
recipient_id -> Int4,
|
|
||||||
comment_id -> Int4,
|
|
||||||
read -> Bool,
|
|
||||||
published -> Timestamp,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// These are necessary since diesel doesn't have self joins / aliases
|
// These are necessary since diesel doesn't have self joins / aliases
|
||||||
table! {
|
table! {
|
||||||
comment_alias_1 (id) {
|
comment_alias_1 (id) {
|
||||||
|
@ -459,25 +466,14 @@ table! {
|
||||||
}
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
user_alias_1 (id) {
|
person_alias_1 (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
name -> Varchar,
|
name -> Varchar,
|
||||||
preferred_username -> Nullable<Varchar>,
|
preferred_username -> Nullable<Varchar>,
|
||||||
password_encrypted -> Text,
|
|
||||||
email -> Nullable<Text>,
|
|
||||||
avatar -> Nullable<Text>,
|
avatar -> Nullable<Text>,
|
||||||
admin -> Bool,
|
|
||||||
banned -> Bool,
|
banned -> Bool,
|
||||||
published -> Timestamp,
|
published -> Timestamp,
|
||||||
updated -> Nullable<Timestamp>,
|
updated -> Nullable<Timestamp>,
|
||||||
show_nsfw -> Bool,
|
|
||||||
theme -> Varchar,
|
|
||||||
default_sort_type -> Int2,
|
|
||||||
default_listing_type -> Int2,
|
|
||||||
lang -> Varchar,
|
|
||||||
show_avatars -> Bool,
|
|
||||||
send_notifications_to_email -> Bool,
|
|
||||||
matrix_user_id -> Nullable<Text>,
|
|
||||||
actor_id -> Varchar,
|
actor_id -> Varchar,
|
||||||
bio -> Nullable<Text>,
|
bio -> Nullable<Text>,
|
||||||
local -> Bool,
|
local -> Bool,
|
||||||
|
@ -486,29 +482,20 @@ table! {
|
||||||
last_refreshed_at -> Timestamp,
|
last_refreshed_at -> Timestamp,
|
||||||
banner -> Nullable<Text>,
|
banner -> Nullable<Text>,
|
||||||
deleted -> Bool,
|
deleted -> Bool,
|
||||||
|
inbox_url -> Varchar,
|
||||||
|
shared_inbox_url -> Nullable<Varchar>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table! {
|
table! {
|
||||||
user_alias_2 (id) {
|
person_alias_2 (id) {
|
||||||
id -> Int4,
|
id -> Int4,
|
||||||
name -> Varchar,
|
name -> Varchar,
|
||||||
preferred_username -> Nullable<Varchar>,
|
preferred_username -> Nullable<Varchar>,
|
||||||
password_encrypted -> Text,
|
|
||||||
email -> Nullable<Text>,
|
|
||||||
avatar -> Nullable<Text>,
|
avatar -> Nullable<Text>,
|
||||||
admin -> Bool,
|
|
||||||
banned -> Bool,
|
banned -> Bool,
|
||||||
published -> Timestamp,
|
published -> Timestamp,
|
||||||
updated -> Nullable<Timestamp>,
|
updated -> Nullable<Timestamp>,
|
||||||
show_nsfw -> Bool,
|
|
||||||
theme -> Varchar,
|
|
||||||
default_sort_type -> Int2,
|
|
||||||
default_listing_type -> Int2,
|
|
||||||
lang -> Varchar,
|
|
||||||
show_avatars -> Bool,
|
|
||||||
send_notifications_to_email -> Bool,
|
|
||||||
matrix_user_id -> Nullable<Text>,
|
|
||||||
actor_id -> Varchar,
|
actor_id -> Varchar,
|
||||||
bio -> Nullable<Text>,
|
bio -> Nullable<Text>,
|
||||||
local -> Bool,
|
local -> Bool,
|
||||||
|
@ -517,64 +504,67 @@ table! {
|
||||||
last_refreshed_at -> Timestamp,
|
last_refreshed_at -> Timestamp,
|
||||||
banner -> Nullable<Text>,
|
banner -> Nullable<Text>,
|
||||||
deleted -> Bool,
|
deleted -> Bool,
|
||||||
|
inbox_url -> Varchar,
|
||||||
|
shared_inbox_url -> Nullable<Varchar>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
joinable!(comment_alias_1 -> user_alias_1 (creator_id));
|
joinable!(comment_alias_1 -> person_alias_1 (creator_id));
|
||||||
joinable!(comment -> comment_alias_1 (parent_id));
|
joinable!(comment -> comment_alias_1 (parent_id));
|
||||||
joinable!(user_mention -> user_alias_1 (recipient_id));
|
joinable!(person_mention -> person_alias_1 (recipient_id));
|
||||||
joinable!(post -> user_alias_1 (creator_id));
|
joinable!(post -> person_alias_1 (creator_id));
|
||||||
joinable!(comment -> user_alias_1 (creator_id));
|
joinable!(comment -> person_alias_1 (creator_id));
|
||||||
|
|
||||||
joinable!(post_report -> user_alias_2 (resolver_id));
|
joinable!(post_report -> person_alias_2 (resolver_id));
|
||||||
joinable!(comment_report -> user_alias_2 (resolver_id));
|
joinable!(comment_report -> person_alias_2 (resolver_id));
|
||||||
|
|
||||||
|
joinable!(comment -> person (creator_id));
|
||||||
joinable!(comment -> post (post_id));
|
joinable!(comment -> post (post_id));
|
||||||
joinable!(comment -> user_ (creator_id));
|
|
||||||
joinable!(comment_aggregates -> comment (comment_id));
|
joinable!(comment_aggregates -> comment (comment_id));
|
||||||
joinable!(comment_like -> comment (comment_id));
|
joinable!(comment_like -> comment (comment_id));
|
||||||
|
joinable!(comment_like -> person (person_id));
|
||||||
joinable!(comment_like -> post (post_id));
|
joinable!(comment_like -> post (post_id));
|
||||||
joinable!(comment_like -> user_ (user_id));
|
|
||||||
joinable!(comment_report -> comment (comment_id));
|
joinable!(comment_report -> comment (comment_id));
|
||||||
joinable!(comment_saved -> comment (comment_id));
|
joinable!(comment_saved -> comment (comment_id));
|
||||||
joinable!(comment_saved -> user_ (user_id));
|
joinable!(comment_saved -> person (person_id));
|
||||||
joinable!(community -> user_ (creator_id));
|
joinable!(community -> person (creator_id));
|
||||||
joinable!(community_aggregates -> community (community_id));
|
joinable!(community_aggregates -> community (community_id));
|
||||||
joinable!(community_follower -> community (community_id));
|
joinable!(community_follower -> community (community_id));
|
||||||
joinable!(community_follower -> user_ (user_id));
|
joinable!(community_follower -> person (person_id));
|
||||||
joinable!(community_moderator -> community (community_id));
|
joinable!(community_moderator -> community (community_id));
|
||||||
joinable!(community_moderator -> user_ (user_id));
|
joinable!(community_moderator -> person (person_id));
|
||||||
joinable!(community_user_ban -> community (community_id));
|
joinable!(community_person_ban -> community (community_id));
|
||||||
joinable!(community_user_ban -> user_ (user_id));
|
joinable!(community_person_ban -> person (person_id));
|
||||||
|
joinable!(local_user -> person (person_id));
|
||||||
joinable!(mod_add_community -> community (community_id));
|
joinable!(mod_add_community -> community (community_id));
|
||||||
joinable!(mod_ban_from_community -> community (community_id));
|
joinable!(mod_ban_from_community -> community (community_id));
|
||||||
|
joinable!(mod_lock_post -> person (mod_person_id));
|
||||||
joinable!(mod_lock_post -> post (post_id));
|
joinable!(mod_lock_post -> post (post_id));
|
||||||
joinable!(mod_lock_post -> user_ (mod_user_id));
|
|
||||||
joinable!(mod_remove_comment -> comment (comment_id));
|
joinable!(mod_remove_comment -> comment (comment_id));
|
||||||
joinable!(mod_remove_comment -> user_ (mod_user_id));
|
joinable!(mod_remove_comment -> person (mod_person_id));
|
||||||
joinable!(mod_remove_community -> community (community_id));
|
joinable!(mod_remove_community -> community (community_id));
|
||||||
joinable!(mod_remove_community -> user_ (mod_user_id));
|
joinable!(mod_remove_community -> person (mod_person_id));
|
||||||
|
joinable!(mod_remove_post -> person (mod_person_id));
|
||||||
joinable!(mod_remove_post -> post (post_id));
|
joinable!(mod_remove_post -> post (post_id));
|
||||||
joinable!(mod_remove_post -> user_ (mod_user_id));
|
joinable!(mod_sticky_post -> person (mod_person_id));
|
||||||
joinable!(mod_sticky_post -> post (post_id));
|
joinable!(mod_sticky_post -> post (post_id));
|
||||||
joinable!(mod_sticky_post -> user_ (mod_user_id));
|
joinable!(password_reset_request -> local_user (local_user_id));
|
||||||
joinable!(password_reset_request -> user_ (user_id));
|
joinable!(person_aggregates -> person (person_id));
|
||||||
|
joinable!(person_ban -> person (person_id));
|
||||||
|
joinable!(person_mention -> comment (comment_id));
|
||||||
|
joinable!(person_mention -> person (recipient_id));
|
||||||
joinable!(post -> community (community_id));
|
joinable!(post -> community (community_id));
|
||||||
joinable!(post -> user_ (creator_id));
|
joinable!(post -> person (creator_id));
|
||||||
joinable!(post_aggregates -> post (post_id));
|
joinable!(post_aggregates -> post (post_id));
|
||||||
|
joinable!(post_like -> person (person_id));
|
||||||
joinable!(post_like -> post (post_id));
|
joinable!(post_like -> post (post_id));
|
||||||
joinable!(post_like -> user_ (user_id));
|
joinable!(post_read -> person (person_id));
|
||||||
joinable!(post_read -> post (post_id));
|
joinable!(post_read -> post (post_id));
|
||||||
joinable!(post_read -> user_ (user_id));
|
|
||||||
joinable!(post_report -> post (post_id));
|
joinable!(post_report -> post (post_id));
|
||||||
|
joinable!(post_saved -> person (person_id));
|
||||||
joinable!(post_saved -> post (post_id));
|
joinable!(post_saved -> post (post_id));
|
||||||
joinable!(post_saved -> user_ (user_id));
|
joinable!(site -> person (creator_id));
|
||||||
joinable!(site -> user_ (creator_id));
|
|
||||||
joinable!(site_aggregates -> site (site_id));
|
joinable!(site_aggregates -> site (site_id));
|
||||||
joinable!(user_aggregates -> user_ (user_id));
|
|
||||||
joinable!(user_ban -> user_ (user_id));
|
|
||||||
joinable!(user_mention -> comment (comment_id));
|
|
||||||
joinable!(user_mention -> user_ (recipient_id));
|
|
||||||
|
|
||||||
allow_tables_to_appear_in_same_query!(
|
allow_tables_to_appear_in_same_query!(
|
||||||
activity,
|
activity,
|
||||||
|
@ -587,7 +577,8 @@ allow_tables_to_appear_in_same_query!(
|
||||||
community_aggregates,
|
community_aggregates,
|
||||||
community_follower,
|
community_follower,
|
||||||
community_moderator,
|
community_moderator,
|
||||||
community_user_ban,
|
community_person_ban,
|
||||||
|
local_user,
|
||||||
mod_add,
|
mod_add,
|
||||||
mod_add_community,
|
mod_add_community,
|
||||||
mod_ban,
|
mod_ban,
|
||||||
|
@ -598,6 +589,10 @@ allow_tables_to_appear_in_same_query!(
|
||||||
mod_remove_post,
|
mod_remove_post,
|
||||||
mod_sticky_post,
|
mod_sticky_post,
|
||||||
password_reset_request,
|
password_reset_request,
|
||||||
|
person,
|
||||||
|
person_aggregates,
|
||||||
|
person_ban,
|
||||||
|
person_mention,
|
||||||
post,
|
post,
|
||||||
post_aggregates,
|
post_aggregates,
|
||||||
post_like,
|
post_like,
|
||||||
|
@ -607,11 +602,7 @@ allow_tables_to_appear_in_same_query!(
|
||||||
private_message,
|
private_message,
|
||||||
site,
|
site,
|
||||||
site_aggregates,
|
site_aggregates,
|
||||||
user_,
|
|
||||||
user_aggregates,
|
|
||||||
user_ban,
|
|
||||||
user_mention,
|
|
||||||
comment_alias_1,
|
comment_alias_1,
|
||||||
user_alias_1,
|
person_alias_1,
|
||||||
user_alias_2,
|
person_alias_2,
|
||||||
);
|
);
|
||||||
|
|
|
@ -69,7 +69,7 @@ pub struct CommentForm {
|
||||||
#[table_name = "comment_like"]
|
#[table_name = "comment_like"]
|
||||||
pub struct CommentLike {
|
pub struct CommentLike {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub user_id: i32,
|
pub person_id: i32,
|
||||||
pub comment_id: i32,
|
pub comment_id: i32,
|
||||||
pub post_id: i32, // TODO this is redundant
|
pub post_id: i32, // TODO this is redundant
|
||||||
pub score: i16,
|
pub score: i16,
|
||||||
|
@ -79,7 +79,7 @@ pub struct CommentLike {
|
||||||
#[derive(Insertable, AsChangeset, Clone)]
|
#[derive(Insertable, AsChangeset, Clone)]
|
||||||
#[table_name = "comment_like"]
|
#[table_name = "comment_like"]
|
||||||
pub struct CommentLikeForm {
|
pub struct CommentLikeForm {
|
||||||
pub user_id: i32,
|
pub person_id: i32,
|
||||||
pub comment_id: i32,
|
pub comment_id: i32,
|
||||||
pub post_id: i32, // TODO this is redundant
|
pub post_id: i32, // TODO this is redundant
|
||||||
pub score: i16,
|
pub score: i16,
|
||||||
|
@ -91,7 +91,7 @@ pub struct CommentLikeForm {
|
||||||
pub struct CommentSaved {
|
pub struct CommentSaved {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub comment_id: i32,
|
pub comment_id: i32,
|
||||||
pub user_id: i32,
|
pub person_id: i32,
|
||||||
pub published: chrono::NaiveDateTime,
|
pub published: chrono::NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,5 +99,5 @@ pub struct CommentSaved {
|
||||||
#[table_name = "comment_saved"]
|
#[table_name = "comment_saved"]
|
||||||
pub struct CommentSavedForm {
|
pub struct CommentSavedForm {
|
||||||
pub comment_id: i32,
|
pub comment_id: i32,
|
||||||
pub user_id: i32,
|
pub person_id: i32,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
schema::{community, community_follower, community_moderator, community_user_ban},
|
schema::{community, community_follower, community_moderator, community_person_ban},
|
||||||
Url,
|
Url,
|
||||||
};
|
};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
@ -79,7 +79,7 @@ pub struct CommunityForm {
|
||||||
pub struct CommunityModerator {
|
pub struct CommunityModerator {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub community_id: i32,
|
pub community_id: i32,
|
||||||
pub user_id: i32,
|
pub person_id: i32,
|
||||||
pub published: chrono::NaiveDateTime,
|
pub published: chrono::NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,24 +87,24 @@ pub struct CommunityModerator {
|
||||||
#[table_name = "community_moderator"]
|
#[table_name = "community_moderator"]
|
||||||
pub struct CommunityModeratorForm {
|
pub struct CommunityModeratorForm {
|
||||||
pub community_id: i32,
|
pub community_id: i32,
|
||||||
pub user_id: i32,
|
pub person_id: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
|
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
|
||||||
#[belongs_to(Community)]
|
#[belongs_to(Community)]
|
||||||
#[table_name = "community_user_ban"]
|
#[table_name = "community_person_ban"]
|
||||||
pub struct CommunityUserBan {
|
pub struct CommunityPersonBan {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub community_id: i32,
|
pub community_id: i32,
|
||||||
pub user_id: i32,
|
pub person_id: i32,
|
||||||
pub published: chrono::NaiveDateTime,
|
pub published: chrono::NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Insertable, AsChangeset, Clone)]
|
#[derive(Insertable, AsChangeset, Clone)]
|
||||||
#[table_name = "community_user_ban"]
|
#[table_name = "community_person_ban"]
|
||||||
pub struct CommunityUserBanForm {
|
pub struct CommunityPersonBanForm {
|
||||||
pub community_id: i32,
|
pub community_id: i32,
|
||||||
pub user_id: i32,
|
pub person_id: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
|
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
|
||||||
|
@ -113,7 +113,7 @@ pub struct CommunityUserBanForm {
|
||||||
pub struct CommunityFollower {
|
pub struct CommunityFollower {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub community_id: i32,
|
pub community_id: i32,
|
||||||
pub user_id: i32,
|
pub person_id: i32,
|
||||||
pub published: chrono::NaiveDateTime,
|
pub published: chrono::NaiveDateTime,
|
||||||
pub pending: Option<bool>,
|
pub pending: Option<bool>,
|
||||||
}
|
}
|
||||||
|
@ -122,6 +122,6 @@ pub struct CommunityFollower {
|
||||||
#[table_name = "community_follower"]
|
#[table_name = "community_follower"]
|
||||||
pub struct CommunityFollowerForm {
|
pub struct CommunityFollowerForm {
|
||||||
pub community_id: i32,
|
pub community_id: i32,
|
||||||
pub user_id: i32,
|
pub person_id: i32,
|
||||||
pub pending: bool,
|
pub pending: bool,
|
||||||
}
|
}
|
||||||
|
|
66
crates/db_schema/src/source/local_user.rs
Normal file
66
crates/db_schema/src/source/local_user.rs
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
use crate::schema::local_user;
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||||
|
#[table_name = "local_user"]
|
||||||
|
pub struct LocalUser {
|
||||||
|
pub id: i32,
|
||||||
|
pub person_id: i32,
|
||||||
|
pub password_encrypted: String,
|
||||||
|
pub email: Option<String>,
|
||||||
|
pub admin: bool,
|
||||||
|
pub show_nsfw: bool,
|
||||||
|
pub theme: String,
|
||||||
|
pub default_sort_type: i16,
|
||||||
|
pub default_listing_type: i16,
|
||||||
|
pub lang: String,
|
||||||
|
pub show_avatars: bool,
|
||||||
|
pub send_notifications_to_email: bool,
|
||||||
|
pub matrix_user_id: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO redo these, check table defaults
|
||||||
|
#[derive(Insertable, AsChangeset, Clone)]
|
||||||
|
#[table_name = "local_user"]
|
||||||
|
pub struct LocalUserForm {
|
||||||
|
pub person_id: i32,
|
||||||
|
pub password_encrypted: String,
|
||||||
|
pub email: Option<Option<String>>,
|
||||||
|
pub admin: Option<bool>,
|
||||||
|
pub show_nsfw: Option<bool>,
|
||||||
|
pub theme: Option<String>,
|
||||||
|
pub default_sort_type: Option<i16>,
|
||||||
|
pub default_listing_type: Option<i16>,
|
||||||
|
pub lang: Option<String>,
|
||||||
|
pub show_avatars: Option<bool>,
|
||||||
|
pub send_notifications_to_email: Option<bool>,
|
||||||
|
pub matrix_user_id: Option<Option<String>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A safe local user view, without settings, password, or email
|
||||||
|
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||||
|
#[table_name = "local_user"]
|
||||||
|
pub struct LocalUserSafe {
|
||||||
|
pub id: i32,
|
||||||
|
pub person_id: i32,
|
||||||
|
pub admin: bool,
|
||||||
|
pub matrix_user_id: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A local user view that removes password encrypted
|
||||||
|
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||||
|
#[table_name = "local_user"]
|
||||||
|
pub struct LocalUserSettings{
|
||||||
|
pub id: i32,
|
||||||
|
pub person_id: i32,
|
||||||
|
pub email: Option<String>,
|
||||||
|
pub admin: bool,
|
||||||
|
pub show_nsfw: bool,
|
||||||
|
pub theme: String,
|
||||||
|
pub default_sort_type: i16,
|
||||||
|
pub default_listing_type: i16,
|
||||||
|
pub lang: String,
|
||||||
|
pub show_avatars: bool,
|
||||||
|
pub send_notifications_to_email: bool,
|
||||||
|
pub matrix_user_id: Option<String>,
|
||||||
|
}
|
|
@ -8,5 +8,6 @@ pub mod post;
|
||||||
pub mod post_report;
|
pub mod post_report;
|
||||||
pub mod private_message;
|
pub mod private_message;
|
||||||
pub mod site;
|
pub mod site;
|
||||||
pub mod user;
|
pub mod person;
|
||||||
pub mod user_mention;
|
pub mod person_mention;
|
||||||
|
pub mod local_user;
|
||||||
|
|
|
@ -15,7 +15,7 @@ use serde::Serialize;
|
||||||
#[table_name = "mod_remove_post"]
|
#[table_name = "mod_remove_post"]
|
||||||
pub struct ModRemovePost {
|
pub struct ModRemovePost {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub mod_user_id: i32,
|
pub mod_person_id: i32,
|
||||||
pub post_id: i32,
|
pub post_id: i32,
|
||||||
pub reason: Option<String>,
|
pub reason: Option<String>,
|
||||||
pub removed: Option<bool>,
|
pub removed: Option<bool>,
|
||||||
|
@ -25,7 +25,7 @@ pub struct ModRemovePost {
|
||||||
#[derive(Insertable, AsChangeset)]
|
#[derive(Insertable, AsChangeset)]
|
||||||
#[table_name = "mod_remove_post"]
|
#[table_name = "mod_remove_post"]
|
||||||
pub struct ModRemovePostForm {
|
pub struct ModRemovePostForm {
|
||||||
pub mod_user_id: i32,
|
pub mod_person_id: i32,
|
||||||
pub post_id: i32,
|
pub post_id: i32,
|
||||||
pub reason: Option<String>,
|
pub reason: Option<String>,
|
||||||
pub removed: Option<bool>,
|
pub removed: Option<bool>,
|
||||||
|
@ -35,7 +35,7 @@ pub struct ModRemovePostForm {
|
||||||
#[table_name = "mod_lock_post"]
|
#[table_name = "mod_lock_post"]
|
||||||
pub struct ModLockPost {
|
pub struct ModLockPost {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub mod_user_id: i32,
|
pub mod_person_id: i32,
|
||||||
pub post_id: i32,
|
pub post_id: i32,
|
||||||
pub locked: Option<bool>,
|
pub locked: Option<bool>,
|
||||||
pub when_: chrono::NaiveDateTime,
|
pub when_: chrono::NaiveDateTime,
|
||||||
|
@ -44,7 +44,7 @@ pub struct ModLockPost {
|
||||||
#[derive(Insertable, AsChangeset)]
|
#[derive(Insertable, AsChangeset)]
|
||||||
#[table_name = "mod_lock_post"]
|
#[table_name = "mod_lock_post"]
|
||||||
pub struct ModLockPostForm {
|
pub struct ModLockPostForm {
|
||||||
pub mod_user_id: i32,
|
pub mod_person_id: i32,
|
||||||
pub post_id: i32,
|
pub post_id: i32,
|
||||||
pub locked: Option<bool>,
|
pub locked: Option<bool>,
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ pub struct ModLockPostForm {
|
||||||
#[table_name = "mod_sticky_post"]
|
#[table_name = "mod_sticky_post"]
|
||||||
pub struct ModStickyPost {
|
pub struct ModStickyPost {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub mod_user_id: i32,
|
pub mod_person_id: i32,
|
||||||
pub post_id: i32,
|
pub post_id: i32,
|
||||||
pub stickied: Option<bool>,
|
pub stickied: Option<bool>,
|
||||||
pub when_: chrono::NaiveDateTime,
|
pub when_: chrono::NaiveDateTime,
|
||||||
|
@ -62,7 +62,7 @@ pub struct ModStickyPost {
|
||||||
#[derive(Insertable, AsChangeset)]
|
#[derive(Insertable, AsChangeset)]
|
||||||
#[table_name = "mod_sticky_post"]
|
#[table_name = "mod_sticky_post"]
|
||||||
pub struct ModStickyPostForm {
|
pub struct ModStickyPostForm {
|
||||||
pub mod_user_id: i32,
|
pub mod_person_id: i32,
|
||||||
pub post_id: i32,
|
pub post_id: i32,
|
||||||
pub stickied: Option<bool>,
|
pub stickied: Option<bool>,
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ pub struct ModStickyPostForm {
|
||||||
#[table_name = "mod_remove_comment"]
|
#[table_name = "mod_remove_comment"]
|
||||||
pub struct ModRemoveComment {
|
pub struct ModRemoveComment {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub mod_user_id: i32,
|
pub mod_person_id: i32,
|
||||||
pub comment_id: i32,
|
pub comment_id: i32,
|
||||||
pub reason: Option<String>,
|
pub reason: Option<String>,
|
||||||
pub removed: Option<bool>,
|
pub removed: Option<bool>,
|
||||||
|
@ -81,7 +81,7 @@ pub struct ModRemoveComment {
|
||||||
#[derive(Insertable, AsChangeset)]
|
#[derive(Insertable, AsChangeset)]
|
||||||
#[table_name = "mod_remove_comment"]
|
#[table_name = "mod_remove_comment"]
|
||||||
pub struct ModRemoveCommentForm {
|
pub struct ModRemoveCommentForm {
|
||||||
pub mod_user_id: i32,
|
pub mod_person_id: i32,
|
||||||
pub comment_id: i32,
|
pub comment_id: i32,
|
||||||
pub reason: Option<String>,
|
pub reason: Option<String>,
|
||||||
pub removed: Option<bool>,
|
pub removed: Option<bool>,
|
||||||
|
@ -91,7 +91,7 @@ pub struct ModRemoveCommentForm {
|
||||||
#[table_name = "mod_remove_community"]
|
#[table_name = "mod_remove_community"]
|
||||||
pub struct ModRemoveCommunity {
|
pub struct ModRemoveCommunity {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub mod_user_id: i32,
|
pub mod_person_id: i32,
|
||||||
pub community_id: i32,
|
pub community_id: i32,
|
||||||
pub reason: Option<String>,
|
pub reason: Option<String>,
|
||||||
pub removed: Option<bool>,
|
pub removed: Option<bool>,
|
||||||
|
@ -102,7 +102,7 @@ pub struct ModRemoveCommunity {
|
||||||
#[derive(Insertable, AsChangeset)]
|
#[derive(Insertable, AsChangeset)]
|
||||||
#[table_name = "mod_remove_community"]
|
#[table_name = "mod_remove_community"]
|
||||||
pub struct ModRemoveCommunityForm {
|
pub struct ModRemoveCommunityForm {
|
||||||
pub mod_user_id: i32,
|
pub mod_person_id: i32,
|
||||||
pub community_id: i32,
|
pub community_id: i32,
|
||||||
pub reason: Option<String>,
|
pub reason: Option<String>,
|
||||||
pub removed: Option<bool>,
|
pub removed: Option<bool>,
|
||||||
|
@ -113,8 +113,8 @@ pub struct ModRemoveCommunityForm {
|
||||||
#[table_name = "mod_ban_from_community"]
|
#[table_name = "mod_ban_from_community"]
|
||||||
pub struct ModBanFromCommunity {
|
pub struct ModBanFromCommunity {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub mod_user_id: i32,
|
pub mod_person_id: i32,
|
||||||
pub other_user_id: i32,
|
pub other_person_id: i32,
|
||||||
pub community_id: i32,
|
pub community_id: i32,
|
||||||
pub reason: Option<String>,
|
pub reason: Option<String>,
|
||||||
pub banned: Option<bool>,
|
pub banned: Option<bool>,
|
||||||
|
@ -125,8 +125,8 @@ pub struct ModBanFromCommunity {
|
||||||
#[derive(Insertable, AsChangeset)]
|
#[derive(Insertable, AsChangeset)]
|
||||||
#[table_name = "mod_ban_from_community"]
|
#[table_name = "mod_ban_from_community"]
|
||||||
pub struct ModBanFromCommunityForm {
|
pub struct ModBanFromCommunityForm {
|
||||||
pub mod_user_id: i32,
|
pub mod_person_id: i32,
|
||||||
pub other_user_id: i32,
|
pub other_person_id: i32,
|
||||||
pub community_id: i32,
|
pub community_id: i32,
|
||||||
pub reason: Option<String>,
|
pub reason: Option<String>,
|
||||||
pub banned: Option<bool>,
|
pub banned: Option<bool>,
|
||||||
|
@ -137,8 +137,8 @@ pub struct ModBanFromCommunityForm {
|
||||||
#[table_name = "mod_ban"]
|
#[table_name = "mod_ban"]
|
||||||
pub struct ModBan {
|
pub struct ModBan {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub mod_user_id: i32,
|
pub mod_person_id: i32,
|
||||||
pub other_user_id: i32,
|
pub other_person_id: i32,
|
||||||
pub reason: Option<String>,
|
pub reason: Option<String>,
|
||||||
pub banned: Option<bool>,
|
pub banned: Option<bool>,
|
||||||
pub expires: Option<chrono::NaiveDateTime>,
|
pub expires: Option<chrono::NaiveDateTime>,
|
||||||
|
@ -148,8 +148,8 @@ pub struct ModBan {
|
||||||
#[derive(Insertable, AsChangeset)]
|
#[derive(Insertable, AsChangeset)]
|
||||||
#[table_name = "mod_ban"]
|
#[table_name = "mod_ban"]
|
||||||
pub struct ModBanForm {
|
pub struct ModBanForm {
|
||||||
pub mod_user_id: i32,
|
pub mod_person_id: i32,
|
||||||
pub other_user_id: i32,
|
pub other_person_id: i32,
|
||||||
pub reason: Option<String>,
|
pub reason: Option<String>,
|
||||||
pub banned: Option<bool>,
|
pub banned: Option<bool>,
|
||||||
pub expires: Option<chrono::NaiveDateTime>,
|
pub expires: Option<chrono::NaiveDateTime>,
|
||||||
|
@ -159,8 +159,8 @@ pub struct ModBanForm {
|
||||||
#[table_name = "mod_add_community"]
|
#[table_name = "mod_add_community"]
|
||||||
pub struct ModAddCommunity {
|
pub struct ModAddCommunity {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub mod_user_id: i32,
|
pub mod_person_id: i32,
|
||||||
pub other_user_id: i32,
|
pub other_person_id: i32,
|
||||||
pub community_id: i32,
|
pub community_id: i32,
|
||||||
pub removed: Option<bool>,
|
pub removed: Option<bool>,
|
||||||
pub when_: chrono::NaiveDateTime,
|
pub when_: chrono::NaiveDateTime,
|
||||||
|
@ -169,8 +169,8 @@ pub struct ModAddCommunity {
|
||||||
#[derive(Insertable, AsChangeset)]
|
#[derive(Insertable, AsChangeset)]
|
||||||
#[table_name = "mod_add_community"]
|
#[table_name = "mod_add_community"]
|
||||||
pub struct ModAddCommunityForm {
|
pub struct ModAddCommunityForm {
|
||||||
pub mod_user_id: i32,
|
pub mod_person_id: i32,
|
||||||
pub other_user_id: i32,
|
pub other_person_id: i32,
|
||||||
pub community_id: i32,
|
pub community_id: i32,
|
||||||
pub removed: Option<bool>,
|
pub removed: Option<bool>,
|
||||||
}
|
}
|
||||||
|
@ -179,8 +179,8 @@ pub struct ModAddCommunityForm {
|
||||||
#[table_name = "mod_add"]
|
#[table_name = "mod_add"]
|
||||||
pub struct ModAdd {
|
pub struct ModAdd {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub mod_user_id: i32,
|
pub mod_person_id: i32,
|
||||||
pub other_user_id: i32,
|
pub other_person_id: i32,
|
||||||
pub removed: Option<bool>,
|
pub removed: Option<bool>,
|
||||||
pub when_: chrono::NaiveDateTime,
|
pub when_: chrono::NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
@ -188,7 +188,7 @@ pub struct ModAdd {
|
||||||
#[derive(Insertable, AsChangeset)]
|
#[derive(Insertable, AsChangeset)]
|
||||||
#[table_name = "mod_add"]
|
#[table_name = "mod_add"]
|
||||||
pub struct ModAddForm {
|
pub struct ModAddForm {
|
||||||
pub mod_user_id: i32,
|
pub mod_person_id: i32,
|
||||||
pub other_user_id: i32,
|
pub other_person_id: i32,
|
||||||
pub removed: Option<bool>,
|
pub removed: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::schema::password_reset_request;
|
||||||
#[table_name = "password_reset_request"]
|
#[table_name = "password_reset_request"]
|
||||||
pub struct PasswordResetRequest {
|
pub struct PasswordResetRequest {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub user_id: i32,
|
pub local_user_id: i32,
|
||||||
pub token_encrypted: String,
|
pub token_encrypted: String,
|
||||||
pub published: chrono::NaiveDateTime,
|
pub published: chrono::NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,6 @@ pub struct PasswordResetRequest {
|
||||||
#[derive(Insertable, AsChangeset)]
|
#[derive(Insertable, AsChangeset)]
|
||||||
#[table_name = "password_reset_request"]
|
#[table_name = "password_reset_request"]
|
||||||
pub struct PasswordResetRequestForm {
|
pub struct PasswordResetRequestForm {
|
||||||
pub user_id: i32,
|
pub local_user_id: i32,
|
||||||
pub token_encrypted: String,
|
pub token_encrypted: String,
|
||||||
}
|
}
|
||||||
|
|
154
crates/db_schema/src/source/person.rs
Normal file
154
crates/db_schema/src/source/person.rs
Normal file
|
@ -0,0 +1,154 @@
|
||||||
|
use crate::{
|
||||||
|
schema::{person, person_alias_1, person_alias_2},
|
||||||
|
Url,
|
||||||
|
};
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||||
|
#[table_name = "person"]
|
||||||
|
pub struct Person {
|
||||||
|
pub id: i32,
|
||||||
|
pub name: String,
|
||||||
|
pub preferred_username: Option<String>,
|
||||||
|
pub avatar: Option<String>,
|
||||||
|
pub banned: bool,
|
||||||
|
pub published: chrono::NaiveDateTime,
|
||||||
|
pub updated: Option<chrono::NaiveDateTime>,
|
||||||
|
pub actor_id: Url,
|
||||||
|
pub bio: Option<String>,
|
||||||
|
pub local: bool,
|
||||||
|
pub private_key: Option<String>,
|
||||||
|
pub public_key: Option<String>,
|
||||||
|
pub last_refreshed_at: chrono::NaiveDateTime,
|
||||||
|
pub banner: Option<String>,
|
||||||
|
pub deleted: bool,
|
||||||
|
pub inbox_url: Url,
|
||||||
|
pub shared_inbox_url: Option<Url>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A safe representation of user, without the sensitive info
|
||||||
|
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||||
|
#[table_name = "person"]
|
||||||
|
pub struct PersonSafe {
|
||||||
|
pub id: i32,
|
||||||
|
pub name: String,
|
||||||
|
pub preferred_username: Option<String>,
|
||||||
|
pub avatar: Option<String>,
|
||||||
|
pub banned: bool,
|
||||||
|
pub published: chrono::NaiveDateTime,
|
||||||
|
pub updated: Option<chrono::NaiveDateTime>,
|
||||||
|
pub actor_id: Url,
|
||||||
|
pub bio: Option<String>,
|
||||||
|
pub local: bool,
|
||||||
|
pub last_refreshed_at: chrono::NaiveDateTime,
|
||||||
|
pub banner: Option<String>,
|
||||||
|
pub deleted: bool,
|
||||||
|
pub inbox_url: Url,
|
||||||
|
pub shared_inbox_url: Option<Url>,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||||
|
#[table_name = "person_alias_1"]
|
||||||
|
pub struct PersonAlias1 {
|
||||||
|
pub id: i32,
|
||||||
|
pub name: String,
|
||||||
|
pub preferred_username: Option<String>,
|
||||||
|
pub avatar: Option<String>,
|
||||||
|
pub banned: bool,
|
||||||
|
pub published: chrono::NaiveDateTime,
|
||||||
|
pub updated: Option<chrono::NaiveDateTime>,
|
||||||
|
pub actor_id: Url,
|
||||||
|
pub bio: Option<String>,
|
||||||
|
pub local: bool,
|
||||||
|
pub private_key: Option<String>,
|
||||||
|
pub public_key: Option<String>,
|
||||||
|
pub last_refreshed_at: chrono::NaiveDateTime,
|
||||||
|
pub banner: Option<String>,
|
||||||
|
pub deleted: bool,
|
||||||
|
pub inbox_url: Url,
|
||||||
|
pub shared_inbox_url: Option<Url>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||||
|
#[table_name = "person_alias_1"]
|
||||||
|
pub struct PersonSafeAlias1 {
|
||||||
|
pub id: i32,
|
||||||
|
pub name: String,
|
||||||
|
pub preferred_username: Option<String>,
|
||||||
|
pub avatar: Option<String>,
|
||||||
|
pub banned: bool,
|
||||||
|
pub published: chrono::NaiveDateTime,
|
||||||
|
pub updated: Option<chrono::NaiveDateTime>,
|
||||||
|
pub actor_id: Url,
|
||||||
|
pub bio: Option<String>,
|
||||||
|
pub local: bool,
|
||||||
|
pub last_refreshed_at: chrono::NaiveDateTime,
|
||||||
|
pub banner: Option<String>,
|
||||||
|
pub deleted: bool,
|
||||||
|
pub inbox_url: Url,
|
||||||
|
pub shared_inbox_url: Option<Url>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||||
|
#[table_name = "person_alias_2"]
|
||||||
|
pub struct PersonAlias2 {
|
||||||
|
pub id: i32,
|
||||||
|
pub name: String,
|
||||||
|
pub preferred_username: Option<String>,
|
||||||
|
pub avatar: Option<String>,
|
||||||
|
pub banned: bool,
|
||||||
|
pub published: chrono::NaiveDateTime,
|
||||||
|
pub updated: Option<chrono::NaiveDateTime>,
|
||||||
|
pub actor_id: Url,
|
||||||
|
pub bio: Option<String>,
|
||||||
|
pub local: bool,
|
||||||
|
pub private_key: Option<String>,
|
||||||
|
pub public_key: Option<String>,
|
||||||
|
pub last_refreshed_at: chrono::NaiveDateTime,
|
||||||
|
pub banner: Option<String>,
|
||||||
|
pub deleted: bool,
|
||||||
|
pub inbox_url: Url,
|
||||||
|
pub shared_inbox_url: Option<Url>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
||||||
|
#[table_name = "person_alias_1"]
|
||||||
|
pub struct PersonSafeAlias2 {
|
||||||
|
pub id: i32,
|
||||||
|
pub name: String,
|
||||||
|
pub preferred_username: Option<String>,
|
||||||
|
pub avatar: Option<String>,
|
||||||
|
pub banned: bool,
|
||||||
|
pub published: chrono::NaiveDateTime,
|
||||||
|
pub updated: Option<chrono::NaiveDateTime>,
|
||||||
|
pub actor_id: Url,
|
||||||
|
pub bio: Option<String>,
|
||||||
|
pub local: bool,
|
||||||
|
pub last_refreshed_at: chrono::NaiveDateTime,
|
||||||
|
pub banner: Option<String>,
|
||||||
|
pub deleted: bool,
|
||||||
|
pub inbox_url: Url,
|
||||||
|
pub shared_inbox_url: Option<Url>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Insertable, AsChangeset, Clone)]
|
||||||
|
#[table_name = "person"]
|
||||||
|
pub struct PersonForm {
|
||||||
|
pub name: String,
|
||||||
|
pub preferred_username: Option<Option<String>>,
|
||||||
|
pub avatar: Option<Option<String>>,
|
||||||
|
pub banned: Option<bool>,
|
||||||
|
pub published: Option<chrono::NaiveDateTime>,
|
||||||
|
pub updated: Option<chrono::NaiveDateTime>,
|
||||||
|
pub actor_id: Option<Url>,
|
||||||
|
pub bio: Option<Option<String>>,
|
||||||
|
pub local: Option<bool>,
|
||||||
|
pub private_key: Option<Option<String>>,
|
||||||
|
pub public_key: Option<Option<String>>,
|
||||||
|
pub last_refreshed_at: Option<chrono::NaiveDateTime>,
|
||||||
|
pub banner: Option<Option<String>>,
|
||||||
|
pub deleted: Option<bool>,
|
||||||
|
pub inbox_url: Option<Url>,
|
||||||
|
pub shared_inbox_url: Option<Option<Url>>,
|
||||||
|
}
|
|
@ -1,10 +1,10 @@
|
||||||
use crate::{schema::user_mention, source::comment::Comment};
|
use crate::{schema::person_mention, source::comment::Comment};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
|
#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
|
||||||
#[belongs_to(Comment)]
|
#[belongs_to(Comment)]
|
||||||
#[table_name = "user_mention"]
|
#[table_name = "person_mention"]
|
||||||
pub struct UserMention {
|
pub struct PersonMention {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub recipient_id: i32,
|
pub recipient_id: i32,
|
||||||
pub comment_id: i32,
|
pub comment_id: i32,
|
||||||
|
@ -13,8 +13,8 @@ pub struct UserMention {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Insertable, AsChangeset)]
|
#[derive(Insertable, AsChangeset)]
|
||||||
#[table_name = "user_mention"]
|
#[table_name = "person_mention"]
|
||||||
pub struct UserMentionForm {
|
pub struct PersonMentionForm {
|
||||||
pub recipient_id: i32,
|
pub recipient_id: i32,
|
||||||
pub comment_id: i32,
|
pub comment_id: i32,
|
||||||
pub read: Option<bool>,
|
pub read: Option<bool>,
|
|
@ -57,7 +57,7 @@ pub struct PostForm {
|
||||||
pub struct PostLike {
|
pub struct PostLike {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub post_id: i32,
|
pub post_id: i32,
|
||||||
pub user_id: i32,
|
pub person_id: i32,
|
||||||
pub score: i16,
|
pub score: i16,
|
||||||
pub published: chrono::NaiveDateTime,
|
pub published: chrono::NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ pub struct PostLike {
|
||||||
#[table_name = "post_like"]
|
#[table_name = "post_like"]
|
||||||
pub struct PostLikeForm {
|
pub struct PostLikeForm {
|
||||||
pub post_id: i32,
|
pub post_id: i32,
|
||||||
pub user_id: i32,
|
pub person_id: i32,
|
||||||
pub score: i16,
|
pub score: i16,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ pub struct PostLikeForm {
|
||||||
pub struct PostSaved {
|
pub struct PostSaved {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
pub post_id: i32,
|
pub post_id: i32,
|
||||||
pub user_id: i32,
|
pub person_id: i32,
|
||||||
pub published: chrono::NaiveDateTime,
|
pub published: chrono::NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ pub struct PostSaved {
|
||||||
#[table_name = "post_saved"]
|
#[table_name = "post_saved"]
|
||||||
pub struct PostSavedForm {
|
pub struct PostSavedForm {
|
||||||
pub post_id: i32,
|
pub post_id: i32,
|
||||||
pub user_id: i32,
|
pub person_id: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
|
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
|
||||||
|
@ -92,11 +92,8 @@ pub struct PostSavedForm {
|
||||||
#[table_name = "post_read"]
|
#[table_name = "post_read"]
|
||||||
pub struct PostRead {
|
pub struct PostRead {
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
|
|
||||||
pub post_id: i32,
|
pub post_id: i32,
|
||||||
|
pub person_id: i32,
|
||||||
pub user_id: i32,
|
|
||||||
|
|
||||||
pub published: chrono::NaiveDateTime,
|
pub published: chrono::NaiveDateTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,6 +101,5 @@ pub struct PostRead {
|
||||||
#[table_name = "post_read"]
|
#[table_name = "post_read"]
|
||||||
pub struct PostReadForm {
|
pub struct PostReadForm {
|
||||||
pub post_id: i32,
|
pub post_id: i32,
|
||||||
|
pub person_id: i32,
|
||||||
pub user_id: i32,
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,220 +0,0 @@
|
||||||
use crate::{
|
|
||||||
schema::{user_, user_alias_1, user_alias_2},
|
|
||||||
Url,
|
|
||||||
};
|
|
||||||
use serde::Serialize;
|
|
||||||
|
|
||||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
|
||||||
#[table_name = "user_"]
|
|
||||||
pub struct User_ {
|
|
||||||
pub id: i32, // person
|
|
||||||
pub name: String, // person
|
|
||||||
pub preferred_username: Option<String>, // person
|
|
||||||
pub password_encrypted: String, // local_user
|
|
||||||
pub email: Option<String>, // local_user
|
|
||||||
pub avatar: Option<String>, // person
|
|
||||||
pub admin: bool, // local_user
|
|
||||||
pub banned: bool, // person?
|
|
||||||
pub published: chrono::NaiveDateTime, // person
|
|
||||||
pub updated: Option<chrono::NaiveDateTime>, // person
|
|
||||||
pub show_nsfw: bool, // local_user
|
|
||||||
pub theme: String, // local_user
|
|
||||||
pub default_sort_type: i16, // local_user
|
|
||||||
pub default_listing_type: i16, // local_user
|
|
||||||
pub lang: String, // local_user
|
|
||||||
pub show_avatars: bool, // local_user
|
|
||||||
pub send_notifications_to_email: bool, // local_user
|
|
||||||
pub matrix_user_id: Option<String>, // local_user
|
|
||||||
pub actor_id: Url, // person
|
|
||||||
pub bio: Option<String>, // person
|
|
||||||
pub local: bool, // person
|
|
||||||
pub private_key: Option<String>, // person
|
|
||||||
pub public_key: Option<String>, // person
|
|
||||||
pub last_refreshed_at: chrono::NaiveDateTime, // person
|
|
||||||
pub banner: Option<String>, // person
|
|
||||||
pub deleted: bool, // person
|
|
||||||
pub inbox_url: Url, // person
|
|
||||||
pub shared_inbox_url: Option<Url>, // person
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A safe representation of user, without the sensitive info
|
|
||||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
|
||||||
#[table_name = "user_"]
|
|
||||||
pub struct UserSafe {
|
|
||||||
pub id: i32,
|
|
||||||
pub name: String,
|
|
||||||
pub preferred_username: Option<String>,
|
|
||||||
pub avatar: Option<String>,
|
|
||||||
pub admin: bool,
|
|
||||||
pub banned: bool,
|
|
||||||
pub published: chrono::NaiveDateTime,
|
|
||||||
pub updated: Option<chrono::NaiveDateTime>,
|
|
||||||
pub matrix_user_id: Option<String>,
|
|
||||||
pub actor_id: Url,
|
|
||||||
pub bio: Option<String>,
|
|
||||||
pub local: bool,
|
|
||||||
pub banner: Option<String>,
|
|
||||||
pub deleted: bool,
|
|
||||||
pub inbox_url: Url,
|
|
||||||
pub shared_inbox_url: Option<Url>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A safe user view with only settings
|
|
||||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
|
||||||
#[table_name = "user_"]
|
|
||||||
pub struct UserSafeSettings {
|
|
||||||
pub id: i32,
|
|
||||||
pub name: String,
|
|
||||||
pub preferred_username: Option<String>,
|
|
||||||
pub email: Option<String>,
|
|
||||||
pub avatar: Option<String>,
|
|
||||||
pub admin: bool,
|
|
||||||
pub banned: bool,
|
|
||||||
pub published: chrono::NaiveDateTime,
|
|
||||||
pub updated: Option<chrono::NaiveDateTime>,
|
|
||||||
pub show_nsfw: bool,
|
|
||||||
pub theme: String,
|
|
||||||
pub default_sort_type: i16,
|
|
||||||
pub default_listing_type: i16,
|
|
||||||
pub lang: String,
|
|
||||||
pub show_avatars: bool,
|
|
||||||
pub send_notifications_to_email: bool,
|
|
||||||
pub matrix_user_id: Option<String>,
|
|
||||||
pub actor_id: Url,
|
|
||||||
pub bio: Option<String>,
|
|
||||||
pub local: bool,
|
|
||||||
pub last_refreshed_at: chrono::NaiveDateTime,
|
|
||||||
pub banner: Option<String>,
|
|
||||||
pub deleted: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
|
||||||
#[table_name = "user_alias_1"]
|
|
||||||
pub struct UserAlias1 {
|
|
||||||
pub id: i32,
|
|
||||||
pub name: String,
|
|
||||||
pub preferred_username: Option<String>,
|
|
||||||
pub password_encrypted: String,
|
|
||||||
pub email: Option<String>,
|
|
||||||
pub avatar: Option<String>,
|
|
||||||
pub admin: bool,
|
|
||||||
pub banned: bool,
|
|
||||||
pub published: chrono::NaiveDateTime,
|
|
||||||
pub updated: Option<chrono::NaiveDateTime>,
|
|
||||||
pub show_nsfw: bool,
|
|
||||||
pub theme: String,
|
|
||||||
pub default_sort_type: i16,
|
|
||||||
pub default_listing_type: i16,
|
|
||||||
pub lang: String,
|
|
||||||
pub show_avatars: bool,
|
|
||||||
pub send_notifications_to_email: bool,
|
|
||||||
pub matrix_user_id: Option<String>,
|
|
||||||
pub actor_id: Url,
|
|
||||||
pub bio: Option<String>,
|
|
||||||
pub local: bool,
|
|
||||||
pub private_key: Option<String>,
|
|
||||||
pub public_key: Option<String>,
|
|
||||||
pub last_refreshed_at: chrono::NaiveDateTime,
|
|
||||||
pub banner: Option<String>,
|
|
||||||
pub deleted: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
|
||||||
#[table_name = "user_alias_1"]
|
|
||||||
pub struct UserSafeAlias1 {
|
|
||||||
pub id: i32,
|
|
||||||
pub name: String,
|
|
||||||
pub preferred_username: Option<String>,
|
|
||||||
pub avatar: Option<String>,
|
|
||||||
pub admin: bool,
|
|
||||||
pub banned: bool,
|
|
||||||
pub published: chrono::NaiveDateTime,
|
|
||||||
pub updated: Option<chrono::NaiveDateTime>,
|
|
||||||
pub matrix_user_id: Option<String>,
|
|
||||||
pub actor_id: Url,
|
|
||||||
pub bio: Option<String>,
|
|
||||||
pub local: bool,
|
|
||||||
pub banner: Option<String>,
|
|
||||||
pub deleted: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
|
||||||
#[table_name = "user_alias_2"]
|
|
||||||
pub struct UserAlias2 {
|
|
||||||
pub id: i32,
|
|
||||||
pub name: String,
|
|
||||||
pub preferred_username: Option<String>,
|
|
||||||
pub password_encrypted: String,
|
|
||||||
pub email: Option<String>,
|
|
||||||
pub avatar: Option<String>,
|
|
||||||
pub admin: bool,
|
|
||||||
pub banned: bool,
|
|
||||||
pub published: chrono::NaiveDateTime,
|
|
||||||
pub updated: Option<chrono::NaiveDateTime>,
|
|
||||||
pub show_nsfw: bool,
|
|
||||||
pub theme: String,
|
|
||||||
pub default_sort_type: i16,
|
|
||||||
pub default_listing_type: i16,
|
|
||||||
pub lang: String,
|
|
||||||
pub show_avatars: bool,
|
|
||||||
pub send_notifications_to_email: bool,
|
|
||||||
pub matrix_user_id: Option<String>,
|
|
||||||
pub actor_id: Url,
|
|
||||||
pub bio: Option<String>,
|
|
||||||
pub local: bool,
|
|
||||||
pub private_key: Option<String>,
|
|
||||||
pub public_key: Option<String>,
|
|
||||||
pub last_refreshed_at: chrono::NaiveDateTime,
|
|
||||||
pub banner: Option<String>,
|
|
||||||
pub deleted: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
|
|
||||||
#[table_name = "user_alias_2"]
|
|
||||||
pub struct UserSafeAlias2 {
|
|
||||||
pub id: i32,
|
|
||||||
pub name: String,
|
|
||||||
pub preferred_username: Option<String>,
|
|
||||||
pub avatar: Option<String>,
|
|
||||||
pub admin: bool,
|
|
||||||
pub banned: bool,
|
|
||||||
pub published: chrono::NaiveDateTime,
|
|
||||||
pub updated: Option<chrono::NaiveDateTime>,
|
|
||||||
pub matrix_user_id: Option<String>,
|
|
||||||
pub actor_id: Url,
|
|
||||||
pub bio: Option<String>,
|
|
||||||
pub local: bool,
|
|
||||||
pub banner: Option<String>,
|
|
||||||
pub deleted: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Insertable, AsChangeset, Clone)]
|
|
||||||
#[table_name = "user_"]
|
|
||||||
pub struct UserForm {
|
|
||||||
pub name: String,
|
|
||||||
pub preferred_username: Option<Option<String>>,
|
|
||||||
pub password_encrypted: String,
|
|
||||||
pub admin: bool,
|
|
||||||
pub banned: Option<bool>,
|
|
||||||
pub email: Option<Option<String>>,
|
|
||||||
pub avatar: Option<Option<String>>,
|
|
||||||
pub published: Option<chrono::NaiveDateTime>,
|
|
||||||
pub updated: Option<chrono::NaiveDateTime>,
|
|
||||||
pub show_nsfw: bool,
|
|
||||||
pub theme: String,
|
|
||||||
pub default_sort_type: i16,
|
|
||||||
pub default_listing_type: i16,
|
|
||||||
pub lang: String,
|
|
||||||
pub show_avatars: bool,
|
|
||||||
pub send_notifications_to_email: bool,
|
|
||||||
pub matrix_user_id: Option<Option<String>>,
|
|
||||||
pub actor_id: Option<Url>,
|
|
||||||
pub bio: Option<Option<String>>,
|
|
||||||
pub local: bool,
|
|
||||||
pub private_key: Option<String>,
|
|
||||||
pub public_key: Option<String>,
|
|
||||||
pub last_refreshed_at: Option<chrono::NaiveDateTime>,
|
|
||||||
pub banner: Option<Option<String>>,
|
|
||||||
pub inbox_url: Option<Url>,
|
|
||||||
pub shared_inbox_url: Option<Option<Url>>,
|
|
||||||
}
|
|
|
@ -26,7 +26,7 @@ use lemmy_db_schema::{
|
||||||
},
|
},
|
||||||
source::{
|
source::{
|
||||||
comment::{Comment, CommentAlias1, CommentSaved},
|
comment::{Comment, CommentAlias1, CommentSaved},
|
||||||
community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
|
community::{Community, CommunityFollower, CommunitySafe, CommunityPersonBan},
|
||||||
post::Post,
|
post::Post,
|
||||||
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
|
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
|
||||||
},
|
},
|
||||||
|
@ -55,7 +55,7 @@ type CommentViewTuple = (
|
||||||
Post,
|
Post,
|
||||||
CommunitySafe,
|
CommunitySafe,
|
||||||
CommentAggregates,
|
CommentAggregates,
|
||||||
Option<CommunityUserBan>,
|
Option<CommunityPersonBan>,
|
||||||
Option<CommunityFollower>,
|
Option<CommunityFollower>,
|
||||||
Option<CommentSaved>,
|
Option<CommentSaved>,
|
||||||
Option<i16>,
|
Option<i16>,
|
||||||
|
@ -545,7 +545,7 @@ mod tests {
|
||||||
let comment_like_form = CommentLikeForm {
|
let comment_like_form = CommentLikeForm {
|
||||||
comment_id: inserted_comment.id,
|
comment_id: inserted_comment.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
user_id: inserted_user.id,
|
person_id: inserted_user.id,
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ use lemmy_db_schema::{
|
||||||
user_,
|
user_,
|
||||||
},
|
},
|
||||||
source::{
|
source::{
|
||||||
community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
|
community::{Community, CommunityFollower, CommunitySafe, CommunityPersonBan},
|
||||||
post::{Post, PostRead, PostSaved},
|
post::{Post, PostRead, PostSaved},
|
||||||
user::{UserSafe, User_},
|
user::{UserSafe, User_},
|
||||||
},
|
},
|
||||||
|
@ -48,7 +48,7 @@ type PostViewTuple = (
|
||||||
Post,
|
Post,
|
||||||
UserSafe,
|
UserSafe,
|
||||||
CommunitySafe,
|
CommunitySafe,
|
||||||
Option<CommunityUserBan>,
|
Option<CommunityPersonBan>,
|
||||||
PostAggregates,
|
PostAggregates,
|
||||||
Option<CommunityFollower>,
|
Option<CommunityFollower>,
|
||||||
Option<PostSaved>,
|
Option<PostSaved>,
|
||||||
|
@ -523,7 +523,7 @@ mod tests {
|
||||||
|
|
||||||
let post_like_form = PostLikeForm {
|
let post_like_form = PostLikeForm {
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
user_id: inserted_user.id,
|
person_id: inserted_user.id,
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -532,7 +532,7 @@ mod tests {
|
||||||
let expected_post_like = PostLike {
|
let expected_post_like = PostLike {
|
||||||
id: inserted_post_like.id,
|
id: inserted_post_like.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
user_id: inserted_user.id,
|
person_id: inserted_user.id,
|
||||||
published: inserted_post_like.published,
|
published: inserted_post_like.published,
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
|
@ -24,7 +24,7 @@ use lemmy_db_schema::{
|
||||||
},
|
},
|
||||||
source::{
|
source::{
|
||||||
comment::{Comment, CommentSaved},
|
comment::{Comment, CommentSaved},
|
||||||
community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
|
community::{Community, CommunityFollower, CommunitySafe, CommunityPersonBan},
|
||||||
post::Post,
|
post::Post,
|
||||||
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
|
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
|
||||||
user_mention::UserMention,
|
user_mention::UserMention,
|
||||||
|
@ -55,7 +55,7 @@ type UserMentionViewTuple = (
|
||||||
CommunitySafe,
|
CommunitySafe,
|
||||||
UserSafeAlias1,
|
UserSafeAlias1,
|
||||||
CommentAggregates,
|
CommentAggregates,
|
||||||
Option<CommunityUserBan>,
|
Option<CommunityPersonBan>,
|
||||||
Option<CommunityFollower>,
|
Option<CommunityFollower>,
|
||||||
Option<CommentSaved>,
|
Option<CommentSaved>,
|
||||||
Option<i16>,
|
Option<i16>,
|
||||||
|
|
Loading…
Reference in a new issue