Add Modlog Filters (#2313)
* Fix crash running locally on windows. * Add support for filtering mod logs * Refactor cleanup * Clippy fix * Condense match statements * Clippy fix 2
This commit is contained in:
parent
08a797c986
commit
21455d6b73
26 changed files with 543 additions and 302 deletions
|
@ -2,7 +2,18 @@ use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
site::{GetModlog, GetModlogResponse},
|
site::{GetModlog, GetModlogResponse},
|
||||||
utils::{blocking, check_private_instance, get_local_user_view_from_jwt_opt},
|
utils::{
|
||||||
|
blocking,
|
||||||
|
check_private_instance,
|
||||||
|
get_local_user_view_from_jwt_opt,
|
||||||
|
is_admin,
|
||||||
|
is_mod_or_admin,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
use lemmy_db_schema::{
|
||||||
|
newtypes::{CommunityId, PersonId},
|
||||||
|
source::site::Site,
|
||||||
|
ModlogActionType,
|
||||||
};
|
};
|
||||||
use lemmy_db_views_moderator::structs::{
|
use lemmy_db_views_moderator::structs::{
|
||||||
AdminPurgeCommentView,
|
AdminPurgeCommentView,
|
||||||
|
@ -20,9 +31,11 @@ use lemmy_db_views_moderator::structs::{
|
||||||
ModRemovePostView,
|
ModRemovePostView,
|
||||||
ModStickyPostView,
|
ModStickyPostView,
|
||||||
ModTransferCommunityView,
|
ModTransferCommunityView,
|
||||||
|
ModlogListParams,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
|
use ModlogActionType::*;
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for GetModlog {
|
impl Perform for GetModlog {
|
||||||
|
@ -42,55 +55,123 @@ impl Perform for GetModlog {
|
||||||
|
|
||||||
check_private_instance(&local_user_view, context.pool()).await?;
|
check_private_instance(&local_user_view, context.pool()).await?;
|
||||||
|
|
||||||
|
let type_ = data.type_.unwrap_or(All);
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let mod_person_id = data.mod_person_id;
|
|
||||||
let page = data.page;
|
|
||||||
let limit = data.limit;
|
|
||||||
let removed_posts = blocking(context.pool(), move |conn| {
|
|
||||||
ModRemovePostView::list(conn, community_id, mod_person_id, page, limit)
|
|
||||||
})
|
|
||||||
.await??;
|
|
||||||
|
|
||||||
let locked_posts = blocking(context.pool(), move |conn| {
|
let site = blocking(context.pool(), Site::read_local_site).await??;
|
||||||
ModLockPostView::list(conn, community_id, mod_person_id, page, limit)
|
let (local_person_id, is_admin) = match local_user_view {
|
||||||
})
|
Some(s) => (s.person.id, is_admin(&s).is_ok()),
|
||||||
.await??;
|
None => (PersonId(-1), false),
|
||||||
|
};
|
||||||
|
let community_id_value = match community_id {
|
||||||
|
Some(s) => s,
|
||||||
|
None => CommunityId(-1),
|
||||||
|
};
|
||||||
|
let is_mod_of_community = data.community_id.is_some()
|
||||||
|
&& is_mod_or_admin(context.pool(), local_person_id, community_id_value)
|
||||||
|
.await
|
||||||
|
.is_ok();
|
||||||
|
let hide_modlog_names = site.hide_modlog_mod_names && !is_mod_of_community && !is_admin;
|
||||||
|
|
||||||
let stickied_posts = blocking(context.pool(), move |conn| {
|
let mod_person_id = if hide_modlog_names {
|
||||||
ModStickyPostView::list(conn, community_id, mod_person_id, page, limit)
|
None
|
||||||
|
} else {
|
||||||
|
data.mod_person_id
|
||||||
|
};
|
||||||
|
let other_person_id = data.other_person_id;
|
||||||
|
let params = ModlogListParams {
|
||||||
|
community_id,
|
||||||
|
mod_person_id,
|
||||||
|
other_person_id,
|
||||||
|
page: data.page,
|
||||||
|
limit: data.limit,
|
||||||
|
hide_modlog_names,
|
||||||
|
};
|
||||||
|
let removed_posts = match type_ {
|
||||||
|
All | ModRemovePost => {
|
||||||
|
blocking(context.pool(), move |conn| {
|
||||||
|
ModRemovePostView::list(conn, params)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??
|
||||||
|
}
|
||||||
|
_ => Default::default(),
|
||||||
|
};
|
||||||
|
|
||||||
let removed_comments = blocking(context.pool(), move |conn| {
|
let locked_posts = match type_ {
|
||||||
ModRemoveCommentView::list(conn, community_id, mod_person_id, page, limit)
|
All | ModLockPost => {
|
||||||
|
blocking(context.pool(), move |conn| {
|
||||||
|
ModLockPostView::list(conn, params)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??
|
||||||
|
}
|
||||||
|
_ => Default::default(),
|
||||||
|
};
|
||||||
|
|
||||||
let banned_from_community = blocking(context.pool(), move |conn| {
|
let stickied_posts = match type_ {
|
||||||
ModBanFromCommunityView::list(conn, community_id, mod_person_id, page, limit)
|
All | ModStickyPost => {
|
||||||
|
blocking(context.pool(), move |conn| {
|
||||||
|
ModStickyPostView::list(conn, params)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??
|
||||||
|
}
|
||||||
|
_ => Default::default(),
|
||||||
|
};
|
||||||
|
|
||||||
let added_to_community = blocking(context.pool(), move |conn| {
|
let removed_comments = match type_ {
|
||||||
ModAddCommunityView::list(conn, community_id, mod_person_id, page, limit)
|
All | ModRemoveComment => {
|
||||||
|
blocking(context.pool(), move |conn| {
|
||||||
|
ModRemoveCommentView::list(conn, params)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??
|
||||||
|
}
|
||||||
|
_ => Default::default(),
|
||||||
|
};
|
||||||
|
|
||||||
let transferred_to_community = blocking(context.pool(), move |conn| {
|
let banned_from_community = match type_ {
|
||||||
ModTransferCommunityView::list(conn, community_id, mod_person_id, page, limit)
|
All | ModBanFromCommunity => {
|
||||||
|
blocking(context.pool(), move |conn| {
|
||||||
|
ModBanFromCommunityView::list(conn, params)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??
|
||||||
|
}
|
||||||
|
_ => Default::default(),
|
||||||
|
};
|
||||||
|
|
||||||
let hidden_communities = blocking(context.pool(), move |conn| {
|
let added_to_community = match type_ {
|
||||||
ModHideCommunityView::list(conn, community_id, mod_person_id, page, limit)
|
All | ModAddCommunity => {
|
||||||
|
blocking(context.pool(), move |conn| {
|
||||||
|
ModAddCommunityView::list(conn, params)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??
|
||||||
|
}
|
||||||
|
_ => Default::default(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let transferred_to_community = match type_ {
|
||||||
|
All | ModTransferCommunity => {
|
||||||
|
blocking(context.pool(), move |conn| {
|
||||||
|
ModTransferCommunityView::list(conn, params)
|
||||||
|
})
|
||||||
|
.await??
|
||||||
|
}
|
||||||
|
_ => Default::default(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let hidden_communities = match type_ {
|
||||||
|
All | ModHideCommunity if other_person_id.is_none() => {
|
||||||
|
blocking(context.pool(), move |conn| {
|
||||||
|
ModHideCommunityView::list(conn, params)
|
||||||
|
})
|
||||||
|
.await??
|
||||||
|
}
|
||||||
|
_ => Default::default(),
|
||||||
|
};
|
||||||
|
|
||||||
// These arrays are only for the full modlog, when a community isn't given
|
// These arrays are only for the full modlog, when a community isn't given
|
||||||
let (
|
let (
|
||||||
removed_communities,
|
|
||||||
banned,
|
banned,
|
||||||
added,
|
added,
|
||||||
|
removed_communities,
|
||||||
admin_purged_persons,
|
admin_purged_persons,
|
||||||
admin_purged_communities,
|
admin_purged_communities,
|
||||||
admin_purged_posts,
|
admin_purged_posts,
|
||||||
|
@ -98,13 +179,44 @@ impl Perform for GetModlog {
|
||||||
) = if data.community_id.is_none() {
|
) = if data.community_id.is_none() {
|
||||||
blocking(context.pool(), move |conn| {
|
blocking(context.pool(), move |conn| {
|
||||||
Ok((
|
Ok((
|
||||||
ModRemoveCommunityView::list(conn, mod_person_id, page, limit)?,
|
match type_ {
|
||||||
ModBanView::list(conn, mod_person_id, page, limit)?,
|
All | ModBan => ModBanView::list(conn, params)?,
|
||||||
ModAddView::list(conn, mod_person_id, page, limit)?,
|
_ => Default::default(),
|
||||||
AdminPurgePersonView::list(conn, mod_person_id, page, limit)?,
|
},
|
||||||
AdminPurgeCommunityView::list(conn, mod_person_id, page, limit)?,
|
match type_ {
|
||||||
AdminPurgePostView::list(conn, mod_person_id, page, limit)?,
|
All | ModAdd => ModAddView::list(conn, params)?,
|
||||||
AdminPurgeCommentView::list(conn, mod_person_id, page, limit)?,
|
_ => Default::default(),
|
||||||
|
},
|
||||||
|
match type_ {
|
||||||
|
All | ModRemoveCommunity if other_person_id.is_none() => {
|
||||||
|
ModRemoveCommunityView::list(conn, params)?
|
||||||
|
}
|
||||||
|
_ => Default::default(),
|
||||||
|
},
|
||||||
|
match type_ {
|
||||||
|
All | AdminPurgePerson if other_person_id.is_none() => {
|
||||||
|
AdminPurgePersonView::list(conn, params)?
|
||||||
|
}
|
||||||
|
_ => Default::default(),
|
||||||
|
},
|
||||||
|
match type_ {
|
||||||
|
All | AdminPurgeCommunity if other_person_id.is_none() => {
|
||||||
|
AdminPurgeCommunityView::list(conn, params)?
|
||||||
|
}
|
||||||
|
_ => Default::default(),
|
||||||
|
},
|
||||||
|
match type_ {
|
||||||
|
All | AdminPurgePost if other_person_id.is_none() => {
|
||||||
|
AdminPurgePostView::list(conn, params)?
|
||||||
|
}
|
||||||
|
_ => Default::default(),
|
||||||
|
},
|
||||||
|
match type_ {
|
||||||
|
All | AdminPurgeComment if other_person_id.is_none() => {
|
||||||
|
AdminPurgeCommentView::list(conn, params)?
|
||||||
|
}
|
||||||
|
_ => Default::default(),
|
||||||
|
},
|
||||||
)) as Result<_, LemmyError>
|
)) as Result<_, LemmyError>
|
||||||
})
|
})
|
||||||
.await??
|
.await??
|
||||||
|
|
|
@ -2,6 +2,7 @@ use crate::sensitive::Sensitive;
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommentId, CommunityId, PersonId, PostId},
|
newtypes::{CommentId, CommunityId, PersonId, PostId},
|
||||||
ListingType,
|
ListingType,
|
||||||
|
ModlogActionType,
|
||||||
SearchType,
|
SearchType,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
|
@ -83,6 +84,8 @@ pub struct GetModlog {
|
||||||
pub page: Option<i64>,
|
pub page: Option<i64>,
|
||||||
pub limit: Option<i64>,
|
pub limit: Option<i64>,
|
||||||
pub auth: Option<Sensitive<String>>,
|
pub auth: Option<Sensitive<String>>,
|
||||||
|
pub type_: Option<ModlogActionType>,
|
||||||
|
pub other_person_id: Option<PersonId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
@ -122,6 +125,7 @@ pub struct CreateSite {
|
||||||
pub default_theme: Option<String>,
|
pub default_theme: Option<String>,
|
||||||
pub default_post_listing_type: Option<String>,
|
pub default_post_listing_type: Option<String>,
|
||||||
pub auth: Sensitive<String>,
|
pub auth: Sensitive<String>,
|
||||||
|
pub hide_modlog_mod_names: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||||
|
@ -143,6 +147,7 @@ pub struct EditSite {
|
||||||
pub default_post_listing_type: Option<String>,
|
pub default_post_listing_type: Option<String>,
|
||||||
pub legal_information: Option<String>,
|
pub legal_information: Option<String>,
|
||||||
pub auth: Sensitive<String>,
|
pub auth: Sensitive<String>,
|
||||||
|
pub hide_modlog_mod_names: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||||
|
|
|
@ -76,6 +76,7 @@ impl PerformCrud for CreateSite {
|
||||||
public_key: Some(keypair.public_key),
|
public_key: Some(keypair.public_key),
|
||||||
default_theme: data.default_theme.clone(),
|
default_theme: data.default_theme.clone(),
|
||||||
default_post_listing_type: data.default_post_listing_type.clone(),
|
default_post_listing_type: data.default_post_listing_type.clone(),
|
||||||
|
hide_modlog_mod_names: data.hide_modlog_mod_names,
|
||||||
..SiteForm::default()
|
..SiteForm::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -86,6 +86,7 @@ impl PerformCrud for EditSite {
|
||||||
default_theme: data.default_theme.clone(),
|
default_theme: data.default_theme.clone(),
|
||||||
default_post_listing_type: data.default_post_listing_type.clone(),
|
default_post_listing_type: data.default_post_listing_type.clone(),
|
||||||
legal_information,
|
legal_information,
|
||||||
|
hide_modlog_mod_names: data.hide_modlog_mod_names,
|
||||||
..SiteForm::default()
|
..SiteForm::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -71,3 +71,23 @@ pub enum SubscribedType {
|
||||||
NotSubscribed,
|
NotSubscribed,
|
||||||
Pending,
|
Pending,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
|
||||||
|
pub enum ModlogActionType {
|
||||||
|
All,
|
||||||
|
ModRemovePost,
|
||||||
|
ModLockPost,
|
||||||
|
ModStickyPost,
|
||||||
|
ModRemoveComment,
|
||||||
|
ModRemoveCommunity,
|
||||||
|
ModBanFromCommunity,
|
||||||
|
ModAddCommunity,
|
||||||
|
ModTransferCommunity,
|
||||||
|
ModAdd,
|
||||||
|
ModBan,
|
||||||
|
ModHideCommunity,
|
||||||
|
AdminPurgePerson,
|
||||||
|
AdminPurgeCommunity,
|
||||||
|
AdminPurgePost,
|
||||||
|
AdminPurgeComment,
|
||||||
|
}
|
||||||
|
|
|
@ -477,6 +477,7 @@ table! {
|
||||||
default_theme -> Text,
|
default_theme -> Text,
|
||||||
default_post_listing_type -> Text,
|
default_post_listing_type -> Text,
|
||||||
legal_information -> Nullable<Text>,
|
legal_information -> Nullable<Text>,
|
||||||
|
hide_modlog_mod_names -> Bool,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ pub struct Site {
|
||||||
pub default_theme: String,
|
pub default_theme: String,
|
||||||
pub default_post_listing_type: String,
|
pub default_post_listing_type: String,
|
||||||
pub legal_information: Option<String>,
|
pub legal_information: Option<String>,
|
||||||
|
pub hide_modlog_mod_names: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -61,4 +62,5 @@ pub struct SiteForm {
|
||||||
pub default_theme: Option<String>,
|
pub default_theme: Option<String>,
|
||||||
pub default_post_listing_type: Option<String>,
|
pub default_post_listing_type: Option<String>,
|
||||||
pub legal_information: Option<Option<String>>,
|
pub legal_information: Option<Option<String>>,
|
||||||
|
pub hide_modlog_mod_names: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::structs::AdminPurgeCommentView;
|
use crate::structs::{AdminPurgeCommentView, ModlogListParams};
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
|
@ -12,30 +12,33 @@ use lemmy_db_schema::{
|
||||||
utils::limit_and_offset,
|
utils::limit_and_offset,
|
||||||
};
|
};
|
||||||
|
|
||||||
type AdminPurgeCommentViewTuple = (AdminPurgeComment, PersonSafe, Post);
|
type AdminPurgeCommentViewTuple = (AdminPurgeComment, Option<PersonSafe>, Post);
|
||||||
|
|
||||||
impl AdminPurgeCommentView {
|
impl AdminPurgeCommentView {
|
||||||
pub fn list(
|
pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
conn: &PgConnection,
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
admin_person_id: Option<PersonId>,
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
page: Option<i64>,
|
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
||||||
limit: Option<i64>,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
let admin_names_join = admin_purge_comment::admin_person_id
|
||||||
|
.eq(person::id)
|
||||||
|
.and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
|
||||||
|
|
||||||
let mut query = admin_purge_comment::table
|
let mut query = admin_purge_comment::table
|
||||||
.inner_join(person::table.on(admin_purge_comment::admin_person_id.eq(person::id)))
|
.left_join(person::table.on(admin_names_join))
|
||||||
.inner_join(post::table)
|
.inner_join(post::table)
|
||||||
.select((
|
.select((
|
||||||
admin_purge_comment::all_columns,
|
admin_purge_comment::all_columns,
|
||||||
Person::safe_columns_tuple(),
|
Person::safe_columns_tuple().nullable(),
|
||||||
post::all_columns,
|
post::all_columns,
|
||||||
))
|
))
|
||||||
.into_boxed();
|
.into_boxed();
|
||||||
|
|
||||||
if let Some(admin_person_id) = admin_person_id {
|
if let Some(admin_person_id) = params.mod_person_id {
|
||||||
query = query.filter(admin_purge_comment::admin_person_id.eq(admin_person_id));
|
query = query.filter(admin_purge_comment::admin_person_id.eq(admin_person_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(page, limit)?;
|
let (limit, offset) = limit_and_offset(params.page, params.limit)?;
|
||||||
|
|
||||||
let res = query
|
let res = query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
@ -43,7 +46,8 @@ impl AdminPurgeCommentView {
|
||||||
.order_by(admin_purge_comment::when_.desc())
|
.order_by(admin_purge_comment::when_.desc())
|
||||||
.load::<AdminPurgeCommentViewTuple>(conn)?;
|
.load::<AdminPurgeCommentViewTuple>(conn)?;
|
||||||
|
|
||||||
Ok(Self::from_tuple_to_vec(res))
|
let results = Self::from_tuple_to_vec(res);
|
||||||
|
Ok(results)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::structs::AdminPurgeCommunityView;
|
use crate::structs::{AdminPurgeCommunityView, ModlogListParams};
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
|
@ -11,28 +11,31 @@ use lemmy_db_schema::{
|
||||||
utils::limit_and_offset,
|
utils::limit_and_offset,
|
||||||
};
|
};
|
||||||
|
|
||||||
type AdminPurgeCommunityViewTuple = (AdminPurgeCommunity, PersonSafe);
|
type AdminPurgeCommunityViewTuple = (AdminPurgeCommunity, Option<PersonSafe>);
|
||||||
|
|
||||||
impl AdminPurgeCommunityView {
|
impl AdminPurgeCommunityView {
|
||||||
pub fn list(
|
pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
conn: &PgConnection,
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
admin_person_id: Option<PersonId>,
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
page: Option<i64>,
|
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
||||||
limit: Option<i64>,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
let admin_names_join = admin_purge_community::admin_person_id
|
||||||
|
.eq(person::id)
|
||||||
|
.and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
|
||||||
|
|
||||||
let mut query = admin_purge_community::table
|
let mut query = admin_purge_community::table
|
||||||
.inner_join(person::table.on(admin_purge_community::admin_person_id.eq(person::id)))
|
.left_join(person::table.on(admin_names_join))
|
||||||
.select((
|
.select((
|
||||||
admin_purge_community::all_columns,
|
admin_purge_community::all_columns,
|
||||||
Person::safe_columns_tuple(),
|
Person::safe_columns_tuple().nullable(),
|
||||||
))
|
))
|
||||||
.into_boxed();
|
.into_boxed();
|
||||||
|
|
||||||
if let Some(admin_person_id) = admin_person_id {
|
if let Some(admin_person_id) = params.mod_person_id {
|
||||||
query = query.filter(admin_purge_community::admin_person_id.eq(admin_person_id));
|
query = query.filter(admin_purge_community::admin_person_id.eq(admin_person_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(page, limit)?;
|
let (limit, offset) = limit_and_offset(params.page, params.limit)?;
|
||||||
|
|
||||||
let res = query
|
let res = query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
@ -40,7 +43,8 @@ impl AdminPurgeCommunityView {
|
||||||
.order_by(admin_purge_community::when_.desc())
|
.order_by(admin_purge_community::when_.desc())
|
||||||
.load::<AdminPurgeCommunityViewTuple>(conn)?;
|
.load::<AdminPurgeCommunityViewTuple>(conn)?;
|
||||||
|
|
||||||
Ok(Self::from_tuple_to_vec(res))
|
let results = Self::from_tuple_to_vec(res);
|
||||||
|
Ok(results)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::structs::AdminPurgePersonView;
|
use crate::structs::{AdminPurgePersonView, ModlogListParams};
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
|
@ -11,28 +11,30 @@ use lemmy_db_schema::{
|
||||||
utils::limit_and_offset,
|
utils::limit_and_offset,
|
||||||
};
|
};
|
||||||
|
|
||||||
type AdminPurgePersonViewTuple = (AdminPurgePerson, PersonSafe);
|
type AdminPurgePersonViewTuple = (AdminPurgePerson, Option<PersonSafe>);
|
||||||
|
|
||||||
impl AdminPurgePersonView {
|
impl AdminPurgePersonView {
|
||||||
pub fn list(
|
pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
conn: &PgConnection,
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
admin_person_id: Option<PersonId>,
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
page: Option<i64>,
|
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
||||||
limit: Option<i64>,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
let admin_names_join = admin_purge_person::admin_person_id
|
||||||
|
.eq(person::id)
|
||||||
|
.and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
|
||||||
let mut query = admin_purge_person::table
|
let mut query = admin_purge_person::table
|
||||||
.inner_join(person::table.on(admin_purge_person::admin_person_id.eq(person::id)))
|
.left_join(person::table.on(admin_names_join))
|
||||||
.select((
|
.select((
|
||||||
admin_purge_person::all_columns,
|
admin_purge_person::all_columns,
|
||||||
Person::safe_columns_tuple(),
|
Person::safe_columns_tuple().nullable(),
|
||||||
))
|
))
|
||||||
.into_boxed();
|
.into_boxed();
|
||||||
|
|
||||||
if let Some(admin_person_id) = admin_person_id {
|
if let Some(admin_person_id) = params.mod_person_id {
|
||||||
query = query.filter(admin_purge_person::admin_person_id.eq(admin_person_id));
|
query = query.filter(admin_purge_person::admin_person_id.eq(admin_person_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(page, limit)?;
|
let (limit, offset) = limit_and_offset(params.page, params.limit)?;
|
||||||
|
|
||||||
let res = query
|
let res = query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
@ -40,7 +42,8 @@ impl AdminPurgePersonView {
|
||||||
.order_by(admin_purge_person::when_.desc())
|
.order_by(admin_purge_person::when_.desc())
|
||||||
.load::<AdminPurgePersonViewTuple>(conn)?;
|
.load::<AdminPurgePersonViewTuple>(conn)?;
|
||||||
|
|
||||||
Ok(Self::from_tuple_to_vec(res))
|
let results = Self::from_tuple_to_vec(res);
|
||||||
|
Ok(results)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::structs::AdminPurgePostView;
|
use crate::structs::{AdminPurgePostView, ModlogListParams};
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
|
@ -12,30 +12,32 @@ use lemmy_db_schema::{
|
||||||
utils::limit_and_offset,
|
utils::limit_and_offset,
|
||||||
};
|
};
|
||||||
|
|
||||||
type AdminPurgePostViewTuple = (AdminPurgePost, PersonSafe, CommunitySafe);
|
type AdminPurgePostViewTuple = (AdminPurgePost, Option<PersonSafe>, CommunitySafe);
|
||||||
|
|
||||||
impl AdminPurgePostView {
|
impl AdminPurgePostView {
|
||||||
pub fn list(
|
pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
conn: &PgConnection,
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
admin_person_id: Option<PersonId>,
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
page: Option<i64>,
|
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
||||||
limit: Option<i64>,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
let admin_names_join = admin_purge_post::admin_person_id
|
||||||
|
.eq(person::id)
|
||||||
|
.and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
|
||||||
let mut query = admin_purge_post::table
|
let mut query = admin_purge_post::table
|
||||||
.inner_join(person::table.on(admin_purge_post::admin_person_id.eq(person::id)))
|
.left_join(person::table.on(admin_names_join))
|
||||||
.inner_join(community::table)
|
.inner_join(community::table)
|
||||||
.select((
|
.select((
|
||||||
admin_purge_post::all_columns,
|
admin_purge_post::all_columns,
|
||||||
Person::safe_columns_tuple(),
|
Person::safe_columns_tuple().nullable(),
|
||||||
Community::safe_columns_tuple(),
|
Community::safe_columns_tuple(),
|
||||||
))
|
))
|
||||||
.into_boxed();
|
.into_boxed();
|
||||||
|
|
||||||
if let Some(admin_person_id) = admin_person_id {
|
if let Some(admin_person_id) = params.mod_person_id {
|
||||||
query = query.filter(admin_purge_post::admin_person_id.eq(admin_person_id));
|
query = query.filter(admin_purge_post::admin_person_id.eq(admin_person_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(page, limit)?;
|
let (limit, offset) = limit_and_offset(params.page, params.limit)?;
|
||||||
|
|
||||||
let res = query
|
let res = query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
@ -43,7 +45,8 @@ impl AdminPurgePostView {
|
||||||
.order_by(admin_purge_post::when_.desc())
|
.order_by(admin_purge_post::when_.desc())
|
||||||
.load::<AdminPurgePostViewTuple>(conn)?;
|
.load::<AdminPurgePostViewTuple>(conn)?;
|
||||||
|
|
||||||
Ok(Self::from_tuple_to_vec(res))
|
let results = Self::from_tuple_to_vec(res);
|
||||||
|
Ok(results)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::structs::ModAddCommunityView;
|
use crate::structs::{ModAddCommunityView, ModlogListParams};
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommunityId, PersonId},
|
newtypes::PersonId,
|
||||||
schema::{community, mod_add_community, person, person_alias_1},
|
schema::{community, mod_add_community, person, person_alias_1},
|
||||||
source::{
|
source::{
|
||||||
community::{Community, CommunitySafe},
|
community::{Community, CommunitySafe},
|
||||||
|
@ -12,39 +12,49 @@ use lemmy_db_schema::{
|
||||||
utils::limit_and_offset,
|
utils::limit_and_offset,
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModAddCommunityViewTuple = (ModAddCommunity, PersonSafe, CommunitySafe, PersonSafeAlias1);
|
type ModAddCommunityViewTuple = (
|
||||||
|
ModAddCommunity,
|
||||||
|
Option<PersonSafe>,
|
||||||
|
CommunitySafe,
|
||||||
|
PersonSafeAlias1,
|
||||||
|
);
|
||||||
|
|
||||||
impl ModAddCommunityView {
|
impl ModAddCommunityView {
|
||||||
pub fn list(
|
pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
conn: &PgConnection,
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
community_id: Option<CommunityId>,
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
mod_person_id: Option<PersonId>,
|
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
||||||
page: Option<i64>,
|
|
||||||
limit: Option<i64>,
|
let admin_names_join = mod_add_community::mod_person_id
|
||||||
) -> Result<Vec<Self>, Error> {
|
.eq(person::id)
|
||||||
|
.and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
|
||||||
let mut query = mod_add_community::table
|
let mut query = mod_add_community::table
|
||||||
.inner_join(person::table.on(mod_add_community::mod_person_id.eq(person::id)))
|
.left_join(person::table.on(admin_names_join))
|
||||||
.inner_join(community::table)
|
.inner_join(community::table)
|
||||||
.inner_join(
|
.inner_join(
|
||||||
person_alias_1::table.on(mod_add_community::other_person_id.eq(person_alias_1::id)),
|
person_alias_1::table.on(mod_add_community::other_person_id.eq(person_alias_1::id)),
|
||||||
)
|
)
|
||||||
.select((
|
.select((
|
||||||
mod_add_community::all_columns,
|
mod_add_community::all_columns,
|
||||||
Person::safe_columns_tuple(),
|
Person::safe_columns_tuple().nullable(),
|
||||||
Community::safe_columns_tuple(),
|
Community::safe_columns_tuple(),
|
||||||
PersonAlias1::safe_columns_tuple(),
|
PersonAlias1::safe_columns_tuple(),
|
||||||
))
|
))
|
||||||
.into_boxed();
|
.into_boxed();
|
||||||
|
|
||||||
if let Some(mod_person_id) = mod_person_id {
|
if let Some(mod_person_id) = params.mod_person_id {
|
||||||
query = query.filter(mod_add_community::mod_person_id.eq(mod_person_id));
|
query = query.filter(mod_add_community::mod_person_id.eq(mod_person_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(community_id) = community_id {
|
if let Some(community_id) = params.community_id {
|
||||||
query = query.filter(mod_add_community::community_id.eq(community_id));
|
query = query.filter(mod_add_community::community_id.eq(community_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(page, limit)?;
|
if let Some(other_person_id) = params.other_person_id {
|
||||||
|
query = query.filter(person_alias_1::id.eq(other_person_id));
|
||||||
|
};
|
||||||
|
|
||||||
|
let (limit, offset) = limit_and_offset(params.page, params.limit)?;
|
||||||
|
|
||||||
let res = query
|
let res = query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
@ -52,7 +62,8 @@ impl ModAddCommunityView {
|
||||||
.order_by(mod_add_community::when_.desc())
|
.order_by(mod_add_community::when_.desc())
|
||||||
.load::<ModAddCommunityViewTuple>(conn)?;
|
.load::<ModAddCommunityViewTuple>(conn)?;
|
||||||
|
|
||||||
Ok(Self::from_tuple_to_vec(res))
|
let results = Self::from_tuple_to_vec(res);
|
||||||
|
Ok(results)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::structs::ModAddView;
|
use crate::structs::{ModAddView, ModlogListParams};
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
|
@ -11,30 +11,36 @@ use lemmy_db_schema::{
|
||||||
utils::limit_and_offset,
|
utils::limit_and_offset,
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModAddViewTuple = (ModAdd, PersonSafe, PersonSafeAlias1);
|
type ModAddViewTuple = (ModAdd, Option<PersonSafe>, PersonSafeAlias1);
|
||||||
|
|
||||||
impl ModAddView {
|
impl ModAddView {
|
||||||
pub fn list(
|
pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
conn: &PgConnection,
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
mod_person_id: Option<PersonId>,
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
page: Option<i64>,
|
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
||||||
limit: Option<i64>,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
let admin_names_join = mod_add::mod_person_id
|
||||||
|
.eq(person::id)
|
||||||
|
.and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
|
||||||
let mut query = mod_add::table
|
let mut query = mod_add::table
|
||||||
.inner_join(person::table.on(mod_add::mod_person_id.eq(person::id)))
|
.left_join(person::table.on(admin_names_join))
|
||||||
.inner_join(person_alias_1::table.on(mod_add::other_person_id.eq(person_alias_1::id)))
|
.inner_join(person_alias_1::table.on(mod_add::other_person_id.eq(person_alias_1::id)))
|
||||||
.select((
|
.select((
|
||||||
mod_add::all_columns,
|
mod_add::all_columns,
|
||||||
Person::safe_columns_tuple(),
|
Person::safe_columns_tuple().nullable(),
|
||||||
PersonAlias1::safe_columns_tuple(),
|
PersonAlias1::safe_columns_tuple(),
|
||||||
))
|
))
|
||||||
.into_boxed();
|
.into_boxed();
|
||||||
|
|
||||||
if let Some(mod_person_id) = mod_person_id {
|
if let Some(mod_person_id) = params.mod_person_id {
|
||||||
query = query.filter(mod_add::mod_person_id.eq(mod_person_id));
|
query = query.filter(mod_add::mod_person_id.eq(mod_person_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(page, limit)?;
|
if let Some(other_person_id) = params.other_person_id {
|
||||||
|
query = query.filter(person_alias_1::id.eq(other_person_id));
|
||||||
|
};
|
||||||
|
|
||||||
|
let (limit, offset) = limit_and_offset(params.page, params.limit)?;
|
||||||
|
|
||||||
let res = query
|
let res = query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
@ -42,7 +48,8 @@ impl ModAddView {
|
||||||
.order_by(mod_add::when_.desc())
|
.order_by(mod_add::when_.desc())
|
||||||
.load::<ModAddViewTuple>(conn)?;
|
.load::<ModAddViewTuple>(conn)?;
|
||||||
|
|
||||||
Ok(Self::from_tuple_to_vec(res))
|
let results = Self::from_tuple_to_vec(res);
|
||||||
|
Ok(results)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::structs::ModBanFromCommunityView;
|
use crate::structs::{ModBanFromCommunityView, ModlogListParams};
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommunityId, PersonId},
|
newtypes::PersonId,
|
||||||
schema::{community, mod_ban_from_community, person, person_alias_1},
|
schema::{community, mod_ban_from_community, person, person_alias_1},
|
||||||
source::{
|
source::{
|
||||||
community::{Community, CommunitySafe},
|
community::{Community, CommunitySafe},
|
||||||
|
@ -14,42 +14,47 @@ use lemmy_db_schema::{
|
||||||
|
|
||||||
type ModBanFromCommunityViewTuple = (
|
type ModBanFromCommunityViewTuple = (
|
||||||
ModBanFromCommunity,
|
ModBanFromCommunity,
|
||||||
PersonSafe,
|
Option<PersonSafe>,
|
||||||
CommunitySafe,
|
CommunitySafe,
|
||||||
PersonSafeAlias1,
|
PersonSafeAlias1,
|
||||||
);
|
);
|
||||||
|
|
||||||
impl ModBanFromCommunityView {
|
impl ModBanFromCommunityView {
|
||||||
pub fn list(
|
pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
conn: &PgConnection,
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
community_id: Option<CommunityId>,
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
mod_person_id: Option<PersonId>,
|
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
||||||
page: Option<i64>,
|
|
||||||
limit: Option<i64>,
|
let admin_names_join = mod_ban_from_community::mod_person_id
|
||||||
) -> Result<Vec<Self>, Error> {
|
.eq(person::id)
|
||||||
|
.and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
|
||||||
let mut query = mod_ban_from_community::table
|
let mut query = mod_ban_from_community::table
|
||||||
.inner_join(person::table.on(mod_ban_from_community::mod_person_id.eq(person::id)))
|
.left_join(person::table.on(admin_names_join))
|
||||||
.inner_join(community::table)
|
.inner_join(community::table)
|
||||||
.inner_join(
|
.inner_join(
|
||||||
person_alias_1::table.on(mod_ban_from_community::other_person_id.eq(person_alias_1::id)),
|
person_alias_1::table.on(mod_ban_from_community::other_person_id.eq(person_alias_1::id)),
|
||||||
)
|
)
|
||||||
.select((
|
.select((
|
||||||
mod_ban_from_community::all_columns,
|
mod_ban_from_community::all_columns,
|
||||||
Person::safe_columns_tuple(),
|
Person::safe_columns_tuple().nullable(),
|
||||||
Community::safe_columns_tuple(),
|
Community::safe_columns_tuple(),
|
||||||
PersonAlias1::safe_columns_tuple(),
|
PersonAlias1::safe_columns_tuple(),
|
||||||
))
|
))
|
||||||
.into_boxed();
|
.into_boxed();
|
||||||
|
|
||||||
if let Some(mod_person_id) = mod_person_id {
|
if let Some(mod_person_id) = params.mod_person_id {
|
||||||
query = query.filter(mod_ban_from_community::mod_person_id.eq(mod_person_id));
|
query = query.filter(mod_ban_from_community::mod_person_id.eq(mod_person_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(community_id) = community_id {
|
if let Some(community_id) = params.community_id {
|
||||||
query = query.filter(mod_ban_from_community::community_id.eq(community_id));
|
query = query.filter(mod_ban_from_community::community_id.eq(community_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(page, limit)?;
|
if let Some(other_person_id) = params.other_person_id {
|
||||||
|
query = query.filter(mod_ban_from_community::other_person_id.eq(other_person_id));
|
||||||
|
};
|
||||||
|
|
||||||
|
let (limit, offset) = limit_and_offset(params.page, params.limit)?;
|
||||||
|
|
||||||
let res = query
|
let res = query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
@ -57,7 +62,8 @@ impl ModBanFromCommunityView {
|
||||||
.order_by(mod_ban_from_community::when_.desc())
|
.order_by(mod_ban_from_community::when_.desc())
|
||||||
.load::<ModBanFromCommunityViewTuple>(conn)?;
|
.load::<ModBanFromCommunityViewTuple>(conn)?;
|
||||||
|
|
||||||
Ok(Self::from_tuple_to_vec(res))
|
let results = Self::from_tuple_to_vec(res);
|
||||||
|
Ok(results)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::structs::ModBanView;
|
use crate::structs::{ModBanView, ModlogListParams};
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
|
@ -11,30 +11,36 @@ use lemmy_db_schema::{
|
||||||
utils::limit_and_offset,
|
utils::limit_and_offset,
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModBanViewTuple = (ModBan, PersonSafe, PersonSafeAlias1);
|
type ModBanViewTuple = (ModBan, Option<PersonSafe>, PersonSafeAlias1);
|
||||||
|
|
||||||
impl ModBanView {
|
impl ModBanView {
|
||||||
pub fn list(
|
pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
conn: &PgConnection,
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
mod_person_id: Option<PersonId>,
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
page: Option<i64>,
|
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
||||||
limit: Option<i64>,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
let admin_names_join = mod_ban::mod_person_id
|
||||||
|
.eq(person::id)
|
||||||
|
.and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
|
||||||
let mut query = mod_ban::table
|
let mut query = mod_ban::table
|
||||||
.inner_join(person::table.on(mod_ban::mod_person_id.eq(person::id)))
|
.left_join(person::table.on(admin_names_join))
|
||||||
.inner_join(person_alias_1::table.on(mod_ban::other_person_id.eq(person_alias_1::id)))
|
.inner_join(person_alias_1::table.on(mod_ban::other_person_id.eq(person_alias_1::id)))
|
||||||
.select((
|
.select((
|
||||||
mod_ban::all_columns,
|
mod_ban::all_columns,
|
||||||
Person::safe_columns_tuple(),
|
Person::safe_columns_tuple().nullable(),
|
||||||
PersonAlias1::safe_columns_tuple(),
|
PersonAlias1::safe_columns_tuple(),
|
||||||
))
|
))
|
||||||
.into_boxed();
|
.into_boxed();
|
||||||
|
|
||||||
if let Some(mod_person_id) = mod_person_id {
|
if let Some(mod_person_id) = params.mod_person_id {
|
||||||
query = query.filter(mod_ban::mod_person_id.eq(mod_person_id));
|
query = query.filter(mod_ban::mod_person_id.eq(mod_person_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(page, limit)?;
|
if let Some(other_person_id) = params.other_person_id {
|
||||||
|
query = query.filter(person_alias_1::id.eq(other_person_id));
|
||||||
|
};
|
||||||
|
|
||||||
|
let (limit, offset) = limit_and_offset(params.page, params.limit)?;
|
||||||
|
|
||||||
let res = query
|
let res = query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
@ -42,7 +48,8 @@ impl ModBanView {
|
||||||
.order_by(mod_ban::when_.desc())
|
.order_by(mod_ban::when_.desc())
|
||||||
.load::<ModBanViewTuple>(conn)?;
|
.load::<ModBanViewTuple>(conn)?;
|
||||||
|
|
||||||
Ok(Self::from_tuple_to_vec(res))
|
let results = Self::from_tuple_to_vec(res);
|
||||||
|
Ok(results)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::structs::ModHideCommunityView;
|
use crate::structs::{ModHideCommunityView, ModlogListParams};
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommunityId, PersonId},
|
newtypes::PersonId,
|
||||||
schema::{community, mod_hide_community, person},
|
schema::{community, mod_hide_community, person},
|
||||||
source::{
|
source::{
|
||||||
community::{Community, CommunitySafe},
|
community::{Community, CommunitySafe},
|
||||||
|
@ -12,36 +12,37 @@ use lemmy_db_schema::{
|
||||||
utils::limit_and_offset,
|
utils::limit_and_offset,
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModHideCommunityViewTuple = (ModHideCommunity, PersonSafe, CommunitySafe);
|
type ModHideCommunityViewTuple = (ModHideCommunity, Option<PersonSafe>, CommunitySafe);
|
||||||
|
|
||||||
impl ModHideCommunityView {
|
impl ModHideCommunityView {
|
||||||
// Pass in mod_id as admin_id because only admins can do this action
|
// Pass in mod_id as admin_id because only admins can do this action
|
||||||
pub fn list(
|
pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
conn: &PgConnection,
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
community_id: Option<CommunityId>,
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
admin_id: Option<PersonId>,
|
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
||||||
page: Option<i64>,
|
|
||||||
limit: Option<i64>,
|
let admin_names_join = mod_hide_community::mod_person_id
|
||||||
) -> Result<Vec<Self>, Error> {
|
.eq(person::id)
|
||||||
|
.and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
|
||||||
let mut query = mod_hide_community::table
|
let mut query = mod_hide_community::table
|
||||||
.inner_join(person::table)
|
.left_join(person::table.on(admin_names_join))
|
||||||
.inner_join(community::table.on(mod_hide_community::community_id.eq(community::id)))
|
.inner_join(community::table.on(mod_hide_community::community_id.eq(community::id)))
|
||||||
.select((
|
.select((
|
||||||
mod_hide_community::all_columns,
|
mod_hide_community::all_columns,
|
||||||
Person::safe_columns_tuple(),
|
Person::safe_columns_tuple().nullable(),
|
||||||
Community::safe_columns_tuple(),
|
Community::safe_columns_tuple(),
|
||||||
))
|
))
|
||||||
.into_boxed();
|
.into_boxed();
|
||||||
|
|
||||||
if let Some(community_id) = community_id {
|
if let Some(community_id) = params.community_id {
|
||||||
query = query.filter(mod_hide_community::community_id.eq(community_id));
|
query = query.filter(mod_hide_community::community_id.eq(community_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(admin_id) = admin_id {
|
if let Some(admin_id) = params.mod_person_id {
|
||||||
query = query.filter(mod_hide_community::mod_person_id.eq(admin_id));
|
query = query.filter(mod_hide_community::mod_person_id.eq(admin_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(page, limit)?;
|
let (limit, offset) = limit_and_offset(params.page, params.limit)?;
|
||||||
|
|
||||||
let res = query
|
let res = query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
@ -49,7 +50,8 @@ impl ModHideCommunityView {
|
||||||
.order_by(mod_hide_community::when_.desc())
|
.order_by(mod_hide_community::when_.desc())
|
||||||
.load::<ModHideCommunityViewTuple>(conn)?;
|
.load::<ModHideCommunityViewTuple>(conn)?;
|
||||||
|
|
||||||
Ok(Self::from_tuple_to_vec(res))
|
let results = Self::from_tuple_to_vec(res);
|
||||||
|
Ok(results)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::structs::ModLockPostView;
|
use crate::structs::{ModLockPostView, ModlogListParams};
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommunityId, PersonId},
|
newtypes::PersonId,
|
||||||
schema::{community, mod_lock_post, person, post},
|
schema::{community, mod_lock_post, person, person_alias_1, post},
|
||||||
source::{
|
source::{
|
||||||
community::{Community, CommunitySafe},
|
community::{Community, CommunitySafe},
|
||||||
moderator::ModLockPost,
|
moderator::ModLockPost,
|
||||||
|
@ -13,37 +13,43 @@ use lemmy_db_schema::{
|
||||||
utils::limit_and_offset,
|
utils::limit_and_offset,
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModLockPostViewTuple = (ModLockPost, PersonSafe, Post, CommunitySafe);
|
type ModLockPostViewTuple = (ModLockPost, Option<PersonSafe>, Post, CommunitySafe);
|
||||||
|
|
||||||
impl ModLockPostView {
|
impl ModLockPostView {
|
||||||
pub fn list(
|
pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
conn: &PgConnection,
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
community_id: Option<CommunityId>,
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
mod_person_id: Option<PersonId>,
|
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
||||||
page: Option<i64>,
|
|
||||||
limit: Option<i64>,
|
let admin_names_join = mod_lock_post::mod_person_id
|
||||||
) -> Result<Vec<Self>, Error> {
|
.eq(person::id)
|
||||||
|
.and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
|
||||||
let mut query = mod_lock_post::table
|
let mut query = mod_lock_post::table
|
||||||
.inner_join(person::table)
|
.left_join(person::table.on(admin_names_join))
|
||||||
.inner_join(post::table)
|
.inner_join(post::table)
|
||||||
.inner_join(community::table.on(post::community_id.eq(community::id)))
|
.inner_join(community::table.on(post::community_id.eq(community::id)))
|
||||||
|
.inner_join(person_alias_1::table.on(post::creator_id.eq(person_alias_1::id)))
|
||||||
.select((
|
.select((
|
||||||
mod_lock_post::all_columns,
|
mod_lock_post::all_columns,
|
||||||
Person::safe_columns_tuple(),
|
Person::safe_columns_tuple().nullable(),
|
||||||
post::all_columns,
|
post::all_columns,
|
||||||
Community::safe_columns_tuple(),
|
Community::safe_columns_tuple(),
|
||||||
))
|
))
|
||||||
.into_boxed();
|
.into_boxed();
|
||||||
|
|
||||||
if let Some(community_id) = community_id {
|
if let Some(community_id) = params.community_id {
|
||||||
query = query.filter(post::community_id.eq(community_id));
|
query = query.filter(post::community_id.eq(community_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(mod_person_id) = mod_person_id {
|
if let Some(mod_person_id) = params.mod_person_id {
|
||||||
query = query.filter(mod_lock_post::mod_person_id.eq(mod_person_id));
|
query = query.filter(mod_lock_post::mod_person_id.eq(mod_person_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(page, limit)?;
|
if let Some(other_person_id) = params.other_person_id {
|
||||||
|
query = query.filter(person_alias_1::id.eq(other_person_id));
|
||||||
|
};
|
||||||
|
|
||||||
|
let (limit, offset) = limit_and_offset(params.page, params.limit)?;
|
||||||
|
|
||||||
let res = query
|
let res = query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
@ -51,7 +57,8 @@ impl ModLockPostView {
|
||||||
.order_by(mod_lock_post::when_.desc())
|
.order_by(mod_lock_post::when_.desc())
|
||||||
.load::<ModLockPostViewTuple>(conn)?;
|
.load::<ModLockPostViewTuple>(conn)?;
|
||||||
|
|
||||||
Ok(Self::from_tuple_to_vec(res))
|
let results = Self::from_tuple_to_vec(res);
|
||||||
|
Ok(results)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::structs::ModRemoveCommentView;
|
use crate::structs::{ModRemoveCommentView, ModlogListParams};
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommunityId, PersonId},
|
newtypes::PersonId,
|
||||||
schema::{comment, community, mod_remove_comment, person, person_alias_1, post},
|
schema::{comment, community, mod_remove_comment, person, person_alias_1, post},
|
||||||
source::{
|
source::{
|
||||||
comment::Comment,
|
comment::Comment,
|
||||||
|
@ -16,7 +16,7 @@ use lemmy_db_schema::{
|
||||||
|
|
||||||
type ModRemoveCommentViewTuple = (
|
type ModRemoveCommentViewTuple = (
|
||||||
ModRemoveComment,
|
ModRemoveComment,
|
||||||
PersonSafe,
|
Option<PersonSafe>,
|
||||||
Comment,
|
Comment,
|
||||||
PersonSafeAlias1,
|
PersonSafeAlias1,
|
||||||
Post,
|
Post,
|
||||||
|
@ -24,22 +24,23 @@ type ModRemoveCommentViewTuple = (
|
||||||
);
|
);
|
||||||
|
|
||||||
impl ModRemoveCommentView {
|
impl ModRemoveCommentView {
|
||||||
pub fn list(
|
pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
conn: &PgConnection,
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
community_id: Option<CommunityId>,
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
mod_person_id: Option<PersonId>,
|
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
||||||
page: Option<i64>,
|
|
||||||
limit: Option<i64>,
|
let admin_names_join = mod_remove_comment::mod_person_id
|
||||||
) -> Result<Vec<Self>, Error> {
|
.eq(person::id)
|
||||||
|
.and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
|
||||||
let mut query = mod_remove_comment::table
|
let mut query = mod_remove_comment::table
|
||||||
.inner_join(person::table)
|
.left_join(person::table.on(admin_names_join))
|
||||||
.inner_join(comment::table)
|
.inner_join(comment::table)
|
||||||
.inner_join(person_alias_1::table.on(comment::creator_id.eq(person_alias_1::id)))
|
.inner_join(person_alias_1::table.on(comment::creator_id.eq(person_alias_1::id)))
|
||||||
.inner_join(post::table.on(comment::post_id.eq(post::id)))
|
.inner_join(post::table.on(comment::post_id.eq(post::id)))
|
||||||
.inner_join(community::table.on(post::community_id.eq(community::id)))
|
.inner_join(community::table.on(post::community_id.eq(community::id)))
|
||||||
.select((
|
.select((
|
||||||
mod_remove_comment::all_columns,
|
mod_remove_comment::all_columns,
|
||||||
Person::safe_columns_tuple(),
|
Person::safe_columns_tuple().nullable(),
|
||||||
comment::all_columns,
|
comment::all_columns,
|
||||||
PersonAlias1::safe_columns_tuple(),
|
PersonAlias1::safe_columns_tuple(),
|
||||||
post::all_columns,
|
post::all_columns,
|
||||||
|
@ -47,15 +48,19 @@ impl ModRemoveCommentView {
|
||||||
))
|
))
|
||||||
.into_boxed();
|
.into_boxed();
|
||||||
|
|
||||||
if let Some(community_id) = community_id {
|
if let Some(community_id) = params.community_id {
|
||||||
query = query.filter(post::community_id.eq(community_id));
|
query = query.filter(post::community_id.eq(community_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(mod_person_id) = mod_person_id {
|
if let Some(mod_person_id) = params.mod_person_id {
|
||||||
query = query.filter(mod_remove_comment::mod_person_id.eq(mod_person_id));
|
query = query.filter(mod_remove_comment::mod_person_id.eq(mod_person_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(page, limit)?;
|
if let Some(other_person_id) = params.other_person_id {
|
||||||
|
query = query.filter(person_alias_1::id.eq(other_person_id));
|
||||||
|
};
|
||||||
|
|
||||||
|
let (limit, offset) = limit_and_offset(params.page, params.limit)?;
|
||||||
|
|
||||||
let res = query
|
let res = query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
@ -63,7 +68,8 @@ impl ModRemoveCommentView {
|
||||||
.order_by(mod_remove_comment::when_.desc())
|
.order_by(mod_remove_comment::when_.desc())
|
||||||
.load::<ModRemoveCommentViewTuple>(conn)?;
|
.load::<ModRemoveCommentViewTuple>(conn)?;
|
||||||
|
|
||||||
Ok(Self::from_tuple_to_vec(res))
|
let results = Self::from_tuple_to_vec(res);
|
||||||
|
Ok(results)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::structs::ModRemoveCommunityView;
|
use crate::structs::{ModRemoveCommunityView, ModlogListParams};
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
|
@ -12,30 +12,32 @@ use lemmy_db_schema::{
|
||||||
utils::limit_and_offset,
|
utils::limit_and_offset,
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModRemoveCommunityTuple = (ModRemoveCommunity, PersonSafe, CommunitySafe);
|
type ModRemoveCommunityTuple = (ModRemoveCommunity, Option<PersonSafe>, CommunitySafe);
|
||||||
|
|
||||||
impl ModRemoveCommunityView {
|
impl ModRemoveCommunityView {
|
||||||
pub fn list(
|
pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
conn: &PgConnection,
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
mod_person_id: Option<PersonId>,
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
page: Option<i64>,
|
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
||||||
limit: Option<i64>,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
let admin_names_join = mod_remove_community::mod_person_id
|
||||||
|
.eq(person::id)
|
||||||
|
.and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
|
||||||
let mut query = mod_remove_community::table
|
let mut query = mod_remove_community::table
|
||||||
.inner_join(person::table)
|
.left_join(person::table.on(admin_names_join))
|
||||||
.inner_join(community::table)
|
.inner_join(community::table)
|
||||||
.select((
|
.select((
|
||||||
mod_remove_community::all_columns,
|
mod_remove_community::all_columns,
|
||||||
Person::safe_columns_tuple(),
|
Person::safe_columns_tuple().nullable(),
|
||||||
Community::safe_columns_tuple(),
|
Community::safe_columns_tuple(),
|
||||||
))
|
))
|
||||||
.into_boxed();
|
.into_boxed();
|
||||||
|
|
||||||
if let Some(mod_person_id) = mod_person_id {
|
if let Some(mod_person_id) = params.mod_person_id {
|
||||||
query = query.filter(mod_remove_community::mod_person_id.eq(mod_person_id));
|
query = query.filter(mod_remove_community::mod_person_id.eq(mod_person_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(page, limit)?;
|
let (limit, offset) = limit_and_offset(params.page, params.limit)?;
|
||||||
|
|
||||||
let res = query
|
let res = query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
@ -43,7 +45,8 @@ impl ModRemoveCommunityView {
|
||||||
.order_by(mod_remove_community::when_.desc())
|
.order_by(mod_remove_community::when_.desc())
|
||||||
.load::<ModRemoveCommunityTuple>(conn)?;
|
.load::<ModRemoveCommunityTuple>(conn)?;
|
||||||
|
|
||||||
Ok(Self::from_tuple_to_vec(res))
|
let results = Self::from_tuple_to_vec(res);
|
||||||
|
Ok(results)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::structs::ModRemovePostView;
|
use crate::structs::{ModRemovePostView, ModlogListParams};
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommunityId, PersonId},
|
newtypes::PersonId,
|
||||||
schema::{community, mod_remove_post, person, post},
|
schema::{community, mod_remove_post, person, person_alias_1, post},
|
||||||
source::{
|
source::{
|
||||||
community::{Community, CommunitySafe},
|
community::{Community, CommunitySafe},
|
||||||
moderator::ModRemovePost,
|
moderator::ModRemovePost,
|
||||||
|
@ -13,37 +13,43 @@ use lemmy_db_schema::{
|
||||||
utils::limit_and_offset,
|
utils::limit_and_offset,
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModRemovePostViewTuple = (ModRemovePost, PersonSafe, Post, CommunitySafe);
|
type ModRemovePostViewTuple = (ModRemovePost, Option<PersonSafe>, Post, CommunitySafe);
|
||||||
|
|
||||||
impl ModRemovePostView {
|
impl ModRemovePostView {
|
||||||
pub fn list(
|
pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
conn: &PgConnection,
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
community_id: Option<CommunityId>,
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
mod_person_id: Option<PersonId>,
|
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
||||||
page: Option<i64>,
|
|
||||||
limit: Option<i64>,
|
let admin_names_join = mod_remove_post::mod_person_id
|
||||||
) -> Result<Vec<Self>, Error> {
|
.eq(person::id)
|
||||||
|
.and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
|
||||||
let mut query = mod_remove_post::table
|
let mut query = mod_remove_post::table
|
||||||
.inner_join(person::table)
|
.left_join(person::table.on(admin_names_join))
|
||||||
.inner_join(post::table)
|
.inner_join(post::table)
|
||||||
.inner_join(community::table.on(post::community_id.eq(community::id)))
|
.inner_join(community::table.on(post::community_id.eq(community::id)))
|
||||||
|
.inner_join(person_alias_1::table.on(post::creator_id.eq(person_alias_1::id)))
|
||||||
.select((
|
.select((
|
||||||
mod_remove_post::all_columns,
|
mod_remove_post::all_columns,
|
||||||
Person::safe_columns_tuple(),
|
Person::safe_columns_tuple().nullable(),
|
||||||
post::all_columns,
|
post::all_columns,
|
||||||
Community::safe_columns_tuple(),
|
Community::safe_columns_tuple(),
|
||||||
))
|
))
|
||||||
.into_boxed();
|
.into_boxed();
|
||||||
|
|
||||||
if let Some(community_id) = community_id {
|
if let Some(community_id) = params.community_id {
|
||||||
query = query.filter(post::community_id.eq(community_id));
|
query = query.filter(post::community_id.eq(community_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(mod_person_id) = mod_person_id {
|
if let Some(mod_person_id) = params.mod_person_id {
|
||||||
query = query.filter(mod_remove_post::mod_person_id.eq(mod_person_id));
|
query = query.filter(mod_remove_post::mod_person_id.eq(mod_person_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(page, limit)?;
|
if let Some(other_person_id) = params.other_person_id {
|
||||||
|
query = query.filter(person_alias_1::id.eq(other_person_id));
|
||||||
|
};
|
||||||
|
|
||||||
|
let (limit, offset) = limit_and_offset(params.page, params.limit)?;
|
||||||
|
|
||||||
let res = query
|
let res = query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
@ -51,7 +57,8 @@ impl ModRemovePostView {
|
||||||
.order_by(mod_remove_post::when_.desc())
|
.order_by(mod_remove_post::when_.desc())
|
||||||
.load::<ModRemovePostViewTuple>(conn)?;
|
.load::<ModRemovePostViewTuple>(conn)?;
|
||||||
|
|
||||||
Ok(Self::from_tuple_to_vec(res))
|
let results = Self::from_tuple_to_vec(res);
|
||||||
|
Ok(results)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::structs::ModStickyPostView;
|
use crate::structs::{ModStickyPostView, ModlogListParams};
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommunityId, PersonId},
|
newtypes::PersonId,
|
||||||
schema::{community, mod_sticky_post, person, post},
|
schema::{community, mod_sticky_post, person, person_alias_1, post},
|
||||||
source::{
|
source::{
|
||||||
community::{Community, CommunitySafe},
|
community::{Community, CommunitySafe},
|
||||||
moderator::ModStickyPost,
|
moderator::ModStickyPost,
|
||||||
|
@ -13,37 +13,43 @@ use lemmy_db_schema::{
|
||||||
utils::limit_and_offset,
|
utils::limit_and_offset,
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModStickyPostViewTuple = (ModStickyPost, PersonSafe, Post, CommunitySafe);
|
type ModStickyPostViewTuple = (ModStickyPost, Option<PersonSafe>, Post, CommunitySafe);
|
||||||
|
|
||||||
impl ModStickyPostView {
|
impl ModStickyPostView {
|
||||||
pub fn list(
|
pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
conn: &PgConnection,
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
community_id: Option<CommunityId>,
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
mod_person_id: Option<PersonId>,
|
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
||||||
page: Option<i64>,
|
|
||||||
limit: Option<i64>,
|
let admin_names_join = mod_sticky_post::mod_person_id
|
||||||
) -> Result<Vec<Self>, Error> {
|
.eq(person::id)
|
||||||
|
.and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
|
||||||
let mut query = mod_sticky_post::table
|
let mut query = mod_sticky_post::table
|
||||||
.inner_join(person::table)
|
.left_join(person::table.on(admin_names_join))
|
||||||
.inner_join(post::table)
|
.inner_join(post::table)
|
||||||
|
.inner_join(person_alias_1::table.on(post::creator_id.eq(person_alias_1::id)))
|
||||||
.inner_join(community::table.on(post::community_id.eq(community::id)))
|
.inner_join(community::table.on(post::community_id.eq(community::id)))
|
||||||
.select((
|
.select((
|
||||||
mod_sticky_post::all_columns,
|
mod_sticky_post::all_columns,
|
||||||
Person::safe_columns_tuple(),
|
Person::safe_columns_tuple().nullable(),
|
||||||
post::all_columns,
|
post::all_columns,
|
||||||
Community::safe_columns_tuple(),
|
Community::safe_columns_tuple(),
|
||||||
))
|
))
|
||||||
.into_boxed();
|
.into_boxed();
|
||||||
|
|
||||||
if let Some(community_id) = community_id {
|
if let Some(community_id) = params.community_id {
|
||||||
query = query.filter(post::community_id.eq(community_id));
|
query = query.filter(post::community_id.eq(community_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(mod_person_id) = mod_person_id {
|
if let Some(mod_person_id) = params.mod_person_id {
|
||||||
query = query.filter(mod_sticky_post::mod_person_id.eq(mod_person_id));
|
query = query.filter(mod_sticky_post::mod_person_id.eq(mod_person_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(page, limit)?;
|
if let Some(other_person_id) = params.other_person_id {
|
||||||
|
query = query.filter(person_alias_1::id.eq(other_person_id));
|
||||||
|
};
|
||||||
|
|
||||||
|
let (limit, offset) = limit_and_offset(params.page, params.limit)?;
|
||||||
|
|
||||||
let res = query
|
let res = query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
@ -51,7 +57,8 @@ impl ModStickyPostView {
|
||||||
.order_by(mod_sticky_post::when_.desc())
|
.order_by(mod_sticky_post::when_.desc())
|
||||||
.load::<ModStickyPostViewTuple>(conn)?;
|
.load::<ModStickyPostViewTuple>(conn)?;
|
||||||
|
|
||||||
Ok(Self::from_tuple_to_vec(res))
|
let results = Self::from_tuple_to_vec(res);
|
||||||
|
Ok(results)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::structs::ModTransferCommunityView;
|
use crate::structs::{ModTransferCommunityView, ModlogListParams};
|
||||||
use diesel::{result::Error, *};
|
use diesel::{result::Error, *};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommunityId, PersonId},
|
newtypes::PersonId,
|
||||||
schema::{community, mod_transfer_community, person, person_alias_1},
|
schema::{community, mod_transfer_community, person, person_alias_1},
|
||||||
source::{
|
source::{
|
||||||
community::{Community, CommunitySafe},
|
community::{Community, CommunitySafe},
|
||||||
|
@ -14,42 +14,47 @@ use lemmy_db_schema::{
|
||||||
|
|
||||||
type ModTransferCommunityViewTuple = (
|
type ModTransferCommunityViewTuple = (
|
||||||
ModTransferCommunity,
|
ModTransferCommunity,
|
||||||
PersonSafe,
|
Option<PersonSafe>,
|
||||||
CommunitySafe,
|
CommunitySafe,
|
||||||
PersonSafeAlias1,
|
PersonSafeAlias1,
|
||||||
);
|
);
|
||||||
|
|
||||||
impl ModTransferCommunityView {
|
impl ModTransferCommunityView {
|
||||||
pub fn list(
|
pub fn list(conn: &PgConnection, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
conn: &PgConnection,
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
community_id: Option<CommunityId>,
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
mod_person_id: Option<PersonId>,
|
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
||||||
page: Option<i64>,
|
|
||||||
limit: Option<i64>,
|
let admin_names_join = mod_transfer_community::mod_person_id
|
||||||
) -> Result<Vec<Self>, Error> {
|
.eq(person::id)
|
||||||
|
.and(show_mod_names_expr.or(person::id.eq(admin_person_id_join)));
|
||||||
let mut query = mod_transfer_community::table
|
let mut query = mod_transfer_community::table
|
||||||
.inner_join(person::table.on(mod_transfer_community::mod_person_id.eq(person::id)))
|
.left_join(person::table.on(admin_names_join))
|
||||||
.inner_join(community::table)
|
.inner_join(community::table)
|
||||||
.inner_join(
|
.inner_join(
|
||||||
person_alias_1::table.on(mod_transfer_community::other_person_id.eq(person_alias_1::id)),
|
person_alias_1::table.on(mod_transfer_community::other_person_id.eq(person_alias_1::id)),
|
||||||
)
|
)
|
||||||
.select((
|
.select((
|
||||||
mod_transfer_community::all_columns,
|
mod_transfer_community::all_columns,
|
||||||
Person::safe_columns_tuple(),
|
Person::safe_columns_tuple().nullable(),
|
||||||
Community::safe_columns_tuple(),
|
Community::safe_columns_tuple(),
|
||||||
PersonAlias1::safe_columns_tuple(),
|
PersonAlias1::safe_columns_tuple(),
|
||||||
))
|
))
|
||||||
.into_boxed();
|
.into_boxed();
|
||||||
|
|
||||||
if let Some(mod_person_id) = mod_person_id {
|
if let Some(mod_person_id) = params.mod_person_id {
|
||||||
query = query.filter(mod_transfer_community::mod_person_id.eq(mod_person_id));
|
query = query.filter(mod_transfer_community::mod_person_id.eq(mod_person_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(community_id) = community_id {
|
if let Some(community_id) = params.community_id {
|
||||||
query = query.filter(mod_transfer_community::community_id.eq(community_id));
|
query = query.filter(mod_transfer_community::community_id.eq(community_id));
|
||||||
};
|
};
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(page, limit)?;
|
if let Some(other_person_id) = params.other_person_id {
|
||||||
|
query = query.filter(person_alias_1::id.eq(other_person_id));
|
||||||
|
};
|
||||||
|
|
||||||
|
let (limit, offset) = limit_and_offset(params.page, params.limit)?;
|
||||||
|
|
||||||
let res = query
|
let res = query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
@ -57,7 +62,8 @@ impl ModTransferCommunityView {
|
||||||
.order_by(mod_transfer_community::when_.desc())
|
.order_by(mod_transfer_community::when_.desc())
|
||||||
.load::<ModTransferCommunityViewTuple>(conn)?;
|
.load::<ModTransferCommunityViewTuple>(conn)?;
|
||||||
|
|
||||||
Ok(Self::from_tuple_to_vec(res))
|
let results = Self::from_tuple_to_vec(res);
|
||||||
|
Ok(results)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
use lemmy_db_schema::source::{
|
use lemmy_db_schema::{
|
||||||
|
newtypes::{CommunityId, PersonId},
|
||||||
|
source::{
|
||||||
comment::Comment,
|
comment::Comment,
|
||||||
community::CommunitySafe,
|
community::CommunitySafe,
|
||||||
moderator::{
|
moderator::{
|
||||||
|
@ -20,13 +22,14 @@ use lemmy_db_schema::source::{
|
||||||
},
|
},
|
||||||
person::{PersonSafe, PersonSafeAlias1},
|
person::{PersonSafe, PersonSafeAlias1},
|
||||||
post::Post,
|
post::Post,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct ModAddCommunityView {
|
pub struct ModAddCommunityView {
|
||||||
pub mod_add_community: ModAddCommunity,
|
pub mod_add_community: ModAddCommunity,
|
||||||
pub moderator: PersonSafe,
|
pub moderator: Option<PersonSafe>,
|
||||||
pub community: CommunitySafe,
|
pub community: CommunitySafe,
|
||||||
pub modded_person: PersonSafeAlias1,
|
pub modded_person: PersonSafeAlias1,
|
||||||
}
|
}
|
||||||
|
@ -34,14 +37,14 @@ pub struct ModAddCommunityView {
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct ModAddView {
|
pub struct ModAddView {
|
||||||
pub mod_add: ModAdd,
|
pub mod_add: ModAdd,
|
||||||
pub moderator: PersonSafe,
|
pub moderator: Option<PersonSafe>,
|
||||||
pub modded_person: PersonSafeAlias1,
|
pub modded_person: PersonSafeAlias1,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct ModBanFromCommunityView {
|
pub struct ModBanFromCommunityView {
|
||||||
pub mod_ban_from_community: ModBanFromCommunity,
|
pub mod_ban_from_community: ModBanFromCommunity,
|
||||||
pub moderator: PersonSafe,
|
pub moderator: Option<PersonSafe>,
|
||||||
pub community: CommunitySafe,
|
pub community: CommunitySafe,
|
||||||
pub banned_person: PersonSafeAlias1,
|
pub banned_person: PersonSafeAlias1,
|
||||||
}
|
}
|
||||||
|
@ -49,21 +52,21 @@ pub struct ModBanFromCommunityView {
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct ModBanView {
|
pub struct ModBanView {
|
||||||
pub mod_ban: ModBan,
|
pub mod_ban: ModBan,
|
||||||
pub moderator: PersonSafe,
|
pub moderator: Option<PersonSafe>,
|
||||||
pub banned_person: PersonSafeAlias1,
|
pub banned_person: PersonSafeAlias1,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct ModHideCommunityView {
|
pub struct ModHideCommunityView {
|
||||||
pub mod_hide_community: ModHideCommunity,
|
pub mod_hide_community: ModHideCommunity,
|
||||||
pub admin: PersonSafe,
|
pub admin: Option<PersonSafe>,
|
||||||
pub community: CommunitySafe,
|
pub community: CommunitySafe,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct ModLockPostView {
|
pub struct ModLockPostView {
|
||||||
pub mod_lock_post: ModLockPost,
|
pub mod_lock_post: ModLockPost,
|
||||||
pub moderator: PersonSafe,
|
pub moderator: Option<PersonSafe>,
|
||||||
pub post: Post,
|
pub post: Post,
|
||||||
pub community: CommunitySafe,
|
pub community: CommunitySafe,
|
||||||
}
|
}
|
||||||
|
@ -71,7 +74,7 @@ pub struct ModLockPostView {
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct ModRemoveCommentView {
|
pub struct ModRemoveCommentView {
|
||||||
pub mod_remove_comment: ModRemoveComment,
|
pub mod_remove_comment: ModRemoveComment,
|
||||||
pub moderator: PersonSafe,
|
pub moderator: Option<PersonSafe>,
|
||||||
pub comment: Comment,
|
pub comment: Comment,
|
||||||
pub commenter: PersonSafeAlias1,
|
pub commenter: PersonSafeAlias1,
|
||||||
pub post: Post,
|
pub post: Post,
|
||||||
|
@ -81,14 +84,14 @@ pub struct ModRemoveCommentView {
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct ModRemoveCommunityView {
|
pub struct ModRemoveCommunityView {
|
||||||
pub mod_remove_community: ModRemoveCommunity,
|
pub mod_remove_community: ModRemoveCommunity,
|
||||||
pub moderator: PersonSafe,
|
pub moderator: Option<PersonSafe>,
|
||||||
pub community: CommunitySafe,
|
pub community: CommunitySafe,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct ModRemovePostView {
|
pub struct ModRemovePostView {
|
||||||
pub mod_remove_post: ModRemovePost,
|
pub mod_remove_post: ModRemovePost,
|
||||||
pub moderator: PersonSafe,
|
pub moderator: Option<PersonSafe>,
|
||||||
pub post: Post,
|
pub post: Post,
|
||||||
pub community: CommunitySafe,
|
pub community: CommunitySafe,
|
||||||
}
|
}
|
||||||
|
@ -96,7 +99,7 @@ pub struct ModRemovePostView {
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct ModStickyPostView {
|
pub struct ModStickyPostView {
|
||||||
pub mod_sticky_post: ModStickyPost,
|
pub mod_sticky_post: ModStickyPost,
|
||||||
pub moderator: PersonSafe,
|
pub moderator: Option<PersonSafe>,
|
||||||
pub post: Post,
|
pub post: Post,
|
||||||
pub community: CommunitySafe,
|
pub community: CommunitySafe,
|
||||||
}
|
}
|
||||||
|
@ -104,7 +107,7 @@ pub struct ModStickyPostView {
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct ModTransferCommunityView {
|
pub struct ModTransferCommunityView {
|
||||||
pub mod_transfer_community: ModTransferCommunity,
|
pub mod_transfer_community: ModTransferCommunity,
|
||||||
pub moderator: PersonSafe,
|
pub moderator: Option<PersonSafe>,
|
||||||
pub community: CommunitySafe,
|
pub community: CommunitySafe,
|
||||||
pub modded_person: PersonSafeAlias1,
|
pub modded_person: PersonSafeAlias1,
|
||||||
}
|
}
|
||||||
|
@ -112,25 +115,35 @@ pub struct ModTransferCommunityView {
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct AdminPurgeCommentView {
|
pub struct AdminPurgeCommentView {
|
||||||
pub admin_purge_comment: AdminPurgeComment,
|
pub admin_purge_comment: AdminPurgeComment,
|
||||||
pub admin: PersonSafe,
|
pub admin: Option<PersonSafe>,
|
||||||
pub post: Post,
|
pub post: Post,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct AdminPurgeCommunityView {
|
pub struct AdminPurgeCommunityView {
|
||||||
pub admin_purge_community: AdminPurgeCommunity,
|
pub admin_purge_community: AdminPurgeCommunity,
|
||||||
pub admin: PersonSafe,
|
pub admin: Option<PersonSafe>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct AdminPurgePersonView {
|
pub struct AdminPurgePersonView {
|
||||||
pub admin_purge_person: AdminPurgePerson,
|
pub admin_purge_person: AdminPurgePerson,
|
||||||
pub admin: PersonSafe,
|
pub admin: Option<PersonSafe>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct AdminPurgePostView {
|
pub struct AdminPurgePostView {
|
||||||
pub admin_purge_post: AdminPurgePost,
|
pub admin_purge_post: AdminPurgePost,
|
||||||
pub admin: PersonSafe,
|
pub admin: Option<PersonSafe>,
|
||||||
pub community: CommunitySafe,
|
pub community: CommunitySafe,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
|
||||||
|
pub struct ModlogListParams {
|
||||||
|
pub community_id: Option<CommunityId>,
|
||||||
|
pub mod_person_id: Option<PersonId>,
|
||||||
|
pub other_person_id: Option<PersonId>,
|
||||||
|
pub page: Option<i64>,
|
||||||
|
pub limit: Option<i64>,
|
||||||
|
pub hide_modlog_names: bool,
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
alter table site drop column hide_modlog_mod_names;
|
|
@ -0,0 +1 @@
|
||||||
|
alter table site add column hide_modlog_mod_names boolean default true NOT NULL;
|
|
@ -70,6 +70,7 @@ async fn main() -> Result<(), LemmyError> {
|
||||||
let manager = ConnectionManager::<PgConnection>::new(&db_url);
|
let manager = ConnectionManager::<PgConnection>::new(&db_url);
|
||||||
let pool = Pool::builder()
|
let pool = Pool::builder()
|
||||||
.max_size(settings.database.pool_size)
|
.max_size(settings.database.pool_size)
|
||||||
|
.min_idle(Some(1))
|
||||||
.build(manager)
|
.build(manager)
|
||||||
.unwrap_or_else(|_| panic!("Error connecting to {}", db_url));
|
.unwrap_or_else(|_| panic!("Error connecting to {}", db_url));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue