Still continuing on....

This commit is contained in:
Dessalines 2021-02-26 08:49:58 -05:00
parent efc9047f87
commit a869a2823b
43 changed files with 1232 additions and 1470 deletions

View file

@ -134,7 +134,7 @@ impl Perform for CreateComment {
let like_form = CommentLikeForm {
comment_id: inserted_comment.id,
post_id,
user_id: user.id,
person_id: user.id,
score: 1,
};
@ -375,7 +375,7 @@ impl Perform for RemoveComment {
// Mod tables
let form = ModRemoveCommentForm {
mod_user_id: user.id,
mod_person_id: user.id,
comment_id: data.comment_id,
removed: Some(removed),
reason: data.reason.to_owned(),
@ -498,7 +498,7 @@ impl Perform for SaveComment {
let comment_saved_form = CommentSavedForm {
comment_id: data.comment_id,
user_id: user.id,
person_id: user.id,
};
if data.save {
@ -559,7 +559,7 @@ impl Perform for CreateCommentLike {
let like_form = CommentLikeForm {
comment_id: data.comment_id,
post_id: orig_comment.post.id,
user_id: user.id,
person_id: user.id,
score: data.score,
};

View file

@ -198,7 +198,7 @@ impl Perform for CreateCommunity {
// The community creator becomes a moderator
let community_moderator_form = CommunityModeratorForm {
community_id: inserted_community.id,
user_id: user.id,
person_id: user.id,
};
let join = move |conn: &'_ _| CommunityModerator::join(conn, &community_moderator_form);
@ -209,7 +209,7 @@ impl Perform for CreateCommunity {
// Follow your own community
let community_follower_form = CommunityFollowerForm {
community_id: inserted_community.id,
user_id: user.id,
person_id: user.id,
pending: false,
};
@ -405,7 +405,7 @@ impl Perform for RemoveCommunity {
None => None,
};
let form = ModRemoveCommunityForm {
mod_user_id: user.id,
mod_person_id: user.id,
community_id: data.community_id,
removed: Some(removed),
reason: data.reason.to_owned(),
@ -501,7 +501,7 @@ impl Perform for FollowCommunity {
.await??;
let community_follower_form = CommunityFollowerForm {
community_id: data.community_id,
user_id: user.id,
person_id: user.id,
pending: false,
};
@ -595,13 +595,13 @@ impl Perform for BanFromCommunity {
// Verify that only mods or admins can ban
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,
user_id: data.user_id,
person_id: data.user_id,
};
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() {
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
let community_follower_form = CommunityFollowerForm {
community_id: data.community_id,
user_id: banned_user_id,
person_id: banned_user_id,
pending: false,
};
blocking(context.pool(), move |conn: &'_ _| {
@ -618,7 +618,7 @@ impl Perform for BanFromCommunity {
.await?
.ok();
} 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() {
return Err(ApiError::err("community_user_already_banned").into());
}
@ -660,8 +660,8 @@ impl Perform for BanFromCommunity {
};
let form = ModBanFromCommunityForm {
mod_user_id: user.id,
other_user_id: data.user_id,
mod_person_id: user.id,
other_person_id: data.user_id,
community_id: data.community_id,
reason: data.reason.to_owned(),
banned: Some(data.ban),
@ -708,7 +708,7 @@ impl Perform for AddModToCommunity {
let community_moderator_form = CommunityModeratorForm {
community_id: data.community_id,
user_id: data.user_id,
person_id: data.user_id,
};
let community_id = data.community_id;
@ -730,8 +730,8 @@ impl Perform for AddModToCommunity {
// Mod tables
let form = ModAddCommunityForm {
mod_user_id: user.id,
other_user_id: data.user_id,
mod_person_id: user.id,
other_person_id: data.user_id,
community_id: data.community_id,
removed: Some(!data.added),
};
@ -829,7 +829,7 @@ impl Perform for TransferCommunity {
for cmod in &community_mods {
let community_moderator_form = CommunityModeratorForm {
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);
@ -840,8 +840,8 @@ impl Perform for TransferCommunity {
// Mod tables
let form = ModAddCommunityForm {
mod_user_id: user.id,
other_user_id: data.user_id,
mod_person_id: user.id,
other_person_id: data.user_id,
community_id: data.community_id,
removed: Some(false),
};

View file

@ -165,7 +165,7 @@ pub(crate) async fn collect_moderated_communities(
Ok(vec![community_id])
} else {
let ids = blocking(pool, move |conn: &'_ _| {
CommunityModerator::get_user_moderated_communities(conn, user_id)
CommunityModerator::get_person_moderated_communities(conn, user_id)
})
.await??;
Ok(ids)

View file

@ -129,7 +129,7 @@ impl Perform for CreatePost {
// They like their own post by default
let like_form = PostLikeForm {
post_id: inserted_post.id,
user_id: user.id,
person_id: user.id,
score: 1,
};
@ -303,7 +303,7 @@ impl Perform for CreatePostLike {
let like_form = PostLikeForm {
post_id: data.post_id,
user_id: user.id,
person_id: user.id,
score: data.score,
};
@ -534,7 +534,7 @@ impl Perform for RemovePost {
// Mod tables
let form = ModRemovePostForm {
mod_user_id: user.id,
mod_person_id: user.id,
post_id: data.post_id,
removed: Some(removed),
reason: data.reason.to_owned(),
@ -601,7 +601,7 @@ impl Perform for LockPost {
// Mod tables
let form = ModLockPostForm {
mod_user_id: user.id,
mod_person_id: user.id,
post_id: data.post_id,
locked: Some(locked),
};
@ -659,7 +659,7 @@ impl Perform for StickyPost {
// Mod tables
let form = ModStickyPostForm {
mod_user_id: user.id,
mod_person_id: user.id,
post_id: data.post_id,
stickied: Some(stickied),
};
@ -705,7 +705,7 @@ impl Perform for SavePost {
let post_saved_form = PostSavedForm {
post_id: data.post_id,
user_id: user.id,
person_id: user.id,
};
if data.save {

View file

@ -511,8 +511,8 @@ impl Perform for TransferSite {
// Mod tables
let form = ModAddForm {
mod_user_id: user.id,
other_user_id: data.user_id,
mod_person_id: user.id,
other_person_id: data.user_id,
removed: Some(false),
};

View file

@ -278,7 +278,7 @@ impl Perform for Register {
// Sign them up for main community no matter what
let community_follower_form = CommunityFollowerForm {
community_id: main_community.id,
user_id: inserted_user.id,
person_id: inserted_user.id,
pending: false,
};
@ -291,7 +291,7 @@ impl Perform for Register {
if no_admins {
let community_moderator_form = CommunityModeratorForm {
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);
@ -611,8 +611,8 @@ impl Perform for AddAdmin {
// Mod tables
let form = ModAddForm {
mod_user_id: user.id,
other_user_id: data.user_id,
mod_person_id: user.id,
other_person_id: data.user_id,
removed: Some(!data.added),
};
@ -693,8 +693,8 @@ impl Perform for BanUser {
};
let form = ModBanForm {
mod_user_id: user.id,
other_user_id: data.user_id,
mod_person_id: user.id,
other_person_id: data.user_id,
reason: data.reason.to_owned(),
banned: Some(data.ban),
expires,
@ -989,7 +989,7 @@ impl Perform for PasswordChange {
// Fetch the user_id from the token
let token = data.token.clone();
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??;

View file

@ -109,7 +109,7 @@ pub(crate) async fn receive_like_comment(
let like_form = CommentLikeForm {
comment_id,
post_id: comment.post_id,
user_id: user.id,
person_id: user.id,
score: 1,
};
let user_id = user.id;
@ -154,7 +154,7 @@ pub(crate) async fn receive_dislike_comment(
let like_form = CommentLikeForm {
comment_id,
post_id: comment.post_id,
user_id: user.id,
person_id: user.id,
score: -1,
};
let user_id = user.id;

View file

@ -80,7 +80,7 @@ pub(crate) async fn receive_like_post(
let post_id = post.id;
let like_form = PostLikeForm {
post_id,
user_id: user.id,
person_id: user.id,
score: 1,
};
let user_id = user.id;
@ -118,7 +118,7 @@ pub(crate) async fn receive_dislike_post(
let post_id = post.id;
let like_form = PostLikeForm {
post_id,
user_id: user.id,
person_id: user.id,
score: -1,
};
let user_id = user.id;

View file

@ -62,7 +62,7 @@ impl ActorType for User_ {
let community_follower_form = CommunityFollowerForm {
community_id: community.id,
user_id: self.id,
person_id: self.id,
pending: true,
};
blocking(&context.pool(), move |conn| {

View file

@ -104,7 +104,7 @@ async fn fetch_remote_community(
for mod_ in creator_and_moderators {
let community_moderator_form = CommunityModeratorForm {
community_id,
user_id: mod_.id,
person_id: mod_.id,
};
CommunityModerator::join(conn, &community_moderator_form)?;

View file

@ -191,7 +191,7 @@ async fn handle_follow(
let community_follower_form = CommunityFollowerForm {
community_id: community.id,
user_id: user.id,
person_id: user.id,
pending: false,
};
@ -246,7 +246,7 @@ async fn handle_undo_follow(
.await??;
let community_follower_form = CommunityFollowerForm {
community_id: community.id,
user_id: user.id,
person_id: user.id,
pending: false,
};

View file

@ -35,35 +35,25 @@ mod tests {
comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
community::{Community, CommunityForm},
post::{Post, PostForm},
user::{UserForm, User_},
person::{PersonForm, Person},
};
#[test]
fn test_crud() {
let conn = establish_unpooled_connection();
let new_user = UserForm {
let new_person = PersonForm {
name: "thommy_comment_agg".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
matrix_user_id: None,
avatar: None,
banner: None,
admin: false,
banned: Some(false),
banned: None,
deleted: None,
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,
local: None,
private_key: None,
public_key: None,
last_refreshed_at: None,
@ -71,30 +61,20 @@ mod tests {
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(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
matrix_user_id: None,
avatar: None,
banner: None,
admin: false,
banned: Some(false),
banned: None,
deleted: None,
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,
local: None,
private_key: None,
public_key: None,
last_refreshed_at: None,
@ -102,11 +82,11 @@ mod tests {
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 {
name: "TIL_comment_agg".into(),
creator_id: inserted_user.id,
creator_id: inserted_person.id,
title: "nada".to_owned(),
description: None,
nsfw: false,
@ -132,7 +112,7 @@ mod tests {
name: "A test post".into(),
url: None,
body: None,
creator_id: inserted_user.id,
creator_id: inserted_person.id,
community_id: inserted_community.id,
removed: None,
deleted: None,
@ -153,7 +133,7 @@ mod tests {
let comment_form = CommentForm {
content: "A test comment".into(),
creator_id: inserted_user.id,
creator_id: inserted_person.id,
post_id: inserted_post.id,
removed: None,
deleted: None,
@ -169,7 +149,7 @@ mod tests {
let child_comment_form = CommentForm {
content: "A test comment".into(),
creator_id: inserted_user.id,
creator_id: inserted_person.id,
post_id: inserted_post.id,
removed: None,
deleted: None,
@ -186,7 +166,7 @@ mod tests {
let comment_like = CommentLikeForm {
comment_id: inserted_comment.id,
post_id: inserted_post.id,
user_id: inserted_user.id,
person_id: inserted_person.id,
score: 1,
};
@ -198,11 +178,11 @@ mod tests {
assert_eq!(1, comment_aggs_before_delete.upvotes);
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 {
comment_id: inserted_comment.id,
post_id: inserted_post.id,
user_id: another_inserted_user.id,
person_id: another_inserted_person.id,
score: -1,
};
@ -215,7 +195,7 @@ mod tests {
assert_eq!(1, comment_aggs_after_dislike.downvotes);
// 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();
assert_eq!(-1, after_like_remove.score);
assert_eq!(0, after_like_remove.upvotes);
@ -229,8 +209,8 @@ mod tests {
assert!(after_delete.is_err());
// This should delete all the associated rows, and fire triggers
User_::delete(&conn, another_inserted_user.id).unwrap();
let user_num_deleted = User_::delete(&conn, inserted_user.id).unwrap();
assert_eq!(1, user_num_deleted);
Person::delete(&conn, another_inserted_person.id).unwrap();
let person_num_deleted = Person::delete(&conn, inserted_person.id).unwrap();
assert_eq!(1, person_num_deleted);
}
}

View file

@ -39,32 +39,22 @@ mod tests {
comment::{Comment, CommentForm},
community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm},
post::{Post, PostForm},
user::{UserForm, User_},
person::{PersonForm, Person},
};
#[test]
fn test_crud() {
let conn = establish_unpooled_connection();
let new_user = UserForm {
let new_person = PersonForm {
name: "thommy_community_agg".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
matrix_user_id: None,
avatar: None,
banner: None,
admin: false,
banned: Some(false),
deleted: 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,
@ -75,27 +65,17 @@ mod tests {
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(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
matrix_user_id: None,
avatar: None,
banner: None,
admin: false,
banned: Some(false),
deleted: 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,
@ -106,11 +86,11 @@ mod tests {
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 {
name: "TIL_community_agg".into(),
creator_id: inserted_user.id,
creator_id: inserted_person.id,
title: "nada".to_owned(),
description: None,
nsfw: false,
@ -134,7 +114,7 @@ mod tests {
let another_community = CommunityForm {
name: "TIL_community_agg_2".into(),
creator_id: inserted_user.id,
creator_id: inserted_person.id,
title: "nada".to_owned(),
description: None,
nsfw: false,
@ -156,25 +136,25 @@ mod tests {
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,
user_id: inserted_user.id,
person_id: inserted_person.id,
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,
user_id: another_inserted_user.id,
person_id: another_inserted_person.id,
pending: false,
};
CommunityFollower::follow(&conn, &second_user_follow).unwrap();
CommunityFollower::follow(&conn, &second_person_follow).unwrap();
let another_community_follow = CommunityFollowerForm {
community_id: another_inserted_community.id,
user_id: inserted_user.id,
person_id: inserted_person.id,
pending: false,
};
@ -184,7 +164,7 @@ mod tests {
name: "A test post".into(),
url: None,
body: None,
creator_id: inserted_user.id,
creator_id: inserted_person.id,
community_id: inserted_community.id,
removed: None,
deleted: None,
@ -205,7 +185,7 @@ mod tests {
let comment_form = CommentForm {
content: "A test comment".into(),
creator_id: inserted_user.id,
creator_id: inserted_person.id,
post_id: inserted_post.id,
removed: None,
deleted: None,
@ -221,7 +201,7 @@ mod tests {
let child_comment_form = CommentForm {
content: "A test comment".into(),
creator_id: inserted_user.id,
creator_id: inserted_person.id,
post_id: inserted_post.id,
removed: None,
deleted: None,
@ -250,12 +230,12 @@ mod tests {
assert_eq!(0, another_community_aggs.comments);
// 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();
assert_eq!(1, after_unfollow.subscribers);
// 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();
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.posts);
// Remove the 2nd user
User_::delete(&conn, another_inserted_user.id).unwrap();
let after_user_delete = CommunityAggregates::read(&conn, inserted_community.id).unwrap();
assert_eq!(1, after_user_delete.subscribers);
// Remove the 2nd person
Person::delete(&conn, another_inserted_person.id).unwrap();
let after_person_delete = CommunityAggregates::read(&conn, inserted_community.id).unwrap();
assert_eq!(1, after_person_delete.subscribers);
// This should delete all the associated rows, and fire triggers
let user_num_deleted = User_::delete(&conn, inserted_user.id).unwrap();
assert_eq!(1, user_num_deleted);
let person_num_deleted = Person::delete(&conn, inserted_person.id).unwrap();
assert_eq!(1, person_num_deleted);
// Should be none found, since the creator was deleted
let after_delete = CommunityAggregates::read(&conn, inserted_community.id);

View file

@ -2,4 +2,4 @@ pub mod comment_aggregates;
pub mod community_aggregates;
pub mod post_aggregates;
pub mod site_aggregates;
pub mod user_aggregates;
pub mod person_aggregates;

View file

@ -1,22 +1,22 @@
use diesel::{result::Error, *};
use lemmy_db_schema::schema::user_aggregates;
use lemmy_db_schema::schema::person_aggregates;
use serde::Serialize;
#[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Clone)]
#[table_name = "user_aggregates"]
pub struct UserAggregates {
#[table_name = "person_aggregates"]
pub struct PersonAggregates {
pub id: i32,
pub user_id: i32,
pub person_id: i32,
pub post_count: i64,
pub post_score: i64,
pub comment_count: i64,
pub comment_score: i64,
}
impl UserAggregates {
pub fn read(conn: &PgConnection, user_id: i32) -> Result<Self, Error> {
user_aggregates::table
.filter(user_aggregates::user_id.eq(user_id))
impl PersonAggregates {
pub fn read(conn: &PgConnection, person_id: i32) -> Result<Self, Error> {
person_aggregates::table
.filter(person_aggregates::person_id.eq(person_id))
.first::<Self>(conn)
}
}
@ -24,7 +24,7 @@ impl UserAggregates {
#[cfg(test)]
mod tests {
use crate::{
aggregates::user_aggregates::UserAggregates,
aggregates::person_aggregates::PersonAggregates,
establish_unpooled_connection,
Crud,
Likeable,
@ -35,32 +35,22 @@ mod tests {
comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
community::{Community, CommunityForm},
post::{Post, PostForm, PostLike, PostLikeForm},
user::{UserForm, User_},
person::{PersonForm, Person},
};
#[test]
fn test_crud() {
let conn = establish_unpooled_connection();
let new_user = UserForm {
let new_person = PersonForm {
name: "thommy_user_agg".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
matrix_user_id: None,
avatar: None,
banner: None,
admin: false,
banned: Some(false),
deleted: 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,
@ -71,27 +61,17 @@ mod tests {
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(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
matrix_user_id: None,
avatar: None,
banner: None,
admin: false,
banned: Some(false),
deleted: 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,
@ -102,11 +82,11 @@ mod tests {
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 {
name: "TIL_site_agg".into(),
creator_id: inserted_user.id,
creator_id: inserted_person.id,
title: "nada".to_owned(),
description: None,
nsfw: false,
@ -132,7 +112,7 @@ mod tests {
name: "A test post".into(),
url: None,
body: None,
creator_id: inserted_user.id,
creator_id: inserted_person.id,
community_id: inserted_community.id,
removed: None,
deleted: None,
@ -153,7 +133,7 @@ mod tests {
let post_like = PostLikeForm {
post_id: inserted_post.id,
user_id: inserted_user.id,
person_id: inserted_person.id,
score: 1,
};
@ -161,7 +141,7 @@ mod tests {
let comment_form = CommentForm {
content: "A test comment".into(),
creator_id: inserted_user.id,
creator_id: inserted_person.id,
post_id: inserted_post.id,
removed: None,
deleted: None,
@ -177,7 +157,7 @@ mod tests {
let mut comment_like = CommentLikeForm {
comment_id: inserted_comment.id,
user_id: inserted_user.id,
person_id: inserted_person.id,
post_id: inserted_post.id,
score: 1,
};
@ -186,7 +166,7 @@ mod tests {
let mut child_comment_form = CommentForm {
content: "A test comment".into(),
creator_id: inserted_user.id,
creator_id: inserted_person.id,
post_id: inserted_post.id,
removed: None,
deleted: None,
@ -202,28 +182,28 @@ mod tests {
let child_comment_like = CommentLikeForm {
comment_id: inserted_child_comment.id,
user_id: another_inserted_user.id,
person_id: another_inserted_person.id,
post_id: inserted_post.id,
score: 1,
};
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, user_aggregates_before_delete.post_score);
assert_eq!(2, user_aggregates_before_delete.comment_count);
assert_eq!(2, user_aggregates_before_delete.comment_score);
assert_eq!(1, person_aggregates_before_delete.post_count);
assert_eq!(1, person_aggregates_before_delete.post_score);
assert_eq!(2, person_aggregates_before_delete.comment_count);
assert_eq!(2, person_aggregates_before_delete.comment_score);
// Remove a post like
PostLike::remove(&conn, inserted_user.id, inserted_post.id).unwrap();
let after_post_like_remove = UserAggregates::read(&conn, inserted_user.id).unwrap();
PostLike::remove(&conn, inserted_person.id, inserted_post.id).unwrap();
let after_post_like_remove = PersonAggregates::read(&conn, inserted_person.id).unwrap();
assert_eq!(0, after_post_like_remove.post_score);
// Remove a parent comment (the scores should also be removed)
Comment::delete(&conn, inserted_comment.id).unwrap();
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_score);
@ -233,24 +213,24 @@ mod tests {
Comment::create(&conn, &child_comment_form).unwrap();
comment_like.comment_id = new_parent_comment.id;
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!(1, after_comment_add.comment_score);
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_count);
assert_eq!(0, after_post_delete.post_score);
assert_eq!(0, after_post_delete.post_count);
// This should delete all the associated rows, and fire triggers
let user_num_deleted = User_::delete(&conn, inserted_user.id).unwrap();
assert_eq!(1, user_num_deleted);
User_::delete(&conn, another_inserted_user.id).unwrap();
let person_num_deleted = Person::delete(&conn, inserted_person.id).unwrap();
assert_eq!(1, person_num_deleted);
Person::delete(&conn, another_inserted_person.id).unwrap();
// 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());
}
}

View file

@ -31,40 +31,27 @@ mod tests {
aggregates::post_aggregates::PostAggregates,
establish_unpooled_connection,
Crud,
Likeable,
ListingType,
SortType,
};
use lemmy_db_schema::source::{
comment::{Comment, CommentForm},
community::{Community, CommunityForm},
post::{Post, PostForm, PostLike, PostLikeForm},
user::{UserForm, User_},
person::{PersonForm, Person},
};
#[test]
fn test_crud() {
let conn = establish_unpooled_connection();
let new_user = UserForm {
let new_person = PersonForm {
name: "thommy_community_agg".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
matrix_user_id: None,
avatar: None,
banner: None,
admin: false,
banned: Some(false),
deleted: 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,
@ -75,27 +62,17 @@ mod tests {
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(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
matrix_user_id: None,
avatar: None,
banner: None,
admin: false,
banned: Some(false),
deleted: 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,
@ -106,11 +83,11 @@ mod tests {
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 {
name: "TIL_community_agg".into(),
creator_id: inserted_user.id,
creator_id: inserted_person.id,
title: "nada".to_owned(),
description: None,
nsfw: false,
@ -136,7 +113,7 @@ mod tests {
name: "A test post".into(),
url: None,
body: None,
creator_id: inserted_user.id,
creator_id: inserted_person.id,
community_id: inserted_community.id,
removed: None,
deleted: None,
@ -157,7 +134,7 @@ mod tests {
let comment_form = CommentForm {
content: "A test comment".into(),
creator_id: inserted_user.id,
creator_id: inserted_person.id,
post_id: inserted_post.id,
removed: None,
deleted: None,
@ -173,7 +150,7 @@ mod tests {
let child_comment_form = CommentForm {
content: "A test comment".into(),
creator_id: inserted_user.id,
creator_id: inserted_person.id,
post_id: inserted_post.id,
removed: None,
deleted: None,
@ -189,7 +166,7 @@ mod tests {
let post_like = PostLikeForm {
post_id: inserted_post.id,
user_id: inserted_user.id,
person_id: inserted_person.id,
score: 1,
};
@ -202,10 +179,10 @@ mod tests {
assert_eq!(1, post_aggs_before_delete.upvotes);
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 {
post_id: inserted_post.id,
user_id: another_inserted_user.id,
person_id: another_inserted_person.id,
score: -1,
};
@ -227,7 +204,7 @@ mod tests {
assert_eq!(1, after_comment_delete.downvotes);
// 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();
assert_eq!(0, after_like_remove.comments);
assert_eq!(-1, after_like_remove.score);
@ -235,9 +212,9 @@ mod tests {
assert_eq!(1, after_like_remove.downvotes);
// This should delete all the associated rows, and fire triggers
User_::delete(&conn, another_inserted_user.id).unwrap();
let user_num_deleted = User_::delete(&conn, inserted_user.id).unwrap();
assert_eq!(1, user_num_deleted);
Person::delete(&conn, another_inserted_person.id).unwrap();
let person_num_deleted = Person::delete(&conn, inserted_person.id).unwrap();
assert_eq!(1, person_num_deleted);
// Should be none found, since the creator was deleted
let after_delete = PostAggregates::read(&conn, inserted_post.id);

View file

@ -28,41 +28,28 @@ mod tests {
use crate::{
aggregates::site_aggregates::SiteAggregates,
establish_unpooled_connection,
Crud,
ListingType,
SortType,
};
use lemmy_db_schema::source::{
comment::{Comment, CommentForm},
community::{Community, CommunityForm},
post::{Post, PostForm},
site::{Site, SiteForm},
user::{UserForm, User_},
person::{PersonForm, Person},
};
#[test]
fn test_crud() {
let conn = establish_unpooled_connection();
let new_user = UserForm {
let new_person = PersonForm {
name: "thommy_site_agg".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
matrix_user_id: None,
avatar: None,
banner: None,
admin: false,
banned: Some(false),
deleted: 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,
@ -73,14 +60,14 @@ mod tests {
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 {
name: "test_site".into(),
description: None,
icon: None,
banner: None,
creator_id: inserted_user.id,
creator_id: inserted_person.id,
enable_downvotes: true,
open_registration: true,
enable_nsfw: true,
@ -91,7 +78,7 @@ mod tests {
let new_community = CommunityForm {
name: "TIL_site_agg".into(),
creator_id: inserted_user.id,
creator_id: inserted_person.id,
title: "nada".to_owned(),
description: None,
nsfw: false,
@ -117,7 +104,7 @@ mod tests {
name: "A test post".into(),
url: None,
body: None,
creator_id: inserted_user.id,
creator_id: inserted_person.id,
community_id: inserted_community.id,
removed: None,
deleted: None,
@ -140,7 +127,7 @@ mod tests {
let comment_form = CommentForm {
content: "A test comment".into(),
creator_id: inserted_user.id,
creator_id: inserted_person.id,
post_id: inserted_post.id,
removed: None,
deleted: None,
@ -157,7 +144,7 @@ mod tests {
let child_comment_form = CommentForm {
content: "A test comment".into(),
creator_id: inserted_user.id,
creator_id: inserted_person.id,
post_id: inserted_post.id,
removed: None,
deleted: None,
@ -185,8 +172,8 @@ mod tests {
assert_eq!(0, site_aggregates_after_post_delete.comments);
// This shouuld delete all the associated rows, and fire triggers
let user_num_deleted = User_::delete(&conn, inserted_user.id).unwrap();
assert_eq!(1, user_num_deleted);
let person_num_deleted = Person::delete(&conn, inserted_person.id).unwrap();
assert_eq!(1, person_num_deleted);
let after_delete = SiteAggregates::read(&conn);
assert!(after_delete.is_err());

View file

@ -124,13 +124,10 @@ mod tests {
use crate::{
establish_unpooled_connection,
source::activity::Activity_,
Crud,
ListingType,
SortType,
};
use lemmy_db_schema::source::{
activity::{Activity, ActivityForm},
user::{UserForm, User_},
person::{PersonForm, Person},
};
use serde_json::Value;
@ -138,28 +135,18 @@ mod tests {
fn test_crud() {
let conn = establish_unpooled_connection();
let creator_form = UserForm {
let creator_form = PersonForm {
name: "activity_creator_pm".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
matrix_user_id: None,
avatar: None,
banner: None,
admin: false,
banned: Some(false),
banned: None,
deleted: None,
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,
local: None,
private_key: None,
public_key: None,
last_refreshed_at: None,
@ -167,7 +154,7 @@ mod tests {
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 =
"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_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();
assert_eq!(expected_activity, read_activity);

View file

@ -166,17 +166,17 @@ impl Likeable<CommentLikeForm> for CommentLike {
use lemmy_db_schema::schema::comment_like::dsl::*;
insert_into(comment_like)
.values(comment_like_form)
.on_conflict((comment_id, user_id))
.on_conflict((comment_id, person_id))
.do_update()
.set(comment_like_form)
.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;
diesel::delete(
dsl::comment_like
.filter(dsl::comment_id.eq(comment_id))
.filter(dsl::user_id.eq(user_id)),
.filter(dsl::person_id.eq(person_id)),
)
.execute(conn)
}
@ -197,7 +197,7 @@ impl Saveable<CommentSavedForm> for CommentSaved {
diesel::delete(
comment_saved
.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)
}
@ -210,32 +210,22 @@ mod tests {
comment::*,
community::{Community, CommunityForm},
post::*,
user::{UserForm, User_},
person::{PersonForm, Person},
};
#[test]
fn test_crud() {
let conn = establish_unpooled_connection();
let new_user = UserForm {
let new_person = PersonForm {
name: "terry".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
matrix_user_id: None,
avatar: None,
banner: None,
admin: false,
banned: Some(false),
deleted: 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,
@ -246,13 +236,13 @@ mod tests {
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 {
name: "test community".to_string(),
title: "nada".to_owned(),
description: None,
creator_id: inserted_user.id,
creator_id: inserted_persod.id,
removed: None,
deleted: None,
updated: None,
@ -274,7 +264,7 @@ mod tests {
let new_post = PostForm {
name: "A test post".into(),
creator_id: inserted_user.id,
creator_id: inserted_persod.id,
url: None,
body: None,
community_id: inserted_community.id,
@ -297,7 +287,7 @@ mod tests {
let comment_form = CommentForm {
content: "A test comment".into(),
creator_id: inserted_user.id,
creator_id: inserted_persod.id,
post_id: inserted_post.id,
removed: None,
deleted: None,
@ -314,7 +304,7 @@ mod tests {
let expected_comment = Comment {
id: inserted_comment.id,
content: "A test comment".into(),
creator_id: inserted_user.id,
creator_id: inserted_persod.id,
post_id: inserted_post.id,
removed: false,
deleted: false,
@ -328,7 +318,7 @@ mod tests {
let child_comment_form = CommentForm {
content: "A child comment".into(),
creator_id: inserted_user.id,
creator_id: inserted_persod.id,
post_id: inserted_post.id,
parent_id: Some(inserted_comment.id),
removed: None,
@ -346,7 +336,7 @@ mod tests {
let comment_like_form = CommentLikeForm {
comment_id: inserted_comment.id,
post_id: inserted_post.id,
user_id: inserted_user.id,
person_id: inserted_persod.id,
score: 1,
};
@ -356,7 +346,7 @@ mod tests {
id: inserted_comment_like.id,
comment_id: inserted_comment.id,
post_id: inserted_post.id,
user_id: inserted_user.id,
person_id: inserted_persod.id,
published: inserted_comment_like.published,
score: 1,
};
@ -364,7 +354,7 @@ mod tests {
// Comment Saved
let comment_saved_form = CommentSavedForm {
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();
@ -372,19 +362,19 @@ mod tests {
let expected_comment_saved = CommentSaved {
id: inserted_comment_saved.id,
comment_id: inserted_comment.id,
user_id: inserted_user.id,
person_id: inserted_persod.id,
published: inserted_comment_saved.published,
};
let read_comment = Comment::read(&conn, inserted_comment.id).unwrap();
let updated_comment = Comment::update(&conn, inserted_comment.id, &comment_form).unwrap();
let like_removed = CommentLike::remove(&conn, inserted_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 num_deleted = Comment::delete(&conn, inserted_comment.id).unwrap();
Comment::delete(&conn, inserted_child_comment.id).unwrap();
Post::delete(&conn, inserted_post.id).unwrap();
Community::delete(&conn, inserted_community.id).unwrap();
User_::delete(&conn, inserted_user.id).unwrap();
Person::delete(&conn, inserted_persod.id).unwrap();
assert_eq!(expected_comment, read_comment);
assert_eq!(expected_comment, inserted_comment);

View file

@ -9,8 +9,8 @@ use lemmy_db_schema::{
CommunityForm,
CommunityModerator,
CommunityModeratorForm,
CommunityUserBan,
CommunityUserBanForm,
CommunityPersonBan,
CommunityPersonBanForm,
},
Url,
};
@ -206,23 +206,23 @@ impl Community_ for Community {
impl Joinable<CommunityModeratorForm> for CommunityModerator {
fn join(
conn: &PgConnection,
community_user_form: &CommunityModeratorForm,
community_moderator_form: &CommunityModeratorForm,
) -> Result<Self, Error> {
use lemmy_db_schema::schema::community_moderator::dsl::*;
insert_into(community_moderator)
.values(community_user_form)
.values(community_moderator_form)
.get_result::<Self>(conn)
}
fn leave(
conn: &PgConnection,
community_user_form: &CommunityModeratorForm,
community_moderator_form: &CommunityModeratorForm,
) -> Result<usize, Error> {
use lemmy_db_schema::schema::community_moderator::dsl::*;
diesel::delete(
community_moderator
.filter(community_id.eq(community_user_form.community_id))
.filter(user_id.eq(community_user_form.user_id)),
.filter(community_id.eq(community_moderator_form.community_id))
.filter(person_id.eq(community_moderator_form.person_id)),
)
.execute(conn)
}
@ -230,9 +230,9 @@ impl Joinable<CommunityModeratorForm> for CommunityModerator {
pub trait CommunityModerator_ {
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,
for_user_id: i32,
for_person_id: i32,
) -> 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)
}
fn get_user_moderated_communities(
fn get_person_moderated_communities(
conn: &PgConnection,
for_user_id: i32,
for_person_id: i32,
) -> Result<Vec<i32>, Error> {
use lemmy_db_schema::schema::community_moderator::dsl::*;
community_moderator
.filter(user_id.eq(for_user_id))
.filter(person_id.eq(for_person_id))
.select(community_id)
.load::<i32>(conn)
}
}
impl Bannable<CommunityUserBanForm> for CommunityUserBan {
impl Bannable<CommunityPersonBanForm> for CommunityPersonBan {
fn ban(
conn: &PgConnection,
community_user_ban_form: &CommunityUserBanForm,
community_person_ban_form: &CommunityPersonBanForm,
) -> Result<Self, Error> {
use lemmy_db_schema::schema::community_user_ban::dsl::*;
insert_into(community_user_ban)
.values(community_user_ban_form)
use lemmy_db_schema::schema::community_person_ban::dsl::*;
insert_into(community_person_ban)
.values(community_person_ban_form)
.get_result::<Self>(conn)
}
fn unban(
conn: &PgConnection,
community_user_ban_form: &CommunityUserBanForm,
community_person_ban_form: &CommunityPersonBanForm,
) -> Result<usize, Error> {
use lemmy_db_schema::schema::community_user_ban::dsl::*;
use lemmy_db_schema::schema::community_person_ban::dsl::*;
diesel::delete(
community_user_ban
.filter(community_id.eq(community_user_ban_form.community_id))
.filter(user_id.eq(community_user_ban_form.user_id)),
community_person_ban
.filter(community_id.eq(community_person_ban_form.community_id))
.filter(person_id.eq(community_person_ban_form.person_id)),
)
.execute(conn)
}
@ -313,7 +313,7 @@ impl Followable<CommunityFollowerForm> for CommunityFollower {
diesel::delete(
community_follower
.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)
}
@ -339,31 +339,21 @@ mod tests {
ListingType,
SortType,
};
use lemmy_db_schema::source::{community::*, user::*};
use lemmy_db_schema::source::{community::*, person::*};
#[test]
fn test_crud() {
let conn = establish_unpooled_connection();
let new_user = UserForm {
let new_person = PersonForm {
name: "bobbee".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
matrix_user_id: None,
avatar: None,
banner: None,
admin: false,
banned: Some(false),
deleted: 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,
@ -374,11 +364,11 @@ mod tests {
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 {
name: "TIL".into(),
creator_id: inserted_user.id,
creator_id: inserted_person.id,
title: "nada".to_owned(),
description: None,
nsfw: false,
@ -402,7 +392,7 @@ mod tests {
let expected_community = Community {
id: inserted_community.id,
creator_id: inserted_user.id,
creator_id: inserted_person.id,
name: "TIL".into(),
title: "nada".to_owned(),
description: None,
@ -425,7 +415,7 @@ mod tests {
let community_follower_form = CommunityFollowerForm {
community_id: inserted_community.id,
user_id: inserted_user.id,
person_id: inserted_person.id,
pending: false,
};
@ -435,55 +425,55 @@ mod tests {
let expected_community_follower = CommunityFollower {
id: inserted_community_follower.id,
community_id: inserted_community.id,
user_id: inserted_user.id,
person_id: inserted_person.id,
pending: Some(false),
published: inserted_community_follower.published,
};
let community_user_form = CommunityModeratorForm {
let community_moderator_form = CommunityModeratorForm {
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 {
id: inserted_community_user.id,
let expected_community_moderator = CommunityModerator {
id: inserted_community_moderator.id,
community_id: inserted_community.id,
user_id: inserted_user.id,
published: inserted_community_user.published,
person_id: inserted_person.id,
published: inserted_community_moderator.published,
};
let community_user_ban_form = CommunityUserBanForm {
let community_person_ban_form = CommunityPersonBanForm {
community_id: inserted_community.id,
user_id: inserted_user.id,
person_id: inserted_person.id,
};
let inserted_community_user_ban =
CommunityUserBan::ban(&conn, &community_user_ban_form).unwrap();
let inserted_community_person_ban =
CommunityPersonBan::ban(&conn, &community_person_ban_form).unwrap();
let expected_community_user_ban = CommunityUserBan {
id: inserted_community_user_ban.id,
let expected_community_person_ban = CommunityPersonBan {
id: inserted_community_person_ban.id,
community_id: inserted_community.id,
user_id: inserted_user.id,
published: inserted_community_user_ban.published,
person_id: inserted_person.id,
published: inserted_community_person_ban.published,
};
let read_community = Community::read(&conn, inserted_community.id).unwrap();
let updated_community =
Community::update(&conn, inserted_community.id, &new_community).unwrap();
let ignored_community = CommunityFollower::unfollow(&conn, &community_follower_form).unwrap();
let left_community = CommunityModerator::leave(&conn, &community_user_form).unwrap();
let unban = CommunityUserBan::unban(&conn, &community_user_ban_form).unwrap();
let left_community = CommunityModerator::leave(&conn, &community_moderator_form).unwrap();
let unban = CommunityPersonBan::unban(&conn, &community_person_ban_form).unwrap();
let num_deleted = Community::delete(&conn, inserted_community.id).unwrap();
User_::delete(&conn, inserted_user.id).unwrap();
Person::delete(&conn, inserted_person.id).unwrap();
assert_eq!(expected_community, read_community);
assert_eq!(expected_community, inserted_community);
assert_eq!(expected_community, updated_community);
assert_eq!(expected_community_follower, inserted_community_follower);
assert_eq!(expected_community_user, inserted_community_user);
assert_eq!(expected_community_user_ban, inserted_community_user_ban);
assert_eq!(expected_community_moderator, inserted_community_moderator);
assert_eq!(expected_community_person_ban, inserted_community_person_ban);
assert_eq!(1, ignored_community);
assert_eq!(1, left_community);
assert_eq!(1, unban);

View 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)
}
}

View file

@ -8,5 +8,6 @@ pub mod post;
pub mod post_report;
pub mod private_message;
pub mod site;
pub mod user;
pub mod user_mention;
pub mod person;
pub mod person_mention;
pub mod local_user;

View file

@ -198,32 +198,22 @@ impl Crud<ModAddForm> for ModAdd {
#[cfg(test)]
mod tests {
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;
#[test]
fn test_crud() {
let conn = establish_unpooled_connection();
let new_mod = UserForm {
let new_mod = PersonForm {
name: "the mod".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
matrix_user_id: None,
avatar: None,
banner: None,
admin: false,
banned: Some(false),
deleted: 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,
@ -234,27 +224,17 @@ mod tests {
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(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
matrix_user_id: None,
avatar: None,
banner: None,
admin: false,
banned: Some(false),
deleted: 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,
@ -265,13 +245,13 @@ mod tests {
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 {
name: "mod_community".to_string(),
title: "nada".to_owned(),
description: None,
creator_id: inserted_user.id,
creator_id: inserted_person.id,
removed: None,
deleted: None,
updated: None,
@ -295,7 +275,7 @@ mod tests {
name: "A test post thweep".into(),
url: None,
body: None,
creator_id: inserted_user.id,
creator_id: inserted_person.id,
community_id: inserted_community.id,
removed: None,
deleted: None,
@ -316,7 +296,7 @@ mod tests {
let comment_form = CommentForm {
content: "A test comment".into(),
creator_id: inserted_user.id,
creator_id: inserted_person.id,
post_id: inserted_post.id,
removed: None,
deleted: None,
@ -334,7 +314,7 @@ mod tests {
// remove post
let mod_remove_post_form = ModRemovePostForm {
mod_user_id: inserted_mod.id,
mod_person_id: inserted_mod.id,
post_id: inserted_post.id,
reason: None,
removed: None,
@ -344,7 +324,7 @@ mod tests {
let expected_mod_remove_post = ModRemovePost {
id: inserted_mod_remove_post.id,
post_id: inserted_post.id,
mod_user_id: inserted_mod.id,
mod_person_id: inserted_mod.id,
reason: None,
removed: Some(true),
when_: inserted_mod_remove_post.when_,
@ -353,7 +333,7 @@ mod tests {
// lock post
let mod_lock_post_form = ModLockPostForm {
mod_user_id: inserted_mod.id,
mod_person_id: inserted_mod.id,
post_id: inserted_post.id,
locked: None,
};
@ -362,7 +342,7 @@ mod tests {
let expected_mod_lock_post = ModLockPost {
id: inserted_mod_lock_post.id,
post_id: inserted_post.id,
mod_user_id: inserted_mod.id,
mod_person_id: inserted_mod.id,
locked: Some(true),
when_: inserted_mod_lock_post.when_,
};
@ -370,7 +350,7 @@ mod tests {
// sticky post
let mod_sticky_post_form = ModStickyPostForm {
mod_user_id: inserted_mod.id,
mod_person_id: inserted_mod.id,
post_id: inserted_post.id,
stickied: None,
};
@ -379,7 +359,7 @@ mod tests {
let expected_mod_sticky_post = ModStickyPost {
id: inserted_mod_sticky_post.id,
post_id: inserted_post.id,
mod_user_id: inserted_mod.id,
mod_person_id: inserted_mod.id,
stickied: Some(true),
when_: inserted_mod_sticky_post.when_,
};
@ -387,7 +367,7 @@ mod tests {
// comment
let mod_remove_comment_form = ModRemoveCommentForm {
mod_user_id: inserted_mod.id,
mod_person_id: inserted_mod.id,
comment_id: inserted_comment.id,
reason: None,
removed: None,
@ -399,7 +379,7 @@ mod tests {
let expected_mod_remove_comment = ModRemoveComment {
id: inserted_mod_remove_comment.id,
comment_id: inserted_comment.id,
mod_user_id: inserted_mod.id,
mod_person_id: inserted_mod.id,
reason: None,
removed: Some(true),
when_: inserted_mod_remove_comment.when_,
@ -408,7 +388,7 @@ mod tests {
// community
let mod_remove_community_form = ModRemoveCommunityForm {
mod_user_id: inserted_mod.id,
mod_person_id: inserted_mod.id,
community_id: inserted_community.id,
reason: None,
removed: None,
@ -421,7 +401,7 @@ mod tests {
let expected_mod_remove_community = ModRemoveCommunity {
id: inserted_mod_remove_community.id,
community_id: inserted_community.id,
mod_user_id: inserted_mod.id,
mod_person_id: inserted_mod.id,
reason: None,
removed: Some(true),
expires: None,
@ -431,8 +411,8 @@ mod tests {
// ban from community
let mod_ban_from_community_form = ModBanFromCommunityForm {
mod_user_id: inserted_mod.id,
other_user_id: inserted_user.id,
mod_person_id: inserted_mod.id,
other_person_id: inserted_person.id,
community_id: inserted_community.id,
reason: None,
banned: None,
@ -445,8 +425,8 @@ mod tests {
let expected_mod_ban_from_community = ModBanFromCommunity {
id: inserted_mod_ban_from_community.id,
community_id: inserted_community.id,
mod_user_id: inserted_mod.id,
other_user_id: inserted_user.id,
mod_person_id: inserted_mod.id,
other_person_id: inserted_person.id,
reason: None,
banned: Some(true),
expires: None,
@ -456,8 +436,8 @@ mod tests {
// ban
let mod_ban_form = ModBanForm {
mod_user_id: inserted_mod.id,
other_user_id: inserted_user.id,
mod_person_id: inserted_mod.id,
other_person_id: inserted_person.id,
reason: None,
banned: None,
expires: None,
@ -466,8 +446,8 @@ mod tests {
let read_mod_ban = ModBan::read(&conn, inserted_mod_ban.id).unwrap();
let expected_mod_ban = ModBan {
id: inserted_mod_ban.id,
mod_user_id: inserted_mod.id,
other_user_id: inserted_user.id,
mod_person_id: inserted_mod.id,
other_person_id: inserted_person.id,
reason: None,
banned: Some(true),
expires: None,
@ -477,8 +457,8 @@ mod tests {
// mod add community
let mod_add_community_form = ModAddCommunityForm {
mod_user_id: inserted_mod.id,
other_user_id: inserted_user.id,
mod_person_id: inserted_mod.id,
other_person_id: inserted_person.id,
community_id: inserted_community.id,
removed: None,
};
@ -489,8 +469,8 @@ mod tests {
let expected_mod_add_community = ModAddCommunity {
id: inserted_mod_add_community.id,
community_id: inserted_community.id,
mod_user_id: inserted_mod.id,
other_user_id: inserted_user.id,
mod_person_id: inserted_mod.id,
other_person_id: inserted_person.id,
removed: Some(false),
when_: inserted_mod_add_community.when_,
};
@ -498,16 +478,16 @@ mod tests {
// mod add
let mod_add_form = ModAddForm {
mod_user_id: inserted_mod.id,
other_user_id: inserted_user.id,
mod_person_id: inserted_mod.id,
other_person_id: inserted_person.id,
removed: None,
};
let inserted_mod_add = ModAdd::create(&conn, &mod_add_form).unwrap();
let read_mod_add = ModAdd::read(&conn, inserted_mod_add.id).unwrap();
let expected_mod_add = ModAdd {
id: inserted_mod_add.id,
mod_user_id: inserted_mod.id,
other_user_id: inserted_user.id,
mod_person_id: inserted_mod.id,
other_person_id: inserted_person.id,
removed: Some(false),
when_: inserted_mod_add.when_,
};
@ -515,8 +495,8 @@ mod tests {
Comment::delete(&conn, inserted_comment.id).unwrap();
Post::delete(&conn, inserted_post.id).unwrap();
Community::delete(&conn, inserted_community.id).unwrap();
User_::delete(&conn, inserted_user.id).unwrap();
User_::delete(&conn, inserted_mod.id).unwrap();
Person::delete(&conn, inserted_person.id).unwrap();
Person::delete(&conn, inserted_mod.id).unwrap();
assert_eq!(expected_mod_remove_post, read_mod_remove_post);
assert_eq!(expected_mod_lock_post, read_mod_lock_post);

View file

@ -28,7 +28,7 @@ impl Crud<PasswordResetRequestForm> for PasswordResetRequest {
pub trait PasswordResetRequest_ {
fn create_token(
conn: &PgConnection,
from_user_id: i32,
from_local_user_id: i32,
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 {
fn create_token(
conn: &PgConnection,
from_user_id: i32,
from_local_user_id: i32,
token: &str,
) -> Result<PasswordResetRequest, Error> {
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 form = PasswordResetRequestForm {
user_id: from_user_id,
local_user_id: from_local_user_id,
token_encrypted: token_hash,
};
@ -79,31 +79,21 @@ mod tests {
ListingType,
SortType,
};
use lemmy_db_schema::source::{password_reset_request::PasswordResetRequest, user::*};
use lemmy_db_schema::source::{password_reset_request::PasswordResetRequest, person::*};
#[test]
fn test_crud() {
let conn = establish_unpooled_connection();
let new_user = UserForm {
let new_person = PersonForm {
name: "thommy prw".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
matrix_user_id: None,
avatar: None,
banner: None,
admin: false,
banned: Some(false),
deleted: 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,
@ -114,23 +104,23 @@ mod tests {
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_encrypted_ = "ca3704aa0b06f5954c79ee837faa152d84d6b2d42838f0637a15eda8337dbdce";
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 {
id: inserted_password_reset_request.id,
user_id: inserted_user.id,
local_user_id: inserted_person.id,
token_encrypted: token_encrypted_.to_string(),
published: inserted_password_reset_request.published,
};
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!(

View 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);
}
}

View file

@ -1,57 +1,57 @@
use crate::Crud;
use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::source::user_mention::*;
use lemmy_db_schema::source::person_mention::*;
impl Crud<UserMentionForm> for UserMention {
fn read(conn: &PgConnection, user_mention_id: i32) -> Result<Self, Error> {
use lemmy_db_schema::schema::user_mention::dsl::*;
user_mention.find(user_mention_id).first::<Self>(conn)
impl Crud<PersonMentionForm> for PersonMention {
fn read(conn: &PgConnection, person_mention_id: i32) -> Result<Self, Error> {
use lemmy_db_schema::schema::person_mention::dsl::*;
person_mention.find(person_mention_id).first::<Self>(conn)
}
fn create(conn: &PgConnection, user_mention_form: &UserMentionForm) -> Result<Self, Error> {
use lemmy_db_schema::schema::user_mention::dsl::*;
fn create(conn: &PgConnection, person_mention_form: &PersonMentionForm) -> Result<Self, Error> {
use lemmy_db_schema::schema::person_mention::dsl::*;
// since the return here isnt utilized, we dont need to do an update
// but get_result doesnt return the existing row here
insert_into(user_mention)
.values(user_mention_form)
insert_into(person_mention)
.values(person_mention_form)
.on_conflict((recipient_id, comment_id))
.do_update()
.set(user_mention_form)
.set(person_mention_form)
.get_result::<Self>(conn)
}
fn update(
conn: &PgConnection,
user_mention_id: i32,
user_mention_form: &UserMentionForm,
person_mention_id: i32,
person_mention_form: &PersonMentionForm,
) -> Result<Self, Error> {
use lemmy_db_schema::schema::user_mention::dsl::*;
diesel::update(user_mention.find(user_mention_id))
.set(user_mention_form)
use lemmy_db_schema::schema::person_mention::dsl::*;
diesel::update(person_mention.find(person_mention_id))
.set(person_mention_form)
.get_result::<Self>(conn)
}
}
pub trait UserMention_ {
pub trait PersonMention_ {
fn update_read(
conn: &PgConnection,
user_mention_id: i32,
person_mention_id: i32,
new_read: bool,
) -> Result<UserMention, Error>;
) -> Result<PersonMention, Error>;
fn mark_all_as_read(
conn: &PgConnection,
for_recipient_id: i32,
) -> Result<Vec<UserMention>, Error>;
) -> Result<Vec<PersonMention>, Error>;
}
impl UserMention_ for UserMention {
impl PersonMention_ for PersonMention {
fn update_read(
conn: &PgConnection,
user_mention_id: i32,
person_mention_id: i32,
new_read: bool,
) -> Result<UserMention, Error> {
use lemmy_db_schema::schema::user_mention::dsl::*;
diesel::update(user_mention.find(user_mention_id))
) -> Result<PersonMention, Error> {
use lemmy_db_schema::schema::person_mention::dsl::*;
diesel::update(person_mention.find(person_mention_id))
.set(read.eq(new_read))
.get_result::<Self>(conn)
}
@ -59,10 +59,10 @@ impl UserMention_ for UserMention {
fn mark_all_as_read(
conn: &PgConnection,
for_recipient_id: i32,
) -> Result<Vec<UserMention>, Error> {
use lemmy_db_schema::schema::user_mention::dsl::*;
) -> Result<Vec<PersonMention>, Error> {
use lemmy_db_schema::schema::person_mention::dsl::*;
diesel::update(
user_mention
person_mention
.filter(recipient_id.eq(for_recipient_id))
.filter(read.eq(false)),
)
@ -78,33 +78,23 @@ mod tests {
comment::*,
community::{Community, CommunityForm},
post::*,
user::*,
user_mention::*,
person::*,
person_mention::*,
};
#[test]
fn test_crud() {
let conn = establish_unpooled_connection();
let new_user = UserForm {
let new_person = PersonForm {
name: "terrylake".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
matrix_user_id: None,
avatar: None,
banner: None,
admin: false,
banned: Some(false),
deleted: 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,
@ -115,27 +105,17 @@ mod tests {
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(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
matrix_user_id: None,
avatar: None,
banner: None,
admin: false,
banned: Some(false),
deleted: 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,
@ -146,13 +126,13 @@ mod tests {
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 {
name: "test community lake".to_string(),
title: "nada".to_owned(),
description: None,
creator_id: inserted_user.id,
creator_id: inserted_person.id,
removed: None,
deleted: None,
updated: None,
@ -174,7 +154,7 @@ mod tests {
let new_post = PostForm {
name: "A test post".into(),
creator_id: inserted_user.id,
creator_id: inserted_person.id,
url: None,
body: None,
community_id: inserted_community.id,
@ -197,7 +177,7 @@ mod tests {
let comment_form = CommentForm {
content: "A test comment".into(),
creator_id: inserted_user.id,
creator_id: inserted_person.id,
post_id: inserted_post.id,
removed: None,
deleted: None,
@ -211,15 +191,15 @@ mod tests {
let inserted_comment = Comment::create(&conn, &comment_form).unwrap();
let user_mention_form = UserMentionForm {
let person_mention_form = PersonMentionForm {
recipient_id: inserted_recipient.id,
comment_id: inserted_comment.id,
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,
recipient_id: inserted_mention.recipient_id,
comment_id: inserted_mention.comment_id,
@ -227,14 +207,14 @@ mod tests {
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 =
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();
Post::delete(&conn, inserted_post.id).unwrap();
Community::delete(&conn, inserted_community.id).unwrap();
User_::delete(&conn, inserted_user.id).unwrap();
User_::delete(&conn, inserted_recipient.id).unwrap();
Person::delete(&conn, inserted_person.id).unwrap();
Person::delete(&conn, inserted_recipient.id).unwrap();
assert_eq!(expected_mention, read_mention);
assert_eq!(expected_mention, inserted_mention);

View file

@ -54,7 +54,7 @@ pub trait Post_ {
) -> Result<Vec<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 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 {
@ -141,8 +141,8 @@ impl Post_ for Post {
.get_result::<Self>(conn)
}
fn is_post_creator(user_id: i32, post_creator_id: i32) -> bool {
user_id == post_creator_id
fn is_post_creator(person_id: i32, post_creator_id: i32) -> bool {
person_id == post_creator_id
}
}
@ -168,17 +168,17 @@ impl Likeable<PostLikeForm> for PostLike {
use lemmy_db_schema::schema::post_like::dsl::*;
insert_into(post_like)
.values(post_like_form)
.on_conflict((post_id, user_id))
.on_conflict((post_id, person_id))
.do_update()
.set(post_like_form)
.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;
diesel::delete(
dsl::post_like
.filter(dsl::post_id.eq(post_id))
.filter(dsl::user_id.eq(user_id)),
.filter(dsl::person_id.eq(person_id)),
)
.execute(conn)
}
@ -189,7 +189,7 @@ impl Saveable<PostSavedForm> for PostSaved {
use lemmy_db_schema::schema::post_saved::dsl::*;
insert_into(post_saved)
.values(post_saved_form)
.on_conflict((post_id, user_id))
.on_conflict((post_id, person_id))
.do_update()
.set(post_saved_form)
.get_result::<Self>(conn)
@ -199,7 +199,7 @@ impl Saveable<PostSavedForm> for PostSaved {
diesel::delete(
post_saved
.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)
}
@ -218,7 +218,7 @@ impl Readable<PostReadForm> for PostRead {
diesel::delete(
post_read
.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)
}
@ -229,32 +229,22 @@ mod tests {
use crate::{establish_unpooled_connection, source::post::*, ListingType, SortType};
use lemmy_db_schema::source::{
community::{Community, CommunityForm},
user::*,
person::*,
};
#[test]
fn test_crud() {
let conn = establish_unpooled_connection();
let new_user = UserForm {
let new_person = PersonForm {
name: "jim".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
matrix_user_id: None,
avatar: None,
banner: None,
admin: false,
banned: Some(false),
deleted: 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,
@ -265,13 +255,13 @@ mod tests {
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 {
name: "test community_3".to_string(),
title: "nada".to_owned(),
description: None,
creator_id: inserted_user.id,
creator_id: inserted_person.id,
removed: None,
deleted: None,
updated: None,
@ -295,7 +285,7 @@ mod tests {
name: "A test post".into(),
url: None,
body: None,
creator_id: inserted_user.id,
creator_id: inserted_person.id,
community_id: inserted_community.id,
removed: None,
deleted: None,
@ -319,7 +309,7 @@ mod tests {
name: "A test post".into(),
url: None,
body: None,
creator_id: inserted_user.id,
creator_id: inserted_person.id,
community_id: inserted_community.id,
published: inserted_post.published,
removed: false,
@ -339,7 +329,7 @@ mod tests {
// Post Like
let post_like_form = PostLikeForm {
post_id: inserted_post.id,
user_id: inserted_user.id,
person_id: inserted_person.id,
score: 1,
};
@ -348,7 +338,7 @@ mod tests {
let expected_post_like = PostLike {
id: inserted_post_like.id,
post_id: inserted_post.id,
user_id: inserted_user.id,
person_id: inserted_person.id,
published: inserted_post_like.published,
score: 1,
};
@ -356,7 +346,7 @@ mod tests {
// Post Save
let post_saved_form = PostSavedForm {
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();
@ -364,14 +354,14 @@ mod tests {
let expected_post_saved = PostSaved {
id: inserted_post_saved.id,
post_id: inserted_post.id,
user_id: inserted_user.id,
person_id: inserted_person.id,
published: inserted_post_saved.published,
};
// Post Read
let post_read_form = PostReadForm {
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();
@ -379,18 +369,18 @@ mod tests {
let expected_post_read = PostRead {
id: inserted_post_read.id,
post_id: inserted_post.id,
user_id: inserted_user.id,
person_id: inserted_person.id,
published: inserted_post_read.published,
};
let read_post = Post::read(&conn, inserted_post.id).unwrap();
let updated_post = Post::update(&conn, inserted_post.id, &new_post).unwrap();
let like_removed = PostLike::remove(&conn, inserted_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 read_removed = PostRead::mark_as_unread(&conn, &post_read_form).unwrap();
let num_deleted = Post::delete(&conn, inserted_post.id).unwrap();
Community::delete(&conn, inserted_community.id).unwrap();
User_::delete(&conn, inserted_user.id).unwrap();
Person::delete(&conn, inserted_person.id).unwrap();
assert_eq!(expected_post, read_post);
assert_eq!(expected_post, inserted_post);

View file

@ -146,31 +146,21 @@ mod tests {
ListingType,
SortType,
};
use lemmy_db_schema::source::{private_message::*, user::*};
use lemmy_db_schema::source::{private_message::*, person::*};
#[test]
fn test_crud() {
let conn = establish_unpooled_connection();
let creator_form = UserForm {
let creator_form = PersonForm {
name: "creator_pm".into(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
matrix_user_id: None,
avatar: None,
banner: None,
admin: false,
banned: Some(false),
deleted: 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,
@ -181,27 +171,17 @@ mod tests {
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(),
preferred_username: None,
password_encrypted: "nope".into(),
email: None,
matrix_user_id: None,
avatar: None,
banner: None,
admin: false,
banned: Some(false),
deleted: 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,
@ -212,7 +192,7 @@ mod tests {
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 {
content: "A test private message".into(),
@ -248,8 +228,8 @@ mod tests {
PrivateMessage::update_deleted(&conn, inserted_private_message.id, true).unwrap();
let marked_read_private_message =
PrivateMessage::update_read(&conn, inserted_private_message.id, true).unwrap();
User_::delete(&conn, inserted_creator.id).unwrap();
User_::delete(&conn, inserted_recipient.id).unwrap();
Person::delete(&conn, inserted_creator.id).unwrap();
Person::delete(&conn, inserted_recipient.id).unwrap();
assert_eq!(expected_private_message, read_private_message);
assert_eq!(expected_private_message, updated_private_message);

View file

@ -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);
}
}

View file

@ -41,7 +41,7 @@ table! {
table! {
comment_like (id) {
id -> Int4,
user_id -> Int4,
person_id -> Int4,
comment_id -> Int4,
post_id -> Int4,
score -> Int2,
@ -67,7 +67,7 @@ table! {
comment_saved (id) {
id -> Int4,
comment_id -> Int4,
user_id -> Int4,
person_id -> Int4,
published -> Timestamp,
}
}
@ -91,9 +91,9 @@ table! {
last_refreshed_at -> Timestamp,
icon -> Nullable<Text>,
banner -> Nullable<Text>,
followers_url -> Text,
inbox_url -> Text,
shared_inbox_url -> Nullable<Text>,
followers_url -> Varchar,
inbox_url -> Varchar,
shared_inbox_url -> Nullable<Varchar>,
}
}
@ -116,7 +116,7 @@ table! {
community_follower (id) {
id -> Int4,
community_id -> Int4,
user_id -> Int4,
person_id -> Int4,
published -> Timestamp,
pending -> Nullable<Bool>,
}
@ -126,25 +126,43 @@ table! {
community_moderator (id) {
id -> Int4,
community_id -> Int4,
user_id -> Int4,
person_id -> Int4,
published -> Timestamp,
}
}
table! {
community_user_ban (id) {
community_person_ban (id) {
id -> Int4,
community_id -> Int4,
user_id -> Int4,
person_id -> Int4,
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! {
mod_add (id) {
id -> Int4,
mod_user_id -> Int4,
other_user_id -> Int4,
mod_person_id -> Int4,
other_person_id -> Int4,
removed -> Nullable<Bool>,
when_ -> Timestamp,
}
@ -153,8 +171,8 @@ table! {
table! {
mod_add_community (id) {
id -> Int4,
mod_user_id -> Int4,
other_user_id -> Int4,
mod_person_id -> Int4,
other_person_id -> Int4,
community_id -> Int4,
removed -> Nullable<Bool>,
when_ -> Timestamp,
@ -164,8 +182,8 @@ table! {
table! {
mod_ban (id) {
id -> Int4,
mod_user_id -> Int4,
other_user_id -> Int4,
mod_person_id -> Int4,
other_person_id -> Int4,
reason -> Nullable<Text>,
banned -> Nullable<Bool>,
expires -> Nullable<Timestamp>,
@ -176,8 +194,8 @@ table! {
table! {
mod_ban_from_community (id) {
id -> Int4,
mod_user_id -> Int4,
other_user_id -> Int4,
mod_person_id -> Int4,
other_person_id -> Int4,
community_id -> Int4,
reason -> Nullable<Text>,
banned -> Nullable<Bool>,
@ -189,7 +207,7 @@ table! {
table! {
mod_lock_post (id) {
id -> Int4,
mod_user_id -> Int4,
mod_person_id -> Int4,
post_id -> Int4,
locked -> Nullable<Bool>,
when_ -> Timestamp,
@ -199,7 +217,7 @@ table! {
table! {
mod_remove_comment (id) {
id -> Int4,
mod_user_id -> Int4,
mod_person_id -> Int4,
comment_id -> Int4,
reason -> Nullable<Text>,
removed -> Nullable<Bool>,
@ -210,7 +228,7 @@ table! {
table! {
mod_remove_community (id) {
id -> Int4,
mod_user_id -> Int4,
mod_person_id -> Int4,
community_id -> Int4,
reason -> Nullable<Text>,
removed -> Nullable<Bool>,
@ -222,7 +240,7 @@ table! {
table! {
mod_remove_post (id) {
id -> Int4,
mod_user_id -> Int4,
mod_person_id -> Int4,
post_id -> Int4,
reason -> Nullable<Text>,
removed -> Nullable<Bool>,
@ -233,7 +251,7 @@ table! {
table! {
mod_sticky_post (id) {
id -> Int4,
mod_user_id -> Int4,
mod_person_id -> Int4,
post_id -> Int4,
stickied -> Nullable<Bool>,
when_ -> Timestamp,
@ -243,9 +261,60 @@ table! {
table! {
password_reset_request (id) {
id -> Int4,
user_id -> Int4,
token_encrypted -> Text,
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) {
id -> Int4,
post_id -> Int4,
user_id -> Int4,
person_id -> Int4,
score -> Int2,
published -> Timestamp,
}
@ -302,7 +371,7 @@ table! {
post_read (id) {
id -> Int4,
post_id -> Int4,
user_id -> Int4,
person_id -> Int4,
published -> Timestamp,
}
}
@ -327,7 +396,7 @@ table! {
post_saved (id) {
id -> Int4,
post_id -> Int4,
user_id -> Int4,
person_id -> Int4,
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
table! {
comment_alias_1 (id) {
@ -459,25 +466,14 @@ table! {
}
table! {
user_alias_1 (id) {
person_alias_1 (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,
@ -486,29 +482,20 @@ table! {
last_refreshed_at -> Timestamp,
banner -> Nullable<Text>,
deleted -> Bool,
inbox_url -> Varchar,
shared_inbox_url -> Nullable<Varchar>,
}
}
table! {
user_alias_2 (id) {
person_alias_2 (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,
@ -517,64 +504,67 @@ table! {
last_refreshed_at -> Timestamp,
banner -> Nullable<Text>,
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!(user_mention -> user_alias_1 (recipient_id));
joinable!(post -> user_alias_1 (creator_id));
joinable!(comment -> user_alias_1 (creator_id));
joinable!(person_mention -> person_alias_1 (recipient_id));
joinable!(post -> person_alias_1 (creator_id));
joinable!(comment -> person_alias_1 (creator_id));
joinable!(post_report -> user_alias_2 (resolver_id));
joinable!(comment_report -> user_alias_2 (resolver_id));
joinable!(post_report -> person_alias_2 (resolver_id));
joinable!(comment_report -> person_alias_2 (resolver_id));
joinable!(comment -> person (creator_id));
joinable!(comment -> post (post_id));
joinable!(comment -> user_ (creator_id));
joinable!(comment_aggregates -> comment (comment_id));
joinable!(comment_like -> comment (comment_id));
joinable!(comment_like -> person (person_id));
joinable!(comment_like -> post (post_id));
joinable!(comment_like -> user_ (user_id));
joinable!(comment_report -> comment (comment_id));
joinable!(comment_saved -> comment (comment_id));
joinable!(comment_saved -> user_ (user_id));
joinable!(community -> user_ (creator_id));
joinable!(comment_saved -> person (person_id));
joinable!(community -> person (creator_id));
joinable!(community_aggregates -> 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 -> user_ (user_id));
joinable!(community_user_ban -> community (community_id));
joinable!(community_user_ban -> user_ (user_id));
joinable!(community_moderator -> person (person_id));
joinable!(community_person_ban -> community (community_id));
joinable!(community_person_ban -> person (person_id));
joinable!(local_user -> person (person_id));
joinable!(mod_add_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 -> user_ (mod_user_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 -> 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 -> user_ (mod_user_id));
joinable!(mod_sticky_post -> person (mod_person_id));
joinable!(mod_sticky_post -> post (post_id));
joinable!(mod_sticky_post -> user_ (mod_user_id));
joinable!(password_reset_request -> user_ (user_id));
joinable!(password_reset_request -> local_user (local_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 -> user_ (creator_id));
joinable!(post -> person (creator_id));
joinable!(post_aggregates -> post (post_id));
joinable!(post_like -> person (person_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 -> user_ (user_id));
joinable!(post_report -> post (post_id));
joinable!(post_saved -> person (person_id));
joinable!(post_saved -> post (post_id));
joinable!(post_saved -> user_ (user_id));
joinable!(site -> user_ (creator_id));
joinable!(site -> person (creator_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!(
activity,
@ -587,7 +577,8 @@ allow_tables_to_appear_in_same_query!(
community_aggregates,
community_follower,
community_moderator,
community_user_ban,
community_person_ban,
local_user,
mod_add,
mod_add_community,
mod_ban,
@ -598,6 +589,10 @@ allow_tables_to_appear_in_same_query!(
mod_remove_post,
mod_sticky_post,
password_reset_request,
person,
person_aggregates,
person_ban,
person_mention,
post,
post_aggregates,
post_like,
@ -607,11 +602,7 @@ allow_tables_to_appear_in_same_query!(
private_message,
site,
site_aggregates,
user_,
user_aggregates,
user_ban,
user_mention,
comment_alias_1,
user_alias_1,
user_alias_2,
person_alias_1,
person_alias_2,
);

View file

@ -69,7 +69,7 @@ pub struct CommentForm {
#[table_name = "comment_like"]
pub struct CommentLike {
pub id: i32,
pub user_id: i32,
pub person_id: i32,
pub comment_id: i32,
pub post_id: i32, // TODO this is redundant
pub score: i16,
@ -79,7 +79,7 @@ pub struct CommentLike {
#[derive(Insertable, AsChangeset, Clone)]
#[table_name = "comment_like"]
pub struct CommentLikeForm {
pub user_id: i32,
pub person_id: i32,
pub comment_id: i32,
pub post_id: i32, // TODO this is redundant
pub score: i16,
@ -91,7 +91,7 @@ pub struct CommentLikeForm {
pub struct CommentSaved {
pub id: i32,
pub comment_id: i32,
pub user_id: i32,
pub person_id: i32,
pub published: chrono::NaiveDateTime,
}
@ -99,5 +99,5 @@ pub struct CommentSaved {
#[table_name = "comment_saved"]
pub struct CommentSavedForm {
pub comment_id: i32,
pub user_id: i32,
pub person_id: i32,
}

View file

@ -1,5 +1,5 @@
use crate::{
schema::{community, community_follower, community_moderator, community_user_ban},
schema::{community, community_follower, community_moderator, community_person_ban},
Url,
};
use serde::Serialize;
@ -79,7 +79,7 @@ pub struct CommunityForm {
pub struct CommunityModerator {
pub id: i32,
pub community_id: i32,
pub user_id: i32,
pub person_id: i32,
pub published: chrono::NaiveDateTime,
}
@ -87,24 +87,24 @@ pub struct CommunityModerator {
#[table_name = "community_moderator"]
pub struct CommunityModeratorForm {
pub community_id: i32,
pub user_id: i32,
pub person_id: i32,
}
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
#[belongs_to(Community)]
#[table_name = "community_user_ban"]
pub struct CommunityUserBan {
#[table_name = "community_person_ban"]
pub struct CommunityPersonBan {
pub id: i32,
pub community_id: i32,
pub user_id: i32,
pub person_id: i32,
pub published: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset, Clone)]
#[table_name = "community_user_ban"]
pub struct CommunityUserBanForm {
#[table_name = "community_person_ban"]
pub struct CommunityPersonBanForm {
pub community_id: i32,
pub user_id: i32,
pub person_id: i32,
}
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
@ -113,7 +113,7 @@ pub struct CommunityUserBanForm {
pub struct CommunityFollower {
pub id: i32,
pub community_id: i32,
pub user_id: i32,
pub person_id: i32,
pub published: chrono::NaiveDateTime,
pub pending: Option<bool>,
}
@ -122,6 +122,6 @@ pub struct CommunityFollower {
#[table_name = "community_follower"]
pub struct CommunityFollowerForm {
pub community_id: i32,
pub user_id: i32,
pub person_id: i32,
pub pending: bool,
}

View 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>,
}

View file

@ -8,5 +8,6 @@ pub mod post;
pub mod post_report;
pub mod private_message;
pub mod site;
pub mod user;
pub mod user_mention;
pub mod person;
pub mod person_mention;
pub mod local_user;

View file

@ -15,7 +15,7 @@ use serde::Serialize;
#[table_name = "mod_remove_post"]
pub struct ModRemovePost {
pub id: i32,
pub mod_user_id: i32,
pub mod_person_id: i32,
pub post_id: i32,
pub reason: Option<String>,
pub removed: Option<bool>,
@ -25,7 +25,7 @@ pub struct ModRemovePost {
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_remove_post"]
pub struct ModRemovePostForm {
pub mod_user_id: i32,
pub mod_person_id: i32,
pub post_id: i32,
pub reason: Option<String>,
pub removed: Option<bool>,
@ -35,7 +35,7 @@ pub struct ModRemovePostForm {
#[table_name = "mod_lock_post"]
pub struct ModLockPost {
pub id: i32,
pub mod_user_id: i32,
pub mod_person_id: i32,
pub post_id: i32,
pub locked: Option<bool>,
pub when_: chrono::NaiveDateTime,
@ -44,7 +44,7 @@ pub struct ModLockPost {
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_lock_post"]
pub struct ModLockPostForm {
pub mod_user_id: i32,
pub mod_person_id: i32,
pub post_id: i32,
pub locked: Option<bool>,
}
@ -53,7 +53,7 @@ pub struct ModLockPostForm {
#[table_name = "mod_sticky_post"]
pub struct ModStickyPost {
pub id: i32,
pub mod_user_id: i32,
pub mod_person_id: i32,
pub post_id: i32,
pub stickied: Option<bool>,
pub when_: chrono::NaiveDateTime,
@ -62,7 +62,7 @@ pub struct ModStickyPost {
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_sticky_post"]
pub struct ModStickyPostForm {
pub mod_user_id: i32,
pub mod_person_id: i32,
pub post_id: i32,
pub stickied: Option<bool>,
}
@ -71,7 +71,7 @@ pub struct ModStickyPostForm {
#[table_name = "mod_remove_comment"]
pub struct ModRemoveComment {
pub id: i32,
pub mod_user_id: i32,
pub mod_person_id: i32,
pub comment_id: i32,
pub reason: Option<String>,
pub removed: Option<bool>,
@ -81,7 +81,7 @@ pub struct ModRemoveComment {
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_remove_comment"]
pub struct ModRemoveCommentForm {
pub mod_user_id: i32,
pub mod_person_id: i32,
pub comment_id: i32,
pub reason: Option<String>,
pub removed: Option<bool>,
@ -91,7 +91,7 @@ pub struct ModRemoveCommentForm {
#[table_name = "mod_remove_community"]
pub struct ModRemoveCommunity {
pub id: i32,
pub mod_user_id: i32,
pub mod_person_id: i32,
pub community_id: i32,
pub reason: Option<String>,
pub removed: Option<bool>,
@ -102,7 +102,7 @@ pub struct ModRemoveCommunity {
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_remove_community"]
pub struct ModRemoveCommunityForm {
pub mod_user_id: i32,
pub mod_person_id: i32,
pub community_id: i32,
pub reason: Option<String>,
pub removed: Option<bool>,
@ -113,8 +113,8 @@ pub struct ModRemoveCommunityForm {
#[table_name = "mod_ban_from_community"]
pub struct ModBanFromCommunity {
pub id: i32,
pub mod_user_id: i32,
pub other_user_id: i32,
pub mod_person_id: i32,
pub other_person_id: i32,
pub community_id: i32,
pub reason: Option<String>,
pub banned: Option<bool>,
@ -125,8 +125,8 @@ pub struct ModBanFromCommunity {
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_ban_from_community"]
pub struct ModBanFromCommunityForm {
pub mod_user_id: i32,
pub other_user_id: i32,
pub mod_person_id: i32,
pub other_person_id: i32,
pub community_id: i32,
pub reason: Option<String>,
pub banned: Option<bool>,
@ -137,8 +137,8 @@ pub struct ModBanFromCommunityForm {
#[table_name = "mod_ban"]
pub struct ModBan {
pub id: i32,
pub mod_user_id: i32,
pub other_user_id: i32,
pub mod_person_id: i32,
pub other_person_id: i32,
pub reason: Option<String>,
pub banned: Option<bool>,
pub expires: Option<chrono::NaiveDateTime>,
@ -148,8 +148,8 @@ pub struct ModBan {
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_ban"]
pub struct ModBanForm {
pub mod_user_id: i32,
pub other_user_id: i32,
pub mod_person_id: i32,
pub other_person_id: i32,
pub reason: Option<String>,
pub banned: Option<bool>,
pub expires: Option<chrono::NaiveDateTime>,
@ -159,8 +159,8 @@ pub struct ModBanForm {
#[table_name = "mod_add_community"]
pub struct ModAddCommunity {
pub id: i32,
pub mod_user_id: i32,
pub other_user_id: i32,
pub mod_person_id: i32,
pub other_person_id: i32,
pub community_id: i32,
pub removed: Option<bool>,
pub when_: chrono::NaiveDateTime,
@ -169,8 +169,8 @@ pub struct ModAddCommunity {
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_add_community"]
pub struct ModAddCommunityForm {
pub mod_user_id: i32,
pub other_user_id: i32,
pub mod_person_id: i32,
pub other_person_id: i32,
pub community_id: i32,
pub removed: Option<bool>,
}
@ -179,8 +179,8 @@ pub struct ModAddCommunityForm {
#[table_name = "mod_add"]
pub struct ModAdd {
pub id: i32,
pub mod_user_id: i32,
pub other_user_id: i32,
pub mod_person_id: i32,
pub other_person_id: i32,
pub removed: Option<bool>,
pub when_: chrono::NaiveDateTime,
}
@ -188,7 +188,7 @@ pub struct ModAdd {
#[derive(Insertable, AsChangeset)]
#[table_name = "mod_add"]
pub struct ModAddForm {
pub mod_user_id: i32,
pub other_user_id: i32,
pub mod_person_id: i32,
pub other_person_id: i32,
pub removed: Option<bool>,
}

View file

@ -4,7 +4,7 @@ use crate::schema::password_reset_request;
#[table_name = "password_reset_request"]
pub struct PasswordResetRequest {
pub id: i32,
pub user_id: i32,
pub local_user_id: i32,
pub token_encrypted: String,
pub published: chrono::NaiveDateTime,
}
@ -12,6 +12,6 @@ pub struct PasswordResetRequest {
#[derive(Insertable, AsChangeset)]
#[table_name = "password_reset_request"]
pub struct PasswordResetRequestForm {
pub user_id: i32,
pub local_user_id: i32,
pub token_encrypted: String,
}

View 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>>,
}

View file

@ -1,10 +1,10 @@
use crate::{schema::user_mention, source::comment::Comment};
use crate::{schema::person_mention, source::comment::Comment};
use serde::Serialize;
#[derive(Clone, Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
#[belongs_to(Comment)]
#[table_name = "user_mention"]
pub struct UserMention {
#[table_name = "person_mention"]
pub struct PersonMention {
pub id: i32,
pub recipient_id: i32,
pub comment_id: i32,
@ -13,8 +13,8 @@ pub struct UserMention {
}
#[derive(Insertable, AsChangeset)]
#[table_name = "user_mention"]
pub struct UserMentionForm {
#[table_name = "person_mention"]
pub struct PersonMentionForm {
pub recipient_id: i32,
pub comment_id: i32,
pub read: Option<bool>,

View file

@ -57,7 +57,7 @@ pub struct PostForm {
pub struct PostLike {
pub id: i32,
pub post_id: i32,
pub user_id: i32,
pub person_id: i32,
pub score: i16,
pub published: chrono::NaiveDateTime,
}
@ -66,7 +66,7 @@ pub struct PostLike {
#[table_name = "post_like"]
pub struct PostLikeForm {
pub post_id: i32,
pub user_id: i32,
pub person_id: i32,
pub score: i16,
}
@ -76,7 +76,7 @@ pub struct PostLikeForm {
pub struct PostSaved {
pub id: i32,
pub post_id: i32,
pub user_id: i32,
pub person_id: i32,
pub published: chrono::NaiveDateTime,
}
@ -84,7 +84,7 @@ pub struct PostSaved {
#[table_name = "post_saved"]
pub struct PostSavedForm {
pub post_id: i32,
pub user_id: i32,
pub person_id: i32,
}
#[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
@ -92,11 +92,8 @@ pub struct PostSavedForm {
#[table_name = "post_read"]
pub struct PostRead {
pub id: i32,
pub post_id: i32,
pub user_id: i32,
pub person_id: i32,
pub published: chrono::NaiveDateTime,
}
@ -104,6 +101,5 @@ pub struct PostRead {
#[table_name = "post_read"]
pub struct PostReadForm {
pub post_id: i32,
pub user_id: i32,
pub person_id: i32,
}

View file

@ -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>>,
}

View file

@ -26,7 +26,7 @@ use lemmy_db_schema::{
},
source::{
comment::{Comment, CommentAlias1, CommentSaved},
community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
community::{Community, CommunityFollower, CommunitySafe, CommunityPersonBan},
post::Post,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
@ -55,7 +55,7 @@ type CommentViewTuple = (
Post,
CommunitySafe,
CommentAggregates,
Option<CommunityUserBan>,
Option<CommunityPersonBan>,
Option<CommunityFollower>,
Option<CommentSaved>,
Option<i16>,
@ -545,7 +545,7 @@ mod tests {
let comment_like_form = CommentLikeForm {
comment_id: inserted_comment.id,
post_id: inserted_post.id,
user_id: inserted_user.id,
person_id: inserted_user.id,
score: 1,
};

View file

@ -23,7 +23,7 @@ use lemmy_db_schema::{
user_,
},
source::{
community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
community::{Community, CommunityFollower, CommunitySafe, CommunityPersonBan},
post::{Post, PostRead, PostSaved},
user::{UserSafe, User_},
},
@ -48,7 +48,7 @@ type PostViewTuple = (
Post,
UserSafe,
CommunitySafe,
Option<CommunityUserBan>,
Option<CommunityPersonBan>,
PostAggregates,
Option<CommunityFollower>,
Option<PostSaved>,
@ -523,7 +523,7 @@ mod tests {
let post_like_form = PostLikeForm {
post_id: inserted_post.id,
user_id: inserted_user.id,
person_id: inserted_user.id,
score: 1,
};
@ -532,7 +532,7 @@ mod tests {
let expected_post_like = PostLike {
id: inserted_post_like.id,
post_id: inserted_post.id,
user_id: inserted_user.id,
person_id: inserted_user.id,
published: inserted_post_like.published,
score: 1,
};

View file

@ -24,7 +24,7 @@ use lemmy_db_schema::{
},
source::{
comment::{Comment, CommentSaved},
community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
community::{Community, CommunityFollower, CommunitySafe, CommunityPersonBan},
post::Post,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
user_mention::UserMention,
@ -55,7 +55,7 @@ type UserMentionViewTuple = (
CommunitySafe,
UserSafeAlias1,
CommentAggregates,
Option<CommunityUserBan>,
Option<CommunityPersonBan>,
Option<CommunityFollower>,
Option<CommentSaved>,
Option<i16>,