]> Untitled Git - lemmy.git/commitdiff
Move user to lemmy_db_schema, create traits for impls
authorFelix Ableitner <me@nutomic.com>
Fri, 18 Dec 2020 18:38:32 +0000 (19:38 +0100)
committerFelix Ableitner <me@nutomic.com>
Fri, 18 Dec 2020 18:38:32 +0000 (19:38 +0100)
74 files changed:
lemmy_api/src/claims.rs
lemmy_api/src/comment.rs
lemmy_api/src/community.rs
lemmy_api/src/lib.rs
lemmy_api/src/post.rs
lemmy_api/src/user.rs
lemmy_apub/src/activities/receive/comment.rs
lemmy_apub/src/activities/receive/comment_undo.rs
lemmy_apub/src/activities/receive/mod.rs
lemmy_apub/src/activities/receive/post.rs
lemmy_apub/src/activities/receive/post_undo.rs
lemmy_apub/src/activities/send/comment.rs
lemmy_apub/src/activities/send/post.rs
lemmy_apub/src/activities/send/private_message.rs
lemmy_apub/src/activities/send/user.rs
lemmy_apub/src/activity_queue.rs
lemmy_apub/src/fetcher.rs
lemmy_apub/src/http/community.rs
lemmy_apub/src/http/post.rs
lemmy_apub/src/http/user.rs
lemmy_apub/src/inbox/community_inbox.rs
lemmy_apub/src/inbox/mod.rs
lemmy_apub/src/inbox/user_inbox.rs
lemmy_apub/src/lib.rs
lemmy_apub/src/objects/comment.rs
lemmy_apub/src/objects/post.rs
lemmy_apub/src/objects/private_message.rs
lemmy_apub/src/objects/user.rs
lemmy_db/Cargo.toml
lemmy_db/src/aggregates/community_aggregates.rs
lemmy_db/src/aggregates/post_aggregates.rs
lemmy_db/src/aggregates/site_aggregates.rs
lemmy_db/src/aggregates/user_aggregates.rs
lemmy_db/src/source/activity.rs
lemmy_db/src/source/comment.rs
lemmy_db/src/source/community.rs
lemmy_db/src/source/moderator.rs
lemmy_db/src/source/password_reset_request.rs
lemmy_db/src/source/post.rs
lemmy_db/src/source/private_message.rs
lemmy_db/src/source/user.rs
lemmy_db/src/source/user_mention.rs
lemmy_db/src/views/comment_report_view.rs
lemmy_db/src/views/comment_view.rs
lemmy_db/src/views/community/community_follower_view.rs
lemmy_db/src/views/community/community_moderator_view.rs
lemmy_db/src/views/community/community_user_ban_view.rs
lemmy_db/src/views/community/community_view.rs
lemmy_db/src/views/moderator/mod_add_community_view.rs
lemmy_db/src/views/moderator/mod_add_view.rs
lemmy_db/src/views/moderator/mod_ban_from_community_view.rs
lemmy_db/src/views/moderator/mod_ban_view.rs
lemmy_db/src/views/moderator/mod_lock_post_view.rs
lemmy_db/src/views/moderator/mod_remove_comment_view.rs
lemmy_db/src/views/moderator/mod_remove_community_view.rs
lemmy_db/src/views/moderator/mod_remove_post_view.rs
lemmy_db/src/views/moderator/mod_sticky_post_view.rs
lemmy_db/src/views/post_report_view.rs
lemmy_db/src/views/post_view.rs
lemmy_db/src/views/private_message_view.rs
lemmy_db/src/views/site_view.rs
lemmy_db/src/views/user_mention_view.rs
lemmy_db/src/views/user_view.rs
lemmy_db_schema/src/lib.rs
lemmy_db_schema/src/source/comment.rs
lemmy_db_schema/src/source/mod.rs
lemmy_db_schema/src/source/post.rs
lemmy_db_schema/src/source/user.rs [new file with mode: 0644]
lemmy_structs/src/lib.rs
lemmy_structs/src/site.rs
src/code_migrations.rs
src/routes/feeds.rs
src/routes/webfinger.rs
tests/integration_test.rs

index 4a0ab12b81c93509b983af031df54c3354e74ed6..f99730bdd3e1f0292a6b9b0ff629b655b7d09534 100644 (file)
@@ -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};
 
index acff6004246ee0500321bb7ee2ec2b3b696e13c8..78c45c497ace1ffc47af31b27e77d66a87df85f9 100644 (file)
@@ -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::{
index 35aafc88ea741ac94c0d1491cd24f41aa18e2ac0..0316beaa3dbb90e8d17b8efbf9eb25c2b340c21e 100644 (file)
@@ -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::{
index 927846c0a45d74dc50d6d74888bf1e0160ce0279..e6c3b8253d8485fcae06c1cfb6d15467ffd6129f 100644 (file)
@@ -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};
index ee09059a5dedb63d31e42f52b57ee0268859aa56..9024541c57293f05b44169f28541ee0c8e705a2f 100644 (file)
@@ -12,6 +12,7 @@ use lemmy_apub::{ApubLikeableType, ApubObjectType};
 use lemmy_db::{
   source::{
     moderator::*,
+    post::Post_,
     post_report::{PostReport, PostReportForm},
   },
   views::{
index 680910b849af0364cdede3074a4cf458bfe7d20a..a6e1cbced0baa3f7a01461c2b07d28d2a91dfc44 100644 (file)
@@ -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::{
index 76337c4fddbaab2aaafd34ed176fef554c92ed49..0149e9313307adc7d3062be4b467bc73f0608e60 100644 (file)
@@ -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,
index f446b28604e646bb3312bf361e607cea64b9a033..7e67204578c03e66b751cfc4425f43a0bf3e8989 100644 (file)
@@ -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;
index a66ddfb950a2bb6ac2c1a8181c92e181058074a2..f52bbea1a310704b8a196746f99fdd10947407ab 100644 (file)
@@ -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;
index 4a3cc13f75614e563e68cb72c955db6f49bd5bab..8e20da75fb905084360b2db385df77e6d66e382a 100644 (file)
@@ -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};
index 817a74e4105746db3ba74a3f38a3f75051db97e6..facaf65f193730be0dead566430bd2c19bbfbdf3 100644 (file)
@@ -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;
index 358e5020a805d2502fc5d2f70cf832a0e50c9949..fa39fd472d019f5f770b962d5aff1c096a0ccfd0 100644 (file)
@@ -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},
index fd7f7c12ac90b1d3a027bf70fdbf340bcd38192c..c79f79ac5247ee16eeba371d23d8d5e98a8facf6 100644 (file)
@@ -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;
index 9abe70d663ec4d9955c86525b866f5ac8053bafb..4c8cb8748bc4d0011ace551d6e043f92ace2fc03 100644 (file)
@@ -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;
index 26c5a5d5611c23bd53976c05e96bed234f8675b6..8c01aff85bb03ce92ca9f9325ea4d4932a3b4663 100644 (file)
@@ -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;
index 07990457c0df92c8f19feadd6d3fe09f3d3d34f2..b32a3eb67797d022d3142f0408fa922f7822660e 100644 (file)
@@ -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};
index d06b221e25e3dedd7f22e371221b1589ef376de4..a4c5d66fce6bfb8276ed5a08d22c739dd33aaea5 100644 (file)
@@ -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::{
index a1a7870f02e610f0c8d1c46608178a1bad190686..0ab14e070a2ee25b9b23d72af416635915321471 100644 (file)
@@ -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;
index ad8464076e22eb70fc292c1618e660a3cb7603f5..8ade352960ca753525af8df68686a09c8c87f4be 100644 (file)
@@ -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;
index 8dcc8edabf7a889bd92176c21cb1046bcff13779..b01347e0d31f0e1f1297b6c32932434f62233b6d 100644 (file)
@@ -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;
index a2bed621cc9a41eb69fe7dbc03df1891f6da9a6a..9d5d4d1b7c5c86338b79e559b084cfce5a6803fe 100644 (file)
@@ -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;
index 415851883d8bc78a652cabf5d8d6eb2cbf413517..2d097772450ba36d73ba05e7174eda128c179c4a 100644 (file)
@@ -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;
index 374772d6d99986fc5883041d4dd2db6ab537f88c..d9feffd38bd9da2bada86252fdfbb8a5e531736e 100644 (file)
@@ -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;
index 78224c32ebd1ed867b970d6bcf176863ded76578..991e782edf324313458402e7d78e0fdde068d74b 100644 (file)
@@ -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;
index 9dd035c5d1f95ce77aa46954a8aa495c09297dd2..a753c8dbecbe96c0d5cd90840200c529250c6395 100644 (file)
@@ -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::{
index 7090cd163ef22573d7382ab0eaa8153dea14a2d9..ed5a5d9ca3b93212edca8b97b86f6caab211fd2b 100644 (file)
@@ -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,
index e69c28110d4dee60a8912cedf933733146cdbf2f..cf176dc69cf4a9f751fdc793fa6f10d566569b1c 100644 (file)
@@ -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;
index 6862867a5ee4ec9f94e308c28e1ba8cf8577d050..3ec1548d4a1b272d40a75ba948916fc88e89a88a 100644 (file)
@@ -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,
index 849dba8e72b1da8bc4f443bc51988fd942f7460f..0442d0145ebcf885f7a3cc6a38545b65ee6dd45e 100644 (file)
@@ -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"
index cb94e6325e56a75cbf4fbc94be3f75e342c2cef7..f452892dbac00cee610418b1b5148396634d1e81 100644 (file)
@@ -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]
index 0b9bfa5fa12badc7cab4829de51fa191f3e3e533..434e52fd9c014e9775138d4e8e53085091ec5d51 100644 (file)
@@ -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]
index ea58b216692a2cf236aa974bb2a68ba3e3dad01d..7fafc8effb55d5b4fff22666006fc5e1e41c20de 100644 (file)
@@ -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]
index 91fa7460d20b59f746bc83c89a8af8d0aea56bf9..61a1ae7cc586188e225b123d8c5495f6f4e4e2e3 100644 (file)
@@ -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]
index 38a353a4a367296e025a4134c4d39fb0637b7df7..ca85cf9fb612f439902cb31eabd0ff5759221c08 100644 (file)
@@ -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]
index 17e9d637a76391eef6fc1d04f780655712718c6e..010ca7da89ad224337a5f196e1860f6fe7e8123e 100644 (file)
 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<Comment, Error>;
+  fn permadelete_for_creator(
+    conn: &PgConnection,
+    for_creator_id: i32,
+  ) -> Result<Vec<Comment>, Error>;
+  fn update_deleted(
+    conn: &PgConnection,
+    comment_id: i32,
+    new_deleted: bool,
+  ) -> Result<Comment, Error>;
+  fn update_removed(
+    conn: &PgConnection,
+    comment_id: i32,
+    new_removed: bool,
+  ) -> Result<Comment, Error>;
+  fn update_removed_for_creator(
+    conn: &PgConnection,
+    for_creator_id: i32,
+    new_removed: bool,
+  ) -> Result<Vec<Comment>, Error>;
+  fn update_read(conn: &PgConnection, comment_id: i32, new_read: bool) -> Result<Comment, Error>;
+  fn update_content(
+    conn: &PgConnection,
+    comment_id: i32,
+    new_content: &str,
+  ) -> Result<Comment, Error>;
+}
+
+impl Comment_ for Comment {
+  fn update_ap_id(conn: &PgConnection, comment_id: i32, apub_id: String) -> Result<Self, Error> {
+    use lemmy_db_schema::schema::comment::dsl::*;
+
+    diesel::update(comment.find(comment_id))
+      .set(ap_id.eq(apub_id))
+      .get_result::<Self>(conn)
+  }
+
+  fn permadelete_for_creator(conn: &PgConnection, for_creator_id: i32) -> Result<Vec<Self>, 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::<Self>(conn)
+  }
+
+  fn update_deleted(
+    conn: &PgConnection,
+    comment_id: i32,
+    new_deleted: bool,
+  ) -> Result<Self, Error> {
+    use lemmy_db_schema::schema::comment::dsl::*;
+    diesel::update(comment.find(comment_id))
+      .set((deleted.eq(new_deleted), updated.eq(naive_now())))
+      .get_result::<Self>(conn)
+  }
+
+  fn update_removed(
+    conn: &PgConnection,
+    comment_id: i32,
+    new_removed: bool,
+  ) -> Result<Self, Error> {
+    use lemmy_db_schema::schema::comment::dsl::*;
+    diesel::update(comment.find(comment_id))
+      .set((removed.eq(new_removed), updated.eq(naive_now())))
+      .get_result::<Self>(conn)
+  }
+
+  fn update_removed_for_creator(
+    conn: &PgConnection,
+    for_creator_id: i32,
+    new_removed: bool,
+  ) -> Result<Vec<Self>, 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::<Self>(conn)
+  }
+
+  fn update_read(conn: &PgConnection, comment_id: i32, new_read: bool) -> Result<Self, Error> {
+    use lemmy_db_schema::schema::comment::dsl::*;
+    diesel::update(comment.find(comment_id))
+      .set(read.eq(new_read))
+      .get_result::<Self>(conn)
+  }
+
+  fn update_content(
+    conn: &PgConnection,
+    comment_id: i32,
+    new_content: &str,
+  ) -> Result<Self, Error> {
+    use lemmy_db_schema::schema::comment::dsl::*;
+    diesel::update(comment.find(comment_id))
+      .set((content.eq(new_content), updated.eq(naive_now())))
+      .get_result::<Self>(conn)
+  }
+}
+
 impl Crud<CommentForm> for Comment {
   fn read(conn: &PgConnection, comment_id: i32) -> Result<Self, Error> {
     use lemmy_db_schema::schema::comment::dsl::*;
@@ -101,7 +205,7 @@ impl Saveable<CommentSavedForm> 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() {
index 13045cca7e1579a1e5d41812ac09163fd1309a20..795ed1232268a46f3785fb12fa6eb13e737c4206 100644 (file)
@@ -421,12 +421,8 @@ impl Followable<CommunityFollowerForm> 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() {
index eb6c2d5667f54ee6a220865c5b66ca05b3821154..ddb1407dc6a8f9956f782f8d54ea3c97246164af 100644 (file)
@@ -391,12 +391,12 @@ impl Crud<ModAddForm> 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]
index 3c9969e41eaadb1dba6af3b085a2dcfc92db4e16..ae38f1c1c728b723a9968ec0a8083889bc5dc155 100644 (file)
@@ -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() {
index 5e8dc1cce2215c66031672273973cfa9d4f92df1..688ef39f3c1d74b2b721bdd74fb651ff1e998ecd 100644 (file)
@@ -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<PostForm> for Post {
@@ -35,6 +38,119 @@ impl Crud<PostForm> for Post {
   }
 }
 
+pub trait Post_ {
+  //fn read(conn: &PgConnection, post_id: i32) -> Result<Post, Error>;
+  fn list_for_community(conn: &PgConnection, the_community_id: i32) -> Result<Vec<Post>, Error>;
+  fn update_ap_id(conn: &PgConnection, post_id: i32, apub_id: String) -> Result<Post, Error>;
+  fn permadelete_for_creator(conn: &PgConnection, for_creator_id: i32) -> Result<Vec<Post>, Error>;
+  fn update_deleted(conn: &PgConnection, post_id: i32, new_deleted: bool) -> Result<Post, Error>;
+  fn update_removed(conn: &PgConnection, post_id: i32, new_removed: bool) -> Result<Post, Error>;
+  fn update_removed_for_creator(
+    conn: &PgConnection,
+    for_creator_id: i32,
+    for_community_id: Option<i32>,
+    new_removed: bool,
+  ) -> 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;
+}
+
+impl Post_ for Post {
+  // TODO: this is a duplicate?
+  //fn read(conn: &PgConnection, post_id: i32) -> Result<Self, Error> {
+  //  use lemmy_db_schema::schema::post::dsl::*;
+  //  post.filter(id.eq(post_id)).first::<Self>(conn)
+  //}
+
+  fn list_for_community(conn: &PgConnection, the_community_id: i32) -> Result<Vec<Self>, 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::<Self>(conn)
+  }
+
+  fn update_ap_id(conn: &PgConnection, post_id: i32, apub_id: String) -> Result<Self, Error> {
+    use lemmy_db_schema::schema::post::dsl::*;
+
+    diesel::update(post.find(post_id))
+      .set(ap_id.eq(apub_id))
+      .get_result::<Self>(conn)
+  }
+
+  fn permadelete_for_creator(conn: &PgConnection, for_creator_id: i32) -> Result<Vec<Self>, 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::<Self>(conn)
+  }
+
+  fn update_deleted(conn: &PgConnection, post_id: i32, new_deleted: bool) -> Result<Self, Error> {
+    use lemmy_db_schema::schema::post::dsl::*;
+    diesel::update(post.find(post_id))
+      .set((deleted.eq(new_deleted), updated.eq(naive_now())))
+      .get_result::<Self>(conn)
+  }
+
+  fn update_removed(conn: &PgConnection, post_id: i32, new_removed: bool) -> Result<Self, Error> {
+    use lemmy_db_schema::schema::post::dsl::*;
+    diesel::update(post.find(post_id))
+      .set((removed.eq(new_removed), updated.eq(naive_now())))
+      .get_result::<Self>(conn)
+  }
+
+  fn update_removed_for_creator(
+    conn: &PgConnection,
+    for_creator_id: i32,
+    for_community_id: Option<i32>,
+    new_removed: bool,
+  ) -> Result<Vec<Self>, 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::<Self>(conn)
+  }
+
+  fn update_locked(conn: &PgConnection, post_id: i32, new_locked: bool) -> Result<Self, Error> {
+    use lemmy_db_schema::schema::post::dsl::*;
+    diesel::update(post.find(post_id))
+      .set(locked.eq(new_locked))
+      .get_result::<Self>(conn)
+  }
+
+  fn update_stickied(conn: &PgConnection, post_id: i32, new_stickied: bool) -> Result<Self, Error> {
+    use lemmy_db_schema::schema::post::dsl::*;
+    diesel::update(post.find(post_id))
+      .set(stickied.eq(new_stickied))
+      .get_result::<Self>(conn)
+  }
+
+  fn is_post_creator(user_id: i32, post_creator_id: i32) -> bool {
+    user_id == post_creator_id
+  }
+}
+
 impl ApubObject<PostForm> for Post {
   fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error> {
     use lemmy_db_schema::schema::post::dsl::*;
@@ -116,11 +232,12 @@ impl Readable<PostReadForm> 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() {
index fd73a864687f57c4e75b7562e838e6a6718d4314..1177eaa9ac1113b10f45d80342b50d65d296899a 100644 (file)
@@ -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() {
index 6bca769e86ed2030076d18db49f30146a697273e..7461f4b45675d1b979d965e71c1876bc40e87b94 100644 (file)
@@ -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<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: String,
-  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,
-}
-
-/// 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: String,
-  pub bio: Option<String>,
-  pub local: bool,
-  pub banner: Option<String>,
-  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<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: String,
-  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: String,
-  pub bio: Option<String>,
-  pub local: bool,
-  pub banner: Option<String>,
-  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<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: String,
-  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: String,
-  pub bio: Option<String>,
-  pub local: bool,
-  pub banner: Option<String>,
-  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<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<String>,
-  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>>,
-}
-
 impl Crud<UserForm> for User_ {
   fn read(conn: &PgConnection, user_id: i32) -> Result<Self, Error> {
     user_
@@ -356,8 +179,26 @@ impl ApubObject<UserForm> for User_ {
   }
 }
 
-impl User_ {
-  pub fn register(conn: &PgConnection, form: &UserForm) -> Result<Self, Error> {
+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");
@@ -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<Self, Error> {
+  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))
@@ -382,7 +219,7 @@ impl User_ {
       .get_result::<Self>(conn)
   }
 
-  pub fn read_from_name(conn: &PgConnection, from_user_name: &str) -> Result<Self, Error> {
+  fn read_from_name(conn: &PgConnection, from_user_name: &str) -> Result<Self, Error> {
     user_
       .filter(local.eq(true))
       .filter(deleted.eq(false))
@@ -390,19 +227,19 @@ impl User_ {
       .first::<Self>(conn)
   }
 
-  pub fn add_admin(conn: &PgConnection, user_id: i32, added: bool) -> Result<Self, Error> {
+  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)
   }
 
-  pub fn ban_user(conn: &PgConnection, user_id: i32, ban: bool) -> Result<Self, Error> {
+  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)
   }
 
-  pub fn find_by_email_or_username(
+  fn find_by_email_or_username(
     conn: &PgConnection,
     username_or_email: &str,
   ) -> Result<Self, Error> {
@@ -413,7 +250,7 @@ impl User_ {
     }
   }
 
-  pub fn find_by_username(conn: &PgConnection, username: &str) -> Result<User_, Error> {
+  fn find_by_username(conn: &PgConnection, username: &str) -> Result<User_, Error> {
     user_
       .filter(deleted.eq(false))
       .filter(local.eq(true))
@@ -421,7 +258,7 @@ impl User_ {
       .first::<User_>(conn)
   }
 
-  pub fn find_by_email(conn: &PgConnection, from_email: &str) -> Result<User_, Error> {
+  fn find_by_email(conn: &PgConnection, from_email: &str) -> Result<User_, Error> {
     user_
       .filter(deleted.eq(false))
       .filter(local.eq(true))
@@ -429,7 +266,7 @@ impl User_ {
       .first::<User_>(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<User_, Error> {
+  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)
   }
 
-  pub fn delete_account(conn: &PgConnection, user_id: i32) -> Result<User_, Error> {
+  fn delete_account(conn: &PgConnection, user_id: i32) -> Result<User_, Error> {
     diesel::update(user_.find(user_id))
       .set((
         preferred_username.eq::<Option<String>>(None),
index 5df17286484b1f35ec87d411b040370b322e119e..64e24d32babd826c45c5d3aeea68cb59bc4b77d3 100644 (file)
@@ -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() {
index b067a9ec1512f1496869f4036b1affeb5aafe278..0bfd6fe8d476ea91ae2eb9fff975c7f4b69cd5c0 100644 (file)
@@ -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;
 
index d4680a3411b9b9a525942a08524c8ccd23c9ba39..3628b5838fd6e522b680c7066db7cd6a264358e7 100644 (file)
@@ -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() {
index 243b91420ef3dbd53b7c08f0dae381d7441f7cfd..144481ce152670982ca18cd4d8f0da08286e0fae 100644 (file)
@@ -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)]
index 8762b97500571b6210968fef988baa0af90e1498..ffd2f622987df92e3da68768316ecc557b2dacfb 100644 (file)
@@ -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)]
index 5dba4ebd305d387bc3071bc4391a6f577ca593c2..80ac78cc3441e2ac2d950df699aef42bfa73ef92 100644 (file)
@@ -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)]
index 6c951b33722bb13794e0b09778108906bda41b39..bd7119364d13bf36af096d3ec875fa3221a3fcb6 100644 (file)
@@ -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;
 
index 1dd7cfc471595c43a85d626e96d4a0000e043b0b..2e048322114570cd41be21835729c56c6bbf881f 100644 (file)
@@ -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)]
index 06648ad7685258aa84159ae10b5792e754c7a88b..c724e826c222c87c4fcd357e92bafebe30edc949 100644 (file)
@@ -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)]
index 3992518bc0258e6b5a946b47711b196cccd0e804..e31d6d19b2c44d4975170f6742333ce27415e059 100644 (file)
@@ -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)]
index 52e890259ea7eec98934ad823e9c966acb7eb8d3..2a3edb6c0f4b0ba8de5b31a0510e265c9a83aefe 100644 (file)
@@ -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)]
index 685d83bbcf4bd525ae3381bc8d7ecb62b3466795..9687e1b580e5ea849c71a1f567336e54fc82a421 100644 (file)
@@ -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;
 
index 0c6519de076710859369f4ea073913f3969ab410..70fb8cbdf048a4d47b8c57dd55bdef25f474a323 100644 (file)
@@ -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;
 
index 1700ac2d99bebe7ac509be02ddefb2a6bece330f..9e7fb6a4533bbadca5744253b41752f5fba47c99 100644 (file)
@@ -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)]
index 98aefd211e21084e59d021e60b0c6946dbacc47e..fe976c8ea8dbe1e2e59dab1302328a2019f8fc9e 100644 (file)
@@ -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;
 
index 40672f8b17c1b24461c4dedc6c7d6925e28b79bf..c51d083f09b476bb145a663c2693d1a10029ea6f 100644 (file)
@@ -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;
 
index 5e186239932108d5e0bab43284fda50cce82b538..9c42f7769d549254204a1fa78f74e1d3349d2f9b 100644 (file)
@@ -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;
 
index fb3fbbf3f679ec9f255c6d5507fb253bafd63a9a..e3bdd178fee80f419d4b5d40fc8e2ef7eaae04f2 100644 (file)
@@ -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() {
index 5d594b12e0383eca98f087a35279783d48f6e388..fa5319765670b5fca686f6ea103dbfadc88508c8 100644 (file)
@@ -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)]
index d956e2e1a9761dd467e187e2a6e287460a77f684..362c808de16fdfd761219bf66bbeca6b4ca9c7e4 100644 (file)
@@ -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)]
index 61fb56260bd62fac34dccba772742957f8b60968..61a788a40b4c3181a457947a36a87589499565a3 100644 (file)
@@ -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;
index 8f59691a67c3a03e9fb82b0cd760585450859ac2..f3109011e91a13d50c3f863da89b967c2ab65d92 100644 (file)
@@ -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)]
index 11451d173f2e2ca67bb17860699fd4e8f6beb79b..3868a3b753969265f9f2f4b36a76228a5b9282be 100644 (file)
@@ -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()
 }
index 3457764030606a8230a55d89e56422202b80591b..8c553a51a4812b35034d8e2dd68325212a4f5bca 100644 (file)
@@ -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<Self, Error> {
-    use crate::schema::comment::dsl::*;
-
-    diesel::update(comment.find(comment_id))
-      .set(ap_id.eq(apub_id))
-      .get_result::<Self>(conn)
-  }
-
-  pub fn permadelete_for_creator(
-    conn: &PgConnection,
-    for_creator_id: i32,
-  ) -> Result<Vec<Self>, 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::<Self>(conn)
-  }
-
-  pub fn update_deleted(
-    conn: &PgConnection,
-    comment_id: i32,
-    new_deleted: bool,
-  ) -> Result<Self, Error> {
-    use crate::schema::comment::dsl::*;
-    diesel::update(comment.find(comment_id))
-      .set((deleted.eq(new_deleted), updated.eq(naive_now())))
-      .get_result::<Self>(conn)
-  }
-
-  pub fn update_removed(
-    conn: &PgConnection,
-    comment_id: i32,
-    new_removed: bool,
-  ) -> Result<Self, Error> {
-    use crate::schema::comment::dsl::*;
-    diesel::update(comment.find(comment_id))
-      .set((removed.eq(new_removed), updated.eq(naive_now())))
-      .get_result::<Self>(conn)
-  }
-
-  pub fn update_removed_for_creator(
-    conn: &PgConnection,
-    for_creator_id: i32,
-    new_removed: bool,
-  ) -> Result<Vec<Self>, 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::<Self>(conn)
-  }
-
-  pub fn update_read(conn: &PgConnection, comment_id: i32, new_read: bool) -> Result<Self, Error> {
-    use crate::schema::comment::dsl::*;
-    diesel::update(comment.find(comment_id))
-      .set(read.eq(new_read))
-      .get_result::<Self>(conn)
-  }
-
-  pub fn update_content(
-    conn: &PgConnection,
-    comment_id: i32,
-    new_content: &str,
-  ) -> Result<Self, Error> {
-    use crate::schema::comment::dsl::*;
-    diesel::update(comment.find(comment_id))
-      .set((content.eq(new_content), updated.eq(naive_now())))
-      .get_result::<Self>(conn)
-  }
-}
-
 impl CommentForm {
   pub fn get_ap_id(&self) -> Result<Url, ParseError> {
     Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string()))
index 38203b5ebf3bdbf0bdf7b7059defcd91c4cddf90..2a5d7a699a4e27eed009f4984c12e37323138597 100644 (file)
@@ -1,2 +1,3 @@
 pub mod comment;
 pub mod post;
+pub mod user;
index a0b974e2de0e69536572ad97e60a0fb5b2392823..b0cc78e0e2d84381f9c74ef7af66377664a95823 100644 (file)
@@ -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<Self, Error> {
-    use crate::schema::post::dsl::*;
-    post.filter(id.eq(post_id)).first::<Self>(conn)
-  }
-
-  pub fn list_for_community(
-    conn: &PgConnection,
-    the_community_id: i32,
-  ) -> Result<Vec<Self>, 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::<Self>(conn)
-  }
-
-  pub fn update_ap_id(conn: &PgConnection, post_id: i32, apub_id: String) -> Result<Self, Error> {
-    use crate::schema::post::dsl::*;
-
-    diesel::update(post.find(post_id))
-      .set(ap_id.eq(apub_id))
-      .get_result::<Self>(conn)
-  }
-
-  pub fn permadelete_for_creator(
-    conn: &PgConnection,
-    for_creator_id: i32,
-  ) -> Result<Vec<Self>, 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::<Self>(conn)
-  }
-
-  pub fn update_deleted(
-    conn: &PgConnection,
-    post_id: i32,
-    new_deleted: bool,
-  ) -> Result<Self, Error> {
-    use crate::schema::post::dsl::*;
-    diesel::update(post.find(post_id))
-      .set((deleted.eq(new_deleted), updated.eq(naive_now())))
-      .get_result::<Self>(conn)
-  }
-
-  pub fn update_removed(
-    conn: &PgConnection,
-    post_id: i32,
-    new_removed: bool,
-  ) -> Result<Self, Error> {
-    use crate::schema::post::dsl::*;
-    diesel::update(post.find(post_id))
-      .set((removed.eq(new_removed), updated.eq(naive_now())))
-      .get_result::<Self>(conn)
-  }
-
-  pub fn update_removed_for_creator(
-    conn: &PgConnection,
-    for_creator_id: i32,
-    for_community_id: Option<i32>,
-    new_removed: bool,
-  ) -> Result<Vec<Self>, 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::<Self>(conn)
-  }
-
-  pub fn update_locked(conn: &PgConnection, post_id: i32, new_locked: bool) -> Result<Self, Error> {
-    use crate::schema::post::dsl::*;
-    diesel::update(post.find(post_id))
-      .set(locked.eq(new_locked))
-      .get_result::<Self>(conn)
-  }
-
-  pub fn update_stickied(
-    conn: &PgConnection,
-    post_id: i32,
-    new_stickied: bool,
-  ) -> Result<Self, Error> {
-    use crate::schema::post::dsl::*;
-    diesel::update(post.find(post_id))
-      .set(stickied.eq(new_stickied))
-      .get_result::<Self>(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, ParseError> {
     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 (file)
index 0000000..3d9d9e5
--- /dev/null
@@ -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<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: String,
+  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,
+}
+
+/// 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: String,
+  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_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: String,
+  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: String,
+  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: String,
+  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: String,
+  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<String>,
+  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>>,
+}
index 595f6d0741845d9c41dc58ef763d9f06272824de..7c3fc5c3605af37b17d2a4546dcbf6a797464a92 100644 (file)
@@ -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};
index 9209a54202cd2325e8c921800fd4d38c6dccee95..0d1542951750d07af8d8a66aeeb39c6b43008df5 100644 (file)
@@ -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)]
index c294be67c60ba9121823db606c174f2f43ff67c3..2afdfabda1c0e1849317caceb2b53b72f4b2302a 100644 (file)
@@ -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},
index 7a4801f403dd014f28a2b2606d39cdf4dfc4bdcb..8a3ecbae99cb21868c04a92bf2a995b3615899e6 100644 (file)
@@ -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;
index d59b4e38909aec88f2bb5605339e97d87db23c14..57c90c967371e670296025db1f9efb4f813cf007 100644 (file)
@@ -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,
index a61c8ff6e02f5e23a3ee93ebf5cbe8b3afe3edf9..5a191352a591bbfecbeb2217ff8860f6490408e9 100644 (file)
@@ -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};