Adding moderator views.
This commit is contained in:
parent
bd6a4a54a9
commit
313f0467c8
35 changed files with 774 additions and 553 deletions
|
@ -15,9 +15,11 @@ use lemmy_db::{
|
|||
source::{comment::Comment, community::*, moderator::*, post::Post, site::*},
|
||||
views::{
|
||||
comment_view::CommentQueryBuilder,
|
||||
community_follower_view::CommunityFollowerView,
|
||||
community_moderator_view::CommunityModeratorView,
|
||||
community_view::{CommunityQueryBuilder, CommunityView},
|
||||
community::{
|
||||
community_follower_view::CommunityFollowerView,
|
||||
community_moderator_view::CommunityModeratorView,
|
||||
community_view::{CommunityQueryBuilder, CommunityView},
|
||||
},
|
||||
user_view::UserViewSafe,
|
||||
},
|
||||
ApubObject,
|
||||
|
|
|
@ -6,7 +6,7 @@ use lemmy_db::{
|
|||
post::Post,
|
||||
user::User_,
|
||||
},
|
||||
views::community_user_ban_view::CommunityUserBanView,
|
||||
views::community::community_user_ban_view::CommunityUserBanView,
|
||||
Crud,
|
||||
DbPool,
|
||||
};
|
||||
|
|
|
@ -15,8 +15,7 @@ use lemmy_db::{
|
|||
source::{moderator::*, post::*},
|
||||
views::{
|
||||
comment_view::CommentQueryBuilder,
|
||||
community_moderator_view::CommunityModeratorView,
|
||||
community_view::CommunityView,
|
||||
community::{community_moderator_view::CommunityModeratorView, community_view::CommunityView},
|
||||
post_view::{PostQueryBuilder, PostView},
|
||||
site_view::SiteView,
|
||||
},
|
||||
|
|
|
@ -12,12 +12,22 @@ use lemmy_apub::fetcher::search_by_apub_id;
|
|||
use lemmy_db::{
|
||||
aggregates::site_aggregates::SiteAggregates,
|
||||
diesel_option_overwrite,
|
||||
moderator_views::*,
|
||||
naive_now,
|
||||
source::{category::*, moderator::*, site::*},
|
||||
views::{
|
||||
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,
|
||||
site_view::SiteView,
|
||||
user_view::{UserQueryBuilder, UserViewSafe},
|
||||
|
|
|
@ -33,8 +33,10 @@ use lemmy_db::{
|
|||
},
|
||||
views::{
|
||||
comment_view::CommentQueryBuilder,
|
||||
community_follower_view::CommunityFollowerView,
|
||||
community_moderator_view::CommunityModeratorView,
|
||||
community::{
|
||||
community_follower_view::CommunityFollowerView,
|
||||
community_moderator_view::CommunityModeratorView,
|
||||
},
|
||||
post_view::PostQueryBuilder,
|
||||
site_view::SiteView,
|
||||
user_mention_view::{UserMentionQueryBuilder, UserMentionView},
|
||||
|
|
|
@ -4,7 +4,11 @@ use activitystreams::{
|
|||
base::{AnyBase, ExtendsExt},
|
||||
};
|
||||
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_utils::{location_info, LemmyError};
|
||||
use lemmy_websocket::{messages::SendCommunityRoomMessage, LemmyContext, UserOperation};
|
||||
|
|
|
@ -25,7 +25,7 @@ use anyhow::Context;
|
|||
use itertools::Itertools;
|
||||
use lemmy_db::{
|
||||
source::community::Community,
|
||||
views::community_follower_view::CommunityFollowerView,
|
||||
views::community::community_follower_view::CommunityFollowerView,
|
||||
DbPool,
|
||||
};
|
||||
use lemmy_structs::blocking;
|
||||
|
|
|
@ -22,7 +22,7 @@ use lemmy_db::{
|
|||
},
|
||||
views::{
|
||||
comment_view::CommentView,
|
||||
community_view::CommunityView,
|
||||
community::community_view::CommunityView,
|
||||
post_view::PostView,
|
||||
user_view::UserViewSafe,
|
||||
},
|
||||
|
|
|
@ -11,7 +11,7 @@ use activitystreams::{
|
|||
use actix_web::{body::Body, web, HttpResponse};
|
||||
use lemmy_db::{
|
||||
source::{community::Community, post::Post},
|
||||
views::community_follower_view::CommunityFollowerView,
|
||||
views::community::community_follower_view::CommunityFollowerView,
|
||||
};
|
||||
use lemmy_structs::blocking;
|
||||
use lemmy_utils::LemmyError;
|
||||
|
|
|
@ -31,7 +31,7 @@ use lemmy_db::{
|
|||
community::{Community, CommunityFollower, CommunityFollowerForm},
|
||||
user::User_,
|
||||
},
|
||||
views::community_user_ban_view::CommunityUserBanView,
|
||||
views::community::community_user_ban_view::CommunityUserBanView,
|
||||
ApubObject,
|
||||
DbPool,
|
||||
Followable,
|
||||
|
|
|
@ -25,7 +25,7 @@ use anyhow::Context;
|
|||
use lemmy_db::{
|
||||
naive_now,
|
||||
source::community::{Community, CommunityForm},
|
||||
views::community_moderator_view::CommunityModeratorView,
|
||||
views::community::community_moderator_view::CommunityModeratorView,
|
||||
DbPool,
|
||||
};
|
||||
use lemmy_structs::blocking;
|
||||
|
|
|
@ -12,7 +12,6 @@ use serde::{Deserialize, Serialize};
|
|||
use std::{env, env::VarError};
|
||||
|
||||
pub mod comment_report;
|
||||
pub mod moderator_views;
|
||||
pub mod post_report;
|
||||
pub mod private_message_view;
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
use crate::{
|
||||
naive_now,
|
||||
schema::{community, community_follower, community_moderator, community_user_ban},
|
||||
views::{community::community_moderator_view::CommunityModeratorView, user_view::UserViewSafe},
|
||||
ApubObject,
|
||||
Bannable,
|
||||
Crud,
|
||||
|
@ -223,7 +224,6 @@ impl Community {
|
|||
}
|
||||
|
||||
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();
|
||||
mods_and_admins.append(
|
||||
&mut CommunityModeratorView::for_community(conn, community_id)
|
||||
|
|
|
@ -13,8 +13,9 @@ use crate::{
|
|||
Crud,
|
||||
};
|
||||
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"]
|
||||
pub struct ModRemovePost {
|
||||
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"]
|
||||
pub struct ModLockPost {
|
||||
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"]
|
||||
pub struct ModStickyPost {
|
||||
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"]
|
||||
pub struct ModRemoveComment {
|
||||
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"]
|
||||
pub struct ModRemoveCommunity {
|
||||
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"]
|
||||
pub struct ModBanFromCommunity {
|
||||
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"]
|
||||
pub struct ModBan {
|
||||
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"]
|
||||
pub struct ModAddCommunity {
|
||||
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"]
|
||||
pub struct ModAdd {
|
||||
pub id: i32,
|
||||
|
|
4
lemmy_db/src/views/community/mod.rs
Normal file
4
lemmy_db/src/views/community/mod.rs
Normal 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;
|
|
@ -1,8 +1,6 @@
|
|||
pub mod comment_view;
|
||||
pub mod community_follower_view;
|
||||
pub mod community_moderator_view;
|
||||
pub mod community_user_ban_view;
|
||||
pub mod community_view;
|
||||
pub mod community;
|
||||
pub mod moderator;
|
||||
pub mod post_view;
|
||||
pub mod site_view;
|
||||
pub mod user_mention_view;
|
||||
|
|
9
lemmy_db/src/views/moderator/mod.rs
Normal file
9
lemmy_db/src/views/moderator/mod.rs
Normal 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;
|
78
lemmy_db/src/views/moderator/mod_add_community_view.rs
Normal file
78
lemmy_db/src/views/moderator/mod_add_community_view.rs
Normal 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>>()
|
||||
}
|
||||
}
|
68
lemmy_db/src/views/moderator/mod_add_view.rs
Normal file
68
lemmy_db/src/views/moderator/mod_add_view.rs
Normal 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>>()
|
||||
}
|
||||
}
|
78
lemmy_db/src/views/moderator/mod_ban_from_community_view.rs
Normal file
78
lemmy_db/src/views/moderator/mod_ban_from_community_view.rs
Normal 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>>()
|
||||
}
|
||||
}
|
68
lemmy_db/src/views/moderator/mod_ban_view.rs
Normal file
68
lemmy_db/src/views/moderator/mod_ban_view.rs
Normal 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>>()
|
||||
}
|
||||
}
|
79
lemmy_db/src/views/moderator/mod_lock_post_view.rs
Normal file
79
lemmy_db/src/views/moderator/mod_lock_post_view.rs
Normal 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>>()
|
||||
}
|
||||
}
|
95
lemmy_db/src/views/moderator/mod_remove_comment_view.rs
Normal file
95
lemmy_db/src/views/moderator/mod_remove_comment_view.rs
Normal 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>>()
|
||||
}
|
||||
}
|
69
lemmy_db/src/views/moderator/mod_remove_community_view.rs
Normal file
69
lemmy_db/src/views/moderator/mod_remove_community_view.rs
Normal 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>>()
|
||||
}
|
||||
}
|
79
lemmy_db/src/views/moderator/mod_remove_post_view.rs
Normal file
79
lemmy_db/src/views/moderator/mod_remove_post_view.rs
Normal 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>>()
|
||||
}
|
||||
}
|
79
lemmy_db/src/views/moderator/mod_sticky_post_view.rs
Normal file
79
lemmy_db/src/views/moderator/mod_sticky_post_view.rs
Normal 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>>()
|
||||
}
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
use lemmy_db::views::{
|
||||
community_follower_view::CommunityFollowerView,
|
||||
community_moderator_view::CommunityModeratorView,
|
||||
community_view::CommunityView,
|
||||
community::{
|
||||
community_follower_view::CommunityFollowerView,
|
||||
community_moderator_view::CommunityModeratorView,
|
||||
community_view::CommunityView,
|
||||
},
|
||||
user_view::UserViewSafe,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
|
@ -2,8 +2,7 @@ use lemmy_db::{
|
|||
post_report::PostReportView,
|
||||
views::{
|
||||
comment_view::CommentView,
|
||||
community_moderator_view::CommunityModeratorView,
|
||||
community_view::CommunityView,
|
||||
community::{community_moderator_view::CommunityModeratorView, community_view::CommunityView},
|
||||
post_view::PostView,
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,10 +1,20 @@
|
|||
use lemmy_db::{
|
||||
aggregates::site_aggregates::SiteAggregates,
|
||||
moderator_views::*,
|
||||
source::{category::*, user::*},
|
||||
views::{
|
||||
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,
|
||||
site_view::SiteView,
|
||||
user_view::UserViewSafe,
|
||||
|
|
|
@ -2,8 +2,10 @@ use lemmy_db::{
|
|||
private_message_view::PrivateMessageView,
|
||||
views::{
|
||||
comment_view::CommentView,
|
||||
community_follower_view::CommunityFollowerView,
|
||||
community_moderator_view::CommunityModeratorView,
|
||||
community::{
|
||||
community_follower_view::CommunityFollowerView,
|
||||
community_moderator_view::CommunityModeratorView,
|
||||
},
|
||||
post_view::PostView,
|
||||
user_mention_view::UserMentionView,
|
||||
user_view::{UserViewDangerous, UserViewSafe},
|
||||
|
|
Loading…
Reference in a new issue