From: Felix Ableitner Date: Fri, 18 Dec 2020 18:38:32 +0000 (+0100) Subject: Move user to lemmy_db_schema, create traits for impls X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/readmes/%7B%7D/%22%7Burl%7D/%7BcanonicalUrl%7D?a=commitdiff_plain;h=f842bbff8dbdee00d85d8bd636d65eb98284310c;p=lemmy.git Move user to lemmy_db_schema, create traits for impls --- diff --git a/lemmy_api/src/claims.rs b/lemmy_api/src/claims.rs index 4a0ab12b..f99730bd 100644 --- a/lemmy_api/src/claims.rs +++ b/lemmy_api/src/claims.rs @@ -1,5 +1,5 @@ use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, TokenData, Validation}; -use lemmy_db::source::user::User_; +use lemmy_db_schema::source::user::User_; use lemmy_utils::settings::Settings; use serde::{Deserialize, Serialize}; diff --git a/lemmy_api/src/comment.rs b/lemmy_api/src/comment.rs index acff6004..78c45c49 100644 --- a/lemmy_api/src/comment.rs +++ b/lemmy_api/src/comment.rs @@ -11,9 +11,9 @@ use actix_web::web::Data; use lemmy_apub::{ApubLikeableType, ApubObjectType}; use lemmy_db::{ source::{ + comment::Comment_, comment_report::{CommentReport, CommentReportForm}, moderator::*, - user::*, }, views::{ comment_report_view::{CommentReportQueryBuilder, CommentReportView}, @@ -30,6 +30,7 @@ use lemmy_db::{ use lemmy_db_schema::source::{ comment::{Comment, CommentForm, CommentLike, CommentLikeForm, CommentSaved, CommentSavedForm}, post::Post, + user::*, }; use lemmy_structs::{blocking, comment::*, send_local_notifs}; use lemmy_utils::{ diff --git a/lemmy_api/src/community.rs b/lemmy_api/src/community.rs index 35aafc88..0316beaa 100644 --- a/lemmy_api/src/community.rs +++ b/lemmy_api/src/community.rs @@ -11,7 +11,7 @@ use anyhow::Context; use lemmy_apub::ActorType; use lemmy_db::{ diesel_option_overwrite, - source::{community::*, moderator::*, site::*}, + source::{comment::Comment_, community::*, moderator::*, post::Post_, site::*}, views::{ comment_view::CommentQueryBuilder, community::{ diff --git a/lemmy_api/src/lib.rs b/lemmy_api/src/lib.rs index 927846c0..e6c3b825 100644 --- a/lemmy_api/src/lib.rs +++ b/lemmy_api/src/lib.rs @@ -1,15 +1,12 @@ use crate::claims::Claims; use actix_web::{web, web::Data}; use lemmy_db::{ - source::{ - community::{Community, CommunityModerator}, - user::User_, - }, + source::community::{Community, CommunityModerator}, views::community::community_user_ban_view::CommunityUserBanView, Crud, DbPool, }; -use lemmy_db_schema::source::post::Post; +use lemmy_db_schema::source::{post::Post, user::User_}; use lemmy_structs::{blocking, comment::*, community::*, post::*, site::*, user::*}; use lemmy_utils::{settings::Settings, APIError, ConnectionId, LemmyError}; use lemmy_websocket::{serialize_websocket_message, LemmyContext, UserOperation}; diff --git a/lemmy_api/src/post.rs b/lemmy_api/src/post.rs index ee09059a..9024541c 100644 --- a/lemmy_api/src/post.rs +++ b/lemmy_api/src/post.rs @@ -12,6 +12,7 @@ use lemmy_apub::{ApubLikeableType, ApubObjectType}; use lemmy_db::{ source::{ moderator::*, + post::Post_, post_report::{PostReport, PostReportForm}, }, views::{ diff --git a/lemmy_api/src/user.rs b/lemmy_api/src/user.rs index 680910b8..a6e1cbce 100644 --- a/lemmy_api/src/user.rs +++ b/lemmy_api/src/user.rs @@ -17,12 +17,14 @@ use lemmy_apub::ApubObjectType; use lemmy_db::{ diesel_option_overwrite, source::{ + comment::Comment_, community::*, moderator::*, password_reset_request::*, + post::Post_, private_message::*, site::*, - user::*, + user::User, user_mention::*, }, views::{ @@ -47,7 +49,7 @@ use lemmy_db::{ }; use lemmy_db_schema::{ naive_now, - source::{comment::Comment, post::Post}, + source::{comment::Comment, post::Post, user::*}, }; use lemmy_structs::{blocking, send_email_to_user, user::*}; use lemmy_utils::{ diff --git a/lemmy_apub/src/activities/receive/comment.rs b/lemmy_apub/src/activities/receive/comment.rs index 76337c4f..0149e931 100644 --- a/lemmy_apub/src/activities/receive/comment.rs +++ b/lemmy_apub/src/activities/receive/comment.rs @@ -4,7 +4,7 @@ use activitystreams::{ base::ExtendsExt, }; use anyhow::Context; -use lemmy_db::{views::comment_view::CommentView, Likeable}; +use lemmy_db::{source::comment::Comment_, views::comment_view::CommentView, Crud, Likeable}; use lemmy_db_schema::source::{ comment::{Comment, CommentLike, CommentLikeForm}, post::Post, diff --git a/lemmy_apub/src/activities/receive/comment_undo.rs b/lemmy_apub/src/activities/receive/comment_undo.rs index f446b286..7e672045 100644 --- a/lemmy_apub/src/activities/receive/comment_undo.rs +++ b/lemmy_apub/src/activities/receive/comment_undo.rs @@ -1,6 +1,6 @@ use crate::activities::receive::get_actor_as_user; use activitystreams::activity::{Dislike, Like}; -use lemmy_db::{views::comment_view::CommentView, Likeable}; +use lemmy_db::{source::comment::Comment_, views::comment_view::CommentView, Likeable}; use lemmy_db_schema::source::comment::{Comment, CommentLike}; use lemmy_structs::{blocking, comment::CommentResponse}; use lemmy_utils::LemmyError; diff --git a/lemmy_apub/src/activities/receive/mod.rs b/lemmy_apub/src/activities/receive/mod.rs index a66ddfb9..f52bbea1 100644 --- a/lemmy_apub/src/activities/receive/mod.rs +++ b/lemmy_apub/src/activities/receive/mod.rs @@ -5,7 +5,7 @@ use activitystreams::{ error::DomainError, }; use anyhow::{anyhow, Context}; -use lemmy_db::source::user::User_; +use lemmy_db_schema::source::user::User_; use lemmy_utils::{location_info, LemmyError}; use lemmy_websocket::LemmyContext; use log::debug; diff --git a/lemmy_apub/src/activities/receive/post.rs b/lemmy_apub/src/activities/receive/post.rs index 4a3cc13f..8e20da75 100644 --- a/lemmy_apub/src/activities/receive/post.rs +++ b/lemmy_apub/src/activities/receive/post.rs @@ -4,7 +4,7 @@ use activitystreams::{ prelude::*, }; use anyhow::Context; -use lemmy_db::{views::post_view::PostView, Likeable}; +use lemmy_db::{source::post::Post_, views::post_view::PostView, Likeable}; use lemmy_db_schema::source::post::{Post, PostLike, PostLikeForm}; use lemmy_structs::{blocking, post::PostResponse}; use lemmy_utils::{location_info, LemmyError}; diff --git a/lemmy_apub/src/activities/receive/post_undo.rs b/lemmy_apub/src/activities/receive/post_undo.rs index 817a74e4..facaf65f 100644 --- a/lemmy_apub/src/activities/receive/post_undo.rs +++ b/lemmy_apub/src/activities/receive/post_undo.rs @@ -1,6 +1,6 @@ use crate::activities::receive::get_actor_as_user; use activitystreams::activity::{Dislike, Like}; -use lemmy_db::{views::post_view::PostView, Likeable}; +use lemmy_db::{source::post::Post_, views::post_view::PostView, Likeable}; use lemmy_db_schema::source::post::{Post, PostLike}; use lemmy_structs::{blocking, post::PostResponse}; use lemmy_utils::LemmyError; diff --git a/lemmy_apub/src/activities/send/comment.rs b/lemmy_apub/src/activities/send/comment.rs index 358e5020..fa39fd47 100644 --- a/lemmy_apub/src/activities/send/comment.rs +++ b/lemmy_apub/src/activities/send/comment.rs @@ -26,12 +26,8 @@ use activitystreams::{ }; use anyhow::anyhow; use itertools::Itertools; -use lemmy_db::{ - source::{community::Community, user::User_}, - Crud, - DbPool, -}; -use lemmy_db_schema::source::{comment::Comment, post::Post}; +use lemmy_db::{source::community::Community, Crud, DbPool}; +use lemmy_db_schema::source::{comment::Comment, post::Post, user::User_}; use lemmy_structs::{blocking, WebFingerResponse}; use lemmy_utils::{ request::{retry, RecvError}, diff --git a/lemmy_apub/src/activities/send/post.rs b/lemmy_apub/src/activities/send/post.rs index fd7f7c12..c79f79ac 100644 --- a/lemmy_apub/src/activities/send/post.rs +++ b/lemmy_apub/src/activities/send/post.rs @@ -21,11 +21,8 @@ use activitystreams::{ prelude::*, public, }; -use lemmy_db::{ - source::{community::Community, user::User_}, - Crud, -}; -use lemmy_db_schema::source::post::Post; +use lemmy_db::{source::community::Community, Crud}; +use lemmy_db_schema::source::{post::Post, user::User_}; use lemmy_structs::blocking; use lemmy_utils::LemmyError; use lemmy_websocket::LemmyContext; diff --git a/lemmy_apub/src/activities/send/private_message.rs b/lemmy_apub/src/activities/send/private_message.rs index 9abe70d6..4c8cb874 100644 --- a/lemmy_apub/src/activities/send/private_message.rs +++ b/lemmy_apub/src/activities/send/private_message.rs @@ -16,10 +16,8 @@ use activitystreams::{ }, prelude::*, }; -use lemmy_db::{ - source::{private_message::PrivateMessage, user::User_}, - Crud, -}; +use lemmy_db::{source::private_message::PrivateMessage, Crud}; +use lemmy_db_schema::source::user::User_; use lemmy_structs::blocking; use lemmy_utils::LemmyError; use lemmy_websocket::LemmyContext; diff --git a/lemmy_apub/src/activities/send/user.rs b/lemmy_apub/src/activities/send/user.rs index 26c5a5d5..8c01aff8 100644 --- a/lemmy_apub/src/activities/send/user.rs +++ b/lemmy_apub/src/activities/send/user.rs @@ -14,14 +14,12 @@ use activitystreams::{ object::ObjectExt, }; use lemmy_db::{ - source::{ - community::{Community, CommunityFollower, CommunityFollowerForm}, - user::User_, - }, + source::community::{Community, CommunityFollower, CommunityFollowerForm}, ApubObject, DbPool, Followable, }; +use lemmy_db_schema::source::user::User_; use lemmy_structs::blocking; use lemmy_utils::LemmyError; use lemmy_websocket::LemmyContext; diff --git a/lemmy_apub/src/activity_queue.rs b/lemmy_apub/src/activity_queue.rs index 07990457..b32a3eb6 100644 --- a/lemmy_apub/src/activity_queue.rs +++ b/lemmy_apub/src/activity_queue.rs @@ -19,10 +19,8 @@ use background_jobs::{ WorkerConfig, }; use itertools::Itertools; -use lemmy_db::{ - source::{community::Community, user::User_}, - DbPool, -}; +use lemmy_db::{source::community::Community, DbPool}; +use lemmy_db_schema::source::user::User_; use lemmy_utils::{location_info, settings::Settings, LemmyError}; use lemmy_websocket::LemmyContext; use log::{debug, warn}; diff --git a/lemmy_apub/src/fetcher.rs b/lemmy_apub/src/fetcher.rs index d06b221e..a4c5d66f 100644 --- a/lemmy_apub/src/fetcher.rs +++ b/lemmy_apub/src/fetcher.rs @@ -15,7 +15,7 @@ use diesel::result::Error::NotFound; use lemmy_db::{ source::{ community::{Community, CommunityModerator, CommunityModeratorForm}, - user::User_, + user::User, }, views::{ comment_view::CommentView, @@ -24,12 +24,13 @@ use lemmy_db::{ user_view::UserViewSafe, }, ApubObject, + Crud, Joinable, SearchType, }; use lemmy_db_schema::{ naive_now, - source::{comment::Comment, post::Post}, + source::{comment::Comment, post::Post, user::User_}, }; use lemmy_structs::{blocking, site::SearchResponse}; use lemmy_utils::{ diff --git a/lemmy_apub/src/http/community.rs b/lemmy_apub/src/http/community.rs index a1a7870f..0ab14e07 100644 --- a/lemmy_apub/src/http/community.rs +++ b/lemmy_apub/src/http/community.rs @@ -10,7 +10,7 @@ use activitystreams::{ }; use actix_web::{body::Body, web, HttpResponse}; use lemmy_db::{ - source::community::Community, + source::{community::Community, post::Post_}, views::community::community_follower_view::CommunityFollowerView, }; use lemmy_db_schema::source::post::Post; diff --git a/lemmy_apub/src/http/post.rs b/lemmy_apub/src/http/post.rs index ad846407..8ade3529 100644 --- a/lemmy_apub/src/http/post.rs +++ b/lemmy_apub/src/http/post.rs @@ -4,6 +4,7 @@ use crate::{ }; use actix_web::{body::Body, web, HttpResponse}; use diesel::result::Error::NotFound; +use lemmy_db::Crud; use lemmy_db_schema::source::post::Post; use lemmy_structs::blocking; use lemmy_utils::LemmyError; diff --git a/lemmy_apub/src/http/user.rs b/lemmy_apub/src/http/user.rs index 8dcc8eda..b01347e0 100644 --- a/lemmy_apub/src/http/user.rs +++ b/lemmy_apub/src/http/user.rs @@ -9,7 +9,8 @@ use activitystreams::{ collection::{CollectionExt, OrderedCollection}, }; use actix_web::{body::Body, web, HttpResponse}; -use lemmy_db::source::user::User_; +use lemmy_db::source::user::User; +use lemmy_db_schema::source::user::User_; use lemmy_structs::blocking; use lemmy_utils::LemmyError; use lemmy_websocket::LemmyContext; diff --git a/lemmy_apub/src/inbox/community_inbox.rs b/lemmy_apub/src/inbox/community_inbox.rs index a2bed621..9d5d4d1b 100644 --- a/lemmy_apub/src/inbox/community_inbox.rs +++ b/lemmy_apub/src/inbox/community_inbox.rs @@ -27,15 +27,13 @@ use activitystreams::{ use actix_web::{web, HttpRequest, HttpResponse}; use anyhow::{anyhow, Context}; use lemmy_db::{ - source::{ - community::{Community, CommunityFollower, CommunityFollowerForm}, - user::User_, - }, + source::community::{Community, CommunityFollower, CommunityFollowerForm}, views::community::community_user_ban_view::CommunityUserBanView, ApubObject, DbPool, Followable, }; +use lemmy_db_schema::source::user::User_; use lemmy_structs::blocking; use lemmy_utils::{location_info, LemmyError}; use lemmy_websocket::LemmyContext; diff --git a/lemmy_apub/src/inbox/mod.rs b/lemmy_apub/src/inbox/mod.rs index 41585188..2d097772 100644 --- a/lemmy_apub/src/inbox/mod.rs +++ b/lemmy_apub/src/inbox/mod.rs @@ -13,10 +13,11 @@ use activitystreams::{ use actix_web::HttpRequest; use anyhow::{anyhow, Context}; use lemmy_db::{ - source::{activity::Activity, community::Community, user::User_}, + source::{activity::Activity, community::Community}, ApubObject, DbPool, }; +use lemmy_db_schema::source::user::User_; use lemmy_structs::blocking; use lemmy_utils::{location_info, settings::Settings, LemmyError}; use lemmy_websocket::LemmyContext; diff --git a/lemmy_apub/src/inbox/user_inbox.rs b/lemmy_apub/src/inbox/user_inbox.rs index 374772d6..d9feffd3 100644 --- a/lemmy_apub/src/inbox/user_inbox.rs +++ b/lemmy_apub/src/inbox/user_inbox.rs @@ -52,11 +52,12 @@ use lemmy_db::{ source::{ community::{Community, CommunityFollower}, private_message::PrivateMessage, - user::User_, + user::User, }, ApubObject, Followable, }; +use lemmy_db_schema::source::user::User_; use lemmy_structs::blocking; use lemmy_utils::{location_info, LemmyError}; use lemmy_websocket::LemmyContext; diff --git a/lemmy_apub/src/lib.rs b/lemmy_apub/src/lib.rs index 78224c32..991e782e 100644 --- a/lemmy_apub/src/lib.rs +++ b/lemmy_apub/src/lib.rs @@ -22,10 +22,8 @@ use activitystreams::{ }; use activitystreams_ext::{Ext1, Ext2}; use anyhow::{anyhow, Context}; -use lemmy_db::{ - source::{activity::Activity, user::User_}, - DbPool, -}; +use lemmy_db::{source::activity::Activity, DbPool}; +use lemmy_db_schema::source::user::User_; use lemmy_structs::blocking; use lemmy_utils::{location_info, settings::Settings, LemmyError}; use lemmy_websocket::LemmyContext; diff --git a/lemmy_apub/src/objects/comment.rs b/lemmy_apub/src/objects/comment.rs index 9dd035c5..a753c8db 100644 --- a/lemmy_apub/src/objects/comment.rs +++ b/lemmy_apub/src/objects/comment.rs @@ -23,14 +23,11 @@ use activitystreams::{ prelude::*, }; use anyhow::{anyhow, Context}; -use lemmy_db::{ - source::{community::Community, user::User_}, - Crud, - DbPool, -}; +use lemmy_db::{source::community::Community, Crud, DbPool}; use lemmy_db_schema::source::{ comment::{Comment, CommentForm}, post::Post, + user::User_, }; use lemmy_structs::blocking; use lemmy_utils::{ diff --git a/lemmy_apub/src/objects/post.rs b/lemmy_apub/src/objects/post.rs index 7090cd16..ed5a5d9c 100644 --- a/lemmy_apub/src/objects/post.rs +++ b/lemmy_apub/src/objects/post.rs @@ -20,12 +20,11 @@ use activitystreams::{ }; use activitystreams_ext::Ext1; use anyhow::Context; -use lemmy_db::{ - source::{community::Community, user::User_}, - Crud, - DbPool, +use lemmy_db::{source::community::Community, Crud, DbPool}; +use lemmy_db_schema::source::{ + post::{Post, PostForm}, + user::User_, }; -use lemmy_db_schema::source::post::{Post, PostForm}; use lemmy_structs::blocking; use lemmy_utils::{ location_info, diff --git a/lemmy_apub/src/objects/private_message.rs b/lemmy_apub/src/objects/private_message.rs index e69c2811..cf176dc6 100644 --- a/lemmy_apub/src/objects/private_message.rs +++ b/lemmy_apub/src/objects/private_message.rs @@ -20,13 +20,11 @@ use activitystreams::{ }; use anyhow::Context; use lemmy_db::{ - source::{ - private_message::{PrivateMessage, PrivateMessageForm}, - user::User_, - }, + source::private_message::{PrivateMessage, PrivateMessageForm}, Crud, DbPool, }; +use lemmy_db_schema::source::user::User_; use lemmy_structs::blocking; use lemmy_utils::{location_info, utils::convert_datetime, LemmyError}; use lemmy_websocket::LemmyContext; diff --git a/lemmy_apub/src/objects/user.rs b/lemmy_apub/src/objects/user.rs index 6862867a..3ec1548d 100644 --- a/lemmy_apub/src/objects/user.rs +++ b/lemmy_apub/src/objects/user.rs @@ -18,12 +18,11 @@ use activitystreams::{ }; use activitystreams_ext::Ext1; use anyhow::Context; -use lemmy_db::{ +use lemmy_db::{ApubObject, DbPool}; +use lemmy_db_schema::{ + naive_now, source::user::{UserForm, User_}, - ApubObject, - DbPool, }; -use lemmy_db_schema::naive_now; use lemmy_structs::blocking; use lemmy_utils::{ location_info, diff --git a/lemmy_db/Cargo.toml b/lemmy_db/Cargo.toml index 849dba8e..0442d014 100644 --- a/lemmy_db/Cargo.toml +++ b/lemmy_db/Cargo.toml @@ -18,7 +18,7 @@ strum = "0.20.0" strum_macros = "0.20.1" log = "0.4.11" sha2 = "0.9.2" -bcrypt = "0.9.0" url = { version = "2.2.0", features = ["serde"] } lazy_static = "1.4.0" regex = "1.4.2" +bcrypt = "0.9.0" diff --git a/lemmy_db/src/aggregates/community_aggregates.rs b/lemmy_db/src/aggregates/community_aggregates.rs index cb94e632..f452892d 100644 --- a/lemmy_db/src/aggregates/community_aggregates.rs +++ b/lemmy_db/src/aggregates/community_aggregates.rs @@ -24,10 +24,7 @@ impl CommunityAggregates { mod tests { use crate::{ aggregates::community_aggregates::CommunityAggregates, - source::{ - community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm}, - user::{UserForm, User_}, - }, + source::community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm}, tests::establish_unpooled_connection, Crud, Followable, @@ -37,6 +34,7 @@ mod tests { use lemmy_db_schema::source::{ comment::{Comment, CommentForm}, post::{Post, PostForm}, + user::{UserForm, User_}, }; #[test] diff --git a/lemmy_db/src/aggregates/post_aggregates.rs b/lemmy_db/src/aggregates/post_aggregates.rs index 0b9bfa5f..434e52fd 100644 --- a/lemmy_db/src/aggregates/post_aggregates.rs +++ b/lemmy_db/src/aggregates/post_aggregates.rs @@ -26,10 +26,7 @@ impl PostAggregates { mod tests { use crate::{ aggregates::post_aggregates::PostAggregates, - source::{ - community::{Community, CommunityForm}, - user::{UserForm, User_}, - }, + source::community::{Community, CommunityForm}, tests::establish_unpooled_connection, Crud, Likeable, @@ -39,6 +36,7 @@ mod tests { use lemmy_db_schema::source::{ comment::{Comment, CommentForm}, post::{Post, PostForm, PostLike, PostLikeForm}, + user::{UserForm, User_}, }; #[test] diff --git a/lemmy_db/src/aggregates/site_aggregates.rs b/lemmy_db/src/aggregates/site_aggregates.rs index ea58b216..7fafc8ef 100644 --- a/lemmy_db/src/aggregates/site_aggregates.rs +++ b/lemmy_db/src/aggregates/site_aggregates.rs @@ -22,10 +22,7 @@ impl SiteAggregates { mod tests { use crate::{ aggregates::site_aggregates::SiteAggregates, - source::{ - community::{Community, CommunityForm}, - user::{UserForm, User_}, - }, + source::community::{Community, CommunityForm}, tests::establish_unpooled_connection, Crud, ListingType, @@ -34,6 +31,7 @@ mod tests { use lemmy_db_schema::source::{ comment::{Comment, CommentForm}, post::{Post, PostForm}, + user::{UserForm, User_}, }; #[test] diff --git a/lemmy_db/src/aggregates/user_aggregates.rs b/lemmy_db/src/aggregates/user_aggregates.rs index 91fa7460..61a1ae7c 100644 --- a/lemmy_db/src/aggregates/user_aggregates.rs +++ b/lemmy_db/src/aggregates/user_aggregates.rs @@ -25,10 +25,7 @@ impl UserAggregates { mod tests { use crate::{ aggregates::user_aggregates::UserAggregates, - source::{ - community::{Community, CommunityForm}, - user::{UserForm, User_}, - }, + source::community::{Community, CommunityForm}, tests::establish_unpooled_connection, Crud, Likeable, @@ -38,6 +35,7 @@ mod tests { use lemmy_db_schema::source::{ comment::{Comment, CommentForm, CommentLike, CommentLikeForm}, post::{Post, PostForm, PostLike, PostLikeForm}, + user::{UserForm, User_}, }; #[test] diff --git a/lemmy_db/src/source/activity.rs b/lemmy_db/src/source/activity.rs index 38a353a4..ca85cf9f 100644 --- a/lemmy_db/src/source/activity.rs +++ b/lemmy_db/src/source/activity.rs @@ -98,15 +98,13 @@ impl Activity { #[cfg(test)] mod tests { use crate::{ - source::{ - activity::{Activity, ActivityForm}, - user::{UserForm, User_}, - }, + source::activity::{Activity, ActivityForm}, tests::establish_unpooled_connection, Crud, ListingType, SortType, }; + use lemmy_db_schema::source::user::{UserForm, User_}; use serde_json::Value; #[test] diff --git a/lemmy_db/src/source/comment.rs b/lemmy_db/src/source/comment.rs index 17e9d637..010ca7da 100644 --- a/lemmy_db/src/source/comment.rs +++ b/lemmy_db/src/source/comment.rs @@ -1,14 +1,118 @@ use crate::{ApubObject, Crud, Likeable, Saveable}; use diesel::{dsl::*, result::Error, *}; -use lemmy_db_schema::source::comment::{ - Comment, - CommentForm, - CommentLike, - CommentLikeForm, - CommentSaved, - CommentSavedForm, +use lemmy_db_schema::{ + naive_now, + source::comment::{ + Comment, + CommentForm, + CommentLike, + CommentLikeForm, + CommentSaved, + CommentSavedForm, + }, }; +pub trait Comment_ { + fn update_ap_id(conn: &PgConnection, comment_id: i32, apub_id: String) -> Result; + fn permadelete_for_creator( + conn: &PgConnection, + for_creator_id: i32, + ) -> Result, Error>; + fn update_deleted( + conn: &PgConnection, + comment_id: i32, + new_deleted: bool, + ) -> Result; + fn update_removed( + conn: &PgConnection, + comment_id: i32, + new_removed: bool, + ) -> Result; + fn update_removed_for_creator( + conn: &PgConnection, + for_creator_id: i32, + new_removed: bool, + ) -> Result, Error>; + fn update_read(conn: &PgConnection, comment_id: i32, new_read: bool) -> Result; + fn update_content( + conn: &PgConnection, + comment_id: i32, + new_content: &str, + ) -> Result; +} + +impl Comment_ for Comment { + fn update_ap_id(conn: &PgConnection, comment_id: i32, apub_id: String) -> Result { + use lemmy_db_schema::schema::comment::dsl::*; + + diesel::update(comment.find(comment_id)) + .set(ap_id.eq(apub_id)) + .get_result::(conn) + } + + fn permadelete_for_creator(conn: &PgConnection, for_creator_id: i32) -> Result, Error> { + use lemmy_db_schema::schema::comment::dsl::*; + diesel::update(comment.filter(creator_id.eq(for_creator_id))) + .set(( + content.eq("*Permananently Deleted*"), + deleted.eq(true), + updated.eq(naive_now()), + )) + .get_results::(conn) + } + + fn update_deleted( + conn: &PgConnection, + comment_id: i32, + new_deleted: bool, + ) -> Result { + use lemmy_db_schema::schema::comment::dsl::*; + diesel::update(comment.find(comment_id)) + .set((deleted.eq(new_deleted), updated.eq(naive_now()))) + .get_result::(conn) + } + + fn update_removed( + conn: &PgConnection, + comment_id: i32, + new_removed: bool, + ) -> Result { + use lemmy_db_schema::schema::comment::dsl::*; + diesel::update(comment.find(comment_id)) + .set((removed.eq(new_removed), updated.eq(naive_now()))) + .get_result::(conn) + } + + fn update_removed_for_creator( + conn: &PgConnection, + for_creator_id: i32, + new_removed: bool, + ) -> Result, Error> { + use lemmy_db_schema::schema::comment::dsl::*; + diesel::update(comment.filter(creator_id.eq(for_creator_id))) + .set((removed.eq(new_removed), updated.eq(naive_now()))) + .get_results::(conn) + } + + fn update_read(conn: &PgConnection, comment_id: i32, new_read: bool) -> Result { + use lemmy_db_schema::schema::comment::dsl::*; + diesel::update(comment.find(comment_id)) + .set(read.eq(new_read)) + .get_result::(conn) + } + + fn update_content( + conn: &PgConnection, + comment_id: i32, + new_content: &str, + ) -> Result { + use lemmy_db_schema::schema::comment::dsl::*; + diesel::update(comment.find(comment_id)) + .set((content.eq(new_content), updated.eq(naive_now()))) + .get_result::(conn) + } +} + impl Crud for Comment { fn read(conn: &PgConnection, comment_id: i32) -> Result { use lemmy_db_schema::schema::comment::dsl::*; @@ -101,7 +205,7 @@ impl Saveable for CommentSaved { #[cfg(test)] mod tests { use crate::{ - source::{community::*, user::*}, + source::community::*, tests::establish_unpooled_connection, Crud, Likeable, @@ -109,7 +213,11 @@ mod tests { Saveable, SortType, }; - use lemmy_db_schema::source::{comment::*, post::*}; + use lemmy_db_schema::source::{ + comment::*, + post::*, + user::{UserForm, User_}, + }; #[test] fn test_crud() { diff --git a/lemmy_db/src/source/community.rs b/lemmy_db/src/source/community.rs index 13045cca..795ed123 100644 --- a/lemmy_db/src/source/community.rs +++ b/lemmy_db/src/source/community.rs @@ -421,12 +421,8 @@ impl Followable for CommunityFollower { #[cfg(test)] mod tests { - use crate::{ - source::{community::*, user::*}, - tests::establish_unpooled_connection, - ListingType, - SortType, - }; + use crate::{source::community::*, tests::establish_unpooled_connection, ListingType, SortType}; + use lemmy_db_schema::source::user::*; #[test] fn test_crud() { diff --git a/lemmy_db/src/source/moderator.rs b/lemmy_db/src/source/moderator.rs index eb6c2d56..ddb1407d 100644 --- a/lemmy_db/src/source/moderator.rs +++ b/lemmy_db/src/source/moderator.rs @@ -391,12 +391,12 @@ impl Crud for ModAdd { #[cfg(test)] mod tests { use crate::{ - source::{community::*, moderator::*, user::*}, + source::{community::*, moderator::*}, tests::establish_unpooled_connection, ListingType, SortType, }; - use lemmy_db_schema::source::{comment::*, post::*}; + use lemmy_db_schema::source::{comment::*, post::*, user::*}; // use Crud; #[test] diff --git a/lemmy_db/src/source/password_reset_request.rs b/lemmy_db/src/source/password_reset_request.rs index 3c9969e4..ae38f1c1 100644 --- a/lemmy_db/src/source/password_reset_request.rs +++ b/lemmy_db/src/source/password_reset_request.rs @@ -75,7 +75,6 @@ impl PasswordResetRequest { #[cfg(test)] mod tests { - use super::super::user::*; use crate::{ source::password_reset_request::PasswordResetRequest, tests::establish_unpooled_connection, @@ -83,6 +82,7 @@ mod tests { ListingType, SortType, }; + use lemmy_db_schema::source::user::*; #[test] fn test_crud() { diff --git a/lemmy_db/src/source/post.rs b/lemmy_db/src/source/post.rs index 5e8dc1cc..688ef39f 100644 --- a/lemmy_db/src/source/post.rs +++ b/lemmy_db/src/source/post.rs @@ -1,14 +1,17 @@ use crate::{ApubObject, Crud, Likeable, Readable, Saveable}; use diesel::{dsl::*, result::Error, *}; -use lemmy_db_schema::source::post::{ - Post, - PostForm, - PostLike, - PostLikeForm, - PostRead, - PostReadForm, - PostSaved, - PostSavedForm, +use lemmy_db_schema::{ + naive_now, + source::post::{ + Post, + PostForm, + PostLike, + PostLikeForm, + PostRead, + PostReadForm, + PostSaved, + PostSavedForm, + }, }; impl Crud for Post { @@ -35,6 +38,119 @@ impl Crud for Post { } } +pub trait Post_ { + //fn read(conn: &PgConnection, post_id: i32) -> Result; + fn list_for_community(conn: &PgConnection, the_community_id: i32) -> Result, Error>; + fn update_ap_id(conn: &PgConnection, post_id: i32, apub_id: String) -> Result; + fn permadelete_for_creator(conn: &PgConnection, for_creator_id: i32) -> Result, Error>; + fn update_deleted(conn: &PgConnection, post_id: i32, new_deleted: bool) -> Result; + fn update_removed(conn: &PgConnection, post_id: i32, new_removed: bool) -> Result; + fn update_removed_for_creator( + conn: &PgConnection, + for_creator_id: i32, + for_community_id: Option, + new_removed: bool, + ) -> Result, Error>; + fn update_locked(conn: &PgConnection, post_id: i32, new_locked: bool) -> Result; + fn update_stickied(conn: &PgConnection, post_id: i32, new_stickied: bool) -> Result; + fn is_post_creator(user_id: i32, post_creator_id: i32) -> bool; +} + +impl Post_ for Post { + // TODO: this is a duplicate? + //fn read(conn: &PgConnection, post_id: i32) -> Result { + // use lemmy_db_schema::schema::post::dsl::*; + // post.filter(id.eq(post_id)).first::(conn) + //} + + fn list_for_community(conn: &PgConnection, the_community_id: i32) -> Result, Error> { + use lemmy_db_schema::schema::post::dsl::*; + post + .filter(community_id.eq(the_community_id)) + .then_order_by(published.desc()) + .then_order_by(stickied.desc()) + .limit(20) + .load::(conn) + } + + fn update_ap_id(conn: &PgConnection, post_id: i32, apub_id: String) -> Result { + use lemmy_db_schema::schema::post::dsl::*; + + diesel::update(post.find(post_id)) + .set(ap_id.eq(apub_id)) + .get_result::(conn) + } + + fn permadelete_for_creator(conn: &PgConnection, for_creator_id: i32) -> Result, Error> { + use lemmy_db_schema::schema::post::dsl::*; + + let perma_deleted = "*Permananently Deleted*"; + let perma_deleted_url = "https://deleted.com"; + + diesel::update(post.filter(creator_id.eq(for_creator_id))) + .set(( + name.eq(perma_deleted), + url.eq(perma_deleted_url), + body.eq(perma_deleted), + deleted.eq(true), + updated.eq(naive_now()), + )) + .get_results::(conn) + } + + fn update_deleted(conn: &PgConnection, post_id: i32, new_deleted: bool) -> Result { + use lemmy_db_schema::schema::post::dsl::*; + diesel::update(post.find(post_id)) + .set((deleted.eq(new_deleted), updated.eq(naive_now()))) + .get_result::(conn) + } + + fn update_removed(conn: &PgConnection, post_id: i32, new_removed: bool) -> Result { + use lemmy_db_schema::schema::post::dsl::*; + diesel::update(post.find(post_id)) + .set((removed.eq(new_removed), updated.eq(naive_now()))) + .get_result::(conn) + } + + fn update_removed_for_creator( + conn: &PgConnection, + for_creator_id: i32, + for_community_id: Option, + new_removed: bool, + ) -> Result, Error> { + use lemmy_db_schema::schema::post::dsl::*; + + let mut update = diesel::update(post).into_boxed(); + update = update.filter(creator_id.eq(for_creator_id)); + + if let Some(for_community_id) = for_community_id { + update = update.filter(community_id.eq(for_community_id)); + } + + update + .set((removed.eq(new_removed), updated.eq(naive_now()))) + .get_results::(conn) + } + + fn update_locked(conn: &PgConnection, post_id: i32, new_locked: bool) -> Result { + use lemmy_db_schema::schema::post::dsl::*; + diesel::update(post.find(post_id)) + .set(locked.eq(new_locked)) + .get_result::(conn) + } + + fn update_stickied(conn: &PgConnection, post_id: i32, new_stickied: bool) -> Result { + use lemmy_db_schema::schema::post::dsl::*; + diesel::update(post.find(post_id)) + .set(stickied.eq(new_stickied)) + .get_result::(conn) + } + + fn is_post_creator(user_id: i32, post_creator_id: i32) -> bool { + user_id == post_creator_id + } +} + impl ApubObject for Post { fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result { use lemmy_db_schema::schema::post::dsl::*; @@ -116,11 +232,12 @@ impl Readable for PostRead { #[cfg(test)] mod tests { use crate::{ - source::{community::*, post::*, user::*}, + source::{community::*, post::*}, tests::establish_unpooled_connection, ListingType, SortType, }; + use lemmy_db_schema::source::user::*; #[test] fn test_crud() { diff --git a/lemmy_db/src/source/private_message.rs b/lemmy_db/src/source/private_message.rs index fd73a864..1177eaa9 100644 --- a/lemmy_db/src/source/private_message.rs +++ b/lemmy_db/src/source/private_message.rs @@ -140,11 +140,12 @@ impl PrivateMessage { #[cfg(test)] mod tests { use crate::{ - source::{private_message::*, user::*}, + source::private_message::*, tests::establish_unpooled_connection, ListingType, SortType, }; + use lemmy_db_schema::source::user::*; #[test] fn test_crud() { diff --git a/lemmy_db/src/source/user.rs b/lemmy_db/src/source/user.rs index 6bca769e..7461f4b4 100644 --- a/lemmy_db/src/source/user.rs +++ b/lemmy_db/src/source/user.rs @@ -3,65 +3,15 @@ use bcrypt::{hash, DEFAULT_COST}; use diesel::{dsl::*, result::Error, *}; use lemmy_db_schema::{ naive_now, - schema::{user_, user_::dsl::*, user_alias_1, user_alias_2}, + schema::user_::dsl::*, + source::user::{UserForm, User_}, }; use lemmy_utils::settings::Settings; -use serde::Serialize; - -#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)] -#[table_name = "user_"] -pub struct User_ { - pub id: i32, - pub name: String, - pub preferred_username: Option, - pub password_encrypted: String, - pub email: Option, - pub avatar: Option, - pub admin: bool, - pub banned: bool, - pub published: chrono::NaiveDateTime, - pub updated: Option, - 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, - pub actor_id: String, - pub bio: Option, - pub local: bool, - pub private_key: Option, - pub public_key: Option, - pub last_refreshed_at: chrono::NaiveDateTime, - pub banner: Option, - pub deleted: bool, -} - -/// 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, - pub avatar: Option, - pub admin: bool, - pub banned: bool, - pub published: chrono::NaiveDateTime, - pub updated: Option, - pub matrix_user_id: Option, - pub actor_id: String, - pub bio: Option, - pub local: bool, - pub banner: Option, - pub deleted: bool, -} mod safe_type { - use crate::{source::user::User_, ToSafe}; - use lemmy_db_schema::schema::user_::columns::*; + use crate::ToSafe; + use lemmy_db_schema::{schema::user_::columns::*, source::user::User_}; + type Columns = ( id, name, @@ -102,59 +52,10 @@ mod safe_type { } } -#[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, - pub password_encrypted: String, - pub email: Option, - pub avatar: Option, - pub admin: bool, - pub banned: bool, - pub published: chrono::NaiveDateTime, - pub updated: Option, - 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, - pub actor_id: String, - pub bio: Option, - pub local: bool, - pub private_key: Option, - pub public_key: Option, - pub last_refreshed_at: chrono::NaiveDateTime, - pub banner: Option, - 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, - pub avatar: Option, - pub admin: bool, - pub banned: bool, - pub published: chrono::NaiveDateTime, - pub updated: Option, - pub matrix_user_id: Option, - pub actor_id: String, - pub bio: Option, - pub local: bool, - pub banner: Option, - pub deleted: bool, -} - mod safe_type_alias_1 { - use crate::{source::user::UserAlias1, ToSafe}; - use lemmy_db_schema::schema::user_alias_1::columns::*; + use crate::ToSafe; + use lemmy_db_schema::{schema::user_alias_1::columns::*, source::user::UserAlias1}; + type Columns = ( id, name, @@ -195,59 +96,10 @@ mod safe_type_alias_1 { } } -#[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, - pub password_encrypted: String, - pub email: Option, - pub avatar: Option, - pub admin: bool, - pub banned: bool, - pub published: chrono::NaiveDateTime, - pub updated: Option, - 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, - pub actor_id: String, - pub bio: Option, - pub local: bool, - pub private_key: Option, - pub public_key: Option, - pub last_refreshed_at: chrono::NaiveDateTime, - pub banner: Option, - 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, - pub avatar: Option, - pub admin: bool, - pub banned: bool, - pub published: chrono::NaiveDateTime, - pub updated: Option, - pub matrix_user_id: Option, - pub actor_id: String, - pub bio: Option, - pub local: bool, - pub banner: Option, - pub deleted: bool, -} - mod safe_type_alias_2 { - use crate::{source::user::UserAlias2, ToSafe}; - use lemmy_db_schema::schema::user_alias_2::columns::*; + use crate::ToSafe; + use lemmy_db_schema::{schema::user_alias_2::columns::*, source::user::UserAlias2}; + type Columns = ( id, name, @@ -288,35 +140,6 @@ mod safe_type_alias_2 { } } -#[derive(Insertable, AsChangeset, Clone)] -#[table_name = "user_"] -pub struct UserForm { - pub name: String, - pub preferred_username: Option>, - pub password_encrypted: String, - pub admin: bool, - pub banned: Option, - pub email: Option>, - pub avatar: Option>, - pub published: Option, - pub updated: Option, - 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>, - pub actor_id: Option, - pub bio: Option>, - pub local: bool, - pub private_key: Option, - pub public_key: Option, - pub last_refreshed_at: Option, - pub banner: Option>, -} - impl Crud for User_ { fn read(conn: &PgConnection, user_id: i32) -> Result { user_ @@ -356,8 +179,26 @@ impl ApubObject for User_ { } } -impl User_ { - pub fn register(conn: &PgConnection, form: &UserForm) -> Result { +pub trait User { + fn register(conn: &PgConnection, form: &UserForm) -> Result; + fn update_password(conn: &PgConnection, user_id: i32, new_password: &str) + -> Result; + fn read_from_name(conn: &PgConnection, from_user_name: &str) -> Result; + fn add_admin(conn: &PgConnection, user_id: i32, added: bool) -> Result; + fn ban_user(conn: &PgConnection, user_id: i32, ban: bool) -> Result; + fn find_by_email_or_username( + conn: &PgConnection, + username_or_email: &str, + ) -> Result; + fn find_by_username(conn: &PgConnection, username: &str) -> Result; + fn find_by_email(conn: &PgConnection, from_email: &str) -> Result; + fn get_profile_url(&self, hostname: &str) -> String; + fn mark_as_updated(conn: &PgConnection, user_id: i32) -> Result; + fn delete_account(conn: &PgConnection, user_id: i32) -> Result; +} + +impl User for User_ { + fn register(conn: &PgConnection, form: &UserForm) -> Result { let mut edited_user = form.clone(); let password_hash = hash(&form.password_encrypted, DEFAULT_COST).expect("Couldn't hash password"); @@ -367,11 +208,7 @@ impl User_ { } // TODO do more individual updates like these - pub fn update_password( - conn: &PgConnection, - user_id: i32, - new_password: &str, - ) -> Result { + fn update_password(conn: &PgConnection, user_id: i32, new_password: &str) -> Result { let password_hash = hash(new_password, DEFAULT_COST).expect("Couldn't hash password"); diesel::update(user_.find(user_id)) @@ -382,7 +219,7 @@ impl User_ { .get_result::(conn) } - pub fn read_from_name(conn: &PgConnection, from_user_name: &str) -> Result { + fn read_from_name(conn: &PgConnection, from_user_name: &str) -> Result { user_ .filter(local.eq(true)) .filter(deleted.eq(false)) @@ -390,19 +227,19 @@ impl User_ { .first::(conn) } - pub fn add_admin(conn: &PgConnection, user_id: i32, added: bool) -> Result { + fn add_admin(conn: &PgConnection, user_id: i32, added: bool) -> Result { diesel::update(user_.find(user_id)) .set(admin.eq(added)) .get_result::(conn) } - pub fn ban_user(conn: &PgConnection, user_id: i32, ban: bool) -> Result { + fn ban_user(conn: &PgConnection, user_id: i32, ban: bool) -> Result { diesel::update(user_.find(user_id)) .set(banned.eq(ban)) .get_result::(conn) } - pub fn find_by_email_or_username( + fn find_by_email_or_username( conn: &PgConnection, username_or_email: &str, ) -> Result { @@ -413,7 +250,7 @@ impl User_ { } } - pub fn find_by_username(conn: &PgConnection, username: &str) -> Result { + fn find_by_username(conn: &PgConnection, username: &str) -> Result { user_ .filter(deleted.eq(false)) .filter(local.eq(true)) @@ -421,7 +258,7 @@ impl User_ { .first::(conn) } - pub fn find_by_email(conn: &PgConnection, from_email: &str) -> Result { + fn find_by_email(conn: &PgConnection, from_email: &str) -> Result { user_ .filter(deleted.eq(false)) .filter(local.eq(true)) @@ -429,7 +266,7 @@ impl User_ { .first::(conn) } - pub fn get_profile_url(&self, hostname: &str) -> String { + fn get_profile_url(&self, hostname: &str) -> String { format!( "{}://{}/u/{}", Settings::get().get_protocol_string(), @@ -438,13 +275,13 @@ impl User_ { ) } - pub fn mark_as_updated(conn: &PgConnection, user_id: i32) -> Result { + fn mark_as_updated(conn: &PgConnection, user_id: i32) -> Result { diesel::update(user_.find(user_id)) .set((last_refreshed_at.eq(naive_now()),)) .get_result::(conn) } - pub fn delete_account(conn: &PgConnection, user_id: i32) -> Result { + fn delete_account(conn: &PgConnection, user_id: i32) -> Result { diesel::update(user_.find(user_id)) .set(( preferred_username.eq::>(None), diff --git a/lemmy_db/src/source/user_mention.rs b/lemmy_db/src/source/user_mention.rs index 5df17286..64e24d32 100644 --- a/lemmy_db/src/source/user_mention.rs +++ b/lemmy_db/src/source/user_mention.rs @@ -79,12 +79,12 @@ impl UserMention { #[cfg(test)] mod tests { use crate::{ - source::{community::*, user::*, user_mention::*}, + source::{community::*, user_mention::*}, tests::establish_unpooled_connection, ListingType, SortType, }; - use lemmy_db_schema::source::{comment::*, post::*}; + use lemmy_db_schema::source::{comment::*, post::*, user::*}; #[test] fn test_crud() { diff --git a/lemmy_db/src/views/comment_report_view.rs b/lemmy_db/src/views/comment_report_view.rs index b067a9ec..0bfd6fe8 100644 --- a/lemmy_db/src/views/comment_report_view.rs +++ b/lemmy_db/src/views/comment_report_view.rs @@ -3,7 +3,6 @@ use crate::{ source::{ comment_report::CommentReport, community::{Community, CommunitySafe}, - user::{UserAlias1, UserAlias2, UserSafe, UserSafeAlias1, UserSafeAlias2, User_}, }, views::ViewToVec, MaybeOptional, @@ -12,7 +11,11 @@ use crate::{ use diesel::{result::Error, *}; use lemmy_db_schema::{ schema::{comment, comment_report, community, post, user_, user_alias_1, user_alias_2}, - source::{comment::Comment, post::Post}, + source::{ + comment::Comment, + post::Post, + user::{UserAlias1, UserAlias2, UserSafe, UserSafeAlias1, UserSafeAlias2, User_}, + }, }; use serde::Serialize; diff --git a/lemmy_db/src/views/comment_view.rs b/lemmy_db/src/views/comment_view.rs index d4680a34..3628b583 100644 --- a/lemmy_db/src/views/comment_view.rs +++ b/lemmy_db/src/views/comment_view.rs @@ -3,10 +3,7 @@ use crate::{ functions::hot_rank, fuzzy_search, limit_and_offset, - source::{ - community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan}, - user::{UserAlias1, UserSafe, UserSafeAlias1, User_}, - }, + source::community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan}, views::ViewToVec, ListingType, MaybeOptional, @@ -31,6 +28,7 @@ use lemmy_db_schema::{ source::{ comment::{Comment, CommentAlias1, CommentSaved}, post::Post, + user::{UserAlias1, UserSafe, UserSafeAlias1, User_}, }, }; use serde::Serialize; @@ -412,14 +410,14 @@ impl ViewToVec for CommentView { #[cfg(test)] mod tests { use crate::{ - source::{community::*, user::*}, + source::community::*, tests::establish_unpooled_connection, views::comment_view::*, Crud, Likeable, *, }; - use lemmy_db_schema::source::{comment::*, post::*}; + use lemmy_db_schema::source::{comment::*, post::*, user::*}; #[test] fn test_crud() { diff --git a/lemmy_db/src/views/community/community_follower_view.rs b/lemmy_db/src/views/community/community_follower_view.rs index 243b9142..144481ce 100644 --- a/lemmy_db/src/views/community/community_follower_view.rs +++ b/lemmy_db/src/views/community/community_follower_view.rs @@ -1,13 +1,13 @@ use crate::{ - source::{ - community::{Community, CommunitySafe}, - user::{UserSafe, User_}, - }, + source::community::{Community, CommunitySafe}, views::ViewToVec, ToSafe, }; use diesel::{result::Error, *}; -use lemmy_db_schema::schema::{community, community_follower, user_}; +use lemmy_db_schema::{ + schema::{community, community_follower, user_}, + source::user::{UserSafe, User_}, +}; use serde::Serialize; #[derive(Debug, Serialize, Clone)] diff --git a/lemmy_db/src/views/community/community_moderator_view.rs b/lemmy_db/src/views/community/community_moderator_view.rs index 8762b975..ffd2f622 100644 --- a/lemmy_db/src/views/community/community_moderator_view.rs +++ b/lemmy_db/src/views/community/community_moderator_view.rs @@ -1,13 +1,13 @@ use crate::{ - source::{ - community::{Community, CommunitySafe}, - user::{UserSafe, User_}, - }, + source::community::{Community, CommunitySafe}, views::ViewToVec, ToSafe, }; use diesel::{result::Error, *}; -use lemmy_db_schema::schema::{community, community_moderator, user_}; +use lemmy_db_schema::{ + schema::{community, community_moderator, user_}, + source::user::{UserSafe, User_}, +}; use serde::Serialize; #[derive(Debug, Serialize, Clone)] diff --git a/lemmy_db/src/views/community/community_user_ban_view.rs b/lemmy_db/src/views/community/community_user_ban_view.rs index 5dba4ebd..80ac78cc 100644 --- a/lemmy_db/src/views/community/community_user_ban_view.rs +++ b/lemmy_db/src/views/community/community_user_ban_view.rs @@ -1,12 +1,12 @@ use crate::{ - source::{ - community::{Community, CommunitySafe}, - user::{UserSafe, User_}, - }, + source::community::{Community, CommunitySafe}, ToSafe, }; use diesel::{result::Error, *}; -use lemmy_db_schema::schema::{community, community_user_ban, user_}; +use lemmy_db_schema::{ + schema::{community, community_user_ban, user_}, + source::user::{UserSafe, User_}, +}; use serde::Serialize; #[derive(Debug, Serialize, Clone)] diff --git a/lemmy_db/src/views/community/community_view.rs b/lemmy_db/src/views/community/community_view.rs index 6c951b33..bd711936 100644 --- a/lemmy_db/src/views/community/community_view.rs +++ b/lemmy_db/src/views/community/community_view.rs @@ -6,7 +6,6 @@ use crate::{ source::{ category::Category, community::{Community, CommunityFollower, CommunitySafe}, - user::{UserSafe, User_}, }, views::ViewToVec, MaybeOptional, @@ -14,12 +13,9 @@ use crate::{ ToSafe, }; use diesel::{result::Error, *}; -use lemmy_db_schema::schema::{ - category, - community, - community_aggregates, - community_follower, - user_, +use lemmy_db_schema::{ + schema::{category, community, community_aggregates, community_follower, user_}, + source::user::{UserSafe, User_}, }; use serde::Serialize; diff --git a/lemmy_db/src/views/moderator/mod_add_community_view.rs b/lemmy_db/src/views/moderator/mod_add_community_view.rs index 1dd7cfc4..2e048322 100644 --- a/lemmy_db/src/views/moderator/mod_add_community_view.rs +++ b/lemmy_db/src/views/moderator/mod_add_community_view.rs @@ -3,13 +3,15 @@ use crate::{ source::{ community::{Community, CommunitySafe}, moderator::ModAddCommunity, - user::{UserAlias1, UserSafe, UserSafeAlias1, User_}, }, views::ViewToVec, ToSafe, }; use diesel::{result::Error, *}; -use lemmy_db_schema::schema::{community, mod_add_community, user_, user_alias_1}; +use lemmy_db_schema::{ + schema::{community, mod_add_community, user_, user_alias_1}, + source::user::{UserAlias1, UserSafe, UserSafeAlias1, User_}, +}; use serde::Serialize; #[derive(Debug, Serialize, Clone)] diff --git a/lemmy_db/src/views/moderator/mod_add_view.rs b/lemmy_db/src/views/moderator/mod_add_view.rs index 06648ad7..c724e826 100644 --- a/lemmy_db/src/views/moderator/mod_add_view.rs +++ b/lemmy_db/src/views/moderator/mod_add_view.rs @@ -1,14 +1,9 @@ -use crate::{ - limit_and_offset, - source::{ - moderator::ModAdd, - user::{UserAlias1, UserSafe, UserSafeAlias1, User_}, - }, - views::ViewToVec, - ToSafe, -}; +use crate::{limit_and_offset, source::moderator::ModAdd, views::ViewToVec, ToSafe}; use diesel::{result::Error, *}; -use lemmy_db_schema::schema::{mod_add, user_, user_alias_1}; +use lemmy_db_schema::{ + schema::{mod_add, user_, user_alias_1}, + source::user::{UserAlias1, UserSafe, UserSafeAlias1, User_}, +}; use serde::Serialize; #[derive(Debug, Serialize, Clone)] diff --git a/lemmy_db/src/views/moderator/mod_ban_from_community_view.rs b/lemmy_db/src/views/moderator/mod_ban_from_community_view.rs index 3992518b..e31d6d19 100644 --- a/lemmy_db/src/views/moderator/mod_ban_from_community_view.rs +++ b/lemmy_db/src/views/moderator/mod_ban_from_community_view.rs @@ -3,13 +3,15 @@ use crate::{ source::{ community::{Community, CommunitySafe}, moderator::ModBanFromCommunity, - user::{UserAlias1, UserSafe, UserSafeAlias1, User_}, }, views::ViewToVec, ToSafe, }; use diesel::{result::Error, *}; -use lemmy_db_schema::schema::{community, mod_ban_from_community, user_, user_alias_1}; +use lemmy_db_schema::{ + schema::{community, mod_ban_from_community, user_, user_alias_1}, + source::user::{UserAlias1, UserSafe, UserSafeAlias1, User_}, +}; use serde::Serialize; #[derive(Debug, Serialize, Clone)] diff --git a/lemmy_db/src/views/moderator/mod_ban_view.rs b/lemmy_db/src/views/moderator/mod_ban_view.rs index 52e89025..2a3edb6c 100644 --- a/lemmy_db/src/views/moderator/mod_ban_view.rs +++ b/lemmy_db/src/views/moderator/mod_ban_view.rs @@ -1,14 +1,9 @@ -use crate::{ - limit_and_offset, - source::{ - moderator::ModBan, - user::{UserAlias1, UserSafe, UserSafeAlias1, User_}, - }, - views::ViewToVec, - ToSafe, -}; +use crate::{limit_and_offset, source::moderator::ModBan, views::ViewToVec, ToSafe}; use diesel::{result::Error, *}; -use lemmy_db_schema::schema::{mod_ban, user_, user_alias_1}; +use lemmy_db_schema::{ + schema::{mod_ban, user_, user_alias_1}, + source::user::{UserAlias1, UserSafe, UserSafeAlias1, User_}, +}; use serde::Serialize; #[derive(Debug, Serialize, Clone)] diff --git a/lemmy_db/src/views/moderator/mod_lock_post_view.rs b/lemmy_db/src/views/moderator/mod_lock_post_view.rs index 685d83bb..9687e1b5 100644 --- a/lemmy_db/src/views/moderator/mod_lock_post_view.rs +++ b/lemmy_db/src/views/moderator/mod_lock_post_view.rs @@ -3,7 +3,6 @@ use crate::{ source::{ community::{Community, CommunitySafe}, moderator::ModLockPost, - user::{UserSafe, User_}, }, views::ViewToVec, ToSafe, @@ -11,7 +10,10 @@ use crate::{ use diesel::{result::Error, *}; use lemmy_db_schema::{ schema::{community, mod_lock_post, post, user_}, - source::post::Post, + source::{ + post::Post, + user::{UserSafe, User_}, + }, }; use serde::Serialize; diff --git a/lemmy_db/src/views/moderator/mod_remove_comment_view.rs b/lemmy_db/src/views/moderator/mod_remove_comment_view.rs index 0c6519de..70fb8cbd 100644 --- a/lemmy_db/src/views/moderator/mod_remove_comment_view.rs +++ b/lemmy_db/src/views/moderator/mod_remove_comment_view.rs @@ -3,7 +3,6 @@ use crate::{ source::{ community::{Community, CommunitySafe}, moderator::ModRemoveComment, - user::{UserAlias1, UserSafe, UserSafeAlias1, User_}, }, views::ViewToVec, ToSafe, @@ -11,7 +10,11 @@ use crate::{ use diesel::{result::Error, *}; use lemmy_db_schema::{ schema::{comment, community, mod_remove_comment, post, user_, user_alias_1}, - source::{comment::Comment, post::Post}, + source::{ + comment::Comment, + post::Post, + user::{UserAlias1, UserSafe, UserSafeAlias1, User_}, + }, }; use serde::Serialize; diff --git a/lemmy_db/src/views/moderator/mod_remove_community_view.rs b/lemmy_db/src/views/moderator/mod_remove_community_view.rs index 1700ac2d..9e7fb6a4 100644 --- a/lemmy_db/src/views/moderator/mod_remove_community_view.rs +++ b/lemmy_db/src/views/moderator/mod_remove_community_view.rs @@ -3,13 +3,15 @@ use crate::{ source::{ community::{Community, CommunitySafe}, moderator::ModRemoveCommunity, - user::{UserSafe, User_}, }, views::ViewToVec, ToSafe, }; use diesel::{result::Error, *}; -use lemmy_db_schema::schema::{community, mod_remove_community, user_}; +use lemmy_db_schema::{ + schema::{community, mod_remove_community, user_}, + source::user::{UserSafe, User_}, +}; use serde::Serialize; #[derive(Debug, Serialize, Clone)] diff --git a/lemmy_db/src/views/moderator/mod_remove_post_view.rs b/lemmy_db/src/views/moderator/mod_remove_post_view.rs index 98aefd21..fe976c8e 100644 --- a/lemmy_db/src/views/moderator/mod_remove_post_view.rs +++ b/lemmy_db/src/views/moderator/mod_remove_post_view.rs @@ -3,7 +3,6 @@ use crate::{ source::{ community::{Community, CommunitySafe}, moderator::ModRemovePost, - user::{UserSafe, User_}, }, views::ViewToVec, ToSafe, @@ -11,7 +10,10 @@ use crate::{ use diesel::{result::Error, *}; use lemmy_db_schema::{ schema::{community, mod_remove_post, post, user_}, - source::post::Post, + source::{ + post::Post, + user::{UserSafe, User_}, + }, }; use serde::Serialize; diff --git a/lemmy_db/src/views/moderator/mod_sticky_post_view.rs b/lemmy_db/src/views/moderator/mod_sticky_post_view.rs index 40672f8b..c51d083f 100644 --- a/lemmy_db/src/views/moderator/mod_sticky_post_view.rs +++ b/lemmy_db/src/views/moderator/mod_sticky_post_view.rs @@ -3,7 +3,6 @@ use crate::{ source::{ community::{Community, CommunitySafe}, moderator::ModStickyPost, - user::{UserSafe, User_}, }, views::ViewToVec, ToSafe, @@ -11,7 +10,10 @@ use crate::{ use diesel::{result::Error, *}; use lemmy_db_schema::{ schema::{community, mod_sticky_post, post, user_}, - source::post::Post, + source::{ + post::Post, + user::{UserSafe, User_}, + }, }; use serde::Serialize; diff --git a/lemmy_db/src/views/post_report_view.rs b/lemmy_db/src/views/post_report_view.rs index 5e186239..9c42f776 100644 --- a/lemmy_db/src/views/post_report_view.rs +++ b/lemmy_db/src/views/post_report_view.rs @@ -3,7 +3,6 @@ use crate::{ source::{ community::{Community, CommunitySafe}, post_report::PostReport, - user::{UserAlias1, UserAlias2, UserSafe, UserSafeAlias1, UserSafeAlias2, User_}, }, views::ViewToVec, MaybeOptional, @@ -12,7 +11,10 @@ use crate::{ use diesel::{result::Error, *}; use lemmy_db_schema::{ schema::{community, post, post_report, user_, user_alias_1, user_alias_2}, - source::post::Post, + source::{ + post::Post, + user::{UserAlias1, UserAlias2, UserSafe, UserSafeAlias1, UserSafeAlias2, User_}, + }, }; use serde::Serialize; diff --git a/lemmy_db/src/views/post_view.rs b/lemmy_db/src/views/post_view.rs index fb3fbbf3..e3bdd178 100644 --- a/lemmy_db/src/views/post_view.rs +++ b/lemmy_db/src/views/post_view.rs @@ -3,10 +3,7 @@ use crate::{ functions::hot_rank, fuzzy_search, limit_and_offset, - source::{ - community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan}, - user::{UserSafe, User_}, - }, + source::community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan}, views::ViewToVec, ListingType, MaybeOptional, @@ -26,7 +23,10 @@ use lemmy_db_schema::{ post_saved, user_, }, - source::post::{Post, PostRead, PostSaved}, + source::{ + post::{Post, PostRead, PostSaved}, + user::{UserSafe, User_}, + }, }; use serde::Serialize; @@ -408,14 +408,14 @@ impl ViewToVec for PostView { mod tests { use crate::{ aggregates::post_aggregates::PostAggregates, - source::{community::*, user::*}, + source::community::*, tests::establish_unpooled_connection, views::post_view::{PostQueryBuilder, PostView}, Crud, Likeable, *, }; - use lemmy_db_schema::source::post::*; + use lemmy_db_schema::source::{post::*, user::*}; #[test] fn test_crud() { diff --git a/lemmy_db/src/views/private_message_view.rs b/lemmy_db/src/views/private_message_view.rs index 5d594b12..fa531976 100644 --- a/lemmy_db/src/views/private_message_view.rs +++ b/lemmy_db/src/views/private_message_view.rs @@ -1,15 +1,15 @@ use crate::{ limit_and_offset, - source::{ - private_message::PrivateMessage, - user::{UserAlias1, UserSafe, UserSafeAlias1, User_}, - }, + source::private_message::PrivateMessage, views::ViewToVec, MaybeOptional, ToSafe, }; use diesel::{result::Error, *}; -use lemmy_db_schema::schema::{private_message, user_, user_alias_1}; +use lemmy_db_schema::{ + schema::{private_message, user_, user_alias_1}, + source::user::{UserAlias1, UserSafe, UserSafeAlias1, User_}, +}; use serde::Serialize; #[derive(Debug, PartialEq, Serialize, Clone)] diff --git a/lemmy_db/src/views/site_view.rs b/lemmy_db/src/views/site_view.rs index d956e2e1..362c808d 100644 --- a/lemmy_db/src/views/site_view.rs +++ b/lemmy_db/src/views/site_view.rs @@ -1,12 +1,9 @@ -use crate::{ - source::{ - site::Site, - user::{UserSafe, User_}, - }, - ToSafe, -}; +use crate::{source::site::Site, ToSafe}; use diesel::{result::Error, *}; -use lemmy_db_schema::schema::{site, user_}; +use lemmy_db_schema::{ + schema::{site, user_}, + source::user::{UserSafe, User_}, +}; use serde::Serialize; #[derive(Debug, Serialize, Clone)] diff --git a/lemmy_db/src/views/user_mention_view.rs b/lemmy_db/src/views/user_mention_view.rs index 61fb5626..61a788a4 100644 --- a/lemmy_db/src/views/user_mention_view.rs +++ b/lemmy_db/src/views/user_mention_view.rs @@ -4,7 +4,6 @@ use crate::{ limit_and_offset, source::{ community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan}, - user::{UserAlias1, UserSafe, UserSafeAlias1, User_}, user_mention::UserMention, }, views::ViewToVec, @@ -30,6 +29,7 @@ use lemmy_db_schema::{ source::{ comment::{Comment, CommentSaved}, post::Post, + user::{UserAlias1, UserSafe, UserSafeAlias1, User_}, }, }; use serde::Serialize; diff --git a/lemmy_db/src/views/user_view.rs b/lemmy_db/src/views/user_view.rs index 8f59691a..f3109011 100644 --- a/lemmy_db/src/views/user_view.rs +++ b/lemmy_db/src/views/user_view.rs @@ -2,14 +2,16 @@ use crate::{ aggregates::user_aggregates::UserAggregates, fuzzy_search, limit_and_offset, - source::user::{UserSafe, User_}, views::ViewToVec, MaybeOptional, SortType, ToSafe, }; use diesel::{dsl::*, result::Error, *}; -use lemmy_db_schema::schema::{user_, user_aggregates}; +use lemmy_db_schema::{ + schema::{user_, user_aggregates}, + source::user::{UserSafe, User_}, +}; use serde::Serialize; #[derive(Debug, Serialize, Clone)] diff --git a/lemmy_db_schema/src/lib.rs b/lemmy_db_schema/src/lib.rs index 11451d17..3868a3b7 100644 --- a/lemmy_db_schema/src/lib.rs +++ b/lemmy_db_schema/src/lib.rs @@ -6,6 +6,7 @@ use chrono::NaiveDateTime; pub mod schema; pub mod source; +// TODO: can probably move this back to lemmy_db pub fn naive_now() -> NaiveDateTime { chrono::prelude::Utc::now().naive_utc() } diff --git a/lemmy_db_schema/src/source/comment.rs b/lemmy_db_schema/src/source/comment.rs index 34577640..8c553a51 100644 --- a/lemmy_db_schema/src/source/comment.rs +++ b/lemmy_db_schema/src/source/comment.rs @@ -1,9 +1,7 @@ use crate::{ - naive_now, schema::{comment, comment_alias_1, comment_like, comment_saved}, source::post::Post, }; -use diesel::{result::Error, PgConnection, *}; use serde::Serialize; use url::{ParseError, Url}; @@ -66,85 +64,6 @@ pub struct CommentForm { pub local: bool, } -impl Comment { - pub fn update_ap_id( - conn: &PgConnection, - comment_id: i32, - apub_id: String, - ) -> Result { - use crate::schema::comment::dsl::*; - - diesel::update(comment.find(comment_id)) - .set(ap_id.eq(apub_id)) - .get_result::(conn) - } - - pub fn permadelete_for_creator( - conn: &PgConnection, - for_creator_id: i32, - ) -> Result, Error> { - use crate::schema::comment::dsl::*; - diesel::update(comment.filter(creator_id.eq(for_creator_id))) - .set(( - content.eq("*Permananently Deleted*"), - deleted.eq(true), - updated.eq(naive_now()), - )) - .get_results::(conn) - } - - pub fn update_deleted( - conn: &PgConnection, - comment_id: i32, - new_deleted: bool, - ) -> Result { - use crate::schema::comment::dsl::*; - diesel::update(comment.find(comment_id)) - .set((deleted.eq(new_deleted), updated.eq(naive_now()))) - .get_result::(conn) - } - - pub fn update_removed( - conn: &PgConnection, - comment_id: i32, - new_removed: bool, - ) -> Result { - use crate::schema::comment::dsl::*; - diesel::update(comment.find(comment_id)) - .set((removed.eq(new_removed), updated.eq(naive_now()))) - .get_result::(conn) - } - - pub fn update_removed_for_creator( - conn: &PgConnection, - for_creator_id: i32, - new_removed: bool, - ) -> Result, Error> { - use crate::schema::comment::dsl::*; - diesel::update(comment.filter(creator_id.eq(for_creator_id))) - .set((removed.eq(new_removed), updated.eq(naive_now()))) - .get_results::(conn) - } - - pub fn update_read(conn: &PgConnection, comment_id: i32, new_read: bool) -> Result { - use crate::schema::comment::dsl::*; - diesel::update(comment.find(comment_id)) - .set(read.eq(new_read)) - .get_result::(conn) - } - - pub fn update_content( - conn: &PgConnection, - comment_id: i32, - new_content: &str, - ) -> Result { - use crate::schema::comment::dsl::*; - diesel::update(comment.find(comment_id)) - .set((content.eq(new_content), updated.eq(naive_now()))) - .get_result::(conn) - } -} - impl CommentForm { pub fn get_ap_id(&self) -> Result { Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string())) diff --git a/lemmy_db_schema/src/source/mod.rs b/lemmy_db_schema/src/source/mod.rs index 38203b5e..2a5d7a69 100644 --- a/lemmy_db_schema/src/source/mod.rs +++ b/lemmy_db_schema/src/source/mod.rs @@ -1,2 +1,3 @@ pub mod comment; pub mod post; +pub mod user; diff --git a/lemmy_db_schema/src/source/post.rs b/lemmy_db_schema/src/source/post.rs index a0b974e2..b0cc78e0 100644 --- a/lemmy_db_schema/src/source/post.rs +++ b/lemmy_db_schema/src/source/post.rs @@ -1,8 +1,4 @@ -use crate::{ - naive_now, - schema::{post, post_like, post_read, post_saved}, -}; -use diesel::{result::Error, *}; +use crate::schema::{post, post_like, post_read, post_saved}; use serde::Serialize; use url::{ParseError, Url}; @@ -53,118 +49,6 @@ pub struct PostForm { pub local: bool, } -impl Post { - pub fn read(conn: &PgConnection, post_id: i32) -> Result { - use crate::schema::post::dsl::*; - post.filter(id.eq(post_id)).first::(conn) - } - - pub fn list_for_community( - conn: &PgConnection, - the_community_id: i32, - ) -> Result, Error> { - use crate::schema::post::dsl::*; - post - .filter(community_id.eq(the_community_id)) - .then_order_by(published.desc()) - .then_order_by(stickied.desc()) - .limit(20) - .load::(conn) - } - - pub fn update_ap_id(conn: &PgConnection, post_id: i32, apub_id: String) -> Result { - use crate::schema::post::dsl::*; - - diesel::update(post.find(post_id)) - .set(ap_id.eq(apub_id)) - .get_result::(conn) - } - - pub fn permadelete_for_creator( - conn: &PgConnection, - for_creator_id: i32, - ) -> Result, Error> { - use crate::schema::post::dsl::*; - - let perma_deleted = "*Permananently Deleted*"; - let perma_deleted_url = "https://deleted.com"; - - diesel::update(post.filter(creator_id.eq(for_creator_id))) - .set(( - name.eq(perma_deleted), - url.eq(perma_deleted_url), - body.eq(perma_deleted), - deleted.eq(true), - updated.eq(naive_now()), - )) - .get_results::(conn) - } - - pub fn update_deleted( - conn: &PgConnection, - post_id: i32, - new_deleted: bool, - ) -> Result { - use crate::schema::post::dsl::*; - diesel::update(post.find(post_id)) - .set((deleted.eq(new_deleted), updated.eq(naive_now()))) - .get_result::(conn) - } - - pub fn update_removed( - conn: &PgConnection, - post_id: i32, - new_removed: bool, - ) -> Result { - use crate::schema::post::dsl::*; - diesel::update(post.find(post_id)) - .set((removed.eq(new_removed), updated.eq(naive_now()))) - .get_result::(conn) - } - - pub fn update_removed_for_creator( - conn: &PgConnection, - for_creator_id: i32, - for_community_id: Option, - new_removed: bool, - ) -> Result, Error> { - use crate::schema::post::dsl::*; - - let mut update = diesel::update(post).into_boxed(); - update = update.filter(creator_id.eq(for_creator_id)); - - if let Some(for_community_id) = for_community_id { - update = update.filter(community_id.eq(for_community_id)); - } - - update - .set((removed.eq(new_removed), updated.eq(naive_now()))) - .get_results::(conn) - } - - pub fn update_locked(conn: &PgConnection, post_id: i32, new_locked: bool) -> Result { - use crate::schema::post::dsl::*; - diesel::update(post.find(post_id)) - .set(locked.eq(new_locked)) - .get_result::(conn) - } - - pub fn update_stickied( - conn: &PgConnection, - post_id: i32, - new_stickied: bool, - ) -> Result { - use crate::schema::post::dsl::*; - diesel::update(post.find(post_id)) - .set(stickied.eq(new_stickied)) - .get_result::(conn) - } - - pub fn is_post_creator(user_id: i32, post_creator_id: i32) -> bool { - user_id == post_creator_id - } -} - impl PostForm { pub fn get_ap_id(&self) -> Result { Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string())) diff --git a/lemmy_db_schema/src/source/user.rs b/lemmy_db_schema/src/source/user.rs new file mode 100644 index 00000000..3d9d9e50 --- /dev/null +++ b/lemmy_db_schema/src/source/user.rs @@ -0,0 +1,182 @@ +use crate::schema::{user_, user_alias_1, user_alias_2}; +use serde::Serialize; + +#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)] +#[table_name = "user_"] +pub struct User_ { + pub id: i32, + pub name: String, + pub preferred_username: Option, + pub password_encrypted: String, + pub email: Option, + pub avatar: Option, + pub admin: bool, + pub banned: bool, + pub published: chrono::NaiveDateTime, + pub updated: Option, + 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, + pub actor_id: String, + pub bio: Option, + pub local: bool, + pub private_key: Option, + pub public_key: Option, + pub last_refreshed_at: chrono::NaiveDateTime, + pub banner: Option, + pub deleted: bool, +} + +/// 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, + pub avatar: Option, + pub admin: bool, + pub banned: bool, + pub published: chrono::NaiveDateTime, + pub updated: Option, + pub matrix_user_id: Option, + pub actor_id: String, + pub bio: Option, + pub local: bool, + pub banner: Option, + 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, + pub password_encrypted: String, + pub email: Option, + pub avatar: Option, + pub admin: bool, + pub banned: bool, + pub published: chrono::NaiveDateTime, + pub updated: Option, + 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, + pub actor_id: String, + pub bio: Option, + pub local: bool, + pub private_key: Option, + pub public_key: Option, + pub last_refreshed_at: chrono::NaiveDateTime, + pub banner: Option, + 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, + pub avatar: Option, + pub admin: bool, + pub banned: bool, + pub published: chrono::NaiveDateTime, + pub updated: Option, + pub matrix_user_id: Option, + pub actor_id: String, + pub bio: Option, + pub local: bool, + pub banner: Option, + 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, + pub password_encrypted: String, + pub email: Option, + pub avatar: Option, + pub admin: bool, + pub banned: bool, + pub published: chrono::NaiveDateTime, + pub updated: Option, + 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, + pub actor_id: String, + pub bio: Option, + pub local: bool, + pub private_key: Option, + pub public_key: Option, + pub last_refreshed_at: chrono::NaiveDateTime, + pub banner: Option, + 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, + pub avatar: Option, + pub admin: bool, + pub banned: bool, + pub published: chrono::NaiveDateTime, + pub updated: Option, + pub matrix_user_id: Option, + pub actor_id: String, + pub bio: Option, + pub local: bool, + pub banner: Option, + pub deleted: bool, +} + +#[derive(Insertable, AsChangeset, Clone)] +#[table_name = "user_"] +pub struct UserForm { + pub name: String, + pub preferred_username: Option>, + pub password_encrypted: String, + pub admin: bool, + pub banned: Option, + pub email: Option>, + pub avatar: Option>, + pub published: Option, + pub updated: Option, + 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>, + pub actor_id: Option, + pub bio: Option>, + pub local: bool, + pub private_key: Option, + pub public_key: Option, + pub last_refreshed_at: Option, + pub banner: Option>, +} diff --git a/lemmy_structs/src/lib.rs b/lemmy_structs/src/lib.rs index 595f6d07..7c3fc5c3 100644 --- a/lemmy_structs/src/lib.rs +++ b/lemmy_structs/src/lib.rs @@ -8,13 +8,13 @@ pub mod websocket; use diesel::PgConnection; use lemmy_db::{ source::{ - user::User_, + user::User, user_mention::{UserMention, UserMentionForm}, }, Crud, DbPool, }; -use lemmy_db_schema::source::{comment::Comment, post::Post}; +use lemmy_db_schema::source::{comment::Comment, post::Post, user::User_}; use lemmy_utils::{email::send_email, settings::Settings, utils::MentionData, LemmyError}; use log::error; use serde::{Deserialize, Serialize}; diff --git a/lemmy_structs/src/site.rs b/lemmy_structs/src/site.rs index 9209a542..0d154295 100644 --- a/lemmy_structs/src/site.rs +++ b/lemmy_structs/src/site.rs @@ -1,6 +1,6 @@ use lemmy_db::{ aggregates::site_aggregates::SiteAggregates, - source::{category::*, user::*}, + source::category::*, views::{ comment_view::CommentView, community::community_view::CommunityView, @@ -20,6 +20,7 @@ use lemmy_db::{ user_view::UserViewSafe, }, }; +use lemmy_db_schema::source::user::User_; use serde::{Deserialize, Serialize}; #[derive(Deserialize)] diff --git a/src/code_migrations.rs b/src/code_migrations.rs index c294be67..2afdfabd 100644 --- a/src/code_migrations.rs +++ b/src/code_migrations.rs @@ -5,15 +5,20 @@ use diesel::{ }; use lemmy_db::{ source::{ + comment::Comment_, community::{Community, CommunityForm}, + post::Post_, private_message::PrivateMessage, - user::{UserForm, User_}, }, Crud, }; use lemmy_db_schema::{ naive_now, - source::{comment::Comment, post::Post}, + source::{ + comment::Comment, + post::Post, + user::{UserForm, User_}, + }, }; use lemmy_utils::{ apub::{generate_actor_keypair, make_apub_endpoint, EndpointType}, diff --git a/src/routes/feeds.rs b/src/routes/feeds.rs index 7a4801f4..8a3ecbae 100644 --- a/src/routes/feeds.rs +++ b/src/routes/feeds.rs @@ -4,7 +4,7 @@ use chrono::{DateTime, NaiveDateTime, Utc}; use diesel::PgConnection; use lemmy_api::claims::Claims; use lemmy_db::{ - source::{community::Community, user::User_}, + source::{community::Community, user::User}, views::{ comment_view::{CommentQueryBuilder, CommentView}, post_view::{PostQueryBuilder, PostView}, @@ -14,6 +14,7 @@ use lemmy_db::{ ListingType, SortType, }; +use lemmy_db_schema::source::user::User_; use lemmy_structs::blocking; use lemmy_utils::{settings::Settings, utils::markdown_to_html, LemmyError}; use lemmy_websocket::LemmyContext; diff --git a/src/routes/webfinger.rs b/src/routes/webfinger.rs index d59b4e38..57c90c96 100644 --- a/src/routes/webfinger.rs +++ b/src/routes/webfinger.rs @@ -1,6 +1,7 @@ use actix_web::{error::ErrorBadRequest, web::Query, *}; use anyhow::anyhow; -use lemmy_db::source::{community::Community, user::User_}; +use lemmy_db::source::{community::Community, user::User}; +use lemmy_db_schema::source::user::User_; use lemmy_structs::{blocking, WebFingerLink, WebFingerResponse}; use lemmy_utils::{ settings::Settings, diff --git a/tests/integration_test.rs b/tests/integration_test.rs index a61c8ff6..5a191352 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -29,14 +29,12 @@ use lemmy_apub::{ }, }; use lemmy_db::{ - source::{ - community::{Community, CommunityForm}, - user::{User_, *}, - }, + source::community::{Community, CommunityForm}, Crud, ListingType, SortType, }; +use lemmy_db_schema::source::user::{UserForm, User_}; use lemmy_rate_limit::{rate_limiter::RateLimiter, RateLimit}; use lemmy_utils::{apub::generate_actor_keypair, settings::Settings}; use lemmy_websocket::{chat_server::ChatServer, LemmyContext};