Adding moderator views.

This commit is contained in:
Dessalines 2020-12-16 16:28:18 -05:00
parent bd6a4a54a9
commit 313f0467c8
35 changed files with 774 additions and 553 deletions

View file

@ -15,9 +15,11 @@ use lemmy_db::{
source::{comment::Comment, community::*, moderator::*, post::Post, site::*}, source::{comment::Comment, community::*, moderator::*, post::Post, site::*},
views::{ views::{
comment_view::CommentQueryBuilder, comment_view::CommentQueryBuilder,
community_follower_view::CommunityFollowerView, community::{
community_moderator_view::CommunityModeratorView, community_follower_view::CommunityFollowerView,
community_view::{CommunityQueryBuilder, CommunityView}, community_moderator_view::CommunityModeratorView,
community_view::{CommunityQueryBuilder, CommunityView},
},
user_view::UserViewSafe, user_view::UserViewSafe,
}, },
ApubObject, ApubObject,

View file

@ -6,7 +6,7 @@ use lemmy_db::{
post::Post, post::Post,
user::User_, user::User_,
}, },
views::community_user_ban_view::CommunityUserBanView, views::community::community_user_ban_view::CommunityUserBanView,
Crud, Crud,
DbPool, DbPool,
}; };

View file

@ -15,8 +15,7 @@ use lemmy_db::{
source::{moderator::*, post::*}, source::{moderator::*, post::*},
views::{ views::{
comment_view::CommentQueryBuilder, comment_view::CommentQueryBuilder,
community_moderator_view::CommunityModeratorView, community::{community_moderator_view::CommunityModeratorView, community_view::CommunityView},
community_view::CommunityView,
post_view::{PostQueryBuilder, PostView}, post_view::{PostQueryBuilder, PostView},
site_view::SiteView, site_view::SiteView,
}, },

View file

@ -12,12 +12,22 @@ use lemmy_apub::fetcher::search_by_apub_id;
use lemmy_db::{ use lemmy_db::{
aggregates::site_aggregates::SiteAggregates, aggregates::site_aggregates::SiteAggregates,
diesel_option_overwrite, diesel_option_overwrite,
moderator_views::*,
naive_now, naive_now,
source::{category::*, moderator::*, site::*}, source::{category::*, moderator::*, site::*},
views::{ views::{
comment_view::CommentQueryBuilder, comment_view::CommentQueryBuilder,
community_view::CommunityQueryBuilder, 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, post_view::PostQueryBuilder,
site_view::SiteView, site_view::SiteView,
user_view::{UserQueryBuilder, UserViewSafe}, user_view::{UserQueryBuilder, UserViewSafe},

View file

@ -33,8 +33,10 @@ use lemmy_db::{
}, },
views::{ views::{
comment_view::CommentQueryBuilder, comment_view::CommentQueryBuilder,
community_follower_view::CommunityFollowerView, community::{
community_moderator_view::CommunityModeratorView, community_follower_view::CommunityFollowerView,
community_moderator_view::CommunityModeratorView,
},
post_view::PostQueryBuilder, post_view::PostQueryBuilder,
site_view::SiteView, site_view::SiteView,
user_mention_view::{UserMentionQueryBuilder, UserMentionView}, user_mention_view::{UserMentionQueryBuilder, UserMentionView},

View file

@ -4,7 +4,11 @@ use activitystreams::{
base::{AnyBase, ExtendsExt}, base::{AnyBase, ExtendsExt},
}; };
use anyhow::Context; use anyhow::Context;
use lemmy_db::{source::community::Community, views::community_view::CommunityView, ApubObject}; use lemmy_db::{
source::community::Community,
views::community::community_view::CommunityView,
ApubObject,
};
use lemmy_structs::{blocking, community::CommunityResponse}; use lemmy_structs::{blocking, community::CommunityResponse};
use lemmy_utils::{location_info, LemmyError}; use lemmy_utils::{location_info, LemmyError};
use lemmy_websocket::{messages::SendCommunityRoomMessage, LemmyContext, UserOperation}; use lemmy_websocket::{messages::SendCommunityRoomMessage, LemmyContext, UserOperation};

View file

@ -25,7 +25,7 @@ use anyhow::Context;
use itertools::Itertools; use itertools::Itertools;
use lemmy_db::{ use lemmy_db::{
source::community::Community, source::community::Community,
views::community_follower_view::CommunityFollowerView, views::community::community_follower_view::CommunityFollowerView,
DbPool, DbPool,
}; };
use lemmy_structs::blocking; use lemmy_structs::blocking;

View file

@ -22,7 +22,7 @@ use lemmy_db::{
}, },
views::{ views::{
comment_view::CommentView, comment_view::CommentView,
community_view::CommunityView, community::community_view::CommunityView,
post_view::PostView, post_view::PostView,
user_view::UserViewSafe, user_view::UserViewSafe,
}, },

View file

@ -11,7 +11,7 @@ use activitystreams::{
use actix_web::{body::Body, web, HttpResponse}; use actix_web::{body::Body, web, HttpResponse};
use lemmy_db::{ use lemmy_db::{
source::{community::Community, post::Post}, source::{community::Community, post::Post},
views::community_follower_view::CommunityFollowerView, views::community::community_follower_view::CommunityFollowerView,
}; };
use lemmy_structs::blocking; use lemmy_structs::blocking;
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;

View file

@ -31,7 +31,7 @@ use lemmy_db::{
community::{Community, CommunityFollower, CommunityFollowerForm}, community::{Community, CommunityFollower, CommunityFollowerForm},
user::User_, user::User_,
}, },
views::community_user_ban_view::CommunityUserBanView, views::community::community_user_ban_view::CommunityUserBanView,
ApubObject, ApubObject,
DbPool, DbPool,
Followable, Followable,

View file

@ -25,7 +25,7 @@ use anyhow::Context;
use lemmy_db::{ use lemmy_db::{
naive_now, naive_now,
source::community::{Community, CommunityForm}, source::community::{Community, CommunityForm},
views::community_moderator_view::CommunityModeratorView, views::community::community_moderator_view::CommunityModeratorView,
DbPool, DbPool,
}; };
use lemmy_structs::blocking; use lemmy_structs::blocking;

View file

@ -12,7 +12,6 @@ use serde::{Deserialize, Serialize};
use std::{env, env::VarError}; use std::{env, env::VarError};
pub mod comment_report; pub mod comment_report;
pub mod moderator_views;
pub mod post_report; pub mod post_report;
pub mod private_message_view; pub mod private_message_view;

View file

@ -1,513 +0,0 @@
use crate::limit_and_offset;
use diesel::{result::Error, *};
use serde::Serialize;
table! {
mod_remove_post_view (id) {
id -> Int4,
mod_user_id -> Int4,
post_id -> Int4,
reason -> Nullable<Text>,
removed -> Nullable<Bool>,
when_ -> Timestamp,
mod_user_name -> Varchar,
post_name -> Varchar,
community_id -> Int4,
community_name -> Varchar,
}
}
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
#[table_name = "mod_remove_post_view"]
pub struct ModRemovePostView {
pub id: i32,
pub mod_user_id: i32,
pub post_id: i32,
pub reason: Option<String>,
pub removed: Option<bool>,
pub when_: chrono::NaiveDateTime,
pub mod_user_name: String,
pub post_name: String,
pub community_id: i32,
pub community_name: String,
}
impl ModRemovePostView {
pub fn list(
conn: &PgConnection,
from_community_id: Option<i32>,
from_mod_user_id: Option<i32>,
page: Option<i64>,
limit: Option<i64>,
) -> Result<Vec<Self>, Error> {
use super::moderator_views::mod_remove_post_view::dsl::*;
let mut query = mod_remove_post_view.into_boxed();
let (limit, offset) = limit_and_offset(page, limit);
if let Some(from_community_id) = from_community_id {
query = query.filter(community_id.eq(from_community_id));
};
if let Some(from_mod_user_id) = from_mod_user_id {
query = query.filter(mod_user_id.eq(from_mod_user_id));
};
query
.limit(limit)
.offset(offset)
.order_by(when_.desc())
.load::<Self>(conn)
}
}
table! {
mod_lock_post_view (id) {
id -> Int4,
mod_user_id -> Int4,
post_id -> Int4,
locked -> Nullable<Bool>,
when_ -> Timestamp,
mod_user_name -> Varchar,
post_name -> Varchar,
community_id -> Int4,
community_name -> Varchar,
}
}
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
#[table_name = "mod_lock_post_view"]
pub struct ModLockPostView {
pub id: i32,
pub mod_user_id: i32,
pub post_id: i32,
pub locked: Option<bool>,
pub when_: chrono::NaiveDateTime,
pub mod_user_name: String,
pub post_name: String,
pub community_id: i32,
pub community_name: String,
}
impl ModLockPostView {
pub fn list(
conn: &PgConnection,
from_community_id: Option<i32>,
from_mod_user_id: Option<i32>,
page: Option<i64>,
limit: Option<i64>,
) -> Result<Vec<Self>, Error> {
use super::moderator_views::mod_lock_post_view::dsl::*;
let mut query = mod_lock_post_view.into_boxed();
let (limit, offset) = limit_and_offset(page, limit);
if let Some(from_community_id) = from_community_id {
query = query.filter(community_id.eq(from_community_id));
};
if let Some(from_mod_user_id) = from_mod_user_id {
query = query.filter(mod_user_id.eq(from_mod_user_id));
};
query
.limit(limit)
.offset(offset)
.order_by(when_.desc())
.load::<Self>(conn)
}
}
table! {
mod_sticky_post_view (id) {
id -> Int4,
mod_user_id -> Int4,
post_id -> Int4,
stickied -> Nullable<Bool>,
when_ -> Timestamp,
mod_user_name -> Varchar,
post_name -> Varchar,
community_id -> Int4,
community_name -> Varchar,
}
}
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
#[table_name = "mod_sticky_post_view"]
pub struct ModStickyPostView {
pub id: i32,
pub mod_user_id: i32,
pub post_id: i32,
pub stickied: Option<bool>,
pub when_: chrono::NaiveDateTime,
pub mod_user_name: String,
pub post_name: String,
pub community_id: i32,
pub community_name: String,
}
impl ModStickyPostView {
pub fn list(
conn: &PgConnection,
from_community_id: Option<i32>,
from_mod_user_id: Option<i32>,
page: Option<i64>,
limit: Option<i64>,
) -> Result<Vec<Self>, Error> {
use super::moderator_views::mod_sticky_post_view::dsl::*;
let mut query = mod_sticky_post_view.into_boxed();
let (limit, offset) = limit_and_offset(page, limit);
if let Some(from_community_id) = from_community_id {
query = query.filter(community_id.eq(from_community_id));
};
if let Some(from_mod_user_id) = from_mod_user_id {
query = query.filter(mod_user_id.eq(from_mod_user_id));
};
query
.limit(limit)
.offset(offset)
.order_by(when_.desc())
.load::<Self>(conn)
}
}
table! {
mod_remove_comment_view (id) {
id -> Int4,
mod_user_id -> Int4,
comment_id -> Int4,
reason -> Nullable<Text>,
removed -> Nullable<Bool>,
when_ -> Timestamp,
mod_user_name -> Varchar,
comment_user_id -> Int4,
comment_user_name -> Varchar,
comment_content -> Text,
post_id -> Int4,
post_name -> Varchar,
community_id -> Int4,
community_name -> Varchar,
}
}
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
#[table_name = "mod_remove_comment_view"]
pub struct ModRemoveCommentView {
pub id: i32,
pub mod_user_id: i32,
pub comment_id: i32,
pub reason: Option<String>,
pub removed: Option<bool>,
pub when_: chrono::NaiveDateTime,
pub mod_user_name: String,
pub comment_user_id: i32,
pub comment_user_name: String,
pub comment_content: String,
pub post_id: i32,
pub post_name: String,
pub community_id: i32,
pub community_name: String,
}
impl ModRemoveCommentView {
pub fn list(
conn: &PgConnection,
from_community_id: Option<i32>,
from_mod_user_id: Option<i32>,
page: Option<i64>,
limit: Option<i64>,
) -> Result<Vec<Self>, Error> {
use super::moderator_views::mod_remove_comment_view::dsl::*;
let mut query = mod_remove_comment_view.into_boxed();
let (limit, offset) = limit_and_offset(page, limit);
if let Some(from_community_id) = from_community_id {
query = query.filter(community_id.eq(from_community_id));
};
if let Some(from_mod_user_id) = from_mod_user_id {
query = query.filter(mod_user_id.eq(from_mod_user_id));
};
query
.limit(limit)
.offset(offset)
.order_by(when_.desc())
.load::<Self>(conn)
}
}
table! {
mod_remove_community_view (id) {
id -> Int4,
mod_user_id -> Int4,
community_id -> Int4,
reason -> Nullable<Text>,
removed -> Nullable<Bool>,
expires -> Nullable<Timestamp>,
when_ -> Timestamp,
mod_user_name -> Varchar,
community_name -> Varchar,
}
}
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
#[table_name = "mod_remove_community_view"]
pub struct ModRemoveCommunityView {
pub id: i32,
pub mod_user_id: i32,
pub community_id: i32,
pub reason: Option<String>,
pub removed: Option<bool>,
pub expires: Option<chrono::NaiveDateTime>,
pub when_: chrono::NaiveDateTime,
pub mod_user_name: String,
pub community_name: String,
}
impl ModRemoveCommunityView {
pub fn list(
conn: &PgConnection,
from_mod_user_id: Option<i32>,
page: Option<i64>,
limit: Option<i64>,
) -> Result<Vec<Self>, Error> {
use super::moderator_views::mod_remove_community_view::dsl::*;
let mut query = mod_remove_community_view.into_boxed();
let (limit, offset) = limit_and_offset(page, limit);
if let Some(from_mod_user_id) = from_mod_user_id {
query = query.filter(mod_user_id.eq(from_mod_user_id));
};
query
.limit(limit)
.offset(offset)
.order_by(when_.desc())
.load::<Self>(conn)
}
}
table! {
mod_ban_from_community_view (id) {
id -> Int4,
mod_user_id -> Int4,
other_user_id -> Int4,
community_id -> Int4,
reason -> Nullable<Text>,
banned -> Nullable<Bool>,
expires -> Nullable<Timestamp>,
when_ -> Timestamp,
mod_user_name -> Varchar,
other_user_name -> Varchar,
community_name -> Varchar,
}
}
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
#[table_name = "mod_ban_from_community_view"]
pub struct ModBanFromCommunityView {
pub id: i32,
pub mod_user_id: i32,
pub other_user_id: i32,
pub community_id: i32,
pub reason: Option<String>,
pub banned: Option<bool>,
pub expires: Option<chrono::NaiveDateTime>,
pub when_: chrono::NaiveDateTime,
pub mod_user_name: String,
pub other_user_name: String,
pub community_name: String,
}
impl ModBanFromCommunityView {
pub fn list(
conn: &PgConnection,
from_community_id: Option<i32>,
from_mod_user_id: Option<i32>,
page: Option<i64>,
limit: Option<i64>,
) -> Result<Vec<Self>, Error> {
use super::moderator_views::mod_ban_from_community_view::dsl::*;
let mut query = mod_ban_from_community_view.into_boxed();
let (limit, offset) = limit_and_offset(page, limit);
if let Some(from_community_id) = from_community_id {
query = query.filter(community_id.eq(from_community_id));
};
if let Some(from_mod_user_id) = from_mod_user_id {
query = query.filter(mod_user_id.eq(from_mod_user_id));
};
query
.limit(limit)
.offset(offset)
.order_by(when_.desc())
.load::<Self>(conn)
}
}
table! {
mod_ban_view (id) {
id -> Int4,
mod_user_id -> Int4,
other_user_id -> Int4,
reason -> Nullable<Text>,
banned -> Nullable<Bool>,
expires -> Nullable<Timestamp>,
when_ -> Timestamp,
mod_user_name -> Varchar,
other_user_name -> Varchar,
}
}
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
#[table_name = "mod_ban_view"]
pub struct ModBanView {
pub id: i32,
pub mod_user_id: i32,
pub other_user_id: i32,
pub reason: Option<String>,
pub banned: Option<bool>,
pub expires: Option<chrono::NaiveDateTime>,
pub when_: chrono::NaiveDateTime,
pub mod_user_name: String,
pub other_user_name: String,
}
impl ModBanView {
pub fn list(
conn: &PgConnection,
from_mod_user_id: Option<i32>,
page: Option<i64>,
limit: Option<i64>,
) -> Result<Vec<Self>, Error> {
use super::moderator_views::mod_ban_view::dsl::*;
let mut query = mod_ban_view.into_boxed();
let (limit, offset) = limit_and_offset(page, limit);
if let Some(from_mod_user_id) = from_mod_user_id {
query = query.filter(mod_user_id.eq(from_mod_user_id));
};
query
.limit(limit)
.offset(offset)
.order_by(when_.desc())
.load::<Self>(conn)
}
}
table! {
mod_add_community_view (id) {
id -> Int4,
mod_user_id -> Int4,
other_user_id -> Int4,
community_id -> Int4,
removed -> Nullable<Bool>,
when_ -> Timestamp,
mod_user_name -> Varchar,
other_user_name -> Varchar,
community_name -> Varchar,
}
}
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
#[table_name = "mod_add_community_view"]
pub struct ModAddCommunityView {
pub id: i32,
pub mod_user_id: i32,
pub other_user_id: i32,
pub community_id: i32,
pub removed: Option<bool>,
pub when_: chrono::NaiveDateTime,
pub mod_user_name: String,
pub other_user_name: String,
pub community_name: String,
}
impl ModAddCommunityView {
pub fn list(
conn: &PgConnection,
from_community_id: Option<i32>,
from_mod_user_id: Option<i32>,
page: Option<i64>,
limit: Option<i64>,
) -> Result<Vec<Self>, Error> {
use super::moderator_views::mod_add_community_view::dsl::*;
let mut query = mod_add_community_view.into_boxed();
let (limit, offset) = limit_and_offset(page, limit);
if let Some(from_community_id) = from_community_id {
query = query.filter(community_id.eq(from_community_id));
};
if let Some(from_mod_user_id) = from_mod_user_id {
query = query.filter(mod_user_id.eq(from_mod_user_id));
};
query
.limit(limit)
.offset(offset)
.order_by(when_.desc())
.load::<Self>(conn)
}
}
table! {
mod_add_view (id) {
id -> Int4,
mod_user_id -> Int4,
other_user_id -> Int4,
removed -> Nullable<Bool>,
when_ -> Timestamp,
mod_user_name -> Varchar,
other_user_name -> Varchar,
}
}
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
#[table_name = "mod_add_view"]
pub struct ModAddView {
pub id: i32,
pub mod_user_id: i32,
pub other_user_id: i32,
pub removed: Option<bool>,
pub when_: chrono::NaiveDateTime,
pub mod_user_name: String,
pub other_user_name: String,
}
impl ModAddView {
pub fn list(
conn: &PgConnection,
from_mod_user_id: Option<i32>,
page: Option<i64>,
limit: Option<i64>,
) -> Result<Vec<Self>, Error> {
use super::moderator_views::mod_add_view::dsl::*;
let mut query = mod_add_view.into_boxed();
let (limit, offset) = limit_and_offset(page, limit);
if let Some(from_mod_user_id) = from_mod_user_id {
query = query.filter(mod_user_id.eq(from_mod_user_id));
};
query
.limit(limit)
.offset(offset)
.order_by(when_.desc())
.load::<Self>(conn)
}
}

View file

@ -1,6 +1,7 @@
use crate::{ use crate::{
naive_now, naive_now,
schema::{community, community_follower, community_moderator, community_user_ban}, schema::{community, community_follower, community_moderator, community_user_ban},
views::{community::community_moderator_view::CommunityModeratorView, user_view::UserViewSafe},
ApubObject, ApubObject,
Bannable, Bannable,
Crud, Crud,
@ -223,7 +224,6 @@ impl Community {
} }
fn community_mods_and_admins(conn: &PgConnection, community_id: i32) -> Result<Vec<i32>, Error> { fn community_mods_and_admins(conn: &PgConnection, community_id: i32) -> Result<Vec<i32>, Error> {
use crate::views::{community_moderator_view::CommunityModeratorView, user_view::UserViewSafe};
let mut mods_and_admins: Vec<i32> = Vec::new(); let mut mods_and_admins: Vec<i32> = Vec::new();
mods_and_admins.append( mods_and_admins.append(
&mut CommunityModeratorView::for_community(conn, community_id) &mut CommunityModeratorView::for_community(conn, community_id)

View file

@ -13,8 +13,9 @@ use crate::{
Crud, Crud,
}; };
use diesel::{dsl::*, result::Error, *}; use diesel::{dsl::*, result::Error, *};
use serde::Serialize;
#[derive(Queryable, Identifiable, PartialEq, Debug)] #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_remove_post"] #[table_name = "mod_remove_post"]
pub struct ModRemovePost { pub struct ModRemovePost {
pub id: i32, pub id: i32,
@ -55,7 +56,7 @@ impl Crud<ModRemovePostForm> for ModRemovePost {
} }
} }
#[derive(Queryable, Identifiable, PartialEq, Debug)] #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_lock_post"] #[table_name = "mod_lock_post"]
pub struct ModLockPost { pub struct ModLockPost {
pub id: i32, pub id: i32,
@ -94,7 +95,7 @@ impl Crud<ModLockPostForm> for ModLockPost {
} }
} }
#[derive(Queryable, Identifiable, PartialEq, Debug)] #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_sticky_post"] #[table_name = "mod_sticky_post"]
pub struct ModStickyPost { pub struct ModStickyPost {
pub id: i32, pub id: i32,
@ -133,7 +134,7 @@ impl Crud<ModStickyPostForm> for ModStickyPost {
} }
} }
#[derive(Queryable, Identifiable, PartialEq, Debug)] #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_remove_comment"] #[table_name = "mod_remove_comment"]
pub struct ModRemoveComment { pub struct ModRemoveComment {
pub id: i32, pub id: i32,
@ -174,7 +175,7 @@ impl Crud<ModRemoveCommentForm> for ModRemoveComment {
} }
} }
#[derive(Queryable, Identifiable, PartialEq, Debug)] #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_remove_community"] #[table_name = "mod_remove_community"]
pub struct ModRemoveCommunity { pub struct ModRemoveCommunity {
pub id: i32, pub id: i32,
@ -221,7 +222,7 @@ impl Crud<ModRemoveCommunityForm> for ModRemoveCommunity {
} }
} }
#[derive(Queryable, Identifiable, PartialEq, Debug)] #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_ban_from_community"] #[table_name = "mod_ban_from_community"]
pub struct ModBanFromCommunity { pub struct ModBanFromCommunity {
pub id: i32, pub id: i32,
@ -270,7 +271,7 @@ impl Crud<ModBanFromCommunityForm> for ModBanFromCommunity {
} }
} }
#[derive(Queryable, Identifiable, PartialEq, Debug)] #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_ban"] #[table_name = "mod_ban"]
pub struct ModBan { pub struct ModBan {
pub id: i32, pub id: i32,
@ -311,7 +312,7 @@ impl Crud<ModBanForm> for ModBan {
} }
} }
#[derive(Queryable, Identifiable, PartialEq, Debug)] #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_add_community"] #[table_name = "mod_add_community"]
pub struct ModAddCommunity { pub struct ModAddCommunity {
pub id: i32, pub id: i32,
@ -352,7 +353,7 @@ impl Crud<ModAddCommunityForm> for ModAddCommunity {
} }
} }
#[derive(Queryable, Identifiable, PartialEq, Debug)] #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "mod_add"] #[table_name = "mod_add"]
pub struct ModAdd { pub struct ModAdd {
pub id: i32, pub id: i32,

View file

@ -0,0 +1,4 @@
pub mod community_follower_view;
pub mod community_moderator_view;
pub mod community_user_ban_view;
pub mod community_view;

View file

@ -1,8 +1,6 @@
pub mod comment_view; pub mod comment_view;
pub mod community_follower_view; pub mod community;
pub mod community_moderator_view; pub mod moderator;
pub mod community_user_ban_view;
pub mod community_view;
pub mod post_view; pub mod post_view;
pub mod site_view; pub mod site_view;
pub mod user_mention_view; pub mod user_mention_view;

View file

@ -0,0 +1,9 @@
pub mod mod_add_community_view;
pub mod mod_add_view;
pub mod mod_ban_from_community_view;
pub mod mod_ban_view;
pub mod mod_lock_post_view;
pub mod mod_remove_comment_view;
pub mod mod_remove_community_view;
pub mod mod_remove_post_view;
pub mod mod_sticky_post_view;

View file

@ -0,0 +1,78 @@
use crate::{
limit_and_offset,
schema::{community, mod_add_community, user_, user_alias_1},
source::{
community::{Community, CommunitySafe},
moderator::ModAddCommunity,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
views::ViewToVec,
ToSafe,
};
use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
pub struct ModAddCommunityView {
pub mod_add_community: ModAddCommunity,
pub moderator: UserSafe,
pub community: CommunitySafe,
pub modded_user: UserSafeAlias1,
}
type ModAddCommunityViewTuple = (ModAddCommunity, UserSafe, CommunitySafe, UserSafeAlias1);
impl ModAddCommunityView {
pub fn list(
conn: &PgConnection,
community_id: Option<i32>,
mod_user_id: Option<i32>,
page: Option<i64>,
limit: Option<i64>,
) -> Result<Vec<Self>, Error> {
let mut query = mod_add_community::table
.inner_join(user_::table.on(mod_add_community::mod_user_id.eq(user_::id)))
.inner_join(community::table)
.inner_join(user_alias_1::table.on(mod_add_community::other_user_id.eq(user_::id)))
.select((
mod_add_community::all_columns,
User_::safe_columns_tuple(),
Community::safe_columns_tuple(),
UserAlias1::safe_columns_tuple(),
))
.into_boxed();
if let Some(mod_user_id) = mod_user_id {
query = query.filter(mod_add_community::mod_user_id.eq(mod_user_id));
};
if let Some(community_id) = community_id {
query = query.filter(mod_add_community::community_id.eq(community_id));
};
let (limit, offset) = limit_and_offset(page, limit);
let res = query
.limit(limit)
.offset(offset)
.order_by(mod_add_community::when_.desc())
.load::<ModAddCommunityViewTuple>(conn)?;
Ok(Self::to_vec(res))
}
}
impl ViewToVec for ModAddCommunityView {
type DbTuple = ModAddCommunityViewTuple;
fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
mrp
.iter()
.map(|a| Self {
mod_add_community: a.0.to_owned(),
moderator: a.1.to_owned(),
community: a.2.to_owned(),
modded_user: a.3.to_owned(),
})
.collect::<Vec<Self>>()
}
}

View file

@ -0,0 +1,68 @@
use crate::{
limit_and_offset,
schema::{mod_add, user_, user_alias_1},
source::{
moderator::ModAdd,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
views::ViewToVec,
ToSafe,
};
use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
pub struct ModAddView {
pub mod_add: ModAdd,
pub moderator: UserSafe,
pub modded_user: UserSafeAlias1,
}
type ModAddViewTuple = (ModAdd, UserSafe, UserSafeAlias1);
impl ModAddView {
pub fn list(
conn: &PgConnection,
mod_user_id: Option<i32>,
page: Option<i64>,
limit: Option<i64>,
) -> Result<Vec<Self>, Error> {
let mut query = mod_add::table
.inner_join(user_::table.on(mod_add::mod_user_id.eq(user_::id)))
.inner_join(user_alias_1::table.on(mod_add::other_user_id.eq(user_::id)))
.select((
mod_add::all_columns,
User_::safe_columns_tuple(),
UserAlias1::safe_columns_tuple(),
))
.into_boxed();
if let Some(mod_user_id) = mod_user_id {
query = query.filter(mod_add::mod_user_id.eq(mod_user_id));
};
let (limit, offset) = limit_and_offset(page, limit);
let res = query
.limit(limit)
.offset(offset)
.order_by(mod_add::when_.desc())
.load::<ModAddViewTuple>(conn)?;
Ok(Self::to_vec(res))
}
}
impl ViewToVec for ModAddView {
type DbTuple = ModAddViewTuple;
fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
mrp
.iter()
.map(|a| Self {
mod_add: a.0.to_owned(),
moderator: a.1.to_owned(),
modded_user: a.2.to_owned(),
})
.collect::<Vec<Self>>()
}
}

View file

@ -0,0 +1,78 @@
use crate::{
limit_and_offset,
schema::{community, mod_ban_from_community, user_, user_alias_1},
source::{
community::{Community, CommunitySafe},
moderator::ModBanFromCommunity,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
views::ViewToVec,
ToSafe,
};
use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
pub struct ModBanFromCommunityView {
pub mod_ban_from_community: ModBanFromCommunity,
pub moderator: UserSafe,
pub community: CommunitySafe,
pub banned_user: UserSafeAlias1,
}
type ModBanFromCommunityViewTuple = (ModBanFromCommunity, UserSafe, CommunitySafe, UserSafeAlias1);
impl ModBanFromCommunityView {
pub fn list(
conn: &PgConnection,
community_id: Option<i32>,
mod_user_id: Option<i32>,
page: Option<i64>,
limit: Option<i64>,
) -> Result<Vec<Self>, Error> {
let mut query = mod_ban_from_community::table
.inner_join(user_::table.on(mod_ban_from_community::mod_user_id.eq(user_::id)))
.inner_join(community::table)
.inner_join(user_alias_1::table.on(mod_ban_from_community::other_user_id.eq(user_::id)))
.select((
mod_ban_from_community::all_columns,
User_::safe_columns_tuple(),
Community::safe_columns_tuple(),
UserAlias1::safe_columns_tuple(),
))
.into_boxed();
if let Some(mod_user_id) = mod_user_id {
query = query.filter(mod_ban_from_community::mod_user_id.eq(mod_user_id));
};
if let Some(community_id) = community_id {
query = query.filter(mod_ban_from_community::community_id.eq(community_id));
};
let (limit, offset) = limit_and_offset(page, limit);
let res = query
.limit(limit)
.offset(offset)
.order_by(mod_ban_from_community::when_.desc())
.load::<ModBanFromCommunityViewTuple>(conn)?;
Ok(Self::to_vec(res))
}
}
impl ViewToVec for ModBanFromCommunityView {
type DbTuple = ModBanFromCommunityViewTuple;
fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
mrp
.iter()
.map(|a| Self {
mod_ban_from_community: a.0.to_owned(),
moderator: a.1.to_owned(),
community: a.2.to_owned(),
banned_user: a.3.to_owned(),
})
.collect::<Vec<Self>>()
}
}

View file

@ -0,0 +1,68 @@
use crate::{
limit_and_offset,
schema::{mod_ban, user_, user_alias_1},
source::{
moderator::ModBan,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
views::ViewToVec,
ToSafe,
};
use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
pub struct ModBanView {
pub mod_ban: ModBan,
pub moderator: UserSafe,
pub banned_user: UserSafeAlias1,
}
type ModBanViewTuple = (ModBan, UserSafe, UserSafeAlias1);
impl ModBanView {
pub fn list(
conn: &PgConnection,
mod_user_id: Option<i32>,
page: Option<i64>,
limit: Option<i64>,
) -> Result<Vec<Self>, Error> {
let mut query = mod_ban::table
.inner_join(user_::table.on(mod_ban::mod_user_id.eq(user_::id)))
.inner_join(user_alias_1::table.on(mod_ban::other_user_id.eq(user_::id)))
.select((
mod_ban::all_columns,
User_::safe_columns_tuple(),
UserAlias1::safe_columns_tuple(),
))
.into_boxed();
if let Some(mod_user_id) = mod_user_id {
query = query.filter(mod_ban::mod_user_id.eq(mod_user_id));
};
let (limit, offset) = limit_and_offset(page, limit);
let res = query
.limit(limit)
.offset(offset)
.order_by(mod_ban::when_.desc())
.load::<ModBanViewTuple>(conn)?;
Ok(Self::to_vec(res))
}
}
impl ViewToVec for ModBanView {
type DbTuple = ModBanViewTuple;
fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
mrp
.iter()
.map(|a| Self {
mod_ban: a.0.to_owned(),
moderator: a.1.to_owned(),
banned_user: a.2.to_owned(),
})
.collect::<Vec<Self>>()
}
}

View file

@ -0,0 +1,79 @@
use crate::{
limit_and_offset,
schema::{community, mod_lock_post, post, user_},
source::{
community::{Community, CommunitySafe},
moderator::ModLockPost,
post::Post,
user::{UserSafe, User_},
},
views::ViewToVec,
ToSafe,
};
use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
pub struct ModLockPostView {
pub mod_lock_post: ModLockPost,
pub moderator: UserSafe,
pub post: Post,
pub community: CommunitySafe,
}
type ModLockPostViewTuple = (ModLockPost, UserSafe, Post, CommunitySafe);
impl ModLockPostView {
pub fn list(
conn: &PgConnection,
community_id: Option<i32>,
mod_user_id: Option<i32>,
page: Option<i64>,
limit: Option<i64>,
) -> Result<Vec<Self>, Error> {
let mut query = mod_lock_post::table
.inner_join(user_::table)
.inner_join(post::table)
.inner_join(community::table.on(post::community_id.eq(community::id)))
.select((
mod_lock_post::all_columns,
User_::safe_columns_tuple(),
post::all_columns,
Community::safe_columns_tuple(),
))
.into_boxed();
if let Some(community_id) = community_id {
query = query.filter(post::community_id.eq(community_id));
};
if let Some(mod_user_id) = mod_user_id {
query = query.filter(mod_lock_post::mod_user_id.eq(mod_user_id));
};
let (limit, offset) = limit_and_offset(page, limit);
let res = query
.limit(limit)
.offset(offset)
.order_by(mod_lock_post::when_.desc())
.load::<ModLockPostViewTuple>(conn)?;
Ok(Self::to_vec(res))
}
}
impl ViewToVec for ModLockPostView {
type DbTuple = ModLockPostViewTuple;
fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
mrp
.iter()
.map(|a| Self {
mod_lock_post: a.0.to_owned(),
moderator: a.1.to_owned(),
post: a.2.to_owned(),
community: a.3.to_owned(),
})
.collect::<Vec<Self>>()
}
}

View file

@ -0,0 +1,95 @@
use crate::{
limit_and_offset,
schema::{comment, community, mod_remove_comment, post, user_, user_alias_1},
source::{
comment::Comment,
community::{Community, CommunitySafe},
moderator::ModRemoveComment,
post::Post,
user::{UserAlias1, UserSafe, UserSafeAlias1, User_},
},
views::ViewToVec,
ToSafe,
};
use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
pub struct ModRemoveCommentView {
pub mod_remove_comment: ModRemoveComment,
pub moderator: UserSafe,
pub comment: Comment,
pub commenter: UserSafeAlias1,
pub post: Post,
pub community: CommunitySafe,
}
type ModRemoveCommentViewTuple = (
ModRemoveComment,
UserSafe,
Comment,
UserSafeAlias1,
Post,
CommunitySafe,
);
impl ModRemoveCommentView {
pub fn list(
conn: &PgConnection,
community_id: Option<i32>,
mod_user_id: Option<i32>,
page: Option<i64>,
limit: Option<i64>,
) -> Result<Vec<Self>, Error> {
let mut query = mod_remove_comment::table
.inner_join(user_::table)
.inner_join(comment::table)
.inner_join(user_alias_1::table.on(comment::creator_id.eq(user_alias_1::id)))
.inner_join(post::table.on(comment::post_id.eq(post::id)))
.inner_join(community::table.on(post::community_id.eq(community::id)))
.select((
mod_remove_comment::all_columns,
User_::safe_columns_tuple(),
comment::all_columns,
UserAlias1::safe_columns_tuple(),
post::all_columns,
Community::safe_columns_tuple(),
))
.into_boxed();
if let Some(community_id) = community_id {
query = query.filter(post::community_id.eq(community_id));
};
if let Some(mod_user_id) = mod_user_id {
query = query.filter(mod_remove_comment::mod_user_id.eq(mod_user_id));
};
let (limit, offset) = limit_and_offset(page, limit);
let res = query
.limit(limit)
.offset(offset)
.order_by(mod_remove_comment::when_.desc())
.load::<ModRemoveCommentViewTuple>(conn)?;
Ok(Self::to_vec(res))
}
}
impl ViewToVec for ModRemoveCommentView {
type DbTuple = ModRemoveCommentViewTuple;
fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
mrp
.iter()
.map(|a| Self {
mod_remove_comment: a.0.to_owned(),
moderator: a.1.to_owned(),
comment: a.2.to_owned(),
commenter: a.3.to_owned(),
post: a.4.to_owned(),
community: a.5.to_owned(),
})
.collect::<Vec<Self>>()
}
}

View file

@ -0,0 +1,69 @@
use crate::{
limit_and_offset,
schema::{community, mod_remove_community, user_},
source::{
community::{Community, CommunitySafe},
moderator::ModRemoveCommunity,
user::{UserSafe, User_},
},
views::ViewToVec,
ToSafe,
};
use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
pub struct ModRemoveCommunityView {
pub mod_remove_community: ModRemoveCommunity,
pub moderator: UserSafe,
pub community: CommunitySafe,
}
type ModRemoveCommunityTuple = (ModRemoveCommunity, UserSafe, CommunitySafe);
impl ModRemoveCommunityView {
pub fn list(
conn: &PgConnection,
mod_user_id: Option<i32>,
page: Option<i64>,
limit: Option<i64>,
) -> Result<Vec<Self>, Error> {
let mut query = mod_remove_community::table
.inner_join(user_::table)
.inner_join(community::table)
.select((
mod_remove_community::all_columns,
User_::safe_columns_tuple(),
Community::safe_columns_tuple(),
))
.into_boxed();
if let Some(mod_user_id) = mod_user_id {
query = query.filter(mod_remove_community::mod_user_id.eq(mod_user_id));
};
let (limit, offset) = limit_and_offset(page, limit);
let res = query
.limit(limit)
.offset(offset)
.order_by(mod_remove_community::when_.desc())
.load::<ModRemoveCommunityTuple>(conn)?;
Ok(Self::to_vec(res))
}
}
impl ViewToVec for ModRemoveCommunityView {
type DbTuple = ModRemoveCommunityTuple;
fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
mrp
.iter()
.map(|a| Self {
mod_remove_community: a.0.to_owned(),
moderator: a.1.to_owned(),
community: a.2.to_owned(),
})
.collect::<Vec<Self>>()
}
}

View file

@ -0,0 +1,79 @@
use crate::{
limit_and_offset,
schema::{community, mod_remove_post, post, user_},
source::{
community::{Community, CommunitySafe},
moderator::ModRemovePost,
post::Post,
user::{UserSafe, User_},
},
views::ViewToVec,
ToSafe,
};
use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
pub struct ModRemovePostView {
pub mod_remove_post: ModRemovePost,
pub moderator: UserSafe,
pub post: Post,
pub community: CommunitySafe,
}
type ModRemovePostViewTuple = (ModRemovePost, UserSafe, Post, CommunitySafe);
impl ModRemovePostView {
pub fn list(
conn: &PgConnection,
community_id: Option<i32>,
mod_user_id: Option<i32>,
page: Option<i64>,
limit: Option<i64>,
) -> Result<Vec<Self>, Error> {
let mut query = mod_remove_post::table
.inner_join(user_::table)
.inner_join(post::table)
.inner_join(community::table.on(post::community_id.eq(community::id)))
.select((
mod_remove_post::all_columns,
User_::safe_columns_tuple(),
post::all_columns,
Community::safe_columns_tuple(),
))
.into_boxed();
if let Some(community_id) = community_id {
query = query.filter(post::community_id.eq(community_id));
};
if let Some(mod_user_id) = mod_user_id {
query = query.filter(mod_remove_post::mod_user_id.eq(mod_user_id));
};
let (limit, offset) = limit_and_offset(page, limit);
let res = query
.limit(limit)
.offset(offset)
.order_by(mod_remove_post::when_.desc())
.load::<ModRemovePostViewTuple>(conn)?;
Ok(Self::to_vec(res))
}
}
impl ViewToVec for ModRemovePostView {
type DbTuple = ModRemovePostViewTuple;
fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
mrp
.iter()
.map(|a| Self {
mod_remove_post: a.0.to_owned(),
moderator: a.1.to_owned(),
post: a.2.to_owned(),
community: a.3.to_owned(),
})
.collect::<Vec<Self>>()
}
}

View file

@ -0,0 +1,79 @@
use crate::{
limit_and_offset,
schema::{community, mod_sticky_post, post, user_},
source::{
community::{Community, CommunitySafe},
moderator::ModStickyPost,
post::Post,
user::{UserSafe, User_},
},
views::ViewToVec,
ToSafe,
};
use diesel::{result::Error, *};
use serde::Serialize;
#[derive(Debug, Serialize, Clone)]
pub struct ModStickyPostView {
pub mod_sticky_post: ModStickyPost,
pub moderator: UserSafe,
pub post: Post,
pub community: CommunitySafe,
}
type ModStickyPostViewTuple = (ModStickyPost, UserSafe, Post, CommunitySafe);
impl ModStickyPostView {
pub fn list(
conn: &PgConnection,
community_id: Option<i32>,
mod_user_id: Option<i32>,
page: Option<i64>,
limit: Option<i64>,
) -> Result<Vec<Self>, Error> {
let mut query = mod_sticky_post::table
.inner_join(user_::table)
.inner_join(post::table)
.inner_join(community::table.on(post::community_id.eq(community::id)))
.select((
mod_sticky_post::all_columns,
User_::safe_columns_tuple(),
post::all_columns,
Community::safe_columns_tuple(),
))
.into_boxed();
if let Some(community_id) = community_id {
query = query.filter(post::community_id.eq(community_id));
};
if let Some(mod_user_id) = mod_user_id {
query = query.filter(mod_sticky_post::mod_user_id.eq(mod_user_id));
};
let (limit, offset) = limit_and_offset(page, limit);
let res = query
.limit(limit)
.offset(offset)
.order_by(mod_sticky_post::when_.desc())
.load::<ModStickyPostViewTuple>(conn)?;
Ok(Self::to_vec(res))
}
}
impl ViewToVec for ModStickyPostView {
type DbTuple = ModStickyPostViewTuple;
fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
mrp
.iter()
.map(|a| Self {
mod_sticky_post: a.0.to_owned(),
moderator: a.1.to_owned(),
post: a.2.to_owned(),
community: a.3.to_owned(),
})
.collect::<Vec<Self>>()
}
}

View file

@ -1,7 +1,9 @@
use lemmy_db::views::{ use lemmy_db::views::{
community_follower_view::CommunityFollowerView, community::{
community_moderator_view::CommunityModeratorView, community_follower_view::CommunityFollowerView,
community_view::CommunityView, community_moderator_view::CommunityModeratorView,
community_view::CommunityView,
},
user_view::UserViewSafe, user_view::UserViewSafe,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View file

@ -2,8 +2,7 @@ use lemmy_db::{
post_report::PostReportView, post_report::PostReportView,
views::{ views::{
comment_view::CommentView, comment_view::CommentView,
community_moderator_view::CommunityModeratorView, community::{community_moderator_view::CommunityModeratorView, community_view::CommunityView},
community_view::CommunityView,
post_view::PostView, post_view::PostView,
}, },
}; };

View file

@ -1,10 +1,20 @@
use lemmy_db::{ use lemmy_db::{
aggregates::site_aggregates::SiteAggregates, aggregates::site_aggregates::SiteAggregates,
moderator_views::*,
source::{category::*, user::*}, source::{category::*, user::*},
views::{ views::{
comment_view::CommentView, comment_view::CommentView,
community_view::CommunityView, community::community_view::CommunityView,
moderator::{
mod_add_community_view::ModAddCommunityView,
mod_add_view::ModAddView,
mod_ban_from_community_view::ModBanFromCommunityView,
mod_ban_view::ModBanView,
mod_lock_post_view::ModLockPostView,
mod_remove_comment_view::ModRemoveCommentView,
mod_remove_community_view::ModRemoveCommunityView,
mod_remove_post_view::ModRemovePostView,
mod_sticky_post_view::ModStickyPostView,
},
post_view::PostView, post_view::PostView,
site_view::SiteView, site_view::SiteView,
user_view::UserViewSafe, user_view::UserViewSafe,

View file

@ -2,8 +2,10 @@ use lemmy_db::{
private_message_view::PrivateMessageView, private_message_view::PrivateMessageView,
views::{ views::{
comment_view::CommentView, comment_view::CommentView,
community_follower_view::CommunityFollowerView, community::{
community_moderator_view::CommunityModeratorView, community_follower_view::CommunityFollowerView,
community_moderator_view::CommunityModeratorView,
},
post_view::PostView, post_view::PostView,
user_mention_view::UserMentionView, user_mention_view::UserMentionView,
user_view::{UserViewDangerous, UserViewSafe}, user_view::{UserViewDangerous, UserViewSafe},