Move user to lemmy_db_schema, create traits for impls

This commit is contained in:
Felix Ableitner 2020-12-18 19:38:32 +01:00
parent 114f3cbfb5
commit f842bbff8d
74 changed files with 651 additions and 624 deletions

View file

@ -1,5 +1,5 @@
use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, TokenData, Validation}; 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 lemmy_utils::settings::Settings;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View file

@ -11,9 +11,9 @@ use actix_web::web::Data;
use lemmy_apub::{ApubLikeableType, ApubObjectType}; use lemmy_apub::{ApubLikeableType, ApubObjectType};
use lemmy_db::{ use lemmy_db::{
source::{ source::{
comment::Comment_,
comment_report::{CommentReport, CommentReportForm}, comment_report::{CommentReport, CommentReportForm},
moderator::*, moderator::*,
user::*,
}, },
views::{ views::{
comment_report_view::{CommentReportQueryBuilder, CommentReportView}, comment_report_view::{CommentReportQueryBuilder, CommentReportView},
@ -30,6 +30,7 @@ use lemmy_db::{
use lemmy_db_schema::source::{ use lemmy_db_schema::source::{
comment::{Comment, CommentForm, CommentLike, CommentLikeForm, CommentSaved, CommentSavedForm}, comment::{Comment, CommentForm, CommentLike, CommentLikeForm, CommentSaved, CommentSavedForm},
post::Post, post::Post,
user::*,
}; };
use lemmy_structs::{blocking, comment::*, send_local_notifs}; use lemmy_structs::{blocking, comment::*, send_local_notifs};
use lemmy_utils::{ use lemmy_utils::{

View file

@ -11,7 +11,7 @@ use anyhow::Context;
use lemmy_apub::ActorType; use lemmy_apub::ActorType;
use lemmy_db::{ use lemmy_db::{
diesel_option_overwrite, diesel_option_overwrite,
source::{community::*, moderator::*, site::*}, source::{comment::Comment_, community::*, moderator::*, post::Post_, site::*},
views::{ views::{
comment_view::CommentQueryBuilder, comment_view::CommentQueryBuilder,
community::{ community::{

View file

@ -1,15 +1,12 @@
use crate::claims::Claims; use crate::claims::Claims;
use actix_web::{web, web::Data}; use actix_web::{web, web::Data};
use lemmy_db::{ use lemmy_db::{
source::{ source::community::{Community, CommunityModerator},
community::{Community, CommunityModerator},
user::User_,
},
views::community::community_user_ban_view::CommunityUserBanView, views::community::community_user_ban_view::CommunityUserBanView,
Crud, Crud,
DbPool, 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_structs::{blocking, comment::*, community::*, post::*, site::*, user::*};
use lemmy_utils::{settings::Settings, APIError, ConnectionId, LemmyError}; use lemmy_utils::{settings::Settings, APIError, ConnectionId, LemmyError};
use lemmy_websocket::{serialize_websocket_message, LemmyContext, UserOperation}; use lemmy_websocket::{serialize_websocket_message, LemmyContext, UserOperation};

View file

@ -12,6 +12,7 @@ use lemmy_apub::{ApubLikeableType, ApubObjectType};
use lemmy_db::{ use lemmy_db::{
source::{ source::{
moderator::*, moderator::*,
post::Post_,
post_report::{PostReport, PostReportForm}, post_report::{PostReport, PostReportForm},
}, },
views::{ views::{

View file

@ -17,12 +17,14 @@ use lemmy_apub::ApubObjectType;
use lemmy_db::{ use lemmy_db::{
diesel_option_overwrite, diesel_option_overwrite,
source::{ source::{
comment::Comment_,
community::*, community::*,
moderator::*, moderator::*,
password_reset_request::*, password_reset_request::*,
post::Post_,
private_message::*, private_message::*,
site::*, site::*,
user::*, user::User,
user_mention::*, user_mention::*,
}, },
views::{ views::{
@ -47,7 +49,7 @@ use lemmy_db::{
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
naive_now, naive_now,
source::{comment::Comment, post::Post}, source::{comment::Comment, post::Post, user::*},
}; };
use lemmy_structs::{blocking, send_email_to_user, user::*}; use lemmy_structs::{blocking, send_email_to_user, user::*};
use lemmy_utils::{ use lemmy_utils::{

View file

@ -4,7 +4,7 @@ use activitystreams::{
base::ExtendsExt, base::ExtendsExt,
}; };
use anyhow::Context; 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::{ use lemmy_db_schema::source::{
comment::{Comment, CommentLike, CommentLikeForm}, comment::{Comment, CommentLike, CommentLikeForm},
post::Post, post::Post,

View file

@ -1,6 +1,6 @@
use crate::activities::receive::get_actor_as_user; use crate::activities::receive::get_actor_as_user;
use activitystreams::activity::{Dislike, Like}; 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_db_schema::source::comment::{Comment, CommentLike};
use lemmy_structs::{blocking, comment::CommentResponse}; use lemmy_structs::{blocking, comment::CommentResponse};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;

View file

@ -5,7 +5,7 @@ use activitystreams::{
error::DomainError, error::DomainError,
}; };
use anyhow::{anyhow, Context}; 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_utils::{location_info, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use log::debug; use log::debug;

View file

@ -4,7 +4,7 @@ use activitystreams::{
prelude::*, prelude::*,
}; };
use anyhow::Context; 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_db_schema::source::post::{Post, PostLike, PostLikeForm};
use lemmy_structs::{blocking, post::PostResponse}; use lemmy_structs::{blocking, post::PostResponse};
use lemmy_utils::{location_info, LemmyError}; use lemmy_utils::{location_info, LemmyError};

View file

@ -1,6 +1,6 @@
use crate::activities::receive::get_actor_as_user; use crate::activities::receive::get_actor_as_user;
use activitystreams::activity::{Dislike, Like}; 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_db_schema::source::post::{Post, PostLike};
use lemmy_structs::{blocking, post::PostResponse}; use lemmy_structs::{blocking, post::PostResponse};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;

View file

@ -26,12 +26,8 @@ use activitystreams::{
}; };
use anyhow::anyhow; use anyhow::anyhow;
use itertools::Itertools; use itertools::Itertools;
use lemmy_db::{ use lemmy_db::{source::community::Community, Crud, DbPool};
source::{community::Community, user::User_}, use lemmy_db_schema::source::{comment::Comment, post::Post, user::User_};
Crud,
DbPool,
};
use lemmy_db_schema::source::{comment::Comment, post::Post};
use lemmy_structs::{blocking, WebFingerResponse}; use lemmy_structs::{blocking, WebFingerResponse};
use lemmy_utils::{ use lemmy_utils::{
request::{retry, RecvError}, request::{retry, RecvError},

View file

@ -21,11 +21,8 @@ use activitystreams::{
prelude::*, prelude::*,
public, public,
}; };
use lemmy_db::{ use lemmy_db::{source::community::Community, Crud};
source::{community::Community, user::User_}, use lemmy_db_schema::source::{post::Post, user::User_};
Crud,
};
use lemmy_db_schema::source::post::Post;
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;

View file

@ -16,10 +16,8 @@ use activitystreams::{
}, },
prelude::*, prelude::*,
}; };
use lemmy_db::{ use lemmy_db::{source::private_message::PrivateMessage, Crud};
source::{private_message::PrivateMessage, user::User_}, use lemmy_db_schema::source::user::User_;
Crud,
};
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;

View file

@ -14,14 +14,12 @@ use activitystreams::{
object::ObjectExt, object::ObjectExt,
}; };
use lemmy_db::{ use lemmy_db::{
source::{ source::community::{Community, CommunityFollower, CommunityFollowerForm},
community::{Community, CommunityFollower, CommunityFollowerForm},
user::User_,
},
ApubObject, ApubObject,
DbPool, DbPool,
Followable, Followable,
}; };
use lemmy_db_schema::source::user::User_;
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;

View file

@ -19,10 +19,8 @@ use background_jobs::{
WorkerConfig, WorkerConfig,
}; };
use itertools::Itertools; use itertools::Itertools;
use lemmy_db::{ use lemmy_db::{source::community::Community, DbPool};
source::{community::Community, user::User_}, use lemmy_db_schema::source::user::User_;
DbPool,
};
use lemmy_utils::{location_info, settings::Settings, LemmyError}; use lemmy_utils::{location_info, settings::Settings, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;
use log::{debug, warn}; use log::{debug, warn};

View file

@ -15,7 +15,7 @@ use diesel::result::Error::NotFound;
use lemmy_db::{ use lemmy_db::{
source::{ source::{
community::{Community, CommunityModerator, CommunityModeratorForm}, community::{Community, CommunityModerator, CommunityModeratorForm},
user::User_, user::User,
}, },
views::{ views::{
comment_view::CommentView, comment_view::CommentView,
@ -24,12 +24,13 @@ use lemmy_db::{
user_view::UserViewSafe, user_view::UserViewSafe,
}, },
ApubObject, ApubObject,
Crud,
Joinable, Joinable,
SearchType, SearchType,
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
naive_now, naive_now,
source::{comment::Comment, post::Post}, source::{comment::Comment, post::Post, user::User_},
}; };
use lemmy_structs::{blocking, site::SearchResponse}; use lemmy_structs::{blocking, site::SearchResponse};
use lemmy_utils::{ use lemmy_utils::{

View file

@ -10,7 +10,7 @@ use activitystreams::{
}; };
use actix_web::{body::Body, web, HttpResponse}; use actix_web::{body::Body, web, HttpResponse};
use lemmy_db::{ use lemmy_db::{
source::community::Community, source::{community::Community, post::Post_},
views::community::community_follower_view::CommunityFollowerView, views::community::community_follower_view::CommunityFollowerView,
}; };
use lemmy_db_schema::source::post::Post; use lemmy_db_schema::source::post::Post;

View file

@ -4,6 +4,7 @@ use crate::{
}; };
use actix_web::{body::Body, web, HttpResponse}; use actix_web::{body::Body, web, HttpResponse};
use diesel::result::Error::NotFound; use diesel::result::Error::NotFound;
use lemmy_db::Crud;
use lemmy_db_schema::source::post::Post; use lemmy_db_schema::source::post::Post;
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;

View file

@ -9,7 +9,8 @@ use activitystreams::{
collection::{CollectionExt, OrderedCollection}, collection::{CollectionExt, OrderedCollection},
}; };
use actix_web::{body::Body, web, HttpResponse}; 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_structs::blocking;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;

View file

@ -27,15 +27,13 @@ use activitystreams::{
use actix_web::{web, HttpRequest, HttpResponse}; use actix_web::{web, HttpRequest, HttpResponse};
use anyhow::{anyhow, Context}; use anyhow::{anyhow, Context};
use lemmy_db::{ use lemmy_db::{
source::{ source::community::{Community, CommunityFollower, CommunityFollowerForm},
community::{Community, CommunityFollower, CommunityFollowerForm},
user::User_,
},
views::community::community_user_ban_view::CommunityUserBanView, views::community::community_user_ban_view::CommunityUserBanView,
ApubObject, ApubObject,
DbPool, DbPool,
Followable, Followable,
}; };
use lemmy_db_schema::source::user::User_;
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::{location_info, LemmyError}; use lemmy_utils::{location_info, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;

View file

@ -13,10 +13,11 @@ use activitystreams::{
use actix_web::HttpRequest; use actix_web::HttpRequest;
use anyhow::{anyhow, Context}; use anyhow::{anyhow, Context};
use lemmy_db::{ use lemmy_db::{
source::{activity::Activity, community::Community, user::User_}, source::{activity::Activity, community::Community},
ApubObject, ApubObject,
DbPool, DbPool,
}; };
use lemmy_db_schema::source::user::User_;
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::{location_info, settings::Settings, LemmyError}; use lemmy_utils::{location_info, settings::Settings, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;

View file

@ -52,11 +52,12 @@ use lemmy_db::{
source::{ source::{
community::{Community, CommunityFollower}, community::{Community, CommunityFollower},
private_message::PrivateMessage, private_message::PrivateMessage,
user::User_, user::User,
}, },
ApubObject, ApubObject,
Followable, Followable,
}; };
use lemmy_db_schema::source::user::User_;
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::{location_info, LemmyError}; use lemmy_utils::{location_info, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;

View file

@ -22,10 +22,8 @@ use activitystreams::{
}; };
use activitystreams_ext::{Ext1, Ext2}; use activitystreams_ext::{Ext1, Ext2};
use anyhow::{anyhow, Context}; use anyhow::{anyhow, Context};
use lemmy_db::{ use lemmy_db::{source::activity::Activity, DbPool};
source::{activity::Activity, user::User_}, use lemmy_db_schema::source::user::User_;
DbPool,
};
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::{location_info, settings::Settings, LemmyError}; use lemmy_utils::{location_info, settings::Settings, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;

View file

@ -23,14 +23,11 @@ use activitystreams::{
prelude::*, prelude::*,
}; };
use anyhow::{anyhow, Context}; use anyhow::{anyhow, Context};
use lemmy_db::{ use lemmy_db::{source::community::Community, Crud, DbPool};
source::{community::Community, user::User_},
Crud,
DbPool,
};
use lemmy_db_schema::source::{ use lemmy_db_schema::source::{
comment::{Comment, CommentForm}, comment::{Comment, CommentForm},
post::Post, post::Post,
user::User_,
}; };
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::{ use lemmy_utils::{

View file

@ -20,12 +20,11 @@ use activitystreams::{
}; };
use activitystreams_ext::Ext1; use activitystreams_ext::Ext1;
use anyhow::Context; use anyhow::Context;
use lemmy_db::{ use lemmy_db::{source::community::Community, Crud, DbPool};
source::{community::Community, user::User_}, use lemmy_db_schema::source::{
Crud, post::{Post, PostForm},
DbPool, user::User_,
}; };
use lemmy_db_schema::source::post::{Post, PostForm};
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::{ use lemmy_utils::{
location_info, location_info,

View file

@ -20,13 +20,11 @@ use activitystreams::{
}; };
use anyhow::Context; use anyhow::Context;
use lemmy_db::{ use lemmy_db::{
source::{ source::private_message::{PrivateMessage, PrivateMessageForm},
private_message::{PrivateMessage, PrivateMessageForm},
user::User_,
},
Crud, Crud,
DbPool, DbPool,
}; };
use lemmy_db_schema::source::user::User_;
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::{location_info, utils::convert_datetime, LemmyError}; use lemmy_utils::{location_info, utils::convert_datetime, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;

View file

@ -18,12 +18,11 @@ use activitystreams::{
}; };
use activitystreams_ext::Ext1; use activitystreams_ext::Ext1;
use anyhow::Context; use anyhow::Context;
use lemmy_db::{ use lemmy_db::{ApubObject, DbPool};
use lemmy_db_schema::{
naive_now,
source::user::{UserForm, User_}, source::user::{UserForm, User_},
ApubObject,
DbPool,
}; };
use lemmy_db_schema::naive_now;
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::{ use lemmy_utils::{
location_info, location_info,

View file

@ -18,7 +18,7 @@ strum = "0.20.0"
strum_macros = "0.20.1" strum_macros = "0.20.1"
log = "0.4.11" log = "0.4.11"
sha2 = "0.9.2" sha2 = "0.9.2"
bcrypt = "0.9.0"
url = { version = "2.2.0", features = ["serde"] } url = { version = "2.2.0", features = ["serde"] }
lazy_static = "1.4.0" lazy_static = "1.4.0"
regex = "1.4.2" regex = "1.4.2"
bcrypt = "0.9.0"

View file

@ -24,10 +24,7 @@ impl CommunityAggregates {
mod tests { mod tests {
use crate::{ use crate::{
aggregates::community_aggregates::CommunityAggregates, aggregates::community_aggregates::CommunityAggregates,
source::{ source::community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm},
community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm},
user::{UserForm, User_},
},
tests::establish_unpooled_connection, tests::establish_unpooled_connection,
Crud, Crud,
Followable, Followable,
@ -37,6 +34,7 @@ mod tests {
use lemmy_db_schema::source::{ use lemmy_db_schema::source::{
comment::{Comment, CommentForm}, comment::{Comment, CommentForm},
post::{Post, PostForm}, post::{Post, PostForm},
user::{UserForm, User_},
}; };
#[test] #[test]

View file

@ -26,10 +26,7 @@ impl PostAggregates {
mod tests { mod tests {
use crate::{ use crate::{
aggregates::post_aggregates::PostAggregates, aggregates::post_aggregates::PostAggregates,
source::{ source::community::{Community, CommunityForm},
community::{Community, CommunityForm},
user::{UserForm, User_},
},
tests::establish_unpooled_connection, tests::establish_unpooled_connection,
Crud, Crud,
Likeable, Likeable,
@ -39,6 +36,7 @@ mod tests {
use lemmy_db_schema::source::{ use lemmy_db_schema::source::{
comment::{Comment, CommentForm}, comment::{Comment, CommentForm},
post::{Post, PostForm, PostLike, PostLikeForm}, post::{Post, PostForm, PostLike, PostLikeForm},
user::{UserForm, User_},
}; };
#[test] #[test]

View file

@ -22,10 +22,7 @@ impl SiteAggregates {
mod tests { mod tests {
use crate::{ use crate::{
aggregates::site_aggregates::SiteAggregates, aggregates::site_aggregates::SiteAggregates,
source::{ source::community::{Community, CommunityForm},
community::{Community, CommunityForm},
user::{UserForm, User_},
},
tests::establish_unpooled_connection, tests::establish_unpooled_connection,
Crud, Crud,
ListingType, ListingType,
@ -34,6 +31,7 @@ mod tests {
use lemmy_db_schema::source::{ use lemmy_db_schema::source::{
comment::{Comment, CommentForm}, comment::{Comment, CommentForm},
post::{Post, PostForm}, post::{Post, PostForm},
user::{UserForm, User_},
}; };
#[test] #[test]

View file

@ -25,10 +25,7 @@ impl UserAggregates {
mod tests { mod tests {
use crate::{ use crate::{
aggregates::user_aggregates::UserAggregates, aggregates::user_aggregates::UserAggregates,
source::{ source::community::{Community, CommunityForm},
community::{Community, CommunityForm},
user::{UserForm, User_},
},
tests::establish_unpooled_connection, tests::establish_unpooled_connection,
Crud, Crud,
Likeable, Likeable,
@ -38,6 +35,7 @@ mod tests {
use lemmy_db_schema::source::{ use lemmy_db_schema::source::{
comment::{Comment, CommentForm, CommentLike, CommentLikeForm}, comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
post::{Post, PostForm, PostLike, PostLikeForm}, post::{Post, PostForm, PostLike, PostLikeForm},
user::{UserForm, User_},
}; };
#[test] #[test]

View file

@ -98,15 +98,13 @@ impl Activity {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{ use crate::{
source::{ source::activity::{Activity, ActivityForm},
activity::{Activity, ActivityForm},
user::{UserForm, User_},
},
tests::establish_unpooled_connection, tests::establish_unpooled_connection,
Crud, Crud,
ListingType, ListingType,
SortType, SortType,
}; };
use lemmy_db_schema::source::user::{UserForm, User_};
use serde_json::Value; use serde_json::Value;
#[test] #[test]

View file

@ -1,14 +1,118 @@
use crate::{ApubObject, Crud, Likeable, Saveable}; use crate::{ApubObject, Crud, Likeable, Saveable};
use diesel::{dsl::*, result::Error, *}; use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::source::comment::{ use lemmy_db_schema::{
Comment, naive_now,
CommentForm, source::comment::{
CommentLike, Comment,
CommentLikeForm, CommentForm,
CommentSaved, CommentLike,
CommentSavedForm, 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 { impl Crud<CommentForm> for Comment {
fn read(conn: &PgConnection, comment_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, comment_id: i32) -> Result<Self, Error> {
use lemmy_db_schema::schema::comment::dsl::*; use lemmy_db_schema::schema::comment::dsl::*;
@ -101,7 +205,7 @@ impl Saveable<CommentSavedForm> for CommentSaved {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{ use crate::{
source::{community::*, user::*}, source::community::*,
tests::establish_unpooled_connection, tests::establish_unpooled_connection,
Crud, Crud,
Likeable, Likeable,
@ -109,7 +213,11 @@ mod tests {
Saveable, Saveable,
SortType, SortType,
}; };
use lemmy_db_schema::source::{comment::*, post::*}; use lemmy_db_schema::source::{
comment::*,
post::*,
user::{UserForm, User_},
};
#[test] #[test]
fn test_crud() { fn test_crud() {

View file

@ -421,12 +421,8 @@ impl Followable<CommunityFollowerForm> for CommunityFollower {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{ use crate::{source::community::*, tests::establish_unpooled_connection, ListingType, SortType};
source::{community::*, user::*}, use lemmy_db_schema::source::user::*;
tests::establish_unpooled_connection,
ListingType,
SortType,
};
#[test] #[test]
fn test_crud() { fn test_crud() {

View file

@ -391,12 +391,12 @@ impl Crud<ModAddForm> for ModAdd {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{ use crate::{
source::{community::*, moderator::*, user::*}, source::{community::*, moderator::*},
tests::establish_unpooled_connection, tests::establish_unpooled_connection,
ListingType, ListingType,
SortType, SortType,
}; };
use lemmy_db_schema::source::{comment::*, post::*}; use lemmy_db_schema::source::{comment::*, post::*, user::*};
// use Crud; // use Crud;
#[test] #[test]

View file

@ -75,7 +75,6 @@ impl PasswordResetRequest {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::super::user::*;
use crate::{ use crate::{
source::password_reset_request::PasswordResetRequest, source::password_reset_request::PasswordResetRequest,
tests::establish_unpooled_connection, tests::establish_unpooled_connection,
@ -83,6 +82,7 @@ mod tests {
ListingType, ListingType,
SortType, SortType,
}; };
use lemmy_db_schema::source::user::*;
#[test] #[test]
fn test_crud() { fn test_crud() {

View file

@ -1,14 +1,17 @@
use crate::{ApubObject, Crud, Likeable, Readable, Saveable}; use crate::{ApubObject, Crud, Likeable, Readable, Saveable};
use diesel::{dsl::*, result::Error, *}; use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::source::post::{ use lemmy_db_schema::{
Post, naive_now,
PostForm, source::post::{
PostLike, Post,
PostLikeForm, PostForm,
PostRead, PostLike,
PostReadForm, PostLikeForm,
PostSaved, PostRead,
PostSavedForm, PostReadForm,
PostSaved,
PostSavedForm,
},
}; };
impl Crud<PostForm> for Post { 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 { impl ApubObject<PostForm> for Post {
fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error> { fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error> {
use lemmy_db_schema::schema::post::dsl::*; use lemmy_db_schema::schema::post::dsl::*;
@ -116,11 +232,12 @@ impl Readable<PostReadForm> for PostRead {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{ use crate::{
source::{community::*, post::*, user::*}, source::{community::*, post::*},
tests::establish_unpooled_connection, tests::establish_unpooled_connection,
ListingType, ListingType,
SortType, SortType,
}; };
use lemmy_db_schema::source::user::*;
#[test] #[test]
fn test_crud() { fn test_crud() {

View file

@ -140,11 +140,12 @@ impl PrivateMessage {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{ use crate::{
source::{private_message::*, user::*}, source::private_message::*,
tests::establish_unpooled_connection, tests::establish_unpooled_connection,
ListingType, ListingType,
SortType, SortType,
}; };
use lemmy_db_schema::source::user::*;
#[test] #[test]
fn test_crud() { fn test_crud() {

View file

@ -3,65 +3,15 @@ use bcrypt::{hash, DEFAULT_COST};
use diesel::{dsl::*, result::Error, *}; use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::{ use lemmy_db_schema::{
naive_now, 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 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 { mod safe_type {
use crate::{source::user::User_, ToSafe}; use crate::ToSafe;
use lemmy_db_schema::schema::user_::columns::*; use lemmy_db_schema::{schema::user_::columns::*, source::user::User_};
type Columns = ( type Columns = (
id, id,
name, 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 { mod safe_type_alias_1 {
use crate::{source::user::UserAlias1, ToSafe}; use crate::ToSafe;
use lemmy_db_schema::schema::user_alias_1::columns::*; use lemmy_db_schema::{schema::user_alias_1::columns::*, source::user::UserAlias1};
type Columns = ( type Columns = (
id, id,
name, 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 { mod safe_type_alias_2 {
use crate::{source::user::UserAlias2, ToSafe}; use crate::ToSafe;
use lemmy_db_schema::schema::user_alias_2::columns::*; use lemmy_db_schema::{schema::user_alias_2::columns::*, source::user::UserAlias2};
type Columns = ( type Columns = (
id, id,
name, 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_ { impl Crud<UserForm> for User_ {
fn read(conn: &PgConnection, user_id: i32) -> Result<Self, Error> { fn read(conn: &PgConnection, user_id: i32) -> Result<Self, Error> {
user_ user_
@ -356,8 +179,26 @@ impl ApubObject<UserForm> for User_ {
} }
} }
impl User_ { pub trait User {
pub fn register(conn: &PgConnection, form: &UserForm) -> Result<Self, Error> { 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 mut edited_user = form.clone();
let password_hash = let password_hash =
hash(&form.password_encrypted, DEFAULT_COST).expect("Couldn't hash password"); hash(&form.password_encrypted, DEFAULT_COST).expect("Couldn't hash password");
@ -367,11 +208,7 @@ impl User_ {
} }
// TODO do more individual updates like these // TODO do more individual updates like these
pub fn update_password( fn update_password(conn: &PgConnection, user_id: i32, new_password: &str) -> Result<Self, Error> {
conn: &PgConnection,
user_id: i32,
new_password: &str,
) -> Result<Self, Error> {
let password_hash = hash(new_password, DEFAULT_COST).expect("Couldn't hash password"); let password_hash = hash(new_password, DEFAULT_COST).expect("Couldn't hash password");
diesel::update(user_.find(user_id)) diesel::update(user_.find(user_id))
@ -382,7 +219,7 @@ impl User_ {
.get_result::<Self>(conn) .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_ user_
.filter(local.eq(true)) .filter(local.eq(true))
.filter(deleted.eq(false)) .filter(deleted.eq(false))
@ -390,19 +227,19 @@ impl User_ {
.first::<Self>(conn) .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)) diesel::update(user_.find(user_id))
.set(admin.eq(added)) .set(admin.eq(added))
.get_result::<Self>(conn) .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)) diesel::update(user_.find(user_id))
.set(banned.eq(ban)) .set(banned.eq(ban))
.get_result::<Self>(conn) .get_result::<Self>(conn)
} }
pub fn find_by_email_or_username( fn find_by_email_or_username(
conn: &PgConnection, conn: &PgConnection,
username_or_email: &str, username_or_email: &str,
) -> Result<Self, Error> { ) -> 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_ user_
.filter(deleted.eq(false)) .filter(deleted.eq(false))
.filter(local.eq(true)) .filter(local.eq(true))
@ -421,7 +258,7 @@ impl User_ {
.first::<User_>(conn) .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_ user_
.filter(deleted.eq(false)) .filter(deleted.eq(false))
.filter(local.eq(true)) .filter(local.eq(true))
@ -429,7 +266,7 @@ impl User_ {
.first::<User_>(conn) .first::<User_>(conn)
} }
pub fn get_profile_url(&self, hostname: &str) -> String { fn get_profile_url(&self, hostname: &str) -> String {
format!( format!(
"{}://{}/u/{}", "{}://{}/u/{}",
Settings::get().get_protocol_string(), 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)) diesel::update(user_.find(user_id))
.set((last_refreshed_at.eq(naive_now()),)) .set((last_refreshed_at.eq(naive_now()),))
.get_result::<Self>(conn) .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)) diesel::update(user_.find(user_id))
.set(( .set((
preferred_username.eq::<Option<String>>(None), preferred_username.eq::<Option<String>>(None),

View file

@ -79,12 +79,12 @@ impl UserMention {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{ use crate::{
source::{community::*, user::*, user_mention::*}, source::{community::*, user_mention::*},
tests::establish_unpooled_connection, tests::establish_unpooled_connection,
ListingType, ListingType,
SortType, SortType,
}; };
use lemmy_db_schema::source::{comment::*, post::*}; use lemmy_db_schema::source::{comment::*, post::*, user::*};
#[test] #[test]
fn test_crud() { fn test_crud() {

View file

@ -3,7 +3,6 @@ use crate::{
source::{ source::{
comment_report::CommentReport, comment_report::CommentReport,
community::{Community, CommunitySafe}, community::{Community, CommunitySafe},
user::{UserAlias1, UserAlias2, UserSafe, UserSafeAlias1, UserSafeAlias2, User_},
}, },
views::ViewToVec, views::ViewToVec,
MaybeOptional, MaybeOptional,
@ -12,7 +11,11 @@ use crate::{
use diesel::{result::Error, *}; use diesel::{result::Error, *};
use lemmy_db_schema::{ use lemmy_db_schema::{
schema::{comment, comment_report, community, post, user_, user_alias_1, user_alias_2}, 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; use serde::Serialize;

View file

@ -3,10 +3,7 @@ use crate::{
functions::hot_rank, functions::hot_rank,
fuzzy_search, fuzzy_search,
limit_and_offset, limit_and_offset,
source::{ source::community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
views::ViewToVec, views::ViewToVec,
ListingType, ListingType,
MaybeOptional, MaybeOptional,
@ -31,6 +28,7 @@ use lemmy_db_schema::{
source::{ source::{
comment::{Comment, CommentAlias1, CommentSaved}, comment::{Comment, CommentAlias1, CommentSaved},
post::Post, post::Post,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
}, },
}; };
use serde::Serialize; use serde::Serialize;
@ -412,14 +410,14 @@ impl ViewToVec for CommentView {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{ use crate::{
source::{community::*, user::*}, source::community::*,
tests::establish_unpooled_connection, tests::establish_unpooled_connection,
views::comment_view::*, views::comment_view::*,
Crud, Crud,
Likeable, Likeable,
*, *,
}; };
use lemmy_db_schema::source::{comment::*, post::*}; use lemmy_db_schema::source::{comment::*, post::*, user::*};
#[test] #[test]
fn test_crud() { fn test_crud() {

View file

@ -1,13 +1,13 @@
use crate::{ use crate::{
source::{ source::community::{Community, CommunitySafe},
community::{Community, CommunitySafe},
user::{UserSafe, User_},
},
views::ViewToVec, views::ViewToVec,
ToSafe, ToSafe,
}; };
use diesel::{result::Error, *}; 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; use serde::Serialize;
#[derive(Debug, Serialize, Clone)] #[derive(Debug, Serialize, Clone)]

View file

@ -1,13 +1,13 @@
use crate::{ use crate::{
source::{ source::community::{Community, CommunitySafe},
community::{Community, CommunitySafe},
user::{UserSafe, User_},
},
views::ViewToVec, views::ViewToVec,
ToSafe, ToSafe,
}; };
use diesel::{result::Error, *}; 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; use serde::Serialize;
#[derive(Debug, Serialize, Clone)] #[derive(Debug, Serialize, Clone)]

View file

@ -1,12 +1,12 @@
use crate::{ use crate::{
source::{ source::community::{Community, CommunitySafe},
community::{Community, CommunitySafe},
user::{UserSafe, User_},
},
ToSafe, ToSafe,
}; };
use diesel::{result::Error, *}; 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; use serde::Serialize;
#[derive(Debug, Serialize, Clone)] #[derive(Debug, Serialize, Clone)]

View file

@ -6,7 +6,6 @@ use crate::{
source::{ source::{
category::Category, category::Category,
community::{Community, CommunityFollower, CommunitySafe}, community::{Community, CommunityFollower, CommunitySafe},
user::{UserSafe, User_},
}, },
views::ViewToVec, views::ViewToVec,
MaybeOptional, MaybeOptional,
@ -14,12 +13,9 @@ use crate::{
ToSafe, ToSafe,
}; };
use diesel::{result::Error, *}; use diesel::{result::Error, *};
use lemmy_db_schema::schema::{ use lemmy_db_schema::{
category, schema::{category, community, community_aggregates, community_follower, user_},
community, source::user::{UserSafe, User_},
community_aggregates,
community_follower,
user_,
}; };
use serde::Serialize; use serde::Serialize;

View file

@ -3,13 +3,15 @@ use crate::{
source::{ source::{
community::{Community, CommunitySafe}, community::{Community, CommunitySafe},
moderator::ModAddCommunity, moderator::ModAddCommunity,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
}, },
views::ViewToVec, views::ViewToVec,
ToSafe, ToSafe,
}; };
use diesel::{result::Error, *}; 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; use serde::Serialize;
#[derive(Debug, Serialize, Clone)] #[derive(Debug, Serialize, Clone)]

View file

@ -1,14 +1,9 @@
use crate::{ use crate::{limit_and_offset, source::moderator::ModAdd, views::ViewToVec, ToSafe};
limit_and_offset,
source::{
moderator::ModAdd,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
views::ViewToVec,
ToSafe,
};
use diesel::{result::Error, *}; 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; use serde::Serialize;
#[derive(Debug, Serialize, Clone)] #[derive(Debug, Serialize, Clone)]

View file

@ -3,13 +3,15 @@ use crate::{
source::{ source::{
community::{Community, CommunitySafe}, community::{Community, CommunitySafe},
moderator::ModBanFromCommunity, moderator::ModBanFromCommunity,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
}, },
views::ViewToVec, views::ViewToVec,
ToSafe, ToSafe,
}; };
use diesel::{result::Error, *}; 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; use serde::Serialize;
#[derive(Debug, Serialize, Clone)] #[derive(Debug, Serialize, Clone)]

View file

@ -1,14 +1,9 @@
use crate::{ use crate::{limit_and_offset, source::moderator::ModBan, views::ViewToVec, ToSafe};
limit_and_offset,
source::{
moderator::ModBan,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
views::ViewToVec,
ToSafe,
};
use diesel::{result::Error, *}; 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; use serde::Serialize;
#[derive(Debug, Serialize, Clone)] #[derive(Debug, Serialize, Clone)]

View file

@ -3,7 +3,6 @@ use crate::{
source::{ source::{
community::{Community, CommunitySafe}, community::{Community, CommunitySafe},
moderator::ModLockPost, moderator::ModLockPost,
user::{UserSafe, User_},
}, },
views::ViewToVec, views::ViewToVec,
ToSafe, ToSafe,
@ -11,7 +10,10 @@ use crate::{
use diesel::{result::Error, *}; use diesel::{result::Error, *};
use lemmy_db_schema::{ use lemmy_db_schema::{
schema::{community, mod_lock_post, post, user_}, schema::{community, mod_lock_post, post, user_},
source::post::Post, source::{
post::Post,
user::{UserSafe, User_},
},
}; };
use serde::Serialize; use serde::Serialize;

View file

@ -3,7 +3,6 @@ use crate::{
source::{ source::{
community::{Community, CommunitySafe}, community::{Community, CommunitySafe},
moderator::ModRemoveComment, moderator::ModRemoveComment,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
}, },
views::ViewToVec, views::ViewToVec,
ToSafe, ToSafe,
@ -11,7 +10,11 @@ use crate::{
use diesel::{result::Error, *}; use diesel::{result::Error, *};
use lemmy_db_schema::{ use lemmy_db_schema::{
schema::{comment, community, mod_remove_comment, post, user_, user_alias_1}, 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; use serde::Serialize;

View file

@ -3,13 +3,15 @@ use crate::{
source::{ source::{
community::{Community, CommunitySafe}, community::{Community, CommunitySafe},
moderator::ModRemoveCommunity, moderator::ModRemoveCommunity,
user::{UserSafe, User_},
}, },
views::ViewToVec, views::ViewToVec,
ToSafe, ToSafe,
}; };
use diesel::{result::Error, *}; 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; use serde::Serialize;
#[derive(Debug, Serialize, Clone)] #[derive(Debug, Serialize, Clone)]

View file

@ -3,7 +3,6 @@ use crate::{
source::{ source::{
community::{Community, CommunitySafe}, community::{Community, CommunitySafe},
moderator::ModRemovePost, moderator::ModRemovePost,
user::{UserSafe, User_},
}, },
views::ViewToVec, views::ViewToVec,
ToSafe, ToSafe,
@ -11,7 +10,10 @@ use crate::{
use diesel::{result::Error, *}; use diesel::{result::Error, *};
use lemmy_db_schema::{ use lemmy_db_schema::{
schema::{community, mod_remove_post, post, user_}, schema::{community, mod_remove_post, post, user_},
source::post::Post, source::{
post::Post,
user::{UserSafe, User_},
},
}; };
use serde::Serialize; use serde::Serialize;

View file

@ -3,7 +3,6 @@ use crate::{
source::{ source::{
community::{Community, CommunitySafe}, community::{Community, CommunitySafe},
moderator::ModStickyPost, moderator::ModStickyPost,
user::{UserSafe, User_},
}, },
views::ViewToVec, views::ViewToVec,
ToSafe, ToSafe,
@ -11,7 +10,10 @@ use crate::{
use diesel::{result::Error, *}; use diesel::{result::Error, *};
use lemmy_db_schema::{ use lemmy_db_schema::{
schema::{community, mod_sticky_post, post, user_}, schema::{community, mod_sticky_post, post, user_},
source::post::Post, source::{
post::Post,
user::{UserSafe, User_},
},
}; };
use serde::Serialize; use serde::Serialize;

View file

@ -3,7 +3,6 @@ use crate::{
source::{ source::{
community::{Community, CommunitySafe}, community::{Community, CommunitySafe},
post_report::PostReport, post_report::PostReport,
user::{UserAlias1, UserAlias2, UserSafe, UserSafeAlias1, UserSafeAlias2, User_},
}, },
views::ViewToVec, views::ViewToVec,
MaybeOptional, MaybeOptional,
@ -12,7 +11,10 @@ use crate::{
use diesel::{result::Error, *}; use diesel::{result::Error, *};
use lemmy_db_schema::{ use lemmy_db_schema::{
schema::{community, post, post_report, user_, user_alias_1, user_alias_2}, 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; use serde::Serialize;

View file

@ -3,10 +3,7 @@ use crate::{
functions::hot_rank, functions::hot_rank,
fuzzy_search, fuzzy_search,
limit_and_offset, limit_and_offset,
source::{ source::community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
user::{UserSafe, User_},
},
views::ViewToVec, views::ViewToVec,
ListingType, ListingType,
MaybeOptional, MaybeOptional,
@ -26,7 +23,10 @@ use lemmy_db_schema::{
post_saved, post_saved,
user_, user_,
}, },
source::post::{Post, PostRead, PostSaved}, source::{
post::{Post, PostRead, PostSaved},
user::{UserSafe, User_},
},
}; };
use serde::Serialize; use serde::Serialize;
@ -408,14 +408,14 @@ impl ViewToVec for PostView {
mod tests { mod tests {
use crate::{ use crate::{
aggregates::post_aggregates::PostAggregates, aggregates::post_aggregates::PostAggregates,
source::{community::*, user::*}, source::community::*,
tests::establish_unpooled_connection, tests::establish_unpooled_connection,
views::post_view::{PostQueryBuilder, PostView}, views::post_view::{PostQueryBuilder, PostView},
Crud, Crud,
Likeable, Likeable,
*, *,
}; };
use lemmy_db_schema::source::post::*; use lemmy_db_schema::source::{post::*, user::*};
#[test] #[test]
fn test_crud() { fn test_crud() {

View file

@ -1,15 +1,15 @@
use crate::{ use crate::{
limit_and_offset, limit_and_offset,
source::{ source::private_message::PrivateMessage,
private_message::PrivateMessage,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
views::ViewToVec, views::ViewToVec,
MaybeOptional, MaybeOptional,
ToSafe, ToSafe,
}; };
use diesel::{result::Error, *}; 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; use serde::Serialize;
#[derive(Debug, PartialEq, Serialize, Clone)] #[derive(Debug, PartialEq, Serialize, Clone)]

View file

@ -1,12 +1,9 @@
use crate::{ use crate::{source::site::Site, ToSafe};
source::{
site::Site,
user::{UserSafe, User_},
},
ToSafe,
};
use diesel::{result::Error, *}; 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; use serde::Serialize;
#[derive(Debug, Serialize, Clone)] #[derive(Debug, Serialize, Clone)]

View file

@ -4,7 +4,6 @@ use crate::{
limit_and_offset, limit_and_offset,
source::{ source::{
community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan}, community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
user_mention::UserMention, user_mention::UserMention,
}, },
views::ViewToVec, views::ViewToVec,
@ -30,6 +29,7 @@ use lemmy_db_schema::{
source::{ source::{
comment::{Comment, CommentSaved}, comment::{Comment, CommentSaved},
post::Post, post::Post,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
}, },
}; };
use serde::Serialize; use serde::Serialize;

View file

@ -2,14 +2,16 @@ use crate::{
aggregates::user_aggregates::UserAggregates, aggregates::user_aggregates::UserAggregates,
fuzzy_search, fuzzy_search,
limit_and_offset, limit_and_offset,
source::user::{UserSafe, User_},
views::ViewToVec, views::ViewToVec,
MaybeOptional, MaybeOptional,
SortType, SortType,
ToSafe, ToSafe,
}; };
use diesel::{dsl::*, result::Error, *}; 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; use serde::Serialize;
#[derive(Debug, Serialize, Clone)] #[derive(Debug, Serialize, Clone)]

View file

@ -6,6 +6,7 @@ use chrono::NaiveDateTime;
pub mod schema; pub mod schema;
pub mod source; pub mod source;
// TODO: can probably move this back to lemmy_db
pub fn naive_now() -> NaiveDateTime { pub fn naive_now() -> NaiveDateTime {
chrono::prelude::Utc::now().naive_utc() chrono::prelude::Utc::now().naive_utc()
} }

View file

@ -1,9 +1,7 @@
use crate::{ use crate::{
naive_now,
schema::{comment, comment_alias_1, comment_like, comment_saved}, schema::{comment, comment_alias_1, comment_like, comment_saved},
source::post::Post, source::post::Post,
}; };
use diesel::{result::Error, PgConnection, *};
use serde::Serialize; use serde::Serialize;
use url::{ParseError, Url}; use url::{ParseError, Url};
@ -66,85 +64,6 @@ pub struct CommentForm {
pub local: bool, 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 { impl CommentForm {
pub fn get_ap_id(&self) -> Result<Url, ParseError> { pub fn get_ap_id(&self) -> Result<Url, ParseError> {
Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string())) Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string()))

View file

@ -1,2 +1,3 @@
pub mod comment; pub mod comment;
pub mod post; pub mod post;
pub mod user;

View file

@ -1,8 +1,4 @@
use crate::{ use crate::schema::{post, post_like, post_read, post_saved};
naive_now,
schema::{post, post_like, post_read, post_saved},
};
use diesel::{result::Error, *};
use serde::Serialize; use serde::Serialize;
use url::{ParseError, Url}; use url::{ParseError, Url};
@ -53,118 +49,6 @@ pub struct PostForm {
pub local: bool, 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 { impl PostForm {
pub fn get_ap_id(&self) -> Result<Url, ParseError> { pub fn get_ap_id(&self) -> Result<Url, ParseError> {
Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string())) Url::parse(&self.ap_id.as_ref().unwrap_or(&"not_a_url".to_string()))

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

View file

@ -8,13 +8,13 @@ pub mod websocket;
use diesel::PgConnection; use diesel::PgConnection;
use lemmy_db::{ use lemmy_db::{
source::{ source::{
user::User_, user::User,
user_mention::{UserMention, UserMentionForm}, user_mention::{UserMention, UserMentionForm},
}, },
Crud, Crud,
DbPool, 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 lemmy_utils::{email::send_email, settings::Settings, utils::MentionData, LemmyError};
use log::error; use log::error;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View file

@ -1,6 +1,6 @@
use lemmy_db::{ use lemmy_db::{
aggregates::site_aggregates::SiteAggregates, aggregates::site_aggregates::SiteAggregates,
source::{category::*, user::*}, source::category::*,
views::{ views::{
comment_view::CommentView, comment_view::CommentView,
community::community_view::CommunityView, community::community_view::CommunityView,
@ -20,6 +20,7 @@ use lemmy_db::{
user_view::UserViewSafe, user_view::UserViewSafe,
}, },
}; };
use lemmy_db_schema::source::user::User_;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Deserialize)] #[derive(Deserialize)]

View file

@ -5,15 +5,20 @@ use diesel::{
}; };
use lemmy_db::{ use lemmy_db::{
source::{ source::{
comment::Comment_,
community::{Community, CommunityForm}, community::{Community, CommunityForm},
post::Post_,
private_message::PrivateMessage, private_message::PrivateMessage,
user::{UserForm, User_},
}, },
Crud, Crud,
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
naive_now, naive_now,
source::{comment::Comment, post::Post}, source::{
comment::Comment,
post::Post,
user::{UserForm, User_},
},
}; };
use lemmy_utils::{ use lemmy_utils::{
apub::{generate_actor_keypair, make_apub_endpoint, EndpointType}, apub::{generate_actor_keypair, make_apub_endpoint, EndpointType},

View file

@ -4,7 +4,7 @@ use chrono::{DateTime, NaiveDateTime, Utc};
use diesel::PgConnection; use diesel::PgConnection;
use lemmy_api::claims::Claims; use lemmy_api::claims::Claims;
use lemmy_db::{ use lemmy_db::{
source::{community::Community, user::User_}, source::{community::Community, user::User},
views::{ views::{
comment_view::{CommentQueryBuilder, CommentView}, comment_view::{CommentQueryBuilder, CommentView},
post_view::{PostQueryBuilder, PostView}, post_view::{PostQueryBuilder, PostView},
@ -14,6 +14,7 @@ use lemmy_db::{
ListingType, ListingType,
SortType, SortType,
}; };
use lemmy_db_schema::source::user::User_;
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::{settings::Settings, utils::markdown_to_html, LemmyError}; use lemmy_utils::{settings::Settings, utils::markdown_to_html, LemmyError};
use lemmy_websocket::LemmyContext; use lemmy_websocket::LemmyContext;

View file

@ -1,6 +1,7 @@
use actix_web::{error::ErrorBadRequest, web::Query, *}; use actix_web::{error::ErrorBadRequest, web::Query, *};
use anyhow::anyhow; 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_structs::{blocking, WebFingerLink, WebFingerResponse};
use lemmy_utils::{ use lemmy_utils::{
settings::Settings, settings::Settings,

View file

@ -29,14 +29,12 @@ use lemmy_apub::{
}, },
}; };
use lemmy_db::{ use lemmy_db::{
source::{ source::community::{Community, CommunityForm},
community::{Community, CommunityForm},
user::{User_, *},
},
Crud, Crud,
ListingType, ListingType,
SortType, SortType,
}; };
use lemmy_db_schema::source::user::{UserForm, User_};
use lemmy_rate_limit::{rate_limiter::RateLimiter, RateLimit}; use lemmy_rate_limit::{rate_limiter::RateLimiter, RateLimit};
use lemmy_utils::{apub::generate_actor_keypair, settings::Settings}; use lemmy_utils::{apub::generate_actor_keypair, settings::Settings};
use lemmy_websocket::{chat_server::ChatServer, LemmyContext}; use lemmy_websocket::{chat_server::ChatServer, LemmyContext};