"bcrypt",
"chrono",
"diesel",
+ "diesel_migrations",
"lazy_static",
+ "lemmy_db_schema",
"lemmy_utils",
"log",
"regex",
Saveable,
SortType,
};
-use lemmy_db_schema::source::{comment::*, comment_report::*, moderator::*, post::Post, user::*};
++use lemmy_db_schema::source::{comment::*, comment_report::*, moderator::*};
use lemmy_structs::{blocking, comment::*, send_local_notifs};
use lemmy_utils::{
apub::{make_apub_endpoint, EndpointType},
use crate::claims::Claims;
use actix_web::{web, web::Data};
use lemmy_db::{
- source::community::{CommunityModerator_, Community_},
+ source::{
- community::{Community, CommunityModerator},
- post::Post,
- site::Site,
- user::User_,
++ community::{CommunityModerator_, Community_},
++ site::Site_,
+ },
views::community::community_user_ban_view::CommunityUserBanView,
Crud,
DbPool,
};
+ use lemmy_db_schema::source::{
+ community::{Community, CommunityModerator},
+ post::Post,
++ site::Site,
+ 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 actix_web::web::Data;
use lemmy_apub::{ApubLikeableType, ApubObjectType};
use lemmy_db::{
- naive_now,
- source::{
- moderator::*,
- post::*,
- post_report::{PostReport, PostReportForm},
- },
+ source::post::Post_,
views::{
comment_view::CommentQueryBuilder,
- community::{community_moderator_view::CommunityModeratorView, community_view::CommunityView},
+ community::community_moderator_view::CommunityModeratorView,
post_report_view::{PostReportQueryBuilder, PostReportView},
post_view::{PostQueryBuilder, PostView},
- site_view::SiteView,
},
Crud,
Likeable,
use anyhow::Context;
use lemmy_apub::fetcher::search_by_apub_id;
use lemmy_db::{
- aggregates::site_aggregates::SiteAggregates,
diesel_option_overwrite,
- naive_now,
- source::{category::*, moderator::*, site::*},
+ source::{category::Category_, site::Site_},
views::{
comment_view::CommentQueryBuilder,
community::community_view::CommunityQueryBuilder,
use lemmy_apub::ApubObjectType;
use lemmy_db::{
diesel_option_overwrite,
- naive_now,
source::{
- comment::*,
- community::*,
- moderator::*,
- password_reset_request::*,
- post::*,
- private_message::*,
- site::*,
- user::*,
- user_mention::*,
+ comment::Comment_,
+ community::Community_,
+ password_reset_request::PasswordResetRequest_,
+ post::Post_,
+ private_message::PrivateMessage_,
++ site::Site_,
+ user::User,
+ user_mention::UserMention_,
},
views::{
comment_report_view::CommentReportView,
[dependencies]
lemmy_utils = { path = "../lemmy_utils" }
+ lemmy_db_schema = { path = "../lemmy_db_schema" }
diesel = { version = "1.4.5", features = ["postgres","chrono","r2d2","serde_json"] }
+diesel_migrations = "1.4.0"
chrono = { version = "0.4.19", features = ["serde"] }
serde = { version = "1.0.118", features = ["derive"] }
serde_json = { version = "1.0.60", features = ["preserve_order"] }
- use crate::schema::site_aggregates;
use diesel::{result::Error, *};
+ use lemmy_db_schema::schema::site_aggregates;
use serde::Serialize;
-#[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize)]
+#[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Clone)]
#[table_name = "site_aggregates"]
pub struct SiteAggregates {
pub id: i32,
extern crate strum_macros;
#[macro_use]
extern crate lazy_static;
+// this is used in tests
+#[allow(unused_imports)]
+#[macro_use]
+extern crate diesel_migrations;
- use chrono::NaiveDateTime;
use diesel::{result::Error, *};
use regex::Regex;
use serde::{Deserialize, Serialize};
}
}
- impl ApubObject<PostForm> for Post {
- fn read_from_apub_id(conn: &PgConnection, object_id: &str) -> Result<Self, Error> {
- use crate::schema::post::dsl::*;
- post.filter(ap_id.eq(object_id)).first::<Self>(conn)
- }
-
- fn upsert(conn: &PgConnection, post_form: &PostForm) -> Result<Post, Error> {
- use crate::schema::post::dsl::*;
- insert_into(post)
- .values(post_form)
- .on_conflict(ap_id)
- .do_update()
- .set(post_form)
- .get_result::<Self>(conn)
- }
+ 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 {
- pub fn list_for_community(
- conn: &PgConnection,
- the_community_id: i32,
- ) -> Result<Vec<Self>, Error> {
- use crate::schema::post::dsl::*;
+ 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())
.set(new_site)
.get_result::<Self>(conn)
}
- use crate::schema::site::dsl::*;
+ fn delete(conn: &PgConnection, site_id: i32) -> Result<usize, Error> {
++ use lemmy_db_schema::schema::site::dsl::*;
+ diesel::delete(site.find(site_id)).execute(conn)
+ }
}
- impl Site {
- pub fn transfer(conn: &PgConnection, new_creator_id: i32) -> Result<Self, Error> {
- use crate::schema::site::dsl::*;
+ pub trait Site_ {
+ fn transfer(conn: &PgConnection, new_creator_id: i32) -> Result<Site, Error>;
++ fn read_simple(conn: &PgConnection) -> Result<Site, Error>;
+ }
+
+ impl Site_ for Site {
+ fn transfer(conn: &PgConnection, new_creator_id: i32) -> Result<Site, Error> {
+ use lemmy_db_schema::schema::site::dsl::*;
diesel::update(site.find(1))
.set((creator_id.eq(new_creator_id), updated.eq(naive_now())))
.get_result::<Self>(conn)
}
- pub fn read_simple(conn: &PgConnection) -> Result<Self, Error> {
- use crate::schema::site::dsl::*;
+
++ fn read_simple(conn: &PgConnection) -> Result<Self, Error> {
++ use lemmy_db_schema::schema::site::dsl::*;
+ site.first::<Self>(conn)
+ }
}
- use crate::{
- aggregates::site_aggregates::SiteAggregates,
-use crate::ToSafe;
++use crate::{aggregates::site_aggregates::SiteAggregates, ToSafe};
+ use diesel::{result::Error, *};
+ use lemmy_db_schema::{
- schema::{site, user_},
+ schema::{site, site_aggregates, user_},
source::{
site::Site,
user::{UserSafe, User_},
--- /dev/null
-#[derive(Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone)]
+ use crate::{schema::comment_report, source::comment::Comment};
+ use serde::{Deserialize, Serialize};
+
++#[derive(
++ Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone,
++)]
+ #[belongs_to(Comment)]
+ #[table_name = "comment_report"]
+ pub struct CommentReport {
+ pub id: i32,
+ pub creator_id: i32,
+ pub comment_id: i32,
+ pub original_comment_text: String,
+ pub reason: String,
+ pub resolved: bool,
+ pub resolver_id: Option<i32>,
+ pub published: chrono::NaiveDateTime,
+ pub updated: Option<chrono::NaiveDateTime>,
+ }
+
+ #[derive(Insertable, AsChangeset, Clone)]
+ #[table_name = "comment_report"]
+ pub struct CommentReportForm {
+ pub creator_id: i32,
+ pub comment_id: i32,
+ pub original_comment_text: String,
+ pub reason: String,
+ }
--- /dev/null
-#[derive(Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone)]
+ use crate::{schema::post_report, source::post::Post};
+ use serde::{Deserialize, Serialize};
+
++#[derive(
++ Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone,
++)]
+ #[belongs_to(Post)]
+ #[table_name = "post_report"]
+ pub struct PostReport {
+ pub id: i32,
+ pub creator_id: i32,
+ pub post_id: i32,
+ pub original_post_name: String,
+ pub original_post_url: Option<String>,
+ pub original_post_body: Option<String>,
+ pub reason: String,
+ pub resolved: bool,
+ pub resolver_id: Option<i32>,
+ pub published: chrono::NaiveDateTime,
+ pub updated: Option<chrono::NaiveDateTime>,
+ }
+
+ #[derive(Insertable, AsChangeset, Clone)]
+ #[table_name = "post_report"]
+ pub struct PostReportForm {
+ pub creator_id: i32,
+ pub post_id: i32,
+ pub original_post_name: String,
+ pub original_post_url: Option<String>,
+ pub original_post_body: Option<String>,
+ pub reason: String,
+ }
pub mod post;
pub mod site;
pub mod user;
-pub mod websocket;
use diesel::PgConnection;
- use lemmy_db::{
- source::{
- comment::Comment,
- post::Post,
- user::User_,
- user_mention::{UserMention, UserMentionForm},
- },
- Crud,
- DbPool,
+ use lemmy_db::{source::user::User, Crud, DbPool};
+ use lemmy_db_schema::source::{
+ comment::Comment,
+ post::Post,
+ user::User_,
+ user_mention::{UserMention, UserMentionForm},
};
use lemmy_utils::{email::send_email, settings::Settings, utils::MentionData, LemmyError};
use log::error;
--use lemmy_db::{
- source::{category::*, user::*},
- aggregates::site_aggregates::SiteAggregates,
-- views::{
-- comment_view::CommentView,
-- community::community_view::CommunityView,
-- moderator::{
-- mod_add_community_view::ModAddCommunityView,
-- mod_add_view::ModAddView,
-- mod_ban_from_community_view::ModBanFromCommunityView,
-- mod_ban_view::ModBanView,
-- mod_lock_post_view::ModLockPostView,
-- mod_remove_comment_view::ModRemoveCommentView,
-- mod_remove_community_view::ModRemoveCommunityView,
-- mod_remove_post_view::ModRemovePostView,
-- mod_sticky_post_view::ModStickyPostView,
-- },
-- post_view::PostView,
-- site_view::SiteView,
-- user_view::UserViewSafe,
++use lemmy_db::views::{
++ comment_view::CommentView,
++ community::community_view::CommunityView,
++ moderator::{
++ mod_add_community_view::ModAddCommunityView,
++ mod_add_view::ModAddView,
++ mod_ban_from_community_view::ModBanFromCommunityView,
++ mod_ban_view::ModBanView,
++ mod_lock_post_view::ModLockPostView,
++ mod_remove_comment_view::ModRemoveCommentView,
++ mod_remove_community_view::ModRemoveCommunityView,
++ mod_remove_post_view::ModRemovePostView,
++ mod_sticky_post_view::ModStickyPostView,
},
++ post_view::PostView,
++ site_view::SiteView,
++ user_view::UserViewSafe,
};
+ use lemmy_db_schema::source::{category::*, user::User_};
use serde::{Deserialize, Serialize};
#[derive(Deserialize)]