mirror of https://github.com/LemmyNet/lemmy.git
Merge crates db_schema and db_queries
parent
ed622abc37
commit
5d0b13f6e7
|
@ -1668,7 +1668,6 @@ dependencies = [
|
|||
"lazy_static",
|
||||
"lemmy_api_common",
|
||||
"lemmy_apub",
|
||||
"lemmy_db_queries",
|
||||
"lemmy_db_schema",
|
||||
"lemmy_db_views",
|
||||
"lemmy_db_views_actor",
|
||||
|
@ -1697,7 +1696,6 @@ dependencies = [
|
|||
"actix-web",
|
||||
"chrono",
|
||||
"diesel",
|
||||
"lemmy_db_queries",
|
||||
"lemmy_db_schema",
|
||||
"lemmy_db_views",
|
||||
"lemmy_db_views_actor",
|
||||
|
@ -1732,7 +1730,6 @@ dependencies = [
|
|||
"lemmy_api_common",
|
||||
"lemmy_apub",
|
||||
"lemmy_apub_lib",
|
||||
"lemmy_db_queries",
|
||||
"lemmy_db_schema",
|
||||
"lemmy_db_views",
|
||||
"lemmy_db_views_actor",
|
||||
|
@ -1776,7 +1773,6 @@ dependencies = [
|
|||
"itertools",
|
||||
"lemmy_api_common",
|
||||
"lemmy_apub_lib",
|
||||
"lemmy_db_queries",
|
||||
"lemmy_db_schema",
|
||||
"lemmy_db_views",
|
||||
"lemmy_db_views_actor",
|
||||
|
@ -1834,15 +1830,16 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "lemmy_db_queries"
|
||||
name = "lemmy_db_schema"
|
||||
version = "0.13.0"
|
||||
dependencies = [
|
||||
"bcrypt",
|
||||
"chrono",
|
||||
"diesel",
|
||||
"diesel-derive-newtype",
|
||||
"diesel_migrations",
|
||||
"lazy_static",
|
||||
"lemmy_db_schema",
|
||||
"lemmy_apub_lib",
|
||||
"lemmy_utils",
|
||||
"log",
|
||||
"regex",
|
||||
|
@ -1855,27 +1852,11 @@ dependencies = [
|
|||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lemmy_db_schema"
|
||||
version = "0.13.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"diesel",
|
||||
"diesel-derive-newtype",
|
||||
"lemmy_apub_lib",
|
||||
"lemmy_utils",
|
||||
"log",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lemmy_db_views"
|
||||
version = "0.13.0"
|
||||
dependencies = [
|
||||
"diesel",
|
||||
"lemmy_db_queries",
|
||||
"lemmy_db_schema",
|
||||
"log",
|
||||
"serde",
|
||||
|
@ -1888,7 +1869,6 @@ name = "lemmy_db_views_actor"
|
|||
version = "0.13.0"
|
||||
dependencies = [
|
||||
"diesel",
|
||||
"lemmy_db_queries",
|
||||
"lemmy_db_schema",
|
||||
"serde",
|
||||
]
|
||||
|
@ -1898,7 +1878,6 @@ name = "lemmy_db_views_moderator"
|
|||
version = "0.13.0"
|
||||
dependencies = [
|
||||
"diesel",
|
||||
"lemmy_db_queries",
|
||||
"lemmy_db_schema",
|
||||
"serde",
|
||||
]
|
||||
|
@ -1918,7 +1897,6 @@ dependencies = [
|
|||
"lazy_static",
|
||||
"lemmy_api_common",
|
||||
"lemmy_apub_lib",
|
||||
"lemmy_db_queries",
|
||||
"lemmy_db_schema",
|
||||
"lemmy_db_views",
|
||||
"lemmy_db_views_actor",
|
||||
|
@ -1954,7 +1932,6 @@ dependencies = [
|
|||
"lemmy_api_crud",
|
||||
"lemmy_apub",
|
||||
"lemmy_apub_lib",
|
||||
"lemmy_db_queries",
|
||||
"lemmy_db_schema",
|
||||
"lemmy_db_views",
|
||||
"lemmy_db_views_actor",
|
||||
|
@ -2020,7 +1997,6 @@ dependencies = [
|
|||
"chrono",
|
||||
"diesel",
|
||||
"lemmy_api_common",
|
||||
"lemmy_db_queries",
|
||||
"lemmy_db_schema",
|
||||
"lemmy_db_views",
|
||||
"lemmy_db_views_actor",
|
||||
|
|
|
@ -22,7 +22,6 @@ members = [
|
|||
"crates/apub_lib_derive",
|
||||
"crates/apub",
|
||||
"crates/utils",
|
||||
"crates/db_queries",
|
||||
"crates/db_schema",
|
||||
"crates/db_views",
|
||||
"crates/db_views_actor",
|
||||
|
@ -38,7 +37,6 @@ lemmy_apub = { version = "=0.13.0", path = "./crates/apub" }
|
|||
lemmy_apub_lib = { version = "=0.13.0", path = "./crates/apub_lib" }
|
||||
lemmy_utils = { version = "=0.13.0", path = "./crates/utils" }
|
||||
lemmy_db_schema = { version = "=0.13.0", path = "./crates/db_schema" }
|
||||
lemmy_db_queries = { version = "=0.13.0", path = "./crates/db_queries" }
|
||||
lemmy_db_views = { version = "=0.13.0", path = "./crates/db_views" }
|
||||
lemmy_db_views_moderator = { version = "=0.13.0", path = "./crates/db_views_moderator" }
|
||||
lemmy_db_views_actor = { version = "=0.13.0", path = "./crates/db_views_actor" }
|
||||
|
|
|
@ -7,7 +7,7 @@ services:
|
|||
- "127.0.0.1:8536:8536"
|
||||
restart: always
|
||||
environment:
|
||||
- RUST_LOG="warn,lemmy_server=info,lemmy_api=info,lemmy_api_common=info,lemmy_api_crud=info,lemmy_apub=info,lemmy_db_queries=info,lemmy_db_schema=info,lemmy_db_views=info,lemmy_db_views_actor=info,lemmy_db_views_moderator=info,lemmy_routes=info,lemmy_utils=info,lemmy_websocket=info"
|
||||
- RUST_LOG="warn,lemmy_server=info,lemmy_api=info,lemmy_api_common=info,lemmy_api_crud=info,lemmy_apub=info,lemmy_db_schema=info,lemmy_db_views=info,lemmy_db_views_actor=info,lemmy_db_views_moderator=info,lemmy_routes=info,lemmy_utils=info,lemmy_websocket=info"
|
||||
volumes:
|
||||
- ./lemmy.hjson:/config/config.hjson:ro
|
||||
depends_on:
|
||||
|
|
|
@ -3,7 +3,7 @@ set -e
|
|||
|
||||
export APUB_TESTING_SEND_SYNC=1
|
||||
export RUST_BACKTRACE=1
|
||||
export RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_queries=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
|
||||
export RUST_LOG="warn,lemmy_server=debug,lemmy_api=debug,lemmy_api_common=debug,lemmy_api_crud=debug,lemmy_apub=debug,lemmy_db_schema=debug,lemmy_db_views=debug,lemmy_db_views_actor=debug,lemmy_db_views_moderator=debug,lemmy_routes=debug,lemmy_utils=debug,lemmy_websocket=debug"
|
||||
|
||||
for INSTANCE in lemmy_alpha lemmy_beta lemmy_gamma lemmy_delta lemmy_epsilon; do
|
||||
psql "${LEMMY_DATABASE_URL}/lemmy" -c "DROP DATABASE IF EXISTS $INSTANCE"
|
||||
|
|
|
@ -13,7 +13,6 @@ doctest = false
|
|||
[dependencies]
|
||||
lemmy_apub = { version = "=0.13.0", path = "../apub" }
|
||||
lemmy_utils = { version = "=0.13.0", path = "../utils" }
|
||||
lemmy_db_queries = { version = "=0.13.0", path = "../db_queries" }
|
||||
lemmy_db_schema = { version = "=0.13.0", path = "../db_schema" }
|
||||
lemmy_db_views = { version = "=0.13.0", path = "../db_views" }
|
||||
lemmy_db_views_moderator = { version = "=0.13.0", path = "../db_views_moderator" }
|
||||
|
|
|
@ -15,8 +15,11 @@ use lemmy_apub::{
|
|||
},
|
||||
fetcher::post_or_comment::PostOrComment,
|
||||
};
|
||||
use lemmy_db_queries::{source::comment::Comment_, Likeable, Saveable};
|
||||
use lemmy_db_schema::{source::comment::*, LocalUserId};
|
||||
use lemmy_db_schema::{
|
||||
newtypes::LocalUserId,
|
||||
source::comment::*,
|
||||
traits::{Likeable, Saveable},
|
||||
};
|
||||
use lemmy_db_views::{comment_view::CommentView, local_user_view::LocalUserView};
|
||||
use lemmy_utils::{ApiError, ConnectionId, LemmyError};
|
||||
use lemmy_websocket::{send::send_comment_ws_message, LemmyContext, UserOperation};
|
||||
|
|
|
@ -8,8 +8,7 @@ use lemmy_api_common::{
|
|||
is_mod_or_admin,
|
||||
};
|
||||
use lemmy_apub::{activities::report::Report, fetcher::object_id::ObjectId};
|
||||
use lemmy_db_queries::Reportable;
|
||||
use lemmy_db_schema::source::comment_report::*;
|
||||
use lemmy_db_schema::{source::comment_report::*, traits::Reportable};
|
||||
use lemmy_db_views::{
|
||||
comment_report_view::{CommentReportQueryBuilder, CommentReportView},
|
||||
comment_view::CommentView,
|
||||
|
|
|
@ -18,22 +18,32 @@ use lemmy_apub::activities::{
|
|||
},
|
||||
following::{follow::FollowCommunity as FollowCommunityApub, undo::UndoFollowCommunity},
|
||||
};
|
||||
use lemmy_db_queries::{
|
||||
source::{comment::Comment_, community::CommunityModerator_, post::Post_},
|
||||
Bannable,
|
||||
Blockable,
|
||||
Crud,
|
||||
Followable,
|
||||
Joinable,
|
||||
};
|
||||
use lemmy_db_schema::source::{
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
comment::Comment,
|
||||
community::*,
|
||||
community::{
|
||||
Community,
|
||||
CommunityFollower,
|
||||
CommunityFollowerForm,
|
||||
CommunityModerator,
|
||||
CommunityModeratorForm,
|
||||
CommunityPersonBan,
|
||||
CommunityPersonBanForm,
|
||||
},
|
||||
community_block::{CommunityBlock, CommunityBlockForm},
|
||||
moderator::*,
|
||||
moderator::{
|
||||
ModAddCommunity,
|
||||
ModAddCommunityForm,
|
||||
ModBanFromCommunity,
|
||||
ModBanFromCommunityForm,
|
||||
ModTransferCommunity,
|
||||
ModTransferCommunityForm,
|
||||
},
|
||||
person::Person,
|
||||
post::Post,
|
||||
site::*,
|
||||
site::Site,
|
||||
},
|
||||
traits::{Bannable, Blockable, Crud, Followable, Joinable},
|
||||
};
|
||||
use lemmy_db_views::comment_view::CommentQueryBuilder;
|
||||
use lemmy_db_views_actor::{
|
||||
|
|
|
@ -191,15 +191,14 @@ pub(crate) fn captcha_as_wav_base64(captcha: &Captcha) -> String {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use lemmy_api_common::check_validator_time;
|
||||
use lemmy_db_queries::{
|
||||
use lemmy_db_schema::{
|
||||
establish_unpooled_connection,
|
||||
source::{local_user::LocalUser_, secret::Secret_},
|
||||
Crud,
|
||||
};
|
||||
use lemmy_db_schema::source::{
|
||||
source::{
|
||||
local_user::{LocalUser, LocalUserForm},
|
||||
person::{Person, PersonForm},
|
||||
secret::Secret,
|
||||
},
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_utils::{claims::Claims, settings::structs::Settings};
|
||||
|
||||
|
|
|
@ -11,25 +11,10 @@ use lemmy_api_common::{
|
|||
password_length_check,
|
||||
person::*,
|
||||
};
|
||||
use lemmy_db_queries::{
|
||||
use lemmy_db_schema::{
|
||||
diesel_option_overwrite,
|
||||
diesel_option_overwrite_to_url,
|
||||
from_opt_str_to_opt_enum,
|
||||
source::{
|
||||
comment::Comment_,
|
||||
community::Community_,
|
||||
local_user::LocalUser_,
|
||||
password_reset_request::PasswordResetRequest_,
|
||||
person::Person_,
|
||||
person_mention::PersonMention_,
|
||||
post::Post_,
|
||||
private_message::PrivateMessage_,
|
||||
},
|
||||
Blockable,
|
||||
Crud,
|
||||
SortType,
|
||||
};
|
||||
use lemmy_db_schema::{
|
||||
naive_now,
|
||||
source::{
|
||||
comment::Comment,
|
||||
|
@ -44,6 +29,8 @@ use lemmy_db_schema::{
|
|||
private_message::PrivateMessage,
|
||||
site::*,
|
||||
},
|
||||
traits::{Blockable, Crud},
|
||||
SortType,
|
||||
};
|
||||
use lemmy_db_views::{
|
||||
comment_report_view::CommentReportView,
|
||||
|
|
|
@ -22,8 +22,10 @@ use lemmy_apub::{
|
|||
},
|
||||
fetcher::post_or_comment::PostOrComment,
|
||||
};
|
||||
use lemmy_db_queries::{source::post::Post_, Crud, Likeable, Saveable};
|
||||
use lemmy_db_schema::source::{moderator::*, post::*};
|
||||
use lemmy_db_schema::{
|
||||
source::{moderator::*, post::*},
|
||||
traits::{Crud, Likeable, Saveable},
|
||||
};
|
||||
use lemmy_db_views::post_view::PostView;
|
||||
use lemmy_utils::{request::fetch_site_metadata, ApiError, ConnectionId, LemmyError};
|
||||
use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperation};
|
||||
|
|
|
@ -14,8 +14,10 @@ use lemmy_api_common::{
|
|||
},
|
||||
};
|
||||
use lemmy_apub::{activities::report::Report, fetcher::object_id::ObjectId};
|
||||
use lemmy_db_queries::Reportable;
|
||||
use lemmy_db_schema::source::post_report::{PostReport, PostReportForm};
|
||||
use lemmy_db_schema::{
|
||||
source::post_report::{PostReport, PostReportForm},
|
||||
traits::Reportable,
|
||||
};
|
||||
use lemmy_db_views::{
|
||||
post_report_view::{PostReportQueryBuilder, PostReportView},
|
||||
post_view::PostView,
|
||||
|
|
|
@ -5,8 +5,7 @@ use lemmy_api_common::{
|
|||
get_local_user_view_from_jwt,
|
||||
person::{MarkPrivateMessageAsRead, PrivateMessageResponse},
|
||||
};
|
||||
use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud};
|
||||
use lemmy_db_schema::source::private_message::PrivateMessage;
|
||||
use lemmy_db_schema::{source::private_message::PrivateMessage, traits::Crud};
|
||||
use lemmy_utils::{ApiError, ConnectionId, LemmyError};
|
||||
use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperation};
|
||||
|
||||
|
|
|
@ -15,20 +15,16 @@ use lemmy_apub::{
|
|||
fetcher::search::{search_by_apub_id, SearchableObjects},
|
||||
EndpointType,
|
||||
};
|
||||
use lemmy_db_queries::{
|
||||
use lemmy_db_schema::{
|
||||
from_opt_str_to_opt_enum,
|
||||
source::site::Site_,
|
||||
Crud,
|
||||
newtypes::PersonId,
|
||||
source::{moderator::*, site::Site},
|
||||
traits::{Crud, DeleteableOrRemoveable},
|
||||
DbPool,
|
||||
DeleteableOrRemoveable,
|
||||
ListingType,
|
||||
SearchType,
|
||||
SortType,
|
||||
};
|
||||
use lemmy_db_schema::{
|
||||
source::{moderator::*, site::Site},
|
||||
PersonId,
|
||||
};
|
||||
use lemmy_db_views::{
|
||||
comment_view::{CommentQueryBuilder, CommentView},
|
||||
post_view::{PostQueryBuilder, PostView},
|
||||
|
@ -450,7 +446,7 @@ impl Perform for TransferSite {
|
|||
|
||||
is_admin(&local_user_view)?;
|
||||
|
||||
let read_site = blocking(context.pool(), move |conn| Site::read_simple(conn)).await??;
|
||||
let read_site = blocking(context.pool(), Site::read_simple).await??;
|
||||
|
||||
// Make sure user is the creator
|
||||
if read_site.creator_id != local_user_view.person.id {
|
||||
|
|
|
@ -11,7 +11,6 @@ path = "src/lib.rs"
|
|||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
lemmy_db_queries = { version = "=0.13.0", path = "../db_queries" }
|
||||
lemmy_db_views = { version = "=0.13.0", path = "../db_views" }
|
||||
lemmy_db_views_moderator = { version = "=0.13.0", path = "../db_views_moderator" }
|
||||
lemmy_db_views_actor = { version = "=0.13.0", path = "../db_views_actor" }
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use lemmy_db_schema::{CommentId, CommentReportId, CommunityId, LocalUserId, PostId};
|
||||
use lemmy_db_schema::newtypes::{CommentId, CommentReportId, CommunityId, LocalUserId, PostId};
|
||||
use lemmy_db_views::{comment_report_view::CommentReportView, comment_view::CommentView};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use lemmy_db_schema::{CommunityId, PersonId};
|
||||
use lemmy_db_schema::newtypes::{CommunityId, PersonId};
|
||||
use lemmy_db_views_actor::{
|
||||
community_moderator_view::CommunityModeratorView,
|
||||
community_view::CommunityView,
|
||||
|
|
|
@ -7,13 +7,8 @@ pub mod websocket;
|
|||
|
||||
use crate::site::FederatedInstances;
|
||||
use diesel::PgConnection;
|
||||
use lemmy_db_queries::{
|
||||
source::{community::Community_, person_block::PersonBlock_, site::Site_},
|
||||
Crud,
|
||||
DbPool,
|
||||
Readable,
|
||||
};
|
||||
use lemmy_db_schema::{
|
||||
newtypes::{CommunityId, LocalUserId, PersonId, PostId},
|
||||
source::{
|
||||
comment::Comment,
|
||||
community::Community,
|
||||
|
@ -24,10 +19,8 @@ use lemmy_db_schema::{
|
|||
secret::Secret,
|
||||
site::Site,
|
||||
},
|
||||
CommunityId,
|
||||
LocalUserId,
|
||||
PersonId,
|
||||
PostId,
|
||||
traits::{Crud, Readable},
|
||||
DbPool,
|
||||
};
|
||||
use lemmy_db_views::local_user_view::{LocalUserSettingsView, LocalUserView};
|
||||
use lemmy_db_views_actor::{
|
||||
|
@ -394,7 +387,7 @@ pub async fn check_person_block(
|
|||
|
||||
pub async fn check_downvotes_enabled(score: i16, pool: &DbPool) -> Result<(), LemmyError> {
|
||||
if score == -1 {
|
||||
let site = blocking(pool, move |conn| Site::read_simple(conn)).await??;
|
||||
let site = blocking(pool, Site::read_simple).await??;
|
||||
if !site.enable_downvotes {
|
||||
return Err(ApiError::err_plain("downvotes_disabled").into());
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ pub struct Login {
|
|||
pub username_or_email: String,
|
||||
pub password: String,
|
||||
}
|
||||
use lemmy_db_schema::{CommunityId, PersonId, PersonMentionId, PrivateMessageId};
|
||||
use lemmy_db_schema::newtypes::{CommunityId, PersonId, PersonMentionId, PrivateMessageId};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Register {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use lemmy_db_schema::{CommunityId, PostId, PostReportId};
|
||||
use lemmy_db_schema::newtypes::{CommunityId, PostId, PostReportId};
|
||||
use lemmy_db_views::{
|
||||
comment_view::CommentView,
|
||||
post_report_view::PostReportView,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use lemmy_db_schema::{CommunityId, PersonId};
|
||||
use lemmy_db_schema::newtypes::{CommunityId, PersonId};
|
||||
use lemmy_db_views::{
|
||||
comment_view::CommentView,
|
||||
local_user_view::LocalUserSettingsView,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use lemmy_db_schema::{CommunityId, PostId};
|
||||
use lemmy_db_schema::newtypes::{CommunityId, PostId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
|
|
|
@ -9,7 +9,6 @@ license = "AGPL-3.0"
|
|||
lemmy_apub = { version = "=0.13.0", path = "../apub" }
|
||||
lemmy_apub_lib = { version = "=0.13.0", path = "../apub_lib" }
|
||||
lemmy_utils = { version = "=0.13.0", path = "../utils" }
|
||||
lemmy_db_queries = { version = "=0.13.0", path = "../db_queries" }
|
||||
lemmy_db_schema = { version = "=0.13.0", path = "../db_schema" }
|
||||
lemmy_db_views = { version = "=0.13.0", path = "../db_views" }
|
||||
lemmy_db_views_moderator = { version = "=0.13.0", path = "../db_views_moderator" }
|
||||
|
|
|
@ -21,12 +21,13 @@ use lemmy_apub::{
|
|||
generate_apub_endpoint,
|
||||
EndpointType,
|
||||
};
|
||||
use lemmy_db_queries::{
|
||||
source::{comment::Comment_, person_mention::PersonMention_},
|
||||
Crud,
|
||||
Likeable,
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
|
||||
person_mention::PersonMention,
|
||||
},
|
||||
traits::{Crud, Likeable},
|
||||
};
|
||||
use lemmy_db_schema::source::{comment::*, person_mention::PersonMention};
|
||||
use lemmy_db_views::comment_view::CommentView;
|
||||
use lemmy_utils::{
|
||||
utils::{remove_slurs, scrape_text_for_mentions},
|
||||
|
|
|
@ -9,8 +9,15 @@ use lemmy_api_common::{
|
|||
send_local_notifs,
|
||||
};
|
||||
use lemmy_apub::activities::deletion::{send_apub_delete, send_apub_remove};
|
||||
use lemmy_db_queries::{source::comment::Comment_, Crud};
|
||||
use lemmy_db_schema::source::{comment::*, community::Community, moderator::*, post::Post};
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
comment::Comment,
|
||||
community::Community,
|
||||
moderator::{ModRemoveComment, ModRemoveCommentForm},
|
||||
post::Post,
|
||||
},
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_db_views::comment_view::CommentView;
|
||||
use lemmy_utils::{ApiError, ConnectionId, LemmyError};
|
||||
use lemmy_websocket::{send::send_comment_ws_message, LemmyContext, UserOperationCrud};
|
||||
|
|
|
@ -2,7 +2,12 @@ use crate::PerformCrud;
|
|||
use actix_web::web::Data;
|
||||
use lemmy_api_common::{blocking, comment::*, get_local_user_view_from_jwt_opt};
|
||||
use lemmy_apub::{build_actor_id_from_shortname, EndpointType};
|
||||
use lemmy_db_queries::{from_opt_str_to_opt_enum, DeleteableOrRemoveable, ListingType, SortType};
|
||||
use lemmy_db_schema::{
|
||||
from_opt_str_to_opt_enum,
|
||||
traits::DeleteableOrRemoveable,
|
||||
ListingType,
|
||||
SortType,
|
||||
};
|
||||
use lemmy_db_views::comment_view::CommentQueryBuilder;
|
||||
use lemmy_utils::{ApiError, ConnectionId, LemmyError};
|
||||
use lemmy_websocket::LemmyContext;
|
||||
|
|
|
@ -13,8 +13,7 @@ use lemmy_apub::activities::{
|
|||
comment::create_or_update::CreateOrUpdateComment,
|
||||
CreateOrUpdateType,
|
||||
};
|
||||
use lemmy_db_queries::source::comment::Comment_;
|
||||
use lemmy_db_schema::source::comment::*;
|
||||
use lemmy_db_schema::source::comment::Comment;
|
||||
use lemmy_db_views::comment_view::CommentView;
|
||||
use lemmy_utils::{
|
||||
utils::{remove_slurs, scrape_text_for_mentions},
|
||||
|
|
|
@ -14,8 +14,9 @@ use lemmy_apub::{
|
|||
generate_shared_inbox_url,
|
||||
EndpointType,
|
||||
};
|
||||
use lemmy_db_queries::{diesel_option_overwrite_to_url, Crud, Followable, Joinable};
|
||||
use lemmy_db_schema::source::{
|
||||
use lemmy_db_schema::{
|
||||
diesel_option_overwrite_to_url,
|
||||
source::{
|
||||
community::{
|
||||
Community,
|
||||
CommunityFollower,
|
||||
|
@ -25,6 +26,8 @@ use lemmy_db_schema::source::{
|
|||
CommunityModeratorForm,
|
||||
},
|
||||
site::Site,
|
||||
},
|
||||
traits::{Crud, Followable, Joinable},
|
||||
};
|
||||
use lemmy_db_views_actor::community_view::CommunityView;
|
||||
use lemmy_utils::{
|
||||
|
|
|
@ -2,10 +2,12 @@ use crate::PerformCrud;
|
|||
use actix_web::web::Data;
|
||||
use lemmy_api_common::{blocking, community::*, get_local_user_view_from_jwt, is_admin};
|
||||
use lemmy_apub::activities::deletion::{send_apub_delete, send_apub_remove};
|
||||
use lemmy_db_queries::{source::community::Community_, Crud};
|
||||
use lemmy_db_schema::source::{
|
||||
community::*,
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
community::Community,
|
||||
moderator::{ModRemoveCommunity, ModRemoveCommunityForm},
|
||||
},
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_db_views_actor::community_moderator_view::CommunityModeratorView;
|
||||
use lemmy_utils::{utils::naive_from_unix, ApiError, ConnectionId, LemmyError};
|
||||
|
|
|
@ -2,8 +2,13 @@ use crate::PerformCrud;
|
|||
use actix_web::web::Data;
|
||||
use lemmy_api_common::{blocking, community::*, get_local_user_view_from_jwt_opt};
|
||||
use lemmy_apub::{build_actor_id_from_shortname, fetcher::object_id::ObjectId, EndpointType};
|
||||
use lemmy_db_queries::{from_opt_str_to_opt_enum, DeleteableOrRemoveable, ListingType, SortType};
|
||||
use lemmy_db_schema::source::community::*;
|
||||
use lemmy_db_schema::{
|
||||
from_opt_str_to_opt_enum,
|
||||
source::community::Community,
|
||||
traits::DeleteableOrRemoveable,
|
||||
ListingType,
|
||||
SortType,
|
||||
};
|
||||
use lemmy_db_views_actor::{
|
||||
community_moderator_view::CommunityModeratorView,
|
||||
community_view::{CommunityQueryBuilder, CommunityView},
|
||||
|
|
|
@ -6,11 +6,12 @@ use lemmy_api_common::{
|
|||
get_local_user_view_from_jwt,
|
||||
};
|
||||
use lemmy_apub::activities::community::update::UpdateCommunity;
|
||||
use lemmy_db_queries::{diesel_option_overwrite_to_url, Crud};
|
||||
use lemmy_db_schema::{
|
||||
diesel_option_overwrite_to_url,
|
||||
naive_now,
|
||||
newtypes::PersonId,
|
||||
source::community::{Community, CommunityForm},
|
||||
PersonId,
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_db_views_actor::community_moderator_view::CommunityModeratorView;
|
||||
use lemmy_utils::{utils::check_slurs_opt, ApiError, ConnectionId, LemmyError};
|
||||
|
|
|
@ -19,8 +19,10 @@ use lemmy_apub::{
|
|||
generate_apub_endpoint,
|
||||
EndpointType,
|
||||
};
|
||||
use lemmy_db_queries::{source::post::Post_, Crud, Likeable};
|
||||
use lemmy_db_schema::source::post::*;
|
||||
use lemmy_db_schema::{
|
||||
source::post::{Post, PostForm, PostLike, PostLikeForm},
|
||||
traits::{Crud, Likeable},
|
||||
};
|
||||
use lemmy_utils::{
|
||||
request::fetch_site_data,
|
||||
utils::{check_slurs, check_slurs_opt, clean_url_params, is_valid_post_title},
|
||||
|
|
|
@ -9,8 +9,14 @@ use lemmy_api_common::{
|
|||
post::*,
|
||||
};
|
||||
use lemmy_apub::activities::deletion::{send_apub_delete, send_apub_remove};
|
||||
use lemmy_db_queries::{source::post::Post_, Crud};
|
||||
use lemmy_db_schema::source::{community::Community, moderator::*, post::*};
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
community::Community,
|
||||
moderator::{ModRemovePost, ModRemovePostForm},
|
||||
post::Post,
|
||||
},
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_utils::{ApiError, ConnectionId, LemmyError};
|
||||
use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
|
||||
|
||||
|
|
|
@ -2,7 +2,12 @@ use crate::PerformCrud;
|
|||
use actix_web::web::Data;
|
||||
use lemmy_api_common::{blocking, get_local_user_view_from_jwt_opt, mark_post_as_read, post::*};
|
||||
use lemmy_apub::{build_actor_id_from_shortname, EndpointType};
|
||||
use lemmy_db_queries::{from_opt_str_to_opt_enum, DeleteableOrRemoveable, ListingType, SortType};
|
||||
use lemmy_db_schema::{
|
||||
from_opt_str_to_opt_enum,
|
||||
traits::DeleteableOrRemoveable,
|
||||
ListingType,
|
||||
SortType,
|
||||
};
|
||||
use lemmy_db_views::{
|
||||
comment_view::CommentQueryBuilder,
|
||||
post_view::{PostQueryBuilder, PostView},
|
||||
|
|
|
@ -8,8 +8,11 @@ use lemmy_api_common::{
|
|||
post::*,
|
||||
};
|
||||
use lemmy_apub::activities::{post::create_or_update::CreateOrUpdatePost, CreateOrUpdateType};
|
||||
use lemmy_db_queries::{source::post::Post_, Crud};
|
||||
use lemmy_db_schema::{naive_now, source::post::*};
|
||||
use lemmy_db_schema::{
|
||||
naive_now,
|
||||
source::post::{Post, PostForm},
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_utils::{
|
||||
request::fetch_site_data,
|
||||
utils::{check_slurs_opt, clean_url_params, is_valid_post_title},
|
||||
|
|
|
@ -15,8 +15,10 @@ use lemmy_apub::{
|
|||
generate_apub_endpoint,
|
||||
EndpointType,
|
||||
};
|
||||
use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud};
|
||||
use lemmy_db_schema::source::private_message::{PrivateMessage, PrivateMessageForm};
|
||||
use lemmy_db_schema::{
|
||||
source::private_message::{PrivateMessage, PrivateMessageForm},
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_db_views::local_user_view::LocalUserView;
|
||||
use lemmy_utils::{utils::remove_slurs, ApiError, ConnectionId, LemmyError};
|
||||
use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
|
||||
|
|
|
@ -9,8 +9,10 @@ use lemmy_apub::activities::private_message::{
|
|||
delete::DeletePrivateMessage as DeletePrivateMessageApub,
|
||||
undo_delete::UndoDeletePrivateMessage,
|
||||
};
|
||||
use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud, DeleteableOrRemoveable};
|
||||
use lemmy_db_schema::source::private_message::PrivateMessage;
|
||||
use lemmy_db_schema::{
|
||||
source::private_message::PrivateMessage,
|
||||
traits::{Crud, DeleteableOrRemoveable},
|
||||
};
|
||||
use lemmy_utils::{ApiError, ConnectionId, LemmyError};
|
||||
use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ use lemmy_api_common::{
|
|||
get_local_user_view_from_jwt,
|
||||
person::{GetPrivateMessages, PrivateMessagesResponse},
|
||||
};
|
||||
use lemmy_db_queries::DeleteableOrRemoveable;
|
||||
use lemmy_db_schema::traits::DeleteableOrRemoveable;
|
||||
use lemmy_db_views::private_message_view::PrivateMessageQueryBuilder;
|
||||
use lemmy_utils::{ConnectionId, LemmyError};
|
||||
use lemmy_websocket::LemmyContext;
|
||||
|
|
|
@ -9,8 +9,7 @@ use lemmy_apub::activities::{
|
|||
private_message::create_or_update::CreateOrUpdatePrivateMessage,
|
||||
CreateOrUpdateType,
|
||||
};
|
||||
use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud};
|
||||
use lemmy_db_schema::source::private_message::PrivateMessage;
|
||||
use lemmy_db_schema::{source::private_message::PrivateMessage, traits::Crud};
|
||||
use lemmy_utils::{utils::remove_slurs, ApiError, ConnectionId, LemmyError};
|
||||
use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
|
||||
|
||||
|
|
|
@ -7,13 +7,12 @@ use lemmy_api_common::{
|
|||
site::*,
|
||||
site_description_length_check,
|
||||
};
|
||||
use lemmy_db_queries::{
|
||||
use lemmy_db_schema::{
|
||||
diesel_option_overwrite,
|
||||
diesel_option_overwrite_to_url,
|
||||
source::site::Site_,
|
||||
Crud,
|
||||
source::site::{Site, SiteForm},
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_db_schema::source::site::{Site, *};
|
||||
use lemmy_db_views::site_view::SiteView;
|
||||
use lemmy_utils::{
|
||||
utils::{check_slurs, check_slurs_opt},
|
||||
|
@ -34,7 +33,7 @@ impl PerformCrud for CreateSite {
|
|||
) -> Result<SiteResponse, LemmyError> {
|
||||
let data: &CreateSite = self;
|
||||
|
||||
let read_site = move |conn: &'_ _| Site::read_simple(conn);
|
||||
let read_site = Site::read_simple;
|
||||
if blocking(context.pool(), read_site).await?.is_ok() {
|
||||
return Err(ApiError::err_plain("site_already_exists").into());
|
||||
};
|
||||
|
|
|
@ -7,15 +7,12 @@ use lemmy_api_common::{
|
|||
site::{EditSite, SiteResponse},
|
||||
site_description_length_check,
|
||||
};
|
||||
use lemmy_db_queries::{
|
||||
use lemmy_db_schema::{
|
||||
diesel_option_overwrite,
|
||||
diesel_option_overwrite_to_url,
|
||||
source::site::Site_,
|
||||
Crud,
|
||||
};
|
||||
use lemmy_db_schema::{
|
||||
naive_now,
|
||||
source::site::{Site, SiteForm},
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_db_views::site_view::SiteView;
|
||||
use lemmy_utils::{utils::check_slurs_opt, ApiError, ConnectionId, LemmyError};
|
||||
|
@ -39,7 +36,7 @@ impl PerformCrud for EditSite {
|
|||
// Make sure user is an admin
|
||||
is_admin(&local_user_view)?;
|
||||
|
||||
let found_site = blocking(context.pool(), move |conn| Site::read_simple(conn)).await??;
|
||||
let found_site = blocking(context.pool(), Site::read_simple).await??;
|
||||
|
||||
let sidebar = diesel_option_overwrite(&data.sidebar);
|
||||
let description = diesel_option_overwrite(&data.description);
|
||||
|
|
|
@ -8,23 +8,25 @@ use lemmy_apub::{
|
|||
generate_shared_inbox_url,
|
||||
EndpointType,
|
||||
};
|
||||
use lemmy_db_queries::{
|
||||
source::{local_user::LocalUser_, site::Site_},
|
||||
Crud,
|
||||
Followable,
|
||||
Joinable,
|
||||
use lemmy_db_schema::{
|
||||
newtypes::CommunityId,
|
||||
source::{
|
||||
community::{
|
||||
Community,
|
||||
CommunityFollower,
|
||||
CommunityFollowerForm,
|
||||
CommunityForm,
|
||||
CommunityModerator,
|
||||
CommunityModeratorForm,
|
||||
},
|
||||
local_user::{LocalUser, LocalUserForm},
|
||||
person::{Person, PersonForm},
|
||||
site::Site,
|
||||
},
|
||||
traits::{Crud, Followable, Joinable},
|
||||
ListingType,
|
||||
SortType,
|
||||
};
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
community::*,
|
||||
local_user::{LocalUser, LocalUserForm},
|
||||
person::*,
|
||||
site::*,
|
||||
},
|
||||
CommunityId,
|
||||
};
|
||||
use lemmy_db_views_actor::person_view::PersonViewSafe;
|
||||
use lemmy_utils::{
|
||||
apub::generate_actor_keypair,
|
||||
|
@ -48,7 +50,7 @@ impl PerformCrud for Register {
|
|||
let data: &Register = self;
|
||||
|
||||
// Make sure site has open registration
|
||||
if let Ok(site) = blocking(context.pool(), move |conn| Site::read_simple(conn)).await? {
|
||||
if let Ok(site) = blocking(context.pool(), Site::read_simple).await? {
|
||||
if !site.open_registration {
|
||||
return Err(ApiError::err_plain("registration_closed").into());
|
||||
}
|
||||
|
|
|
@ -2,8 +2,7 @@ use crate::PerformCrud;
|
|||
use actix_web::web::Data;
|
||||
use bcrypt::verify;
|
||||
use lemmy_api_common::{blocking, get_local_user_view_from_jwt, person::*};
|
||||
use lemmy_db_queries::source::{comment::Comment_, person::Person_, post::Post_};
|
||||
use lemmy_db_schema::source::{comment::Comment, person::*, post::Post};
|
||||
use lemmy_db_schema::source::{comment::Comment, person::Person, post::Post};
|
||||
use lemmy_utils::{ApiError, ConnectionId, LemmyError};
|
||||
use lemmy_websocket::LemmyContext;
|
||||
|
||||
|
|
|
@ -2,8 +2,7 @@ use crate::PerformCrud;
|
|||
use actix_web::web::Data;
|
||||
use lemmy_api_common::{blocking, get_local_user_view_from_jwt_opt, person::*};
|
||||
use lemmy_apub::{build_actor_id_from_shortname, fetcher::object_id::ObjectId, EndpointType};
|
||||
use lemmy_db_queries::{from_opt_str_to_opt_enum, SortType};
|
||||
use lemmy_db_schema::source::person::*;
|
||||
use lemmy_db_schema::{from_opt_str_to_opt_enum, source::person::Person, SortType};
|
||||
use lemmy_db_views::{comment_view::CommentQueryBuilder, post_view::PostQueryBuilder};
|
||||
use lemmy_db_views_actor::{
|
||||
community_moderator_view::CommunityModeratorView,
|
||||
|
|
|
@ -13,7 +13,6 @@ doctest = false
|
|||
[dependencies]
|
||||
lemmy_utils = { version = "=0.13.0", path = "../utils" }
|
||||
lemmy_apub_lib = { version = "=0.13.0", path = "../apub_lib" }
|
||||
lemmy_db_queries = { version = "=0.13.0", path = "../db_queries" }
|
||||
lemmy_db_schema = { version = "=0.13.0", path = "../db_schema" }
|
||||
lemmy_db_views = { version = "=0.13.0", path = "../db_views" }
|
||||
lemmy_db_views_actor = { version = "=0.13.0", path = "../db_views_actor" }
|
||||
|
|
|
@ -21,8 +21,10 @@ use lemmy_apub_lib::{
|
|||
values::PublicUrl,
|
||||
verify::verify_domains_match,
|
||||
};
|
||||
use lemmy_db_queries::Crud;
|
||||
use lemmy_db_schema::source::{comment::Comment, community::Community, person::Person, post::Post};
|
||||
use lemmy_db_schema::{
|
||||
source::{comment::Comment, community::Community, person::Person, post::Post},
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::{send::send_comment_ws_message, LemmyContext, UserOperationCrud};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
|
@ -7,10 +7,11 @@ use anyhow::anyhow;
|
|||
use itertools::Itertools;
|
||||
use lemmy_api_common::{blocking, send_local_notifs};
|
||||
use lemmy_apub_lib::{traits::ActorType, webfinger::WebfingerResponse};
|
||||
use lemmy_db_queries::{Crud, DbPool};
|
||||
use lemmy_db_schema::{
|
||||
newtypes::LocalUserId,
|
||||
source::{comment::Comment, community::Community, person::Person, post::Post},
|
||||
LocalUserId,
|
||||
traits::Crud,
|
||||
DbPool,
|
||||
};
|
||||
use lemmy_utils::{
|
||||
request::{retry, RecvError},
|
||||
|
|
|
@ -23,10 +23,12 @@ use lemmy_apub_lib::{
|
|||
traits::{ActivityFields, ActivityHandler, ActorType},
|
||||
values::PublicUrl,
|
||||
};
|
||||
use lemmy_db_queries::{source::community::CommunityModerator_, Joinable};
|
||||
use lemmy_db_schema::source::{
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
community::{Community, CommunityModerator, CommunityModeratorForm},
|
||||
person::Person,
|
||||
},
|
||||
traits::Joinable,
|
||||
};
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::LemmyContext;
|
||||
|
|
|
@ -21,8 +21,8 @@ use lemmy_apub_lib::{
|
|||
traits::{ActivityFields, ActivityHandler, ActorType},
|
||||
values::PublicUrl,
|
||||
};
|
||||
use lemmy_db_queries::{Bannable, Followable};
|
||||
use lemmy_db_schema::source::{
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
community::{
|
||||
Community,
|
||||
CommunityFollower,
|
||||
|
@ -31,6 +31,8 @@ use lemmy_db_schema::source::{
|
|||
CommunityPersonBanForm,
|
||||
},
|
||||
person::Person,
|
||||
},
|
||||
traits::{Bannable, Followable},
|
||||
};
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::LemmyContext;
|
||||
|
|
|
@ -24,10 +24,12 @@ use lemmy_apub_lib::{
|
|||
traits::{ActivityFields, ActivityHandler, ActorType},
|
||||
values::PublicUrl,
|
||||
};
|
||||
use lemmy_db_queries::Joinable;
|
||||
use lemmy_db_schema::source::{
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
community::{Community, CommunityModerator, CommunityModeratorForm},
|
||||
person::Person,
|
||||
},
|
||||
traits::Joinable,
|
||||
};
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::LemmyContext;
|
||||
|
|
|
@ -25,10 +25,12 @@ use lemmy_apub_lib::{
|
|||
traits::{ActivityFields, ActivityHandler, ActorType},
|
||||
values::PublicUrl,
|
||||
};
|
||||
use lemmy_db_queries::Bannable;
|
||||
use lemmy_db_schema::source::{
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
community::{Community, CommunityPersonBan, CommunityPersonBanForm},
|
||||
person::Person,
|
||||
},
|
||||
traits::Bannable,
|
||||
};
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::LemmyContext;
|
||||
|
|
|
@ -22,10 +22,12 @@ use lemmy_apub_lib::{
|
|||
traits::{ActivityFields, ActivityHandler, ActorType},
|
||||
values::PublicUrl,
|
||||
};
|
||||
use lemmy_db_queries::Crud;
|
||||
use lemmy_db_schema::source::{
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
community::{Community, CommunityForm},
|
||||
person::Person,
|
||||
},
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::{send::send_community_ws_message, LemmyContext, UserOperationCrud};
|
||||
|
|
|
@ -26,11 +26,8 @@ use lemmy_apub_lib::{
|
|||
traits::{ActivityFields, ActivityHandler, ActorType},
|
||||
values::PublicUrl,
|
||||
};
|
||||
use lemmy_db_queries::{
|
||||
source::{comment::Comment_, community::Community_, post::Post_},
|
||||
Crud,
|
||||
};
|
||||
use lemmy_db_schema::source::{
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
comment::Comment,
|
||||
community::Community,
|
||||
moderator::{
|
||||
|
@ -43,6 +40,8 @@ use lemmy_db_schema::source::{
|
|||
},
|
||||
person::Person,
|
||||
post::Post,
|
||||
},
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::{
|
||||
|
|
|
@ -12,7 +12,6 @@ use lemmy_apub_lib::{
|
|||
traits::{ActivityFields, ActorType, ApubObject},
|
||||
verify::verify_domains_match,
|
||||
};
|
||||
use lemmy_db_queries::source::{comment::Comment_, community::Community_, post::Post_};
|
||||
use lemmy_db_schema::source::{comment::Comment, community::Community, person::Person, post::Post};
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::{
|
||||
|
|
|
@ -27,7 +27,6 @@ use lemmy_apub_lib::{
|
|||
traits::{ActivityFields, ActivityHandler, ActorType},
|
||||
values::PublicUrl,
|
||||
};
|
||||
use lemmy_db_queries::source::{comment::Comment_, community::Community_, post::Post_};
|
||||
use lemmy_db_schema::source::{comment::Comment, community::Community, person::Person, post::Post};
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::{
|
||||
|
|
|
@ -21,10 +21,12 @@ use lemmy_apub_lib::{
|
|||
traits::{ActivityFields, ActivityHandler, ActorType},
|
||||
verify::verify_urls_match,
|
||||
};
|
||||
use lemmy_db_queries::Followable;
|
||||
use lemmy_db_schema::source::{
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
community::{Community, CommunityFollower},
|
||||
person::Person,
|
||||
},
|
||||
traits::Followable,
|
||||
};
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::LemmyContext;
|
||||
|
|
|
@ -21,10 +21,12 @@ use lemmy_apub_lib::{
|
|||
traits::{ActivityFields, ActivityHandler, ActorType},
|
||||
verify::verify_urls_match,
|
||||
};
|
||||
use lemmy_db_queries::Followable;
|
||||
use lemmy_db_schema::source::{
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
community::{Community, CommunityFollower, CommunityFollowerForm},
|
||||
person::Person,
|
||||
},
|
||||
traits::Followable,
|
||||
};
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::LemmyContext;
|
||||
|
|
|
@ -21,10 +21,12 @@ use lemmy_apub_lib::{
|
|||
traits::{ActivityFields, ActivityHandler, ActorType},
|
||||
verify::verify_urls_match,
|
||||
};
|
||||
use lemmy_db_queries::Followable;
|
||||
use lemmy_db_schema::source::{
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
community::{Community, CommunityFollower, CommunityFollowerForm},
|
||||
person::Person,
|
||||
},
|
||||
traits::Followable,
|
||||
};
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::LemmyContext;
|
||||
|
|
|
@ -21,8 +21,10 @@ use lemmy_apub_lib::{
|
|||
values::PublicUrl,
|
||||
verify::{verify_domains_match, verify_urls_match},
|
||||
};
|
||||
use lemmy_db_queries::Crud;
|
||||
use lemmy_db_schema::source::{community::Community, person::Person, post::Post};
|
||||
use lemmy_db_schema::{
|
||||
source::{community::Community, person::Person, post::Post},
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
|
@ -12,8 +12,10 @@ use lemmy_apub_lib::{
|
|||
traits::{ActivityFields, ActivityHandler, ActorType},
|
||||
verify::verify_domains_match,
|
||||
};
|
||||
use lemmy_db_queries::Crud;
|
||||
use lemmy_db_schema::source::{person::Person, private_message::PrivateMessage};
|
||||
use lemmy_db_schema::{
|
||||
source::{person::Person, private_message::PrivateMessage},
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
|
@ -16,8 +16,10 @@ use lemmy_apub_lib::{
|
|||
traits::{ActivityFields, ActivityHandler, ActorType},
|
||||
verify::verify_domains_match,
|
||||
};
|
||||
use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud};
|
||||
use lemmy_db_schema::source::{person::Person, private_message::PrivateMessage};
|
||||
use lemmy_db_schema::{
|
||||
source::{person::Person, private_message::PrivateMessage},
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
|
@ -21,8 +21,10 @@ use lemmy_apub_lib::{
|
|||
traits::{ActivityFields, ActivityHandler, ActorType},
|
||||
verify::{verify_domains_match, verify_urls_match},
|
||||
};
|
||||
use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud};
|
||||
use lemmy_db_schema::source::{person::Person, private_message::PrivateMessage};
|
||||
use lemmy_db_schema::{
|
||||
source::{person::Person, private_message::PrivateMessage},
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
|
@ -16,15 +16,15 @@ use lemmy_apub_lib::{
|
|||
data::Data,
|
||||
traits::{ActivityFields, ActivityHandler, ActorType},
|
||||
};
|
||||
use lemmy_db_queries::{Crud, Reportable};
|
||||
use lemmy_db_schema::{
|
||||
newtypes::CommunityId,
|
||||
source::{
|
||||
comment_report::{CommentReport, CommentReportForm},
|
||||
community::Community,
|
||||
person::Person,
|
||||
post_report::{PostReport, PostReportForm},
|
||||
},
|
||||
CommunityId,
|
||||
traits::{Crud, Reportable},
|
||||
};
|
||||
use lemmy_db_views::{comment_report_view::CommentReportView, post_report_view::PostReportView};
|
||||
use lemmy_utils::LemmyError;
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
use crate::activities::voting::vote::VoteType;
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_db_queries::Likeable;
|
||||
use lemmy_db_schema::source::{
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
comment::{Comment, CommentLike, CommentLikeForm},
|
||||
person::Person,
|
||||
post::{Post, PostLike, PostLikeForm},
|
||||
},
|
||||
traits::Likeable,
|
||||
};
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::{
|
||||
|
|
|
@ -27,10 +27,10 @@ use lemmy_apub_lib::{
|
|||
values::PublicUrl,
|
||||
verify::verify_urls_match,
|
||||
};
|
||||
use lemmy_db_queries::Crud;
|
||||
use lemmy_db_schema::{
|
||||
newtypes::CommunityId,
|
||||
source::{community::Community, person::Person},
|
||||
CommunityId,
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::LemmyContext;
|
||||
|
|
|
@ -18,10 +18,10 @@ use lemmy_apub_lib::{
|
|||
traits::{ActivityFields, ActivityHandler, ActorType},
|
||||
values::PublicUrl,
|
||||
};
|
||||
use lemmy_db_queries::Crud;
|
||||
use lemmy_db_schema::{
|
||||
newtypes::CommunityId,
|
||||
source::{community::Community, person::Person},
|
||||
CommunityId,
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::LemmyContext;
|
||||
|
|
|
@ -7,10 +7,12 @@ use activitystreams::collection::{CollectionExt, OrderedCollection};
|
|||
use anyhow::Context;
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::{data::Data, traits::ActivityHandler};
|
||||
use lemmy_db_queries::Joinable;
|
||||
use lemmy_db_schema::source::{
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
community::{Community, CommunityModerator, CommunityModeratorForm},
|
||||
person::Person,
|
||||
},
|
||||
traits::Joinable,
|
||||
};
|
||||
use lemmy_db_views_actor::community_moderator_view::CommunityModeratorView;
|
||||
use lemmy_utils::{location_info, LemmyError};
|
||||
|
|
|
@ -3,8 +3,7 @@ use anyhow::anyhow;
|
|||
use diesel::{NotFound, PgConnection};
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::{traits::ApubObject, APUB_JSON_CONTENT_TYPE};
|
||||
use lemmy_db_queries::DbPool;
|
||||
use lemmy_db_schema::DbUrl;
|
||||
use lemmy_db_schema::{newtypes::DbUrl, DbPool};
|
||||
use lemmy_utils::{request::retry, settings::structs::Settings, LemmyError};
|
||||
use lemmy_websocket::LemmyContext;
|
||||
use reqwest::StatusCode;
|
||||
|
|
|
@ -11,11 +11,10 @@ use lemmy_apub_lib::{
|
|||
traits::ApubObject,
|
||||
webfinger::{webfinger_resolve_actor, WebfingerType},
|
||||
};
|
||||
use lemmy_db_queries::{
|
||||
source::{community::Community_, person::Person_},
|
||||
use lemmy_db_schema::{
|
||||
source::{comment::Comment, community::Community, person::Person, post::Post},
|
||||
DbPool,
|
||||
};
|
||||
use lemmy_db_schema::source::{comment::Comment, community::Community, person::Person, post::Post};
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::LemmyContext;
|
||||
use serde::Deserialize;
|
||||
|
|
|
@ -5,8 +5,7 @@ use crate::{
|
|||
use actix_web::{body::Body, web, web::Path, HttpResponse};
|
||||
use diesel::result::Error::NotFound;
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_db_queries::Crud;
|
||||
use lemmy_db_schema::{source::comment::Comment, CommentId};
|
||||
use lemmy_db_schema::{newtypes::CommentId, source::comment::Comment, traits::Crud};
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::LemmyContext;
|
||||
use serde::Deserialize;
|
||||
|
|
|
@ -24,7 +24,6 @@ use activitystreams::{
|
|||
use actix_web::{body::Body, web, web::Payload, HttpRequest, HttpResponse};
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::traits::{ActivityFields, ActivityHandler};
|
||||
use lemmy_db_queries::source::{activity::Activity_, community::Community_};
|
||||
use lemmy_db_schema::source::{activity::Activity, community::Community};
|
||||
use lemmy_db_views_actor::{
|
||||
community_follower_view::CommunityFollowerView,
|
||||
|
|
|
@ -24,8 +24,7 @@ use lemmy_apub_lib::{
|
|||
traits::{ActivityFields, ActivityHandler},
|
||||
APUB_JSON_CONTENT_TYPE,
|
||||
};
|
||||
use lemmy_db_queries::{source::activity::Activity_, DbPool};
|
||||
use lemmy_db_schema::source::activity::Activity;
|
||||
use lemmy_db_schema::{source::activity::Activity, DbPool};
|
||||
use lemmy_utils::{location_info, LemmyError};
|
||||
use lemmy_websocket::LemmyContext;
|
||||
use log::{info, trace};
|
||||
|
|
|
@ -25,7 +25,6 @@ use activitystreams::{
|
|||
use actix_web::{body::Body, web, web::Payload, HttpRequest, HttpResponse};
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::traits::{ActivityFields, ActivityHandler};
|
||||
use lemmy_db_queries::source::person::Person_;
|
||||
use lemmy_db_schema::source::person::Person;
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::LemmyContext;
|
||||
|
|
|
@ -5,8 +5,7 @@ use crate::{
|
|||
use actix_web::{body::Body, web, HttpResponse};
|
||||
use diesel::result::Error::NotFound;
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_db_queries::Crud;
|
||||
use lemmy_db_schema::{source::post::Post, PostId};
|
||||
use lemmy_db_schema::{newtypes::PostId, source::post::Post, traits::Crud};
|
||||
use lemmy_utils::LemmyError;
|
||||
use lemmy_websocket::LemmyContext;
|
||||
use serde::Deserialize;
|
||||
|
|
|
@ -9,11 +9,10 @@ use crate::fetcher::post_or_comment::PostOrComment;
|
|||
use anyhow::{anyhow, Context};
|
||||
use lemmy_api_common::blocking;
|
||||
use lemmy_apub_lib::{activity_queue::send_activity, traits::ActorType};
|
||||
use lemmy_db_queries::{source::activity::Activity_, DbPool};
|
||||
use lemmy_db_schema::{
|
||||
newtypes::{CommunityId, DbUrl},
|
||||
source::{activity::Activity, person::Person},
|
||||
CommunityId,
|
||||
DbUrl,
|
||||
DbPool,
|
||||
};
|
||||
use lemmy_db_views_actor::community_person_ban_view::CommunityPersonBanView;
|
||||
use lemmy_utils::{location_info, settings::structs::Settings, LemmyError};
|
||||
|
|
|
@ -20,15 +20,16 @@ use lemmy_apub_lib::{
|
|||
values::{MediaTypeHtml, MediaTypeMarkdown, PublicUrl},
|
||||
verify::verify_domains_match,
|
||||
};
|
||||
use lemmy_db_queries::{source::comment::Comment_, Crud, DbPool};
|
||||
use lemmy_db_schema::{
|
||||
newtypes::CommentId,
|
||||
source::{
|
||||
comment::{Comment, CommentForm},
|
||||
community::Community,
|
||||
person::Person,
|
||||
post::Post,
|
||||
},
|
||||
CommentId,
|
||||
traits::Crud,
|
||||
DbPool,
|
||||
};
|
||||
use lemmy_utils::{
|
||||
location_info,
|
||||
|
|
|
@ -23,10 +23,10 @@ use lemmy_apub_lib::{
|
|||
values::{MediaTypeHtml, MediaTypeMarkdown},
|
||||
verify::verify_domains_match,
|
||||
};
|
||||
use lemmy_db_queries::{source::community::Community_, DbPool};
|
||||
use lemmy_db_schema::{
|
||||
naive_now,
|
||||
source::community::{Community, CommunityForm},
|
||||
DbPool,
|
||||
};
|
||||
use lemmy_db_views_actor::community_follower_view::CommunityFollowerView;
|
||||
use lemmy_utils::{
|
||||
|
|
|
@ -5,7 +5,7 @@ use activitystreams::{
|
|||
use anyhow::anyhow;
|
||||
use chrono::NaiveDateTime;
|
||||
use lemmy_apub_lib::values::MediaTypeMarkdown;
|
||||
use lemmy_db_queries::DbPool;
|
||||
use lemmy_db_schema::DbPool;
|
||||
use lemmy_utils::{utils::convert_datetime, LemmyError};
|
||||
use lemmy_websocket::LemmyContext;
|
||||
use url::Url;
|
||||
|
|
|
@ -19,10 +19,10 @@ use lemmy_apub_lib::{
|
|||
values::{MediaTypeHtml, MediaTypeMarkdown},
|
||||
verify::verify_domains_match,
|
||||
};
|
||||
use lemmy_db_queries::{source::person::Person_, DbPool};
|
||||
use lemmy_db_schema::{
|
||||
naive_now,
|
||||
source::person::{Person as DbPerson, PersonForm},
|
||||
DbPool,
|
||||
};
|
||||
use lemmy_utils::{
|
||||
utils::{check_slurs, check_slurs_opt, convert_datetime, markdown_to_html},
|
||||
|
|
|
@ -21,7 +21,6 @@ use lemmy_apub_lib::{
|
|||
values::{MediaTypeHtml, MediaTypeMarkdown},
|
||||
verify::verify_domains_match,
|
||||
};
|
||||
use lemmy_db_queries::{source::post::Post_, Crud, DbPool};
|
||||
use lemmy_db_schema::{
|
||||
self,
|
||||
source::{
|
||||
|
@ -29,6 +28,8 @@ use lemmy_db_schema::{
|
|||
person::Person,
|
||||
post::{Post, PostForm},
|
||||
},
|
||||
traits::Crud,
|
||||
DbPool,
|
||||
};
|
||||
use lemmy_utils::{
|
||||
request::fetch_site_data,
|
||||
|
|
|
@ -16,10 +16,13 @@ use lemmy_apub_lib::{
|
|||
values::{MediaTypeHtml, MediaTypeMarkdown},
|
||||
verify::verify_domains_match,
|
||||
};
|
||||
use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud, DbPool};
|
||||
use lemmy_db_schema::source::{
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
person::Person,
|
||||
private_message::{PrivateMessage, PrivateMessageForm},
|
||||
},
|
||||
traits::Crud,
|
||||
DbPool,
|
||||
};
|
||||
use lemmy_utils::{utils::convert_datetime, LemmyError};
|
||||
use lemmy_websocket::LemmyContext;
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
[package]
|
||||
name = "lemmy_db_queries"
|
||||
version = "0.13.0"
|
||||
edition = "2018"
|
||||
description = "A link aggregator for the fediverse"
|
||||
license = "AGPL-3.0"
|
||||
|
||||
[lib]
|
||||
name = "lemmy_db_queries"
|
||||
path = "src/lib.rs"
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
lemmy_utils = { version = "=0.13.0", path = "../utils" }
|
||||
lemmy_db_schema = { version = "=0.13.0", path = "../db_schema" }
|
||||
diesel = { version = "1.4.8", features = ["postgres","chrono","r2d2","serde_json"] }
|
||||
diesel_migrations = "1.4.0"
|
||||
chrono = { version = "0.4.19", features = ["serde"] }
|
||||
serde = { version = "1.0.130", features = ["derive"] }
|
||||
serde_json = { version = "1.0.68", features = ["preserve_order"] }
|
||||
strum = "0.21.0"
|
||||
strum_macros = "0.21.1"
|
||||
log = "0.4.14"
|
||||
sha2 = "0.9.8"
|
||||
url = { version = "2.2.2", features = ["serde"] }
|
||||
lazy_static = "1.4.0"
|
||||
regex = "1.5.4"
|
||||
bcrypt = "0.10.1"
|
||||
|
||||
[dev-dependencies]
|
||||
serial_test = "0.5.1"
|
|
@ -1,348 +0,0 @@
|
|||
#[macro_use]
|
||||
extern crate diesel;
|
||||
#[macro_use]
|
||||
extern crate strum_macros;
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
// this is used in tests
|
||||
#[allow(unused_imports)]
|
||||
#[macro_use]
|
||||
extern crate diesel_migrations;
|
||||
|
||||
#[cfg(test)]
|
||||
extern crate serial_test;
|
||||
|
||||
use diesel::{result::Error, *};
|
||||
use lemmy_db_schema::{CommunityId, DbUrl, PersonId};
|
||||
use lemmy_utils::ApiError;
|
||||
use regex::Regex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{env, env::VarError};
|
||||
use url::Url;
|
||||
|
||||
pub mod aggregates;
|
||||
pub mod source;
|
||||
|
||||
pub type DbPool = diesel::r2d2::Pool<diesel::r2d2::ConnectionManager<diesel::PgConnection>>;
|
||||
|
||||
pub trait Crud {
|
||||
type Form;
|
||||
type IdType;
|
||||
fn create(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
|
||||
where
|
||||
Self: Sized;
|
||||
fn read(conn: &PgConnection, id: Self::IdType) -> Result<Self, Error>
|
||||
where
|
||||
Self: Sized;
|
||||
fn update(conn: &PgConnection, id: Self::IdType, form: &Self::Form) -> Result<Self, Error>
|
||||
where
|
||||
Self: Sized;
|
||||
fn delete(_conn: &PgConnection, _id: Self::IdType) -> Result<usize, Error>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Followable {
|
||||
type Form;
|
||||
fn follow(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
|
||||
where
|
||||
Self: Sized;
|
||||
fn follow_accepted(
|
||||
conn: &PgConnection,
|
||||
community_id: CommunityId,
|
||||
person_id: PersonId,
|
||||
) -> Result<Self, Error>
|
||||
where
|
||||
Self: Sized;
|
||||
fn unfollow(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
|
||||
where
|
||||
Self: Sized;
|
||||
fn has_local_followers(conn: &PgConnection, community_id: CommunityId) -> Result<bool, Error>;
|
||||
}
|
||||
|
||||
pub trait Joinable {
|
||||
type Form;
|
||||
fn join(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
|
||||
where
|
||||
Self: Sized;
|
||||
fn leave(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
||||
pub trait Likeable {
|
||||
type Form;
|
||||
type IdType;
|
||||
fn like(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
|
||||
where
|
||||
Self: Sized;
|
||||
fn remove(
|
||||
conn: &PgConnection,
|
||||
person_id: PersonId,
|
||||
item_id: Self::IdType,
|
||||
) -> Result<usize, Error>
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
||||
pub trait Bannable {
|
||||
type Form;
|
||||
fn ban(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
|
||||
where
|
||||
Self: Sized;
|
||||
fn unban(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
||||
pub trait Saveable {
|
||||
type Form;
|
||||
fn save(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
|
||||
where
|
||||
Self: Sized;
|
||||
fn unsave(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
||||
pub trait Blockable {
|
||||
type Form;
|
||||
fn block(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
|
||||
where
|
||||
Self: Sized;
|
||||
fn unblock(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
||||
pub trait Readable {
|
||||
type Form;
|
||||
fn mark_as_read(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
|
||||
where
|
||||
Self: Sized;
|
||||
fn mark_as_unread(conn: &PgConnection, form: &Self::Form) -> Result<usize, Error>
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
||||
pub trait Reportable {
|
||||
type Form;
|
||||
type IdType;
|
||||
fn report(conn: &PgConnection, form: &Self::Form) -> Result<Self, Error>
|
||||
where
|
||||
Self: Sized;
|
||||
fn resolve(
|
||||
conn: &PgConnection,
|
||||
report_id: Self::IdType,
|
||||
resolver_id: PersonId,
|
||||
) -> Result<usize, Error>
|
||||
where
|
||||
Self: Sized;
|
||||
fn unresolve(
|
||||
conn: &PgConnection,
|
||||
report_id: Self::IdType,
|
||||
resolver_id: PersonId,
|
||||
) -> Result<usize, Error>
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
||||
pub trait DeleteableOrRemoveable {
|
||||
fn blank_out_deleted_or_removed_info(self) -> Self;
|
||||
}
|
||||
|
||||
pub trait MaybeOptional<T> {
|
||||
fn get_optional(self) -> Option<T>;
|
||||
}
|
||||
|
||||
impl<T> MaybeOptional<T> for T {
|
||||
fn get_optional(self) -> Option<T> {
|
||||
Some(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> MaybeOptional<T> for Option<T> {
|
||||
fn get_optional(self) -> Option<T> {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ToSafe {
|
||||
type SafeColumns;
|
||||
fn safe_columns_tuple() -> Self::SafeColumns;
|
||||
}
|
||||
|
||||
pub trait ToSafeSettings {
|
||||
type SafeSettingsColumns;
|
||||
fn safe_settings_columns_tuple() -> Self::SafeSettingsColumns;
|
||||
}
|
||||
|
||||
pub trait ViewToVec {
|
||||
type DbTuple;
|
||||
fn from_tuple_to_vec(tuple: Vec<Self::DbTuple>) -> Vec<Self>
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
||||
pub fn get_database_url_from_env() -> Result<String, VarError> {
|
||||
env::var("LEMMY_DATABASE_URL")
|
||||
}
|
||||
|
||||
#[derive(EnumString, ToString, Debug, Serialize, Deserialize, Clone, Copy)]
|
||||
pub enum SortType {
|
||||
Active,
|
||||
Hot,
|
||||
New,
|
||||
TopDay,
|
||||
TopWeek,
|
||||
TopMonth,
|
||||
TopYear,
|
||||
TopAll,
|
||||
MostComments,
|
||||
NewComments,
|
||||
}
|
||||
|
||||
#[derive(EnumString, ToString, Debug, Serialize, Deserialize, Clone, Copy)]
|
||||
pub enum ListingType {
|
||||
All,
|
||||
Local,
|
||||
Subscribed,
|
||||
Community,
|
||||
}
|
||||
|
||||
#[derive(EnumString, ToString, Debug, Serialize, Deserialize, Clone, Copy)]
|
||||
pub enum SearchType {
|
||||
All,
|
||||
Comments,
|
||||
Posts,
|
||||
Communities,
|
||||
Users,
|
||||
Url,
|
||||
}
|
||||
|
||||
pub fn from_opt_str_to_opt_enum<T: std::str::FromStr>(opt: &Option<String>) -> Option<T> {
|
||||
opt.as_ref().map(|t| T::from_str(t).ok()).flatten()
|
||||
}
|
||||
|
||||
pub fn fuzzy_search(q: &str) -> String {
|
||||
let replaced = q.replace(" ", "%");
|
||||
format!("%{}%", replaced)
|
||||
}
|
||||
|
||||
pub fn limit_and_offset(page: Option<i64>, limit: Option<i64>) -> (i64, i64) {
|
||||
let page = page.unwrap_or(1);
|
||||
let limit = limit.unwrap_or(10);
|
||||
let offset = limit * (page - 1);
|
||||
(limit, offset)
|
||||
}
|
||||
|
||||
pub fn is_email_regex(test: &str) -> bool {
|
||||
EMAIL_REGEX.is_match(test)
|
||||
}
|
||||
|
||||
pub fn diesel_option_overwrite(opt: &Option<String>) -> Option<Option<String>> {
|
||||
match opt {
|
||||
// An empty string is an erase
|
||||
Some(unwrapped) => {
|
||||
if !unwrapped.eq("") {
|
||||
Some(Some(unwrapped.to_owned()))
|
||||
} else {
|
||||
Some(None)
|
||||
}
|
||||
}
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn diesel_option_overwrite_to_url(
|
||||
opt: &Option<String>,
|
||||
) -> Result<Option<Option<DbUrl>>, ApiError> {
|
||||
match opt.as_ref().map(|s| s.as_str()) {
|
||||
// An empty string is an erase
|
||||
Some("") => Ok(Some(None)),
|
||||
Some(str_url) => match Url::parse(str_url) {
|
||||
Ok(url) => Ok(Some(Some(url.into()))),
|
||||
Err(e) => Err(ApiError::err("invalid_url", e)),
|
||||
},
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
embed_migrations!();
|
||||
|
||||
pub fn establish_unpooled_connection() -> PgConnection {
|
||||
let db_url = match get_database_url_from_env() {
|
||||
Ok(url) => url,
|
||||
Err(e) => panic!(
|
||||
"Failed to read database URL from env var LEMMY_DATABASE_URL: {}",
|
||||
e
|
||||
),
|
||||
};
|
||||
let conn =
|
||||
PgConnection::establish(&db_url).unwrap_or_else(|_| panic!("Error connecting to {}", db_url));
|
||||
embedded_migrations::run(&conn).expect("load migrations");
|
||||
conn
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref EMAIL_REGEX: Regex =
|
||||
Regex::new(r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$")
|
||||
.expect("compile email regex");
|
||||
}
|
||||
|
||||
pub mod functions {
|
||||
use diesel::sql_types::*;
|
||||
|
||||
sql_function! {
|
||||
fn hot_rank(score: BigInt, time: Timestamp) -> Integer;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{fuzzy_search, *};
|
||||
use crate::is_email_regex;
|
||||
|
||||
#[test]
|
||||
fn test_fuzzy_search() {
|
||||
let test = "This is a fuzzy search";
|
||||
assert_eq!(fuzzy_search(test), "%This%is%a%fuzzy%search%".to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_email() {
|
||||
assert!(is_email_regex("gush@gmail.com"));
|
||||
assert!(!is_email_regex("nada_neutho"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_diesel_option_overwrite() {
|
||||
assert_eq!(diesel_option_overwrite(&None), None);
|
||||
assert_eq!(diesel_option_overwrite(&Some("".to_string())), Some(None));
|
||||
assert_eq!(
|
||||
diesel_option_overwrite(&Some("test".to_string())),
|
||||
Some(Some("test".to_string()))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_diesel_option_overwrite_to_url() {
|
||||
assert!(matches!(diesel_option_overwrite_to_url(&None), Ok(None)));
|
||||
assert!(matches!(
|
||||
diesel_option_overwrite_to_url(&Some("".to_string())),
|
||||
Ok(Some(None))
|
||||
));
|
||||
assert!(matches!(
|
||||
diesel_option_overwrite_to_url(&Some("invalid_url".to_string())),
|
||||
Err(_)
|
||||
));
|
||||
let example_url = "https://example.com";
|
||||
assert!(matches!(
|
||||
diesel_option_overwrite_to_url(&Some(example_url.to_string())),
|
||||
Ok(Some(Some(url))) if url == Url::parse(example_url).unwrap().into()
|
||||
));
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
use diesel::{result::Error, *};
|
||||
use lemmy_db_schema::source::secret::Secret;
|
||||
|
||||
pub trait Secret_ {
|
||||
fn init(conn: &PgConnection) -> Result<Secret, Error>;
|
||||
}
|
||||
|
||||
impl Secret_ for Secret {
|
||||
/// Initialize the Secrets from the DB.
|
||||
/// Warning: You should only call this once.
|
||||
fn init(conn: &PgConnection) -> Result<Secret, Error> {
|
||||
read_secrets(conn)
|
||||
}
|
||||
}
|
||||
|
||||
fn read_secrets(conn: &PgConnection) -> Result<Secret, Error> {
|
||||
use lemmy_db_schema::schema::secret::dsl::*;
|
||||
secret.first::<Secret>(conn)
|
||||
}
|
|
@ -12,9 +12,19 @@ doctest = false
|
|||
lemmy_utils = { version = "=0.13.0", path = "../utils" }
|
||||
lemmy_apub_lib = { version = "=0.13.0", path = "../apub_lib" }
|
||||
diesel = { version = "1.4.8", features = ["postgres","chrono","r2d2","serde_json"] }
|
||||
diesel_migrations = "1.4.0"
|
||||
chrono = { version = "0.4.19", features = ["serde"] }
|
||||
serde = { version = "1.0.130", features = ["derive"] }
|
||||
serde_json = { version = "1.0.68", features = ["preserve_order"] }
|
||||
log = "0.4.14"
|
||||
url = { version = "2.2.2", features = ["serde"] }
|
||||
diesel-derive-newtype = "0.1.2"
|
||||
regex = "1.5.4"
|
||||
lazy_static = "1.4.0"
|
||||
strum = "0.21.0"
|
||||
strum_macros = "0.21.1"
|
||||
sha2 = "0.9.8"
|
||||
bcrypt = "0.10.1"
|
||||
|
||||
[dev-dependencies]
|
||||
serial_test = "0.5.1"
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{newtypes::CommentId, schema::comment_aggregates};
|
||||
use diesel::{result::Error, *};
|
||||
use lemmy_db_schema::{schema::comment_aggregates, CommentId};
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Clone)]
|
||||
|
@ -26,14 +26,13 @@ mod tests {
|
|||
use crate::{
|
||||
aggregates::comment_aggregates::CommentAggregates,
|
||||
establish_unpooled_connection,
|
||||
Crud,
|
||||
Likeable,
|
||||
};
|
||||
use lemmy_db_schema::source::{
|
||||
source::{
|
||||
comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
|
||||
community::{Community, CommunityForm},
|
||||
person::{Person, PersonForm},
|
||||
post::{Post, PostForm},
|
||||
},
|
||||
traits::{Crud, Likeable},
|
||||
};
|
||||
use serial_test::serial;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{newtypes::CommunityId, schema::community_aggregates};
|
||||
use diesel::{result::Error, *};
|
||||
use lemmy_db_schema::{schema::community_aggregates, CommunityId};
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Clone)]
|
||||
|
@ -30,14 +30,13 @@ mod tests {
|
|||
use crate::{
|
||||
aggregates::community_aggregates::CommunityAggregates,
|
||||
establish_unpooled_connection,
|
||||
Crud,
|
||||
Followable,
|
||||
};
|
||||
use lemmy_db_schema::source::{
|
||||
source::{
|
||||
comment::{Comment, CommentForm},
|
||||
community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm},
|
||||
person::{Person, PersonForm},
|
||||
post::{Post, PostForm},
|
||||
},
|
||||
traits::{Crud, Followable},
|
||||
};
|
||||
use serial_test::serial;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{newtypes::PersonId, schema::person_aggregates};
|
||||
use diesel::{result::Error, *};
|
||||
use lemmy_db_schema::{schema::person_aggregates, PersonId};
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Clone)]
|
||||
|
@ -26,14 +26,13 @@ mod tests {
|
|||
use crate::{
|
||||
aggregates::person_aggregates::PersonAggregates,
|
||||
establish_unpooled_connection,
|
||||
Crud,
|
||||
Likeable,
|
||||
};
|
||||
use lemmy_db_schema::source::{
|
||||
source::{
|
||||
comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
|
||||
community::{Community, CommunityForm},
|
||||
person::{Person, PersonForm},
|
||||
post::{Post, PostForm, PostLike, PostLikeForm},
|
||||
},
|
||||
traits::{Crud, Likeable},
|
||||
};
|
||||
use serial_test::serial;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{newtypes::PostId, schema::post_aggregates};
|
||||
use diesel::{result::Error, *};
|
||||
use lemmy_db_schema::{schema::post_aggregates, PostId};
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Queryable, Associations, Identifiable, PartialEq, Debug, Serialize, Clone)]
|
||||
|
@ -30,14 +30,13 @@ mod tests {
|
|||
use crate::{
|
||||
aggregates::post_aggregates::PostAggregates,
|
||||
establish_unpooled_connection,
|
||||
Crud,
|
||||
Likeable,
|
||||
};
|
||||
use lemmy_db_schema::source::{
|
||||
source::{
|
||||
comment::{Comment, CommentForm},
|
||||
community::{Community, CommunityForm},
|
||||
person::{Person, PersonForm},
|
||||
post::{Post, PostForm, PostLike, PostLikeForm},
|
||||
},
|
||||
traits::{Crud, Likeable},
|
||||
};
|
||||
use serial_test::serial;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
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, Clone)]
|
||||
|
@ -25,13 +25,17 @@ impl SiteAggregates {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{aggregates::site_aggregates::SiteAggregates, establish_unpooled_connection, Crud};
|
||||
use lemmy_db_schema::source::{
|
||||
use crate::{
|
||||
aggregates::site_aggregates::SiteAggregates,
|
||||
establish_unpooled_connection,
|
||||
source::{
|
||||
comment::{Comment, CommentForm},
|
||||
community::{Community, CommunityForm},
|
||||
person::{Person, PersonForm},
|
||||
post::{Post, PostForm},
|
||||
site::{Site, SiteForm},
|
||||
},
|
||||
traits::Crud,
|
||||
};
|
||||
use serial_test::serial;
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
use crate::Crud;
|
||||
use crate::{newtypes::DbUrl, source::activity::*, traits::Crud};
|
||||
use diesel::{dsl::*, result::Error, sql_types::Text, *};
|
||||
use lemmy_db_schema::{source::activity::*, DbUrl};
|
||||
use serde::Serialize;
|
||||
use serde_json::Value;
|
||||
use std::{
|
||||
|
@ -12,12 +11,12 @@ impl Crud for Activity {
|
|||
type Form = ActivityForm;
|
||||
type IdType = i32;
|
||||
fn read(conn: &PgConnection, activity_id: i32) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::activity::dsl::*;
|
||||
use crate::schema::activity::dsl::*;
|
||||
activity.find(activity_id).first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn create(conn: &PgConnection, new_activity: &ActivityForm) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::activity::dsl::*;
|
||||
use crate::schema::activity::dsl::*;
|
||||
insert_into(activity)
|
||||
.values(new_activity)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -28,40 +27,19 @@ impl Crud for Activity {
|
|||
activity_id: i32,
|
||||
new_activity: &ActivityForm,
|
||||
) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::activity::dsl::*;
|
||||
use crate::schema::activity::dsl::*;
|
||||
diesel::update(activity.find(activity_id))
|
||||
.set(new_activity)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
fn delete(conn: &PgConnection, activity_id: i32) -> Result<usize, Error> {
|
||||
use lemmy_db_schema::schema::activity::dsl::*;
|
||||
use crate::schema::activity::dsl::*;
|
||||
diesel::delete(activity.find(activity_id)).execute(conn)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Activity_ {
|
||||
fn insert<T>(
|
||||
conn: &PgConnection,
|
||||
ap_id: DbUrl,
|
||||
data: &T,
|
||||
local: bool,
|
||||
sensitive: bool,
|
||||
) -> Result<Activity, IoError>
|
||||
where
|
||||
T: Serialize + Debug;
|
||||
|
||||
fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Activity, Error>;
|
||||
fn delete_olds(conn: &PgConnection) -> Result<usize, Error>;
|
||||
|
||||
/// Returns up to 20 activities of type `Announce/Create/Page` from the community
|
||||
fn read_community_outbox(
|
||||
conn: &PgConnection,
|
||||
community_actor_id: &DbUrl,
|
||||
) -> Result<Vec<Value>, Error>;
|
||||
}
|
||||
|
||||
impl Activity_ for Activity {
|
||||
fn insert<T>(
|
||||
impl Activity {
|
||||
pub fn insert<T>(
|
||||
conn: &PgConnection,
|
||||
ap_id: DbUrl,
|
||||
data: &T,
|
||||
|
@ -88,21 +66,21 @@ impl Activity_ for Activity {
|
|||
}
|
||||
}
|
||||
|
||||
fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Activity, Error> {
|
||||
use lemmy_db_schema::schema::activity::dsl::*;
|
||||
pub fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Activity, Error> {
|
||||
use crate::schema::activity::dsl::*;
|
||||
activity.filter(ap_id.eq(object_id)).first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn delete_olds(conn: &PgConnection) -> Result<usize, Error> {
|
||||
use lemmy_db_schema::schema::activity::dsl::*;
|
||||
pub fn delete_olds(conn: &PgConnection) -> Result<usize, Error> {
|
||||
use crate::schema::activity::dsl::*;
|
||||
diesel::delete(activity.filter(published.lt(now - 6.months()))).execute(conn)
|
||||
}
|
||||
|
||||
fn read_community_outbox(
|
||||
pub fn read_community_outbox(
|
||||
conn: &PgConnection,
|
||||
community_actor_id: &DbUrl,
|
||||
) -> Result<Vec<Value>, Error> {
|
||||
use lemmy_db_schema::schema::activity::dsl::*;
|
||||
use crate::schema::activity::dsl::*;
|
||||
let res: Vec<Value> = activity
|
||||
.select(data)
|
||||
.filter(
|
||||
|
@ -122,10 +100,13 @@ impl Activity_ for Activity {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{establish_unpooled_connection, source::activity::Activity_};
|
||||
use lemmy_db_schema::source::{
|
||||
use crate::{
|
||||
establish_unpooled_connection,
|
||||
newtypes::DbUrl,
|
||||
source::{
|
||||
activity::{Activity, ActivityForm},
|
||||
person::{Person, PersonForm},
|
||||
},
|
||||
};
|
||||
use serde_json::Value;
|
||||
use serial_test::serial;
|
|
@ -1,7 +1,6 @@
|
|||
use crate::{Crud, DeleteableOrRemoveable, Likeable, Saveable};
|
||||
use diesel::{dsl::*, result::Error, *};
|
||||
use lemmy_db_schema::{
|
||||
use crate::{
|
||||
naive_now,
|
||||
newtypes::{CommentId, DbUrl, PersonId},
|
||||
source::comment::{
|
||||
Comment,
|
||||
CommentForm,
|
||||
|
@ -10,67 +9,32 @@ use lemmy_db_schema::{
|
|||
CommentSaved,
|
||||
CommentSavedForm,
|
||||
},
|
||||
CommentId,
|
||||
DbUrl,
|
||||
PersonId,
|
||||
traits::{Crud, DeleteableOrRemoveable, Likeable, Saveable},
|
||||
};
|
||||
use chrono::NaiveDateTime;
|
||||
use diesel::{dsl::*, result::Error, *};
|
||||
use lemmy_apub_lib::traits::ApubObject;
|
||||
use lemmy_utils::LemmyError;
|
||||
use url::Url;
|
||||
|
||||
pub trait Comment_ {
|
||||
fn update_ap_id(
|
||||
conn: &PgConnection,
|
||||
comment_id: CommentId,
|
||||
apub_id: DbUrl,
|
||||
) -> Result<Comment, Error>;
|
||||
fn permadelete_for_creator(
|
||||
conn: &PgConnection,
|
||||
for_creator_id: PersonId,
|
||||
) -> Result<Vec<Comment>, Error>;
|
||||
fn update_deleted(
|
||||
conn: &PgConnection,
|
||||
comment_id: CommentId,
|
||||
new_deleted: bool,
|
||||
) -> Result<Comment, Error>;
|
||||
fn update_removed(
|
||||
conn: &PgConnection,
|
||||
comment_id: CommentId,
|
||||
new_removed: bool,
|
||||
) -> Result<Comment, Error>;
|
||||
fn update_removed_for_creator(
|
||||
conn: &PgConnection,
|
||||
for_creator_id: PersonId,
|
||||
new_removed: bool,
|
||||
) -> Result<Vec<Comment>, Error>;
|
||||
fn update_read(
|
||||
conn: &PgConnection,
|
||||
comment_id: CommentId,
|
||||
new_read: bool,
|
||||
) -> Result<Comment, Error>;
|
||||
fn update_content(
|
||||
conn: &PgConnection,
|
||||
comment_id: CommentId,
|
||||
new_content: &str,
|
||||
) -> Result<Comment, Error>;
|
||||
fn upsert(conn: &PgConnection, comment_form: &CommentForm) -> Result<Comment, Error>;
|
||||
}
|
||||
|
||||
impl Comment_ for Comment {
|
||||
fn update_ap_id(
|
||||
impl Comment {
|
||||
pub fn update_ap_id(
|
||||
conn: &PgConnection,
|
||||
comment_id: CommentId,
|
||||
apub_id: DbUrl,
|
||||
) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::comment::dsl::*;
|
||||
use crate::schema::comment::dsl::*;
|
||||
|
||||
diesel::update(comment.find(comment_id))
|
||||
.set(ap_id.eq(apub_id))
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
|
||||
fn permadelete_for_creator(
|
||||
pub fn permadelete_for_creator(
|
||||
conn: &PgConnection,
|
||||
for_creator_id: PersonId,
|
||||
) -> Result<Vec<Self>, Error> {
|
||||
use lemmy_db_schema::schema::comment::dsl::*;
|
||||
use crate::schema::comment::dsl::*;
|
||||
diesel::update(comment.filter(creator_id.eq(for_creator_id)))
|
||||
.set((
|
||||
content.eq("*Permananently Deleted*"),
|
||||
|
@ -80,63 +44,63 @@ impl Comment_ for Comment {
|
|||
.get_results::<Self>(conn)
|
||||
}
|
||||
|
||||
fn update_deleted(
|
||||
pub fn update_deleted(
|
||||
conn: &PgConnection,
|
||||
comment_id: CommentId,
|
||||
new_deleted: bool,
|
||||
) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::comment::dsl::*;
|
||||
use crate::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(
|
||||
pub fn update_removed(
|
||||
conn: &PgConnection,
|
||||
comment_id: CommentId,
|
||||
new_removed: bool,
|
||||
) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::comment::dsl::*;
|
||||
use crate::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(
|
||||
pub fn update_removed_for_creator(
|
||||
conn: &PgConnection,
|
||||
for_creator_id: PersonId,
|
||||
new_removed: bool,
|
||||
) -> Result<Vec<Self>, Error> {
|
||||
use lemmy_db_schema::schema::comment::dsl::*;
|
||||
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)
|
||||
}
|
||||
|
||||
fn update_read(
|
||||
pub fn update_read(
|
||||
conn: &PgConnection,
|
||||
comment_id: CommentId,
|
||||
new_read: bool,
|
||||
) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::comment::dsl::*;
|
||||
use crate::schema::comment::dsl::*;
|
||||
diesel::update(comment.find(comment_id))
|
||||
.set(read.eq(new_read))
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
|
||||
fn update_content(
|
||||
pub fn update_content(
|
||||
conn: &PgConnection,
|
||||
comment_id: CommentId,
|
||||
new_content: &str,
|
||||
) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::comment::dsl::*;
|
||||
use crate::schema::comment::dsl::*;
|
||||
diesel::update(comment.find(comment_id))
|
||||
.set((content.eq(new_content), updated.eq(naive_now())))
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
|
||||
fn upsert(conn: &PgConnection, comment_form: &CommentForm) -> Result<Comment, Error> {
|
||||
use lemmy_db_schema::schema::comment::dsl::*;
|
||||
pub fn upsert(conn: &PgConnection, comment_form: &CommentForm) -> Result<Comment, Error> {
|
||||
use crate::schema::comment::dsl::*;
|
||||
insert_into(comment)
|
||||
.values(comment_form)
|
||||
.on_conflict(ap_id)
|
||||
|
@ -150,17 +114,17 @@ impl Crud for Comment {
|
|||
type Form = CommentForm;
|
||||
type IdType = CommentId;
|
||||
fn read(conn: &PgConnection, comment_id: CommentId) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::comment::dsl::*;
|
||||
use crate::schema::comment::dsl::*;
|
||||
comment.find(comment_id).first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn delete(conn: &PgConnection, comment_id: CommentId) -> Result<usize, Error> {
|
||||
use lemmy_db_schema::schema::comment::dsl::*;
|
||||
use crate::schema::comment::dsl::*;
|
||||
diesel::delete(comment.find(comment_id)).execute(conn)
|
||||
}
|
||||
|
||||
fn create(conn: &PgConnection, comment_form: &CommentForm) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::comment::dsl::*;
|
||||
use crate::schema::comment::dsl::*;
|
||||
insert_into(comment)
|
||||
.values(comment_form)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -171,7 +135,7 @@ impl Crud for Comment {
|
|||
comment_id: CommentId,
|
||||
comment_form: &CommentForm,
|
||||
) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::comment::dsl::*;
|
||||
use crate::schema::comment::dsl::*;
|
||||
diesel::update(comment.find(comment_id))
|
||||
.set(comment_form)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -182,7 +146,7 @@ impl Likeable for CommentLike {
|
|||
type Form = CommentLikeForm;
|
||||
type IdType = CommentId;
|
||||
fn like(conn: &PgConnection, comment_like_form: &CommentLikeForm) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::comment_like::dsl::*;
|
||||
use crate::schema::comment_like::dsl::*;
|
||||
insert_into(comment_like)
|
||||
.values(comment_like_form)
|
||||
.on_conflict((comment_id, person_id))
|
||||
|
@ -195,7 +159,7 @@ impl Likeable for CommentLike {
|
|||
person_id: PersonId,
|
||||
comment_id: CommentId,
|
||||
) -> Result<usize, Error> {
|
||||
use lemmy_db_schema::schema::comment_like::dsl;
|
||||
use crate::schema::comment_like::dsl;
|
||||
diesel::delete(
|
||||
dsl::comment_like
|
||||
.filter(dsl::comment_id.eq(comment_id))
|
||||
|
@ -208,7 +172,7 @@ impl Likeable for CommentLike {
|
|||
impl Saveable for CommentSaved {
|
||||
type Form = CommentSavedForm;
|
||||
fn save(conn: &PgConnection, comment_saved_form: &CommentSavedForm) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::comment_saved::dsl::*;
|
||||
use crate::schema::comment_saved::dsl::*;
|
||||
insert_into(comment_saved)
|
||||
.values(comment_saved_form)
|
||||
.on_conflict((comment_id, person_id))
|
||||
|
@ -217,7 +181,7 @@ impl Saveable for CommentSaved {
|
|||
.get_result::<Self>(conn)
|
||||
}
|
||||
fn unsave(conn: &PgConnection, comment_saved_form: &CommentSavedForm) -> Result<usize, Error> {
|
||||
use lemmy_db_schema::schema::comment_saved::dsl::*;
|
||||
use crate::schema::comment_saved::dsl::*;
|
||||
diesel::delete(
|
||||
comment_saved
|
||||
.filter(comment_id.eq(comment_saved_form.comment_id))
|
||||
|
@ -234,14 +198,36 @@ impl DeleteableOrRemoveable for Comment {
|
|||
}
|
||||
}
|
||||
|
||||
impl ApubObject for Comment {
|
||||
type DataType = PgConnection;
|
||||
|
||||
fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
|
||||
None
|
||||
}
|
||||
|
||||
fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, LemmyError> {
|
||||
use crate::schema::comment::dsl::*;
|
||||
let object_id: DbUrl = object_id.into();
|
||||
Ok(comment.filter(ap_id.eq(object_id)).first::<Self>(conn).ok())
|
||||
}
|
||||
|
||||
fn delete(self, conn: &PgConnection) -> Result<(), LemmyError> {
|
||||
Comment::update_deleted(conn, self.id, true)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{establish_unpooled_connection, Crud, Likeable, Saveable};
|
||||
use lemmy_db_schema::source::{
|
||||
use crate::{
|
||||
establish_unpooled_connection,
|
||||
source::{
|
||||
comment::*,
|
||||
community::{Community, CommunityForm},
|
||||
person::{Person, PersonForm},
|
||||
post::*,
|
||||
},
|
||||
traits::{Crud, Likeable, Saveable},
|
||||
};
|
||||
use serial_test::serial;
|
||||
|
|
@ -1,11 +1,10 @@
|
|||
use crate::Reportable;
|
||||
use diesel::{dsl::*, result::Error, *};
|
||||
use lemmy_db_schema::{
|
||||
use crate::{
|
||||
naive_now,
|
||||
newtypes::{CommentReportId, PersonId},
|
||||
source::comment_report::{CommentReport, CommentReportForm},
|
||||
CommentReportId,
|
||||
PersonId,
|
||||
traits::Reportable,
|
||||
};
|
||||
use diesel::{dsl::*, result::Error, *};
|
||||
|
||||
impl Reportable for CommentReport {
|
||||
type Form = CommentReportForm;
|
||||
|
@ -15,7 +14,7 @@ impl Reportable for CommentReport {
|
|||
/// * `conn` - the postgres connection
|
||||
/// * `comment_report_form` - the filled CommentReportForm to insert
|
||||
fn report(conn: &PgConnection, comment_report_form: &CommentReportForm) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::comment_report::dsl::*;
|
||||
use crate::schema::comment_report::dsl::*;
|
||||
insert_into(comment_report)
|
||||
.values(comment_report_form)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -31,7 +30,7 @@ impl Reportable for CommentReport {
|
|||
report_id: Self::IdType,
|
||||
by_resolver_id: PersonId,
|
||||
) -> Result<usize, Error> {
|
||||
use lemmy_db_schema::schema::comment_report::dsl::*;
|
||||
use crate::schema::comment_report::dsl::*;
|
||||
update(comment_report.find(report_id))
|
||||
.set((
|
||||
resolved.eq(true),
|
||||
|
@ -51,7 +50,7 @@ impl Reportable for CommentReport {
|
|||
report_id: Self::IdType,
|
||||
by_resolver_id: PersonId,
|
||||
) -> Result<usize, Error> {
|
||||
use lemmy_db_schema::schema::comment_report::dsl::*;
|
||||
use crate::schema::comment_report::dsl::*;
|
||||
update(comment_report.find(report_id))
|
||||
.set((
|
||||
resolved.eq(false),
|
|
@ -1,7 +1,6 @@
|
|||
use crate::{Bannable, Crud, DeleteableOrRemoveable, Followable, Joinable};
|
||||
use diesel::{dsl::*, result::Error, *};
|
||||
use lemmy_db_schema::{
|
||||
use crate::{
|
||||
naive_now,
|
||||
newtypes::{CommunityId, DbUrl, PersonId},
|
||||
source::community::{
|
||||
Community,
|
||||
CommunityFollower,
|
||||
|
@ -13,14 +12,16 @@ use lemmy_db_schema::{
|
|||
CommunityPersonBanForm,
|
||||
CommunitySafe,
|
||||
},
|
||||
CommunityId,
|
||||
DbUrl,
|
||||
PersonId,
|
||||
traits::{Bannable, Crud, DeleteableOrRemoveable, Followable, Joinable},
|
||||
};
|
||||
use chrono::NaiveDateTime;
|
||||
use diesel::{dsl::*, result::Error, ExpressionMethods, PgConnection, QueryDsl, RunQueryDsl};
|
||||
use lemmy_apub_lib::traits::{ActorType, ApubObject};
|
||||
use lemmy_utils::LemmyError;
|
||||
use url::Url;
|
||||
|
||||
mod safe_type {
|
||||
use crate::{source::community::Community, ToSafe};
|
||||
use lemmy_db_schema::schema::community::*;
|
||||
use crate::{schema::community::*, source::community::Community, traits::ToSafe};
|
||||
|
||||
type Columns = (
|
||||
id,
|
||||
|
@ -64,17 +65,17 @@ impl Crud for Community {
|
|||
type Form = CommunityForm;
|
||||
type IdType = CommunityId;
|
||||
fn read(conn: &PgConnection, community_id: CommunityId) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::community::dsl::*;
|
||||
use crate::schema::community::dsl::*;
|
||||
community.find(community_id).first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn delete(conn: &PgConnection, community_id: CommunityId) -> Result<usize, Error> {
|
||||
use lemmy_db_schema::schema::community::dsl::*;
|
||||
use crate::schema::community::dsl::*;
|
||||
diesel::delete(community.find(community_id)).execute(conn)
|
||||
}
|
||||
|
||||
fn create(conn: &PgConnection, new_community: &CommunityForm) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::community::dsl::*;
|
||||
use crate::schema::community::dsl::*;
|
||||
insert_into(community)
|
||||
.values(new_community)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -85,81 +86,61 @@ impl Crud for Community {
|
|||
community_id: CommunityId,
|
||||
new_community: &CommunityForm,
|
||||
) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::community::dsl::*;
|
||||
use crate::schema::community::dsl::*;
|
||||
diesel::update(community.find(community_id))
|
||||
.set(new_community)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Community_ {
|
||||
fn read_from_name(conn: &PgConnection, community_name: &str) -> Result<Community, Error>;
|
||||
fn update_deleted(
|
||||
conn: &PgConnection,
|
||||
community_id: CommunityId,
|
||||
new_deleted: bool,
|
||||
) -> Result<Community, Error>;
|
||||
fn update_removed(
|
||||
conn: &PgConnection,
|
||||
community_id: CommunityId,
|
||||
new_removed: bool,
|
||||
) -> Result<Community, Error>;
|
||||
fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error>;
|
||||
fn read_from_followers_url(
|
||||
conn: &PgConnection,
|
||||
followers_url: &DbUrl,
|
||||
) -> Result<Community, Error>;
|
||||
fn upsert(conn: &PgConnection, community_form: &CommunityForm) -> Result<Community, Error>;
|
||||
}
|
||||
|
||||
impl Community_ for Community {
|
||||
fn read_from_name(conn: &PgConnection, community_name: &str) -> Result<Community, Error> {
|
||||
use lemmy_db_schema::schema::community::dsl::*;
|
||||
impl Community {
|
||||
pub fn read_from_name(conn: &PgConnection, community_name: &str) -> Result<Community, Error> {
|
||||
use crate::schema::community::dsl::*;
|
||||
community
|
||||
.filter(local.eq(true))
|
||||
.filter(name.eq(community_name))
|
||||
.first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn update_deleted(
|
||||
pub fn update_deleted(
|
||||
conn: &PgConnection,
|
||||
community_id: CommunityId,
|
||||
new_deleted: bool,
|
||||
) -> Result<Community, Error> {
|
||||
use lemmy_db_schema::schema::community::dsl::*;
|
||||
use crate::schema::community::dsl::*;
|
||||
diesel::update(community.find(community_id))
|
||||
.set((deleted.eq(new_deleted), updated.eq(naive_now())))
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
|
||||
fn update_removed(
|
||||
pub fn update_removed(
|
||||
conn: &PgConnection,
|
||||
community_id: CommunityId,
|
||||
new_removed: bool,
|
||||
) -> Result<Community, Error> {
|
||||
use lemmy_db_schema::schema::community::dsl::*;
|
||||
use crate::schema::community::dsl::*;
|
||||
diesel::update(community.find(community_id))
|
||||
.set((removed.eq(new_removed), updated.eq(naive_now())))
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
|
||||
fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error> {
|
||||
use lemmy_db_schema::schema::community::dsl::*;
|
||||
pub fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error> {
|
||||
use crate::schema::community::dsl::*;
|
||||
community.select(actor_id).distinct().load::<String>(conn)
|
||||
}
|
||||
|
||||
fn read_from_followers_url(
|
||||
pub fn read_from_followers_url(
|
||||
conn: &PgConnection,
|
||||
followers_url_: &DbUrl,
|
||||
) -> Result<Community, Error> {
|
||||
use lemmy_db_schema::schema::community::dsl::*;
|
||||
use crate::schema::community::dsl::*;
|
||||
community
|
||||
.filter(followers_url.eq(followers_url_))
|
||||
.first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn upsert(conn: &PgConnection, community_form: &CommunityForm) -> Result<Community, Error> {
|
||||
use lemmy_db_schema::schema::community::dsl::*;
|
||||
pub fn upsert(conn: &PgConnection, community_form: &CommunityForm) -> Result<Community, Error> {
|
||||
use crate::schema::community::dsl::*;
|
||||
insert_into(community)
|
||||
.values(community_form)
|
||||
.on_conflict(actor_id)
|
||||
|
@ -175,7 +156,7 @@ impl Joinable for CommunityModerator {
|
|||
conn: &PgConnection,
|
||||
community_moderator_form: &CommunityModeratorForm,
|
||||
) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::community_moderator::dsl::*;
|
||||
use crate::schema::community_moderator::dsl::*;
|
||||
insert_into(community_moderator)
|
||||
.values(community_moderator_form)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -185,7 +166,7 @@ impl Joinable for CommunityModerator {
|
|||
conn: &PgConnection,
|
||||
community_moderator_form: &CommunityModeratorForm,
|
||||
) -> Result<usize, Error> {
|
||||
use lemmy_db_schema::schema::community_moderator::dsl::*;
|
||||
use crate::schema::community_moderator::dsl::*;
|
||||
diesel::delete(
|
||||
community_moderator
|
||||
.filter(community_id.eq(community_moderator_form.community_id))
|
||||
|
@ -215,31 +196,20 @@ impl DeleteableOrRemoveable for Community {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait CommunityModerator_ {
|
||||
fn delete_for_community(
|
||||
conn: &PgConnection,
|
||||
for_community_id: CommunityId,
|
||||
) -> Result<usize, Error>;
|
||||
fn get_person_moderated_communities(
|
||||
conn: &PgConnection,
|
||||
for_person_id: PersonId,
|
||||
) -> Result<Vec<CommunityId>, Error>;
|
||||
}
|
||||
|
||||
impl CommunityModerator_ for CommunityModerator {
|
||||
fn delete_for_community(
|
||||
impl CommunityModerator {
|
||||
pub fn delete_for_community(
|
||||
conn: &PgConnection,
|
||||
for_community_id: CommunityId,
|
||||
) -> Result<usize, Error> {
|
||||
use lemmy_db_schema::schema::community_moderator::dsl::*;
|
||||
use crate::schema::community_moderator::dsl::*;
|
||||
diesel::delete(community_moderator.filter(community_id.eq(for_community_id))).execute(conn)
|
||||
}
|
||||
|
||||
fn get_person_moderated_communities(
|
||||
pub fn get_person_moderated_communities(
|
||||
conn: &PgConnection,
|
||||
for_person_id: PersonId,
|
||||
) -> Result<Vec<CommunityId>, Error> {
|
||||
use lemmy_db_schema::schema::community_moderator::dsl::*;
|
||||
use crate::schema::community_moderator::dsl::*;
|
||||
community_moderator
|
||||
.filter(person_id.eq(for_person_id))
|
||||
.select(community_id)
|
||||
|
@ -253,7 +223,7 @@ impl Bannable for CommunityPersonBan {
|
|||
conn: &PgConnection,
|
||||
community_person_ban_form: &CommunityPersonBanForm,
|
||||
) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::community_person_ban::dsl::*;
|
||||
use crate::schema::community_person_ban::dsl::*;
|
||||
insert_into(community_person_ban)
|
||||
.values(community_person_ban_form)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -263,7 +233,7 @@ impl Bannable for CommunityPersonBan {
|
|||
conn: &PgConnection,
|
||||
community_person_ban_form: &CommunityPersonBanForm,
|
||||
) -> Result<usize, Error> {
|
||||
use lemmy_db_schema::schema::community_person_ban::dsl::*;
|
||||
use crate::schema::community_person_ban::dsl::*;
|
||||
diesel::delete(
|
||||
community_person_ban
|
||||
.filter(community_id.eq(community_person_ban_form.community_id))
|
||||
|
@ -279,7 +249,7 @@ impl Followable for CommunityFollower {
|
|||
conn: &PgConnection,
|
||||
community_follower_form: &CommunityFollowerForm,
|
||||
) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::community_follower::dsl::*;
|
||||
use crate::schema::community_follower::dsl::*;
|
||||
insert_into(community_follower)
|
||||
.values(community_follower_form)
|
||||
.on_conflict((community_id, person_id))
|
||||
|
@ -295,7 +265,7 @@ impl Followable for CommunityFollower {
|
|||
where
|
||||
Self: Sized,
|
||||
{
|
||||
use lemmy_db_schema::schema::community_follower::dsl::*;
|
||||
use crate::schema::community_follower::dsl::*;
|
||||
diesel::update(
|
||||
community_follower
|
||||
.filter(community_id.eq(community_id_))
|
||||
|
@ -308,7 +278,7 @@ impl Followable for CommunityFollower {
|
|||
conn: &PgConnection,
|
||||
community_follower_form: &CommunityFollowerForm,
|
||||
) -> Result<usize, Error> {
|
||||
use lemmy_db_schema::schema::community_follower::dsl::*;
|
||||
use crate::schema::community_follower::dsl::*;
|
||||
diesel::delete(
|
||||
community_follower
|
||||
.filter(community_id.eq(&community_follower_form.community_id))
|
||||
|
@ -319,7 +289,7 @@ impl Followable for CommunityFollower {
|
|||
// TODO: this function name only makes sense if you call it with a remote community. for a local
|
||||
// community, it will also return true if only remote followers exist
|
||||
fn has_local_followers(conn: &PgConnection, community_id_: CommunityId) -> Result<bool, Error> {
|
||||
use lemmy_db_schema::schema::community_follower::dsl::*;
|
||||
use crate::schema::community_follower::dsl::*;
|
||||
diesel::select(exists(
|
||||
community_follower.filter(community_id.eq(community_id_)),
|
||||
))
|
||||
|
@ -327,10 +297,66 @@ impl Followable for CommunityFollower {
|
|||
}
|
||||
}
|
||||
|
||||
impl ApubObject for Community {
|
||||
type DataType = PgConnection;
|
||||
|
||||
fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
|
||||
Some(self.last_refreshed_at)
|
||||
}
|
||||
|
||||
fn read_from_apub_id(conn: &PgConnection, object_id: Url) -> Result<Option<Self>, LemmyError> {
|
||||
use crate::schema::community::dsl::*;
|
||||
let object_id: DbUrl = object_id.into();
|
||||
Ok(
|
||||
community
|
||||
.filter(actor_id.eq(object_id))
|
||||
.first::<Self>(conn)
|
||||
.ok(),
|
||||
)
|
||||
}
|
||||
|
||||
fn delete(self, conn: &PgConnection) -> Result<(), LemmyError> {
|
||||
use crate::schema::community::dsl::*;
|
||||
diesel::update(community.find(self.id))
|
||||
.set((deleted.eq(true), updated.eq(naive_now())))
|
||||
.get_result::<Self>(conn)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl ActorType for Community {
|
||||
fn is_local(&self) -> bool {
|
||||
self.local
|
||||
}
|
||||
fn actor_id(&self) -> Url {
|
||||
self.actor_id.to_owned().into()
|
||||
}
|
||||
fn name(&self) -> String {
|
||||
self.name.clone()
|
||||
}
|
||||
fn public_key(&self) -> Option<String> {
|
||||
self.public_key.to_owned()
|
||||
}
|
||||
fn private_key(&self) -> Option<String> {
|
||||
self.private_key.to_owned()
|
||||
}
|
||||
|
||||
fn inbox_url(&self) -> Url {
|
||||
self.inbox_url.clone().into()
|
||||
}
|
||||
|
||||
fn shared_inbox_url(&self) -> Option<Url> {
|
||||
self.shared_inbox_url.clone().map(|s| s.into_inner())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{establish_unpooled_connection, Bannable, Crud, Followable, Joinable};
|
||||
use lemmy_db_schema::source::{community::*, person::*};
|
||||
use crate::{
|
||||
establish_unpooled_connection,
|
||||
source::{community::*, person::*},
|
||||
traits::{Bannable, Crud, Followable, Joinable},
|
||||
};
|
||||
use serial_test::serial;
|
||||
|
||||
#[test]
|
|
@ -1,11 +1,13 @@
|
|||
use crate::Blockable;
|
||||
use crate::{
|
||||
source::community_block::{CommunityBlock, CommunityBlockForm},
|
||||
traits::Blockable,
|
||||
};
|
||||
use diesel::{dsl::*, result::Error, *};
|
||||
use lemmy_db_schema::source::community_block::{CommunityBlock, CommunityBlockForm};
|
||||
|
||||
impl Blockable for CommunityBlock {
|
||||
type Form = CommunityBlockForm;
|
||||
fn block(conn: &PgConnection, community_block_form: &Self::Form) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::community_block::dsl::*;
|
||||
use crate::schema::community_block::dsl::*;
|
||||
insert_into(community_block)
|
||||
.values(community_block_form)
|
||||
.on_conflict((person_id, community_id))
|
||||
|
@ -14,7 +16,7 @@ impl Blockable for CommunityBlock {
|
|||
.get_result::<Self>(conn)
|
||||
}
|
||||
fn unblock(conn: &PgConnection, community_block_form: &Self::Form) -> Result<usize, Error> {
|
||||
use lemmy_db_schema::schema::community_block::dsl::*;
|
||||
use crate::schema::community_block::dsl::*;
|
||||
diesel::delete(
|
||||
community_block
|
||||
.filter(person_id.eq(community_block_form.person_id))
|
|
@ -1,16 +1,19 @@
|
|||
use crate::Crud;
|
||||
use bcrypt::{hash, DEFAULT_COST};
|
||||
use diesel::{dsl::*, result::Error, *};
|
||||
use lemmy_db_schema::{
|
||||
use crate::{
|
||||
naive_now,
|
||||
newtypes::LocalUserId,
|
||||
schema::local_user::dsl::*,
|
||||
source::local_user::{LocalUser, LocalUserForm},
|
||||
LocalUserId,
|
||||
traits::Crud,
|
||||
};
|
||||
use bcrypt::{hash, DEFAULT_COST};
|
||||
use diesel::{dsl::*, result::Error, *};
|
||||
|
||||
mod safe_settings_type {
|
||||
use crate::ToSafeSettings;
|
||||
use lemmy_db_schema::{schema::local_user::columns::*, source::local_user::LocalUser};
|
||||
use crate::{
|
||||
schema::local_user::columns::*,
|
||||
source::local_user::LocalUser,
|
||||
traits::ToSafeSettings,
|
||||
};
|
||||
|
||||
type Columns = (
|
||||
id,
|
||||
|
@ -56,17 +59,8 @@ mod safe_settings_type {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait LocalUser_ {
|
||||
fn register(conn: &PgConnection, form: &LocalUserForm) -> Result<LocalUser, Error>;
|
||||
fn update_password(
|
||||
conn: &PgConnection,
|
||||
local_user_id: LocalUserId,
|
||||
new_password: &str,
|
||||
) -> Result<LocalUser, Error>;
|
||||
}
|
||||
|
||||
impl LocalUser_ for LocalUser {
|
||||
fn register(conn: &PgConnection, form: &LocalUserForm) -> Result<Self, Error> {
|
||||
impl LocalUser {
|
||||
pub fn register(conn: &PgConnection, form: &LocalUserForm) -> Result<Self, Error> {
|
||||
let mut edited_user = form.clone();
|
||||
let password_hash =
|
||||
hash(&form.password_encrypted, DEFAULT_COST).expect("Couldn't hash password");
|
||||
|
@ -75,7 +69,7 @@ impl LocalUser_ for LocalUser {
|
|||
Self::create(conn, &edited_user)
|
||||
}
|
||||
|
||||
fn update_password(
|
||||
pub fn update_password(
|
||||
conn: &PgConnection,
|
||||
local_user_id: LocalUserId,
|
||||
new_password: &str,
|
|
@ -1,24 +1,23 @@
|
|||
use crate::Crud;
|
||||
use crate::{source::moderator::*, traits::Crud};
|
||||
use diesel::{dsl::*, result::Error, *};
|
||||
use lemmy_db_schema::source::moderator::*;
|
||||
|
||||
impl Crud for ModRemovePost {
|
||||
type Form = ModRemovePostForm;
|
||||
type IdType = i32;
|
||||
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_remove_post::dsl::*;
|
||||
use crate::schema::mod_remove_post::dsl::*;
|
||||
mod_remove_post.find(from_id).first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn create(conn: &PgConnection, form: &ModRemovePostForm) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_remove_post::dsl::*;
|
||||
use crate::schema::mod_remove_post::dsl::*;
|
||||
insert_into(mod_remove_post)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
|
||||
fn update(conn: &PgConnection, from_id: i32, form: &ModRemovePostForm) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_remove_post::dsl::*;
|
||||
use crate::schema::mod_remove_post::dsl::*;
|
||||
diesel::update(mod_remove_post.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -29,19 +28,19 @@ impl Crud for ModLockPost {
|
|||
type Form = ModLockPostForm;
|
||||
type IdType = i32;
|
||||
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_lock_post::dsl::*;
|
||||
use crate::schema::mod_lock_post::dsl::*;
|
||||
mod_lock_post.find(from_id).first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn create(conn: &PgConnection, form: &ModLockPostForm) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_lock_post::dsl::*;
|
||||
use crate::schema::mod_lock_post::dsl::*;
|
||||
insert_into(mod_lock_post)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
|
||||
fn update(conn: &PgConnection, from_id: i32, form: &ModLockPostForm) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_lock_post::dsl::*;
|
||||
use crate::schema::mod_lock_post::dsl::*;
|
||||
diesel::update(mod_lock_post.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -52,19 +51,19 @@ impl Crud for ModStickyPost {
|
|||
type Form = ModStickyPostForm;
|
||||
type IdType = i32;
|
||||
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_sticky_post::dsl::*;
|
||||
use crate::schema::mod_sticky_post::dsl::*;
|
||||
mod_sticky_post.find(from_id).first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn create(conn: &PgConnection, form: &ModStickyPostForm) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_sticky_post::dsl::*;
|
||||
use crate::schema::mod_sticky_post::dsl::*;
|
||||
insert_into(mod_sticky_post)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
|
||||
fn update(conn: &PgConnection, from_id: i32, form: &ModStickyPostForm) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_sticky_post::dsl::*;
|
||||
use crate::schema::mod_sticky_post::dsl::*;
|
||||
diesel::update(mod_sticky_post.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -75,19 +74,19 @@ impl Crud for ModRemoveComment {
|
|||
type Form = ModRemoveCommentForm;
|
||||
type IdType = i32;
|
||||
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_remove_comment::dsl::*;
|
||||
use crate::schema::mod_remove_comment::dsl::*;
|
||||
mod_remove_comment.find(from_id).first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn create(conn: &PgConnection, form: &ModRemoveCommentForm) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_remove_comment::dsl::*;
|
||||
use crate::schema::mod_remove_comment::dsl::*;
|
||||
insert_into(mod_remove_comment)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
|
||||
fn update(conn: &PgConnection, from_id: i32, form: &ModRemoveCommentForm) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_remove_comment::dsl::*;
|
||||
use crate::schema::mod_remove_comment::dsl::*;
|
||||
diesel::update(mod_remove_comment.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -98,12 +97,12 @@ impl Crud for ModRemoveCommunity {
|
|||
type Form = ModRemoveCommunityForm;
|
||||
type IdType = i32;
|
||||
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_remove_community::dsl::*;
|
||||
use crate::schema::mod_remove_community::dsl::*;
|
||||
mod_remove_community.find(from_id).first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn create(conn: &PgConnection, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_remove_community::dsl::*;
|
||||
use crate::schema::mod_remove_community::dsl::*;
|
||||
insert_into(mod_remove_community)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -114,7 +113,7 @@ impl Crud for ModRemoveCommunity {
|
|||
from_id: i32,
|
||||
form: &ModRemoveCommunityForm,
|
||||
) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_remove_community::dsl::*;
|
||||
use crate::schema::mod_remove_community::dsl::*;
|
||||
diesel::update(mod_remove_community.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -125,12 +124,12 @@ impl Crud for ModBanFromCommunity {
|
|||
type Form = ModBanFromCommunityForm;
|
||||
type IdType = i32;
|
||||
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_ban_from_community::dsl::*;
|
||||
use crate::schema::mod_ban_from_community::dsl::*;
|
||||
mod_ban_from_community.find(from_id).first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn create(conn: &PgConnection, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_ban_from_community::dsl::*;
|
||||
use crate::schema::mod_ban_from_community::dsl::*;
|
||||
insert_into(mod_ban_from_community)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -141,7 +140,7 @@ impl Crud for ModBanFromCommunity {
|
|||
from_id: i32,
|
||||
form: &ModBanFromCommunityForm,
|
||||
) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_ban_from_community::dsl::*;
|
||||
use crate::schema::mod_ban_from_community::dsl::*;
|
||||
diesel::update(mod_ban_from_community.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -152,17 +151,17 @@ impl Crud for ModBan {
|
|||
type Form = ModBanForm;
|
||||
type IdType = i32;
|
||||
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_ban::dsl::*;
|
||||
use crate::schema::mod_ban::dsl::*;
|
||||
mod_ban.find(from_id).first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn create(conn: &PgConnection, form: &ModBanForm) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_ban::dsl::*;
|
||||
use crate::schema::mod_ban::dsl::*;
|
||||
insert_into(mod_ban).values(form).get_result::<Self>(conn)
|
||||
}
|
||||
|
||||
fn update(conn: &PgConnection, from_id: i32, form: &ModBanForm) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_ban::dsl::*;
|
||||
use crate::schema::mod_ban::dsl::*;
|
||||
diesel::update(mod_ban.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -173,19 +172,19 @@ impl Crud for ModAddCommunity {
|
|||
type Form = ModAddCommunityForm;
|
||||
type IdType = i32;
|
||||
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_add_community::dsl::*;
|
||||
use crate::schema::mod_add_community::dsl::*;
|
||||
mod_add_community.find(from_id).first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn create(conn: &PgConnection, form: &ModAddCommunityForm) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_add_community::dsl::*;
|
||||
use crate::schema::mod_add_community::dsl::*;
|
||||
insert_into(mod_add_community)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
|
||||
fn update(conn: &PgConnection, from_id: i32, form: &ModAddCommunityForm) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_add_community::dsl::*;
|
||||
use crate::schema::mod_add_community::dsl::*;
|
||||
diesel::update(mod_add_community.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -196,12 +195,12 @@ impl Crud for ModTransferCommunity {
|
|||
type Form = ModTransferCommunityForm;
|
||||
type IdType = i32;
|
||||
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_transfer_community::dsl::*;
|
||||
use crate::schema::mod_transfer_community::dsl::*;
|
||||
mod_transfer_community.find(from_id).first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn create(conn: &PgConnection, form: &ModTransferCommunityForm) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_transfer_community::dsl::*;
|
||||
use crate::schema::mod_transfer_community::dsl::*;
|
||||
insert_into(mod_transfer_community)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -212,7 +211,7 @@ impl Crud for ModTransferCommunity {
|
|||
from_id: i32,
|
||||
form: &ModTransferCommunityForm,
|
||||
) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_transfer_community::dsl::*;
|
||||
use crate::schema::mod_transfer_community::dsl::*;
|
||||
diesel::update(mod_transfer_community.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -223,17 +222,17 @@ impl Crud for ModAdd {
|
|||
type Form = ModAddForm;
|
||||
type IdType = i32;
|
||||
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_add::dsl::*;
|
||||
use crate::schema::mod_add::dsl::*;
|
||||
mod_add.find(from_id).first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn create(conn: &PgConnection, form: &ModAddForm) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_add::dsl::*;
|
||||
use crate::schema::mod_add::dsl::*;
|
||||
insert_into(mod_add).values(form).get_result::<Self>(conn)
|
||||
}
|
||||
|
||||
fn update(conn: &PgConnection, from_id: i32, form: &ModAddForm) -> Result<Self, Error> {
|
||||
use lemmy_db_schema::schema::mod_add::dsl::*;
|
||||
use crate::schema::mod_add::dsl::*;
|
||||
diesel::update(mod_add.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
|
@ -242,8 +241,11 @@ impl Crud for ModAdd {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{establish_unpooled_connection, Crud};
|
||||
use lemmy_db_schema::source::{comment::*, community::*, moderator::*, person::*, post::*};
|
||||
use crate::{
|
||||
establish_unpooled_connection,
|
||||
source::{comment::*, community::*, moderator::*, person::*, post::*},
|
||||
traits::Crud,
|
||||
};
|
||||
use serial_test::serial;
|
||||
|
||||
// use Crud;
|
|
@ -1,10 +1,10 @@
|
|||
use crate::Crud;
|
||||
use diesel::{dsl::*, result::Error, PgConnection, *};
|
||||
use lemmy_db_schema::{
|
||||
use crate::{
|
||||
newtypes::LocalUserId,
|
||||
schema::password_reset_request::dsl::*,
|
||||
source::password_reset_request::*,
|
||||
LocalUserId,
|
||||
traits::Crud,
|
||||
};
|
||||
use diesel::{dsl::*, result::Error, PgConnection, *};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
impl Crud for PasswordResetRequest {
|
||||
|
@ -31,17 +31,8 @@ impl Crud for PasswordResetRequest {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait PasswordResetRequest_ {
|
||||
fn create_token(
|
||||
conn: &PgConnection,
|
||||
from_local_user_id: LocalUserId,
|
||||
token: &str,
|
||||
) -> Result<PasswordResetRequest, Error>;
|
||||
fn read_from_token(conn: &PgConnection, token: &str) -> Result<PasswordResetRequest, Error>;
|
||||
}
|
||||
|
||||
impl PasswordResetRequest_ for PasswordResetRequest {
|
||||
fn create_token(
|
||||
impl PasswordResetRequest {
|
||||
pub fn create_token(
|
||||
conn: &PgConnection,
|
||||
from_local_user_id: LocalUserId,
|
||||
token: &str,
|
||||
|
@ -57,7 +48,7 @@ impl PasswordResetRequest_ for PasswordResetRequest {
|
|||
|
||||
Self::create(conn, &form)
|
||||
}
|
||||
fn read_from_token(conn: &PgConnection, token: &str) -> Result<PasswordResetRequest, Error> {
|
||||
pub fn read_from_token(conn: &PgConnection, token: &str) -> Result<PasswordResetRequest, Error> {
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(token);
|
||||
let token_hash: String = bytes_to_hex(hasher.finalize().to_vec());
|
||||
|
@ -80,13 +71,12 @@ fn bytes_to_hex(bytes: Vec<u8>) -> String {
|
|||
mod tests {
|
||||
use crate::{
|
||||
establish_unpooled_connection,
|
||||
source::password_reset_request::PasswordResetRequest_,
|
||||
Crud,
|
||||
};
|
||||
use lemmy_db_schema::source::{
|
||||
source::{
|
||||
local_user::{LocalUser, LocalUserForm},
|
||||
password_reset_request::PasswordResetRequest,
|
||||
person::*,
|
||||
},
|
||||
traits::Crud,
|
||||
};
|
||||
use serial_test::serial;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue