let like_form = CommentLikeForm {
comment_id: inserted_comment.id,
post_id,
- user_id: user.id,
+ person_id: user.id,
score: 1,
};
// 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(),
let comment_saved_form = CommentSavedForm {
comment_id: data.comment_id,
- user_id: user.id,
+ person_id: user.id,
};
if data.save {
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,
};
// 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);
// Follow your own community
let community_follower_form = CommunityFollowerForm {
community_id: inserted_community.id,
- user_id: user.id,
+ person_id: user.id,
pending: false,
};
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(),
.await??;
let community_follower_form = CommunityFollowerForm {
community_id: data.community_id,
- user_id: user.id,
+ person_id: user.id,
pending: false,
};
// 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());
}
// 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: &'_ _| {
.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());
}
};
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),
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;
// 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),
};
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);
// 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),
};
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)
// 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,
};
let like_form = PostLikeForm {
post_id: data.post_id,
- user_id: user.id,
+ person_id: user.id,
score: data.score,
};
// 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(),
// Mod tables
let form = ModLockPostForm {
- mod_user_id: user.id,
+ mod_person_id: user.id,
post_id: data.post_id,
locked: Some(locked),
};
// Mod tables
let form = ModStickyPostForm {
- mod_user_id: user.id,
+ mod_person_id: user.id,
post_id: data.post_id,
stickied: Some(stickied),
};
let post_saved_form = PostSavedForm {
post_id: data.post_id,
- user_id: user.id,
+ person_id: user.id,
};
if data.save {
// 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),
};
// 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,
};
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);
// 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),
};
};
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,
// 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??;
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;
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;
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;
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;
let community_follower_form = CommunityFollowerForm {
community_id: community.id,
- user_id: self.id,
+ person_id: self.id,
pending: true,
};
blocking(&context.pool(), move |conn| {
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)?;
let community_follower_form = CommunityFollowerForm {
community_id: community.id,
- user_id: user.id,
+ person_id: user.id,
pending: false,
};
.await??;
let community_follower_form = CommunityFollowerForm {
community_id: community.id,
- user_id: user.id,
+ person_id: user.id,
pending: false,
};
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,
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,
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,
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,
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,
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,
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,
};
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,
};
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);
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);
}
}
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,
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,
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,
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,
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,
};
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,
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,
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,
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);
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);
pub mod community_aggregates;
pub mod post_aggregates;
pub mod site_aggregates;
-pub mod user_aggregates;
+pub mod person_aggregates;
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)
}
}
#[cfg(test)]
mod tests {
use crate::{
- aggregates::user_aggregates::UserAggregates,
+ aggregates::person_aggregates::PersonAggregates,
establish_unpooled_connection,
Crud,
Likeable,
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,
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,
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,
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,
let post_like = PostLikeForm {
post_id: inserted_post.id,
- user_id: inserted_user.id,
+ person_id: inserted_person.id,
score: 1,
};
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,
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,
};
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,
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);
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());
}
}
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,
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,
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,
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,
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,
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,
let post_like = PostLikeForm {
post_id: inserted_post.id,
- user_id: inserted_user.id,
+ person_id: inserted_person.id,
score: 1,
};
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,
};
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);
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);
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,
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,
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,
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,
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,
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,
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());
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;
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,
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";
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);
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)
}
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)
}
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,
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,
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,
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,
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,
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,
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,
};
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,
};
// 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();
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);
CommunityForm,
CommunityModerator,
CommunityModeratorForm,
- CommunityUserBan,
- CommunityUserBanForm,
+ CommunityPersonBan,
+ CommunityPersonBanForm,
},
Url,
};
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)
}
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>;
}
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)
}
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)
}
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,
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,
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,
let community_follower_form = CommunityFollowerForm {
community_id: inserted_community.id,
- user_id: inserted_user.id,
+ person_id: inserted_person.id,
pending: false,
};
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);
--- /dev/null
+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)
+ }
+}
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;
#[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,
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,
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,
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,
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,
// 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,
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_,
// 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,
};
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_,
};
// 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,
};
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_,
};
// 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,
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_,
// 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,
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,
// 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,
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,
// 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,
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,
// 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,
};
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_,
};
// 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_,
};
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);
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>;
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();
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,
};
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,
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!(
--- /dev/null
+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);
+ }
+}
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)
}
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)),
)
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,
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,
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,
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,
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,
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,
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);
) -> 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 {
.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
}
}
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)
}
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)
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)
}
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)
}
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,
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,
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,
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,
// Post Like
let post_like_form = PostLikeForm {
post_id: inserted_post.id,
- user_id: inserted_user.id,
+ person_id: inserted_person.id,
score: 1,
};
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,
};
// 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();
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();
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);
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,
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,
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(),
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);
+++ /dev/null
-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);
- }
-}
table! {
comment_like (id) {
id -> Int4,
- user_id -> Int4,
+ person_id -> Int4,
comment_id -> Int4,
post_id -> Int4,
score -> Int2,
comment_saved (id) {
id -> Int4,
comment_id -> Int4,
- user_id -> Int4,
+ person_id -> Int4,
published -> Timestamp,
}
}
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>,
}
}
community_follower (id) {
id -> Int4,
community_id -> Int4,
- user_id -> Int4,
+ person_id -> Int4,
published -> Timestamp,
pending -> Nullable<Bool>,
}
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,
}
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,
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>,
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>,
table! {
mod_lock_post (id) {
id -> Int4,
- mod_user_id -> Int4,
+ mod_person_id -> Int4,
post_id -> Int4,
locked -> Nullable<Bool>,
when_ -> Timestamp,
table! {
mod_remove_comment (id) {
id -> Int4,
- mod_user_id -> Int4,
+ mod_person_id -> Int4,
comment_id -> Int4,
reason -> Nullable<Text>,
removed -> Nullable<Bool>,
table! {
mod_remove_community (id) {
id -> Int4,
- mod_user_id -> Int4,
+ mod_person_id -> Int4,
community_id -> Int4,
reason -> Nullable<Text>,
removed -> Nullable<Bool>,
table! {
mod_remove_post (id) {
id -> Int4,
- mod_user_id -> Int4,
+ mod_person_id -> Int4,
post_id -> Int4,
reason -> Nullable<Text>,
removed -> Nullable<Bool>,
table! {
mod_sticky_post (id) {
id -> Int4,
- mod_user_id -> Int4,
+ mod_person_id -> Int4,
post_id -> Int4,
stickied -> Nullable<Bool>,
when_ -> Timestamp,
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,
}
}
post_like (id) {
id -> Int4,
post_id -> Int4,
- user_id -> Int4,
+ person_id -> Int4,
score -> Int2,
published -> Timestamp,
}
post_read (id) {
id -> Int4,
post_id -> Int4,
- user_id -> Int4,
+ person_id -> Int4,
published -> Timestamp,
}
}
post_saved (id) {
id -> Int4,
post_id -> Int4,
- user_id -> Int4,
+ person_id -> Int4,
published -> Timestamp,
}
}
}
}
-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) {
}
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,
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,
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,
community_aggregates,
community_follower,
community_moderator,
- community_user_ban,
+ community_person_ban,
+ local_user,
mod_add,
mod_add_community,
mod_ban,
mod_remove_post,
mod_sticky_post,
password_reset_request,
+ person,
+ person_aggregates,
+ person_ban,
+ person_mention,
post,
post_aggregates,
post_like,
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,
);
#[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,
#[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,
pub struct CommentSaved {
pub id: i32,
pub comment_id: i32,
- pub user_id: i32,
+ pub person_id: i32,
pub published: chrono::NaiveDateTime,
}
#[table_name = "comment_saved"]
pub struct CommentSavedForm {
pub comment_id: i32,
- pub user_id: i32,
+ pub person_id: i32,
}
use crate::{
- schema::{community, community_follower, community_moderator, community_user_ban},
+ schema::{community, community_follower, community_moderator, community_person_ban},
Url,
};
use serde::Serialize;
pub struct CommunityModerator {
pub id: i32,
pub community_id: i32,
- pub user_id: i32,
+ pub person_id: i32,
pub published: chrono::NaiveDateTime,
}
#[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)]
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>,
}
#[table_name = "community_follower"]
pub struct CommunityFollowerForm {
pub community_id: i32,
- pub user_id: i32,
+ pub person_id: i32,
pub pending: bool,
}
--- /dev/null
+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>,
+}
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;
#[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>,
#[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>,
#[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,
#[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>,
}
#[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,
#[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>,
}
#[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>,
#[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>,
#[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>,
#[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>,
#[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>,
#[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>,
#[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>,
#[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>,
#[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,
#[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>,
}
#[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,
}
#[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>,
}
#[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,
}
#[derive(Insertable, AsChangeset)]
#[table_name = "password_reset_request"]
pub struct PasswordResetRequestForm {
- pub user_id: i32,
+ pub local_user_id: i32,
pub token_encrypted: String,
}
--- /dev/null
+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>>,
+}
-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,
}
#[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>,
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,
}
#[table_name = "post_like"]
pub struct PostLikeForm {
pub post_id: i32,
- pub user_id: i32,
+ pub person_id: i32,
pub score: i16,
}
pub struct PostSaved {
pub id: i32,
pub post_id: i32,
- pub user_id: i32,
+ pub person_id: i32,
pub published: chrono::NaiveDateTime,
}
#[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)]
#[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,
}
#[table_name = "post_read"]
pub struct PostReadForm {
pub post_id: i32,
-
- pub user_id: i32,
+ pub person_id: i32,
}
+++ /dev/null
-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>>,
-}
},
source::{
comment::{Comment, CommentAlias1, CommentSaved},
- community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
+ community::{Community, CommunityFollower, CommunitySafe, CommunityPersonBan},
post::Post,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
Post,
CommunitySafe,
CommentAggregates,
- Option<CommunityUserBan>,
+ Option<CommunityPersonBan>,
Option<CommunityFollower>,
Option<CommentSaved>,
Option<i16>,
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,
};
user_,
},
source::{
- community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
+ community::{Community, CommunityFollower, CommunitySafe, CommunityPersonBan},
post::{Post, PostRead, PostSaved},
user::{UserSafe, User_},
},
Post,
UserSafe,
CommunitySafe,
- Option<CommunityUserBan>,
+ Option<CommunityPersonBan>,
PostAggregates,
Option<CommunityFollower>,
Option<PostSaved>,
let post_like_form = PostLikeForm {
post_id: inserted_post.id,
- user_id: inserted_user.id,
+ person_id: inserted_user.id,
score: 1,
};
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,
};
},
source::{
comment::{Comment, CommentSaved},
- community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
+ community::{Community, CommunityFollower, CommunitySafe, CommunityPersonBan},
post::Post,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
user_mention::UserMention,
CommunitySafe,
UserSafeAlias1,
CommentAggregates,
- Option<CommunityUserBan>,
+ Option<CommunityPersonBan>,
Option<CommunityFollower>,
Option<CommentSaved>,
Option<i16>,