"jsonwebtoken",
"lazy_static",
"lemmy_apub",
- "lemmy_db",
+ "lemmy_db_queries",
"lemmy_db_schema",
+ "lemmy_db_views",
"lemmy_rate_limit",
"lemmy_structs",
"lemmy_utils",
"http-signature-normalization-reqwest",
"itertools",
"lazy_static",
- "lemmy_db",
+ "lemmy_db_queries",
"lemmy_db_schema",
+ "lemmy_db_views",
"lemmy_structs",
"lemmy_utils",
"lemmy_websocket",
]
[[package]]
-name = "lemmy_db"
+name = "lemmy_db_aggregates"
+version = "0.1.0"
+dependencies = [
+ "chrono",
+ "diesel",
+ "lemmy_db_queries",
+ "lemmy_db_schema",
+ "serde 1.0.118",
+]
+
+[[package]]
+name = "lemmy_db_queries"
version = "0.1.0"
dependencies = [
"bcrypt",
"url",
]
+[[package]]
+name = "lemmy_db_views"
+version = "0.1.0"
+dependencies = [
+ "diesel",
+ "lemmy_db_aggregates",
+ "lemmy_db_queries",
+ "lemmy_db_schema",
+ "serde 1.0.118",
+]
+
[[package]]
name = "lemmy_rate_limit"
version = "0.1.0"
"lazy_static",
"lemmy_api",
"lemmy_apub",
- "lemmy_db",
+ "lemmy_db_aggregates",
+ "lemmy_db_queries",
"lemmy_db_schema",
+ "lemmy_db_views",
"lemmy_rate_limit",
"lemmy_structs",
"lemmy_utils",
"actix-web",
"chrono",
"diesel",
- "lemmy_db",
+ "lemmy_db_queries",
"lemmy_db_schema",
+ "lemmy_db_views",
"lemmy_utils",
"log",
"serde 1.0.118",
"background-jobs",
"chrono",
"diesel",
- "lemmy_db",
+ "lemmy_db_queries",
"lemmy_db_schema",
"lemmy_rate_limit",
"lemmy_structs",
"lemmy_api",
"lemmy_apub",
"lemmy_utils",
- "lemmy_db",
+ "lemmy_db_queries",
"lemmy_db_schema",
"lemmy_structs",
"lemmy_rate_limit",
lemmy_apub = { path = "./lemmy_apub" }
lemmy_utils = { path = "./lemmy_utils" }
lemmy_db_schema = { path = "./lemmy_db_schema" }
-lemmy_db = { path = "./lemmy_db" }
+lemmy_db_queries = { path = "lemmy_db_queries" }
+lemmy_db_views = { path = "./lemmy_db_views" }
+lemmy_db_aggregates = { path = "./lemmy_db_aggregates" }
lemmy_structs = { path = "./lemmy_structs" }
lemmy_rate_limit = { path = "./lemmy_rate_limit" }
lemmy_websocket = { path = "./lemmy_websocket" }
[dependencies]
lemmy_apub = { path = "../lemmy_apub" }
lemmy_utils = { path = "../lemmy_utils" }
-lemmy_db = { path = "../lemmy_db" }
+lemmy_db_queries = { path = "../lemmy_db_queries" }
lemmy_db_schema = { path = "../lemmy_db_schema" }
+lemmy_db_views = { path = "../lemmy_db_views" }
lemmy_structs = { path = "../lemmy_structs" }
lemmy_rate_limit = { path = "../lemmy_rate_limit" }
lemmy_websocket = { path = "../lemmy_websocket" }
use lemmy_apub::{ApubLikeableType, ApubObjectType};
use lemmy_db::{
source::comment::Comment_,
- views::{
- comment_report_view::{CommentReportQueryBuilder, CommentReportView},
- comment_view::{CommentQueryBuilder, CommentView},
- },
Crud,
Likeable,
ListingType,
SortType,
};
use lemmy_db_schema::source::{comment::*, comment_report::*, moderator::*};
+use lemmy_db_views::{
+ comment_report_view::{CommentReportQueryBuilder, CommentReportView},
+ comment_view::{CommentQueryBuilder, CommentView},
+};
use lemmy_structs::{blocking, comment::*, send_local_notifs};
use lemmy_utils::{
apub::{make_apub_endpoint, EndpointType},
community::{CommunityModerator_, Community_},
post::Post_,
},
- views::{
- comment_view::CommentQueryBuilder,
- community::{
- community_follower_view::CommunityFollowerView,
- community_moderator_view::CommunityModeratorView,
- community_view::{CommunityQueryBuilder, CommunityView},
- },
- user_view::UserViewSafe,
- },
ApubObject,
Bannable,
Crud,
naive_now,
source::{comment::Comment, community::*, moderator::*, post::Post, site::*},
};
+use lemmy_db_views::{
+ comment_view::CommentQueryBuilder,
+ community::{
+ community_follower_view::CommunityFollowerView,
+ community_moderator_view::CommunityModeratorView,
+ community_view::{CommunityQueryBuilder, CommunityView},
+ },
+ user_view::UserViewSafe,
+};
use lemmy_structs::{blocking, community::*};
use lemmy_utils::{
apub::{generate_actor_keypair, make_apub_endpoint, EndpointType},
community::{CommunityModerator_, Community_},
site::Site_,
},
- views::community::community_user_ban_view::CommunityUserBanView,
Crud,
DbPool,
};
site::Site,
user::User_,
};
+use lemmy_db_views::community::{
+ community_user_ban_view::CommunityUserBanView,
+ community_view::CommunityView,
+};
use lemmy_structs::{blocking, comment::*, community::*, post::*, site::*, user::*};
use lemmy_utils::{settings::Settings, APIError, ConnectionId, LemmyError};
use lemmy_websocket::{serialize_websocket_message, LemmyContext, UserOperation};
community_id: i32,
) -> Result<(), LemmyError> {
let is_mod_or_admin = blocking(pool, move |conn| {
- Community::is_mod_or_admin(conn, user_id, community_id)
+ CommunityView::is_mod_or_admin(conn, user_id, community_id)
})
.await?;
if !is_mod_or_admin {
};
use actix_web::web::Data;
use lemmy_apub::{ApubLikeableType, ApubObjectType};
-use lemmy_db::{
- source::post::Post_,
- views::{
- comment_view::CommentQueryBuilder,
- community::community_moderator_view::CommunityModeratorView,
- post_report_view::{PostReportQueryBuilder, PostReportView},
- post_view::{PostQueryBuilder, PostView},
- },
- Crud,
- Likeable,
- ListingType,
- Reportable,
- Saveable,
- SortType,
-};
+use lemmy_db::{source::post::Post_, Crud, Likeable, ListingType, Reportable, Saveable, SortType};
use lemmy_db_schema::{
naive_now,
source::{
post_report::{PostReport, PostReportForm},
},
};
+use lemmy_db_views::{
+ comment_view::CommentQueryBuilder,
+ community::community_moderator_view::CommunityModeratorView,
+ post_report_view::{PostReportQueryBuilder, PostReportView},
+ post_view::{PostQueryBuilder, PostView},
+};
use lemmy_structs::{blocking, post::*};
use lemmy_utils::{
apub::{make_apub_endpoint, EndpointType},
use lemmy_db::{
diesel_option_overwrite,
source::{category::Category_, site::Site_},
- views::{
- comment_view::CommentQueryBuilder,
- community::community_view::CommunityQueryBuilder,
- moderator::{
- mod_add_community_view::ModAddCommunityView,
- mod_add_view::ModAddView,
- mod_ban_from_community_view::ModBanFromCommunityView,
- mod_ban_view::ModBanView,
- mod_lock_post_view::ModLockPostView,
- mod_remove_comment_view::ModRemoveCommentView,
- mod_remove_community_view::ModRemoveCommunityView,
- mod_remove_post_view::ModRemovePostView,
- mod_sticky_post_view::ModStickyPostView,
- },
- post_view::PostQueryBuilder,
- site_view::SiteView,
- user_view::{UserQueryBuilder, UserViewSafe},
- },
Crud,
SearchType,
SortType,
site::{Site, *},
},
};
+use lemmy_db_views::{
+ comment_view::CommentQueryBuilder,
+ community::community_view::CommunityQueryBuilder,
+ moderator::{
+ mod_add_community_view::ModAddCommunityView,
+ mod_add_view::ModAddView,
+ mod_ban_from_community_view::ModBanFromCommunityView,
+ mod_ban_view::ModBanView,
+ mod_lock_post_view::ModLockPostView,
+ mod_remove_comment_view::ModRemoveCommentView,
+ mod_remove_community_view::ModRemoveCommunityView,
+ mod_remove_post_view::ModRemovePostView,
+ mod_sticky_post_view::ModStickyPostView,
+ },
+ post_view::PostQueryBuilder,
+ site_view::SiteView,
+ user_view::{UserQueryBuilder, UserViewSafe},
+};
use lemmy_structs::{blocking, site::*, user::Register};
use lemmy_utils::{
location_info,
user::User,
user_mention::UserMention_,
},
- views::{
- comment_report_view::CommentReportView,
- comment_view::CommentQueryBuilder,
- community::{
- community_follower_view::CommunityFollowerView,
- community_moderator_view::CommunityModeratorView,
- },
- post_report_view::PostReportView,
- post_view::PostQueryBuilder,
- private_message_view::{PrivateMessageQueryBuilder, PrivateMessageView},
- user_mention_view::{UserMentionQueryBuilder, UserMentionView},
- user_view::{UserViewDangerous, UserViewSafe},
- },
Crud,
Followable,
Joinable,
user_mention::*,
},
};
+use lemmy_db_views::{
+ comment_report_view::CommentReportView,
+ comment_view::CommentQueryBuilder,
+ community::{
+ community_follower_view::CommunityFollowerView,
+ community_moderator_view::CommunityModeratorView,
+ },
+ post_report_view::PostReportView,
+ post_view::PostQueryBuilder,
+ private_message_view::{PrivateMessageQueryBuilder, PrivateMessageView},
+ user_mention_view::{UserMentionQueryBuilder, UserMentionView},
+ user_view::{UserViewDangerous, UserViewSafe},
+};
use lemmy_structs::{blocking, send_email_to_user, user::*};
use lemmy_utils::{
apub::{generate_actor_keypair, make_apub_endpoint, EndpointType},
[dependencies]
lemmy_utils = { path = "../lemmy_utils" }
-lemmy_db = { path = "../lemmy_db" }
+lemmy_db_queries = { path = "../lemmy_db_queries" }
lemmy_db_schema = { path = "../lemmy_db_schema" }
+lemmy_db_views = { path = "../lemmy_db_views" }
lemmy_structs = { path = "../lemmy_structs" }
lemmy_websocket = { path = "../lemmy_websocket" }
diesel = "1.4.5"
base::ExtendsExt,
};
use anyhow::Context;
-use lemmy_db::{source::comment::Comment_, views::comment_view::CommentView, Crud, Likeable};
+use lemmy_db::{source::comment::Comment_, Crud, Likeable};
use lemmy_db_schema::source::{
comment::{Comment, CommentLike, CommentLikeForm},
post::Post,
};
+use lemmy_db_views::comment_view::CommentView;
use lemmy_structs::{blocking, comment::CommentResponse, send_local_notifs};
use lemmy_utils::{location_info, utils::scrape_text_for_mentions, LemmyError};
use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperation};
use crate::activities::receive::get_actor_as_user;
use activitystreams::activity::{Dislike, Like};
-use lemmy_db::{source::comment::Comment_, views::comment_view::CommentView, Likeable};
+use lemmy_db::{source::comment::Comment_, Likeable};
use lemmy_db_schema::source::comment::{Comment, CommentLike};
+use lemmy_db_views::comment_view::CommentView;
use lemmy_structs::{blocking, comment::CommentResponse};
use lemmy_utils::LemmyError;
use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperation};
base::{AnyBase, ExtendsExt},
};
use anyhow::Context;
-use lemmy_db::{
- source::community::Community_,
- views::community::community_view::CommunityView,
- ApubObject,
-};
+use lemmy_db::{source::community::Community_, ApubObject};
use lemmy_db_schema::source::community::Community;
+use lemmy_db_views::community::community_view::CommunityView;
use lemmy_structs::{blocking, community::CommunityResponse};
use lemmy_utils::{location_info, LemmyError};
use lemmy_websocket::{messages::SendCommunityRoomMessage, LemmyContext, UserOperation};
prelude::*,
};
use anyhow::Context;
-use lemmy_db::{source::post::Post_, views::post_view::PostView, Likeable};
+use lemmy_db::{source::post::Post_, Likeable};
use lemmy_db_schema::source::post::{Post, PostLike, PostLikeForm};
+use lemmy_db_views::post_view::PostView;
use lemmy_structs::{blocking, post::PostResponse};
use lemmy_utils::{location_info, LemmyError};
use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation};
use crate::activities::receive::get_actor_as_user;
use activitystreams::activity::{Dislike, Like};
-use lemmy_db::{source::post::Post_, views::post_view::PostView, Likeable};
+use lemmy_db::{source::post::Post_, Likeable};
use lemmy_db_schema::source::post::{Post, PostLike};
+use lemmy_db_views::post_view::PostView;
use lemmy_structs::{blocking, post::PostResponse};
use lemmy_utils::LemmyError;
use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation};
public,
};
use anyhow::{anyhow, Context};
-use lemmy_db::{
- source::private_message::PrivateMessage_,
- views::private_message_view::PrivateMessageView,
-};
+use lemmy_db::source::private_message::PrivateMessage_;
use lemmy_db_schema::source::private_message::PrivateMessage;
+use lemmy_db_views::private_message_view::PrivateMessageView;
use lemmy_structs::{blocking, user::PrivateMessageResponse};
use lemmy_utils::{location_info, LemmyError};
use lemmy_websocket::{messages::SendUserRoomMessage, LemmyContext, UserOperation};
};
use anyhow::Context;
use itertools::Itertools;
-use lemmy_db::{views::community::community_follower_view::CommunityFollowerView, DbPool};
+use lemmy_db::DbPool;
use lemmy_db_schema::source::community::Community;
+use lemmy_db_views::community::community_follower_view::CommunityFollowerView;
use lemmy_structs::blocking;
use lemmy_utils::{location_info, settings::Settings, LemmyError};
use lemmy_websocket::LemmyContext;
use anyhow::{anyhow, Context};
use chrono::NaiveDateTime;
use diesel::result::Error::NotFound;
-use lemmy_db::{
- source::user::User,
- views::{
- comment_view::CommentView,
- community::community_view::CommunityView,
- post_view::PostView,
- user_view::UserViewSafe,
- },
- ApubObject,
- Crud,
- Joinable,
- SearchType,
-};
+use lemmy_db::{source::user::User, ApubObject, Crud, Joinable, SearchType};
use lemmy_db_schema::{
naive_now,
source::{
user::User_,
},
};
+use lemmy_db_views::{
+ comment_view::CommentView,
+ community::community_view::CommunityView,
+ post_view::PostView,
+ user_view::UserViewSafe,
+};
use lemmy_structs::{blocking, site::SearchResponse};
use lemmy_utils::{
location_info,
collection::{CollectionExt, OrderedCollection, UnorderedCollection},
};
use actix_web::{body::Body, web, HttpResponse};
-use lemmy_db::{
- source::{community::Community_, post::Post_},
- views::community::community_follower_view::CommunityFollowerView,
-};
+use lemmy_db::source::{community::Community_, post::Post_};
use lemmy_db_schema::source::{community::Community, post::Post};
+use lemmy_db_views::community::community_follower_view::CommunityFollowerView;
use lemmy_structs::blocking;
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
};
use actix_web::{web, HttpRequest, HttpResponse};
use anyhow::{anyhow, Context};
-use lemmy_db::{
- source::community::Community_,
- views::community::community_user_ban_view::CommunityUserBanView,
- ApubObject,
- DbPool,
- Followable,
-};
+use lemmy_db::{source::community::Community_, ApubObject, DbPool, Followable};
use lemmy_db_schema::source::{
community::{Community, CommunityFollower, CommunityFollowerForm},
user::User_,
};
+use lemmy_db_views::community::community_user_ban_view::CommunityUserBanView;
use lemmy_structs::blocking;
use lemmy_utils::{location_info, LemmyError};
use lemmy_websocket::LemmyContext;
};
use activitystreams_ext::Ext2;
use anyhow::Context;
-use lemmy_db::{views::community::community_moderator_view::CommunityModeratorView, DbPool};
+use lemmy_db::DbPool;
use lemmy_db_schema::{
naive_now,
source::community::{Community, CommunityForm},
};
+use lemmy_db_views::community::community_moderator_view::CommunityModeratorView;
use lemmy_structs::blocking;
use lemmy_utils::{
location_info,
--- /dev/null
+[package]
+name = "lemmy_db_aggregates"
+version = "0.1.0"
+edition = "2018"
+
+[dependencies]
+lemmy_db_schema = { path = "../lemmy_db_schema" }
+lemmy_db_queries = { path = "../lemmy_db_queries" }
+diesel = { version = "1.4.5", features = ["postgres","chrono","r2d2","serde_json"] }
+serde = { version = "1.0.118", features = ["derive"] }
+chrono = { version = "0.4.19", features = ["serde"] }
#[cfg(test)]
mod tests {
- use crate::{
- aggregates::comment_aggregates::CommentAggregates,
- source::{
- comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
- community::{Community, CommunityForm},
- post::{Post, PostForm},
- user::{UserForm, User_},
- },
- tests::establish_unpooled_connection,
- Crud,
- Likeable,
- ListingType,
- SortType,
+ use crate::comment_aggregates::CommentAggregates;
+ use lemmy_db::{establish_unpooled_connection, Crud, Likeable, ListingType, SortType};
+ use lemmy_db_schema::source::{
+ comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
+ community::{Community, CommunityForm},
+ post::{Post, PostForm},
+ user::{UserForm, User_},
};
#[test]
#[cfg(test)]
mod tests {
- use crate::{
- aggregates::community_aggregates::CommunityAggregates,
- tests::establish_unpooled_connection,
- Crud,
- Followable,
- ListingType,
- SortType,
- };
+ use crate::community_aggregates::CommunityAggregates;
+ use lemmy_db::{establish_unpooled_connection, Crud, Followable, ListingType, SortType};
use lemmy_db_schema::source::{
comment::{Comment, CommentForm},
community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm},
#[cfg(test)]
mod tests {
- use crate::{
- aggregates::post_aggregates::PostAggregates,
- tests::establish_unpooled_connection,
- Crud,
- Likeable,
- ListingType,
- SortType,
- };
+ use crate::post_aggregates::PostAggregates;
+ use lemmy_db::{establish_unpooled_connection, Crud, Likeable, ListingType, SortType};
use lemmy_db_schema::source::{
comment::{Comment, CommentForm},
community::{Community, CommunityForm},
#[cfg(test)]
mod tests {
- use crate::{
- aggregates::site_aggregates::SiteAggregates,
- tests::establish_unpooled_connection,
- Crud,
- ListingType,
- SortType,
- };
+ use crate::site_aggregates::SiteAggregates;
+ use lemmy_db::{establish_unpooled_connection, Crud, ListingType, SortType};
use lemmy_db_schema::source::{
comment::{Comment, CommentForm},
community::{Community, CommunityForm},
post::{Post, PostForm},
+ site::{Site, SiteForm},
user::{UserForm, User_},
};
#[cfg(test)]
mod tests {
- use crate::{
- aggregates::user_aggregates::UserAggregates,
- tests::establish_unpooled_connection,
- Crud,
- Likeable,
- ListingType,
- SortType,
- };
+ use crate::user_aggregates::UserAggregates;
+ use lemmy_db::{establish_unpooled_connection, Crud, Likeable, ListingType, SortType};
use lemmy_db_schema::source::{
comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
community::{Community, CommunityForm},
[package]
-name = "lemmy_db"
+name = "lemmy_db_queries"
version = "0.1.0"
edition = "2018"
use serde::{Deserialize, Serialize};
use std::{env, env::VarError};
-pub mod aggregates;
pub mod source;
-pub mod views;
pub type DbPool = diesel::r2d2::Pool<diesel::r2d2::ConnectionManager<diesel::PgConnection>>;
}
}
-pub(crate) trait ToSafe {
+pub trait ToSafe {
type SafeColumns;
fn safe_columns_tuple() -> Self::SafeColumns;
}
}
}
+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).unwrap();
+ conn
+}
+
lazy_static! {
static ref EMAIL_REGEX: Regex =
Regex::new(r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$").unwrap();
}
-pub(crate) mod functions {
+pub mod functions {
use diesel::sql_types::*;
sql_function! {
#[cfg(test)]
mod tests {
use super::fuzzy_search;
- use crate::{get_database_url_from_env, is_email_regex};
- use diesel::{Connection, PgConnection};
-
- 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).unwrap();
- conn
- }
+ use crate::is_email_regex;
#[test]
fn test_fuzzy_search() {
#[cfg(test)]
mod tests {
- use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType};
+ use crate::{
+ establish_unpooled_connection,
+ source::activity::Activity_,
+ Crud,
+ ListingType,
+ SortType,
+ };
use lemmy_db_schema::source::{
activity::{Activity, ActivityForm},
user::{UserForm, User_},
#[cfg(test)]
mod tests {
- use crate::tests::establish_unpooled_connection;
+ use crate::{establish_unpooled_connection, source::category::Category_};
use lemmy_db_schema::source::category::Category;
#[test]
#[cfg(test)]
mod tests {
- use crate::{
- tests::establish_unpooled_connection,
- Crud,
- Likeable,
- ListingType,
- Saveable,
- SortType,
- };
+ use crate::{establish_unpooled_connection, Crud, Likeable, ListingType, Saveable, SortType};
use lemmy_db_schema::source::{
comment::*,
community::{Community, CommunityForm},
-use crate::{
- views::{community::community_moderator_view::CommunityModeratorView, user_view::UserViewSafe},
- ApubObject,
- Bannable,
- Crud,
- Followable,
- Joinable,
-};
+use crate::{ApubObject, Bannable, Crud, Followable, Joinable};
use diesel::{dsl::*, result::Error, *};
use lemmy_db_schema::{
naive_now,
community_id: i32,
new_creator_id: i32,
) -> Result<Community, Error>;
- fn community_mods_and_admins(conn: &PgConnection, community_id: i32) -> Result<Vec<i32>, Error>;
fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error>;
- fn is_mod_or_admin(conn: &PgConnection, user_id: i32, community_id: i32) -> bool;
}
impl Community_ for Community {
.get_result::<Self>(conn)
}
- fn community_mods_and_admins(conn: &PgConnection, community_id: i32) -> Result<Vec<i32>, Error> {
- let mut mods_and_admins: Vec<i32> = Vec::new();
- mods_and_admins.append(
- &mut CommunityModeratorView::for_community(conn, community_id)
- .map(|v| v.into_iter().map(|m| m.moderator.id).collect())?,
- );
- mods_and_admins
- .append(&mut UserViewSafe::admins(conn).map(|v| v.into_iter().map(|a| a.user.id).collect())?);
- Ok(mods_and_admins)
- }
-
fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error> {
use lemmy_db_schema::schema::community::dsl::*;
community.select(actor_id).distinct().load::<String>(conn)
}
-
- fn is_mod_or_admin(conn: &PgConnection, user_id: i32, community_id: i32) -> bool {
- Self::community_mods_and_admins(conn, community_id)
- .unwrap_or_default()
- .contains(&user_id)
- }
}
impl Joinable<CommunityModeratorForm> for CommunityModerator {
#[cfg(test)]
mod tests {
use crate::{
- tests::establish_unpooled_connection,
+ establish_unpooled_connection,
Bannable,
Crud,
Followable,
#[cfg(test)]
mod tests {
- use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType};
+ use crate::{establish_unpooled_connection, Crud, ListingType, SortType};
use lemmy_db_schema::source::{comment::*, community::*, moderator::*, post::*, user::*};
// use Crud;
#[cfg(test)]
mod tests {
- use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType};
+ use crate::{
+ establish_unpooled_connection,
+ source::password_reset_request::PasswordResetRequest_,
+ Crud,
+ ListingType,
+ SortType,
+ };
use lemmy_db_schema::source::{password_reset_request::PasswordResetRequest, user::*};
#[test]
#[cfg(test)]
mod tests {
- use crate::{source::post::*, tests::establish_unpooled_connection, ListingType, SortType};
+ use crate::{establish_unpooled_connection, source::post::*, ListingType, SortType};
use lemmy_db_schema::source::{
community::{Community, CommunityForm},
user::*,
#[cfg(test)]
mod tests {
- use crate::{tests::establish_unpooled_connection, ListingType, SortType};
+ use crate::{
+ establish_unpooled_connection,
+ source::private_message::PrivateMessage_,
+ Crud,
+ ListingType,
+ SortType,
+ };
use lemmy_db_schema::source::{private_message::*, user::*};
#[test]
#[cfg(test)]
mod tests {
- use crate::{source::user::*, tests::establish_unpooled_connection, ListingType, SortType};
+ use crate::{establish_unpooled_connection, source::user::*, ListingType, SortType};
#[test]
fn test_crud() {
#[cfg(test)]
mod tests {
- use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType};
+ use crate::{establish_unpooled_connection, Crud, ListingType, SortType};
use lemmy_db_schema::source::{
comment::*,
community::{Community, CommunityForm},
pub mod schema;
pub mod source;
-// TODO: can probably move this back to lemmy_db
+// TODO: can probably move this back to lemmy_db_queries
pub fn naive_now() -> NaiveDateTime {
chrono::prelude::Utc::now().naive_utc()
}
use crate::{schema::comment_report, source::comment::Comment};
use serde::{Deserialize, Serialize};
-#[derive(
- Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone,
-)]
+#[derive(Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone)]
#[belongs_to(Comment)]
#[table_name = "comment_report"]
pub struct CommentReport {
use crate::{schema::post_report, source::post::Post};
use serde::{Deserialize, Serialize};
-#[derive(
- Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone,
-)]
+#[derive(Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone)]
#[belongs_to(Post)]
#[table_name = "post_report"]
pub struct PostReport {
--- /dev/null
+[package]
+name = "lemmy_db_views"
+version = "0.1.0"
+edition = "2018"
+
+[dependencies]
+lemmy_db_queries = { path = "../lemmy_db_queries" }
+lemmy_db_schema = { path = "../lemmy_db_schema" }
+lemmy_db_aggregates = { path = "../lemmy_db_aggregates" }
+diesel = { version = "1.4.5", features = ["postgres","chrono","r2d2","serde_json"] }
+serde = { version = "1.0.118", features = ["derive"] }
\ No newline at end of file
-use crate::{limit_and_offset, views::ViewToVec, MaybeOptional, ToSafe};
+use crate::ViewToVec;
use diesel::{result::Error, *};
+use lemmy_db::{limit_and_offset, MaybeOptional, ToSafe};
use lemmy_db_schema::{
schema::{comment, comment_report, community, post, user_, user_alias_1, user_alias_2},
source::{
-use crate::{
- aggregates::comment_aggregates::CommentAggregates,
+use crate::ViewToVec;
+use diesel::{result::Error, *};
+use lemmy_db::{
functions::hot_rank,
fuzzy_search,
limit_and_offset,
- views::ViewToVec,
ListingType,
MaybeOptional,
SortType,
ToSafe,
};
-use diesel::{result::Error, *};
+use lemmy_db_aggregates::comment_aggregates::CommentAggregates;
use lemmy_db_schema::{
schema::{
comment,
#[cfg(test)]
mod tests {
- use crate::{tests::establish_unpooled_connection, views::comment_view::*, Crud, Likeable, *};
+ use crate::comment_view::*;
+ use lemmy_db::{establish_unpooled_connection, Crud, Likeable, ListingType, SortType};
+ use lemmy_db_aggregates::comment_aggregates::CommentAggregates;
use lemmy_db_schema::source::{comment::*, community::*, post::*, user::*};
#[test]
-use crate::{views::ViewToVec, ToSafe};
+use crate::ViewToVec;
use diesel::{result::Error, *};
+use lemmy_db::ToSafe;
use lemmy_db_schema::{
schema::{community, community_follower, user_},
source::{
-use crate::{views::ViewToVec, ToSafe};
+use crate::ViewToVec;
use diesel::{result::Error, *};
+use lemmy_db::ToSafe;
use lemmy_db_schema::{
schema::{community, community_moderator, user_},
source::{
-use crate::ToSafe;
use diesel::{result::Error, *};
+use lemmy_db::ToSafe;
use lemmy_db_schema::{
schema::{community, community_user_ban, user_},
source::{
use crate::{
- aggregates::community_aggregates::CommunityAggregates,
+ community::community_moderator_view::CommunityModeratorView,
+ user_view::UserViewSafe,
+ ViewToVec,
+};
+use diesel::{result::Error, *};
+use lemmy_db::{
functions::hot_rank,
fuzzy_search,
limit_and_offset,
- views::ViewToVec,
MaybeOptional,
SortType,
ToSafe,
};
-use diesel::{result::Error, *};
+use lemmy_db_aggregates::community_aggregates::CommunityAggregates;
use lemmy_db_schema::{
schema::{category, community, community_aggregates, community_follower, user_},
source::{
counts,
})
}
+
+ // TODO: this function is only used by is_mod_or_admin() below, can probably be merged
+ fn community_mods_and_admins(conn: &PgConnection, community_id: i32) -> Result<Vec<i32>, Error> {
+ let mut mods_and_admins: Vec<i32> = Vec::new();
+ mods_and_admins.append(
+ &mut CommunityModeratorView::for_community(conn, community_id)
+ .map(|v| v.into_iter().map(|m| m.moderator.id).collect())?,
+ );
+ mods_and_admins
+ .append(&mut UserViewSafe::admins(conn).map(|v| v.into_iter().map(|a| a.user.id).collect())?);
+ Ok(mods_and_admins)
+ }
+
+ pub fn is_mod_or_admin(conn: &PgConnection, user_id: i32, community_id: i32) -> bool {
+ Self::community_mods_and_admins(conn, community_id)
+ .unwrap_or_default()
+ .contains(&user_id)
+ }
}
pub struct CommunityQueryBuilder<'a> {
-use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use crate::ViewToVec;
use diesel::{result::Error, *};
+use lemmy_db::{limit_and_offset, ToSafe};
use lemmy_db_schema::{
schema::{community, mod_add_community, user_, user_alias_1},
source::{
-use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use crate::ViewToVec;
use diesel::{result::Error, *};
+use lemmy_db::{limit_and_offset, ToSafe};
use lemmy_db_schema::{
schema::{mod_add, user_, user_alias_1},
source::{
-use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use crate::ViewToVec;
use diesel::{result::Error, *};
+use lemmy_db::{limit_and_offset, ToSafe};
use lemmy_db_schema::{
schema::{community, mod_ban_from_community, user_, user_alias_1},
source::{
-use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use crate::ViewToVec;
use diesel::{result::Error, *};
+use lemmy_db::{limit_and_offset, ToSafe};
use lemmy_db_schema::{
schema::{mod_ban, user_, user_alias_1},
source::{
-use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use crate::ViewToVec;
use diesel::{result::Error, *};
+use lemmy_db::{limit_and_offset, ToSafe};
use lemmy_db_schema::{
schema::{community, mod_lock_post, post, user_},
source::{
-use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use crate::ViewToVec;
use diesel::{result::Error, *};
+use lemmy_db::{limit_and_offset, ToSafe};
use lemmy_db_schema::{
schema::{comment, community, mod_remove_comment, post, user_, user_alias_1},
source::{
-use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use crate::ViewToVec;
use diesel::{result::Error, *};
+use lemmy_db::{limit_and_offset, ToSafe};
use lemmy_db_schema::{
schema::{community, mod_remove_community, user_},
source::{
-use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use crate::ViewToVec;
use diesel::{result::Error, *};
+use lemmy_db::{limit_and_offset, ToSafe};
use lemmy_db_schema::{
schema::{community, mod_remove_post, post, user_},
source::{
-use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use crate::ViewToVec;
use diesel::{result::Error, *};
+use lemmy_db::{limit_and_offset, ToSafe};
use lemmy_db_schema::{
schema::{community, mod_sticky_post, post, user_},
source::{
-use crate::{limit_and_offset, views::ViewToVec, MaybeOptional, ToSafe};
+use crate::ViewToVec;
use diesel::{result::Error, *};
+use lemmy_db::{limit_and_offset, MaybeOptional, ToSafe};
use lemmy_db_schema::{
schema::{community, post, post_report, user_, user_alias_1, user_alias_2},
source::{
-use crate::{
- aggregates::post_aggregates::PostAggregates,
+use crate::ViewToVec;
+use diesel::{result::Error, *};
+use lemmy_db::{
functions::hot_rank,
fuzzy_search,
limit_and_offset,
- views::ViewToVec,
ListingType,
MaybeOptional,
SortType,
ToSafe,
};
-use diesel::{result::Error, *};
+use lemmy_db_aggregates::post_aggregates::PostAggregates;
use lemmy_db_schema::{
schema::{
community,
#[cfg(test)]
mod tests {
- use crate::{
- aggregates::post_aggregates::PostAggregates,
- tests::establish_unpooled_connection,
- views::post_view::{PostQueryBuilder, PostView},
- Crud,
- Likeable,
- *,
- };
+ use crate::post_view::{PostQueryBuilder, PostView};
+ use lemmy_db::{establish_unpooled_connection, Crud, Likeable, ListingType, SortType};
+ use lemmy_db_aggregates::post_aggregates::PostAggregates;
use lemmy_db_schema::source::{community::*, post::*, user::*};
#[test]
-use crate::{limit_and_offset, views::ViewToVec, MaybeOptional, ToSafe};
+use crate::ViewToVec;
use diesel::{result::Error, *};
+use lemmy_db::{limit_and_offset, MaybeOptional, ToSafe};
use lemmy_db_schema::{
schema::{private_message, user_, user_alias_1},
source::{
-use crate::{aggregates::site_aggregates::SiteAggregates, ToSafe};
use diesel::{result::Error, *};
+use lemmy_db::ToSafe;
+use lemmy_db_aggregates::site_aggregates::SiteAggregates;
use lemmy_db_schema::{
schema::{site, site_aggregates, user_},
source::{
-use crate::{
- aggregates::comment_aggregates::CommentAggregates,
- functions::hot_rank,
- limit_and_offset,
- views::ViewToVec,
- MaybeOptional,
- SortType,
- ToSafe,
-};
+use crate::ViewToVec;
use diesel::{result::Error, *};
+use lemmy_db::{functions::hot_rank, limit_and_offset, MaybeOptional, SortType, ToSafe};
+use lemmy_db_aggregates::comment_aggregates::CommentAggregates;
use lemmy_db_schema::{
schema::{
comment,
-use crate::{
- aggregates::user_aggregates::UserAggregates,
- fuzzy_search,
- limit_and_offset,
- views::ViewToVec,
- MaybeOptional,
- SortType,
- ToSafe,
-};
+use crate::ViewToVec;
use diesel::{dsl::*, result::Error, *};
+use lemmy_db::{fuzzy_search, limit_and_offset, MaybeOptional, SortType, ToSafe};
+use lemmy_db_aggregates::user_aggregates::UserAggregates;
use lemmy_db_schema::{
schema::{user_, user_aggregates},
source::user::{UserSafe, User_},
path = "src/lib.rs"
[dependencies]
-lemmy_db = { path = "../lemmy_db" }
+lemmy_db_queries = { path = "../lemmy_db_queries" }
+lemmy_db_views = { path = "../lemmy_db_views" }
lemmy_db_schema = { path = "../lemmy_db_schema" }
lemmy_utils = { path = "../lemmy_utils" }
serde = { version = "1.0.118", features = ["derive"] }
-use lemmy_db::views::{comment_report_view::CommentReportView, comment_view::CommentView};
+use lemmy_db_views::{comment_report_view::CommentReportView, comment_view::CommentView};
use serde::{Deserialize, Serialize};
#[derive(Deserialize)]
-use lemmy_db::views::{
+use lemmy_db_views::{
community::{
community_follower_view::CommunityFollowerView,
community_moderator_view::CommunityModeratorView,
-use lemmy_db::views::{
+use lemmy_db_views::{
comment_view::CommentView,
community::community_moderator_view::CommunityModeratorView,
post_report_view::PostReportView,
-use lemmy_db::views::{
+use lemmy_db_schema::source::{category::*, user::User_};
+use lemmy_db_views::{
comment_view::CommentView,
community::community_view::CommunityView,
moderator::{
site_view::SiteView,
user_view::UserViewSafe,
};
-use lemmy_db_schema::source::{category::*, user::User_};
use serde::{Deserialize, Serialize};
#[derive(Deserialize)]
-use lemmy_db::views::{
+use lemmy_db_views::{
comment_view::CommentView,
community::{
community_follower_view::CommunityFollowerView,
/// added to the config.
///
/// Note: The env var `LEMMY_DATABASE_URL` is parsed in
- /// `lemmy_db/src/lib.rs::get_database_url_from_env()`
+ /// `lemmy_db_queries/src/lib.rs::get_database_url_from_env()`
fn init() -> Result<Self, ConfigError> {
let mut s = Config::new();
[dependencies]
lemmy_utils = { path = "../lemmy_utils" }
lemmy_structs = { path = "../lemmy_structs" }
-lemmy_db = { path = "../lemmy_db" }
+lemmy_db_queries = { path = "../lemmy_db_queries" }
lemmy_db_schema = { path = "../lemmy_db_schema" }
lemmy_rate_limit = { path = "../lemmy_rate_limit" }
reqwest = { version = "0.10.10", features = ["json"] }
use lemmy_api::claims::Claims;
use lemmy_db::{
source::{community::Community_, user::User},
- views::{
- comment_view::{CommentQueryBuilder, CommentView},
- post_view::{PostQueryBuilder, PostView},
- site_view::SiteView,
- user_mention_view::{UserMentionQueryBuilder, UserMentionView},
- },
ListingType,
SortType,
};
use lemmy_db_schema::source::{community::Community, user::User_};
+use lemmy_db_views::{
+ comment_view::{CommentQueryBuilder, CommentView},
+ post_view::{PostQueryBuilder, PostView},
+ site_view::SiteView,
+ user_mention_view::{UserMentionQueryBuilder, UserMentionView},
+};
use lemmy_structs::blocking;
use lemmy_utils::{settings::Settings, utils::markdown_to_html, LemmyError};
use lemmy_websocket::LemmyContext;
use actix_web::{body::Body, error::ErrorBadRequest, *};
use anyhow::anyhow;
use lemmy_api::version;
-use lemmy_db::views::site_view::SiteView;
+use lemmy_db_views::site_view::SiteView;
use lemmy_structs::blocking;
use lemmy_utils::{settings::Settings, LemmyError};
use lemmy_websocket::LemmyContext;