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};
use lemmy_apub::{ApubLikeableType, ApubObjectType};
use lemmy_db::{
source::{
+ comment::Comment_,
comment_report::{CommentReport, CommentReportForm},
moderator::*,
- user::*,
},
views::{
comment_report_view::{CommentReportQueryBuilder, CommentReportView},
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::{
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::{
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};
use lemmy_db::{
source::{
moderator::*,
+ post::Post_,
post_report::{PostReport, PostReportForm},
},
views::{
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::{
};
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::{
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,
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;
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;
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};
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;
};
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},
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;
},
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;
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;
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};
use lemmy_db::{
source::{
community::{Community, CommunityModerator, CommunityModeratorForm},
- user::User_,
+ user::User,
},
views::{
comment_view::CommentView,
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::{
};
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;
};
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;
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;
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;
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;
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;
};
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;
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::{
};
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,
};
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;
};
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,
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"
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,
use lemmy_db_schema::source::{
comment::{Comment, CommentForm},
post::{Post, PostForm},
+ user::{UserForm, User_},
};
#[test]
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,
use lemmy_db_schema::source::{
comment::{Comment, CommentForm},
post::{Post, PostForm, PostLike, PostLikeForm},
+ user::{UserForm, User_},
};
#[test]
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,
use lemmy_db_schema::source::{
comment::{Comment, CommentForm},
post::{Post, PostForm},
+ user::{UserForm, User_},
};
#[test]
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,
use lemmy_db_schema::source::{
comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
post::{Post, PostForm, PostLike, PostLikeForm},
+ user::{UserForm, User_},
};
#[test]
#[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]
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::*;
#[cfg(test)]
mod tests {
use crate::{
- source::{community::*, user::*},
+ source::community::*,
tests::establish_unpooled_connection,
Crud,
Likeable,
Saveable,
SortType,
};
- use lemmy_db_schema::source::{comment::*, post::*};
+ use lemmy_db_schema::source::{
+ comment::*,
+ post::*,
+ user::{UserForm, User_},
+ };
#[test]
fn test_crud() {
#[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() {
#[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]
#[cfg(test)]
mod tests {
- use super::super::user::*;
use crate::{
source::password_reset_request::PasswordResetRequest,
tests::establish_unpooled_connection,
ListingType,
SortType,
};
+ use lemmy_db_schema::source::user::*;
#[test]
fn test_crud() {
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 {
}
}
+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::*;
#[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() {
#[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() {
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,
}
}
-#[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,
}
}
-#[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,
}
}
-#[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_
}
}
-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");
}
// 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))
.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))
.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> {
}
}
- 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))
.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))
.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(),
)
}
- 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),
#[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() {
source::{
comment_report::CommentReport,
community::{Community, CommunitySafe},
- user::{UserAlias1, UserAlias2, UserSafe, UserSafeAlias1, UserSafeAlias2, User_},
},
views::ViewToVec,
MaybeOptional,
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;
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,
source::{
comment::{Comment, CommentAlias1, CommentSaved},
post::Post,
+ user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
};
use serde::Serialize;
#[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() {
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)]
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)]
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)]
source::{
category::Category,
community::{Community, CommunityFollower, CommunitySafe},
- user::{UserSafe, User_},
},
views::ViewToVec,
MaybeOptional,
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;
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)]
-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)]
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)]
-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)]
source::{
community::{Community, CommunitySafe},
moderator::ModLockPost,
- user::{UserSafe, User_},
},
views::ViewToVec,
ToSafe,
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;
source::{
community::{Community, CommunitySafe},
moderator::ModRemoveComment,
- user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
views::ViewToVec,
ToSafe,
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;
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)]
source::{
community::{Community, CommunitySafe},
moderator::ModRemovePost,
- user::{UserSafe, User_},
},
views::ViewToVec,
ToSafe,
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;
source::{
community::{Community, CommunitySafe},
moderator::ModStickyPost,
- user::{UserSafe, User_},
},
views::ViewToVec,
ToSafe,
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;
source::{
community::{Community, CommunitySafe},
post_report::PostReport,
- user::{UserAlias1, UserAlias2, UserSafe, UserSafeAlias1, UserSafeAlias2, User_},
},
views::ViewToVec,
MaybeOptional,
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;
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,
post_saved,
user_,
},
- source::post::{Post, PostRead, PostSaved},
+ source::{
+ post::{Post, PostRead, PostSaved},
+ user::{UserSafe, User_},
+ },
};
use serde::Serialize;
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() {
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)]
-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)]
limit_and_offset,
source::{
community::{Community, CommunityFollower, CommunitySafe, CommunityUserBan},
- user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
user_mention::UserMention,
},
views::ViewToVec,
source::{
comment::{Comment, CommentSaved},
post::Post,
+ user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
};
use serde::Serialize;
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)]
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()
}
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};
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()))
pub mod comment;
pub mod post;
+pub mod user;
-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};
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()))
--- /dev/null
+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>>,
+}
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};
use lemmy_db::{
aggregates::site_aggregates::SiteAggregates,
- source::{category::*, user::*},
+ source::category::*,
views::{
comment_view::CommentView,
community::community_view::CommunityView,
user_view::UserViewSafe,
},
};
+use lemmy_db_schema::source::user::User_;
use serde::{Deserialize, Serialize};
#[derive(Deserialize)]
};
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},
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},
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;
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,
},
};
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};