mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-10-01 01:36:12 -04:00
Move user to lemmy_db_schema, create traits for impls
This commit is contained in:
parent
114f3cbfb5
commit
f842bbff8d
@ -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};
|
||||
|
||||
|
@ -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::{
|
||||
|
@ -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::{
|
||||
|
@ -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};
|
||||
|
@ -12,6 +12,7 @@ use lemmy_apub::{ApubLikeableType, ApubObjectType};
|
||||
use lemmy_db::{
|
||||
source::{
|
||||
moderator::*,
|
||||
post::Post_,
|
||||
post_report::{PostReport, PostReportForm},
|
||||
},
|
||||
views::{
|
||||
|
@ -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::{
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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};
|
||||
|
@ -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;
|
||||
|
@ -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},
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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};
|
||||
|
@ -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::{
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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::{
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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"
|
||||
|
@ -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]
|
||||
|
@ -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]
|
||||
|
@ -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]
|
||||
|
@ -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]
|
||||
|
@ -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]
|
||||
|
@ -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<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() {
|
||||
|
@ -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() {
|
||||
|
@ -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]
|
||||
|
@ -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() {
|
||||
|
@ -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() {
|
||||
|
@ -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() {
|
||||
|
@ -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),
|
||||
|
@ -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() {
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -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)]
|
||||
|
@ -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)]
|
||||
|
@ -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)]
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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)]
|
||||
|
@ -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)]
|
||||
|
@ -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)]
|
||||
|
@ -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)]
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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)]
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -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)]
|
||||
|
@ -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)]
|
||||
|
@ -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;
|
||||
|
@ -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)]
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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()))
|
||||
|
@ -1,2 +1,3 @@
|
||||
pub mod comment;
|
||||
pub mod post;
|
||||
pub mod user;
|
||||
|
@ -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()))
|
||||
|
182
lemmy_db_schema/src/source/user.rs
Normal file
182
lemmy_db_schema/src/source/user.rs
Normal file
@ -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>>,
|
||||
}
|
@ -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};
|
||||
|
@ -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)]
|
||||
|
@ -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},
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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};
|
||||
|
Loading…
Reference in New Issue
Block a user