mirror of https://github.com/LemmyNet/lemmy
Commiting before I lose everything. I'll do this properly in a merge
parent
8590a612f6
commit
e94885eb97
@ -1 +1,2 @@
|
||||
drop table user_
|
||||
drop table user_ban;
|
||||
drop table user_;
|
||||
|
@ -1,3 +1,4 @@
|
||||
drop view community_view;
|
||||
drop view community_moderator_view;
|
||||
drop view community_follower_view;
|
||||
drop view community_user_ban_view;
|
||||
|
@ -0,0 +1,8 @@
|
||||
drop view mod_remove_post_view;
|
||||
drop view mod_lock_post_view;
|
||||
drop view mod_remove_comment_view;
|
||||
drop view mod_remove_community_view;
|
||||
drop view mod_ban_from_community_view;
|
||||
drop view mod_ban_view;
|
||||
drop view mod_add_community_view;
|
||||
drop view mod_add_view;
|
@ -0,0 +1,61 @@
|
||||
create view mod_remove_post_view as
|
||||
select mrp.*,
|
||||
(select name from user_ u where mrp.mod_user_id = u.id) as mod_user_name,
|
||||
(select name from post p where mrp.post_id = p.id) as post_name,
|
||||
(select c.id from post p, community c where mrp.post_id = p.id and p.community_id = c.id) as community_id,
|
||||
(select c.name from post p, community c where mrp.post_id = p.id and p.community_id = c.id) as community_name
|
||||
from mod_remove_post mrp;
|
||||
|
||||
create view mod_lock_post_view as
|
||||
select mlp.*,
|
||||
(select name from user_ u where mlp.mod_user_id = u.id) as mod_user_name,
|
||||
(select name from post p where mlp.post_id = p.id) as post_name,
|
||||
(select c.id from post p, community c where mlp.post_id = p.id and p.community_id = c.id) as community_id,
|
||||
(select c.name from post p, community c where mlp.post_id = p.id and p.community_id = c.id) as community_name
|
||||
from mod_lock_post mlp;
|
||||
|
||||
create view mod_remove_comment_view as
|
||||
select mrc.*,
|
||||
(select name from user_ u where mrc.mod_user_id = u.id) as mod_user_name,
|
||||
(select c.id from comment c where mrc.comment_id = c.id) as comment_user_id,
|
||||
(select name from user_ u, comment c where mrc.comment_id = c.id and u.id = c.creator_id) as comment_user_name,
|
||||
(select content from comment c where mrc.comment_id = c.id) as comment_content,
|
||||
(select p.id from post p, comment c where mrc.comment_id = c.id and c.post_id = p.id) as post_id,
|
||||
(select p.name from post p, comment c where mrc.comment_id = c.id and c.post_id = p.id) as post_name,
|
||||
(select co.id from comment c, post p, community co where mrc.comment_id = c.id and c.post_id = p.id and p.community_id = co.id) as community_id,
|
||||
(select co.name from comment c, post p, community co where mrc.comment_id = c.id and c.post_id = p.id and p.community_id = co.id) as community_name
|
||||
from mod_remove_comment mrc;
|
||||
|
||||
create view mod_remove_community_view as
|
||||
select mrc.*,
|
||||
(select name from user_ u where mrc.mod_user_id = u.id) as mod_user_name,
|
||||
(select c.name from community c where mrc.community_id = c.id) as community_name
|
||||
from mod_remove_community mrc;
|
||||
|
||||
create view mod_ban_from_community_view as
|
||||
select mb.*,
|
||||
(select name from user_ u where mb.mod_user_id = u.id) as mod_user_name,
|
||||
(select name from user_ u where mb.other_user_id = u.id) as other_user_name,
|
||||
(select name from community c where mb.community_id = c.id) as community_name
|
||||
from mod_ban_from_community mb;
|
||||
|
||||
create view mod_ban_view as
|
||||
select mb.*,
|
||||
(select name from user_ u where mb.mod_user_id = u.id) as mod_user_name,
|
||||
(select name from user_ u where mb.other_user_id = u.id) as other_user_name
|
||||
from mod_ban_from_community mb;
|
||||
|
||||
|
||||
create view mod_add_community_view as
|
||||
select ma.*,
|
||||
(select name from user_ u where ma.mod_user_id = u.id) as mod_user_name,
|
||||
(select name from user_ u where ma.other_user_id = u.id) as other_user_name,
|
||||
(select name from community c where ma.community_id = c.id) as community_name
|
||||
from mod_add_community ma;
|
||||
|
||||
|
||||
create view mod_add_view as
|
||||
select ma.*,
|
||||
(select name from user_ u where ma.mod_user_id = u.id) as mod_user_name,
|
||||
(select name from user_ u where ma.other_user_id = u.id) as other_user_name
|
||||
from mod_add ma;
|
@ -0,0 +1,655 @@
|
||||
extern crate diesel;
|
||||
use schema::{mod_remove_post, mod_lock_post, mod_remove_comment, mod_remove_community, mod_ban_from_community, mod_ban, mod_add_community, mod_add};
|
||||
use diesel::*;
|
||||
use diesel::result::Error;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use {Crud};
|
||||
|
||||
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
|
||||
#[table_name="mod_remove_post"]
|
||||
pub struct ModRemovePost {
|
||||
pub id: i32,
|
||||
pub mod_user_id: i32,
|
||||
pub post_id: i32,
|
||||
pub reason: Option<String>,
|
||||
pub removed: Option<bool>,
|
||||
pub when_: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
|
||||
#[table_name="mod_remove_post"]
|
||||
pub struct ModRemovePostForm {
|
||||
pub mod_user_id: i32,
|
||||
pub post_id: i32,
|
||||
pub reason: Option<String>,
|
||||
pub removed: Option<bool>,
|
||||
}
|
||||
|
||||
impl Crud<ModRemovePostForm> for ModRemovePost {
|
||||
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
||||
use schema::mod_remove_post::dsl::*;
|
||||
mod_remove_post.find(from_id)
|
||||
.first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
|
||||
use schema::mod_remove_post::dsl::*;
|
||||
diesel::delete(mod_remove_post.find(from_id))
|
||||
.execute(conn)
|
||||
}
|
||||
|
||||
fn create(conn: &PgConnection, form: &ModRemovePostForm) -> Result<Self, Error> {
|
||||
use schema::mod_remove_post::dsl::*;
|
||||
insert_into(mod_remove_post)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
|
||||
fn update(conn: &PgConnection, from_id: i32, form: &ModRemovePostForm) -> Result<Self, Error> {
|
||||
use schema::mod_remove_post::dsl::*;
|
||||
diesel::update(mod_remove_post.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
|
||||
#[table_name="mod_lock_post"]
|
||||
pub struct ModLockPost {
|
||||
pub id: i32,
|
||||
pub mod_user_id: i32,
|
||||
pub post_id: i32,
|
||||
pub locked: Option<bool>,
|
||||
pub when_: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
|
||||
#[table_name="mod_lock_post"]
|
||||
pub struct ModLockPostForm {
|
||||
pub mod_user_id: i32,
|
||||
pub post_id: i32,
|
||||
pub locked: Option<bool>,
|
||||
}
|
||||
|
||||
impl Crud<ModLockPostForm> for ModLockPost {
|
||||
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
||||
use schema::mod_lock_post::dsl::*;
|
||||
mod_lock_post.find(from_id)
|
||||
.first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
|
||||
use schema::mod_lock_post::dsl::*;
|
||||
diesel::delete(mod_lock_post.find(from_id))
|
||||
.execute(conn)
|
||||
}
|
||||
|
||||
fn create(conn: &PgConnection, form: &ModLockPostForm) -> Result<Self, Error> {
|
||||
use schema::mod_lock_post::dsl::*;
|
||||
insert_into(mod_lock_post)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
|
||||
fn update(conn: &PgConnection, from_id: i32, form: &ModLockPostForm) -> Result<Self, Error> {
|
||||
use schema::mod_lock_post::dsl::*;
|
||||
diesel::update(mod_lock_post.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
|
||||
#[table_name="mod_remove_comment"]
|
||||
pub struct ModRemoveComment {
|
||||
pub id: i32,
|
||||
pub mod_user_id: i32,
|
||||
pub comment_id: i32,
|
||||
pub reason: Option<String>,
|
||||
pub removed: Option<bool>,
|
||||
pub when_: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
|
||||
#[table_name="mod_remove_comment"]
|
||||
pub struct ModRemoveCommentForm {
|
||||
pub mod_user_id: i32,
|
||||
pub comment_id: i32,
|
||||
pub reason: Option<String>,
|
||||
pub removed: Option<bool>,
|
||||
}
|
||||
|
||||
impl Crud<ModRemoveCommentForm> for ModRemoveComment {
|
||||
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
||||
use schema::mod_remove_comment::dsl::*;
|
||||
mod_remove_comment.find(from_id)
|
||||
.first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
|
||||
use schema::mod_remove_comment::dsl::*;
|
||||
diesel::delete(mod_remove_comment.find(from_id))
|
||||
.execute(conn)
|
||||
}
|
||||
|
||||
fn create(conn: &PgConnection, form: &ModRemoveCommentForm) -> Result<Self, Error> {
|
||||
use schema::mod_remove_comment::dsl::*;
|
||||
insert_into(mod_remove_comment)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
|
||||
fn update(conn: &PgConnection, from_id: i32, form: &ModRemoveCommentForm) -> Result<Self, Error> {
|
||||
use schema::mod_remove_comment::dsl::*;
|
||||
diesel::update(mod_remove_comment.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
|
||||
#[table_name="mod_remove_community"]
|
||||
pub struct ModRemoveCommunity {
|
||||
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,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
|
||||
#[table_name="mod_remove_community"]
|
||||
pub struct ModRemoveCommunityForm {
|
||||
pub mod_user_id: i32,
|
||||
pub community_id: i32,
|
||||
pub reason: Option<String>,
|
||||
pub removed: Option<bool>,
|
||||
pub expires: Option<chrono::NaiveDateTime>,
|
||||
}
|
||||
|
||||
impl Crud<ModRemoveCommunityForm> for ModRemoveCommunity {
|
||||
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
||||
use schema::mod_remove_community::dsl::*;
|
||||
mod_remove_community.find(from_id)
|
||||
.first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
|
||||
use schema::mod_remove_community::dsl::*;
|
||||
diesel::delete(mod_remove_community.find(from_id))
|
||||
.execute(conn)
|
||||
}
|
||||
|
||||
fn create(conn: &PgConnection, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
|
||||
use schema::mod_remove_community::dsl::*;
|
||||
insert_into(mod_remove_community)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
|
||||
fn update(conn: &PgConnection, from_id: i32, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
|
||||
use schema::mod_remove_community::dsl::*;
|
||||
diesel::update(mod_remove_community.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
|
||||
#[table_name="mod_ban_from_community"]
|
||||
pub struct ModBanFromCommunity {
|
||||
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,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
|
||||
#[table_name="mod_ban_from_community"]
|
||||
pub struct ModBanFromCommunityForm {
|
||||
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>,
|
||||
}
|
||||
|
||||
impl Crud<ModBanFromCommunityForm> for ModBanFromCommunity {
|
||||
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
||||
use schema::mod_ban_from_community::dsl::*;
|
||||
mod_ban_from_community.find(from_id)
|
||||
.first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
|
||||
use schema::mod_ban_from_community::dsl::*;
|
||||
diesel::delete(mod_ban_from_community.find(from_id))
|
||||
.execute(conn)
|
||||
}
|
||||
|
||||
fn create(conn: &PgConnection, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
|
||||
use schema::mod_ban_from_community::dsl::*;
|
||||
insert_into(mod_ban_from_community)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
|
||||
fn update(conn: &PgConnection, from_id: i32, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
|
||||
use schema::mod_ban_from_community::dsl::*;
|
||||
diesel::update(mod_ban_from_community.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
|
||||
#[table_name="mod_ban"]
|
||||
pub struct ModBan {
|
||||
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,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
|
||||
#[table_name="mod_ban"]
|
||||
pub struct ModBanForm {
|
||||
pub mod_user_id: i32,
|
||||
pub other_user_id: i32,
|
||||
pub reason: Option<String>,
|
||||
pub banned: Option<bool>,
|
||||
pub expires: Option<chrono::NaiveDateTime>,
|
||||
}
|
||||
|
||||
impl Crud<ModBanForm> for ModBan {
|
||||
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
||||
use schema::mod_ban::dsl::*;
|
||||
mod_ban.find(from_id)
|
||||
.first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
|
||||
use schema::mod_ban::dsl::*;
|
||||
diesel::delete(mod_ban.find(from_id))
|
||||
.execute(conn)
|
||||
}
|
||||
|
||||
fn create(conn: &PgConnection, form: &ModBanForm) -> Result<Self, Error> {
|
||||
use schema::mod_ban::dsl::*;
|
||||
insert_into(mod_ban)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
|
||||
fn update(conn: &PgConnection, from_id: i32, form: &ModBanForm) -> Result<Self, Error> {
|
||||
use schema::mod_ban::dsl::*;
|
||||
diesel::update(mod_ban.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
|
||||
#[table_name="mod_add_community"]
|
||||
pub struct ModAddCommunity {
|
||||
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,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
|
||||
#[table_name="mod_add_community"]
|
||||
pub struct ModAddCommunityForm {
|
||||
pub mod_user_id: i32,
|
||||
pub other_user_id: i32,
|
||||
pub community_id: i32,
|
||||
pub removed: Option<bool>,
|
||||
}
|
||||
|
||||
impl Crud<ModAddCommunityForm> for ModAddCommunity {
|
||||
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
||||
use schema::mod_add_community::dsl::*;
|
||||
mod_add_community.find(from_id)
|
||||
.first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
|
||||
use schema::mod_add_community::dsl::*;
|
||||
diesel::delete(mod_add_community.find(from_id))
|
||||
.execute(conn)
|
||||
}
|
||||
|
||||
fn create(conn: &PgConnection, form: &ModAddCommunityForm) -> Result<Self, Error> {
|
||||
use schema::mod_add_community::dsl::*;
|
||||
insert_into(mod_add_community)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
|
||||
fn update(conn: &PgConnection, from_id: i32, form: &ModAddCommunityForm) -> Result<Self, Error> {
|
||||
use schema::mod_add_community::dsl::*;
|
||||
diesel::update(mod_add_community.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
|
||||
#[table_name="mod_add"]
|
||||
pub struct ModAdd {
|
||||
pub id: i32,
|
||||
pub mod_user_id: i32,
|
||||
pub other_user_id: i32,
|
||||
pub removed: Option<bool>,
|
||||
pub when_: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
|
||||
#[table_name="mod_add"]
|
||||
pub struct ModAddForm {
|
||||
pub mod_user_id: i32,
|
||||
pub other_user_id: i32,
|
||||
pub removed: Option<bool>,
|
||||
}
|
||||
|
||||
impl Crud<ModAddForm> for ModAdd {
|
||||
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
||||
use schema::mod_add::dsl::*;
|
||||
mod_add.find(from_id)
|
||||
.first::<Self>(conn)
|
||||
}
|
||||
|
||||
fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
|
||||
use schema::mod_add::dsl::*;
|
||||
diesel::delete(mod_add.find(from_id))
|
||||
.execute(conn)
|
||||
}
|
||||
|
||||
fn create(conn: &PgConnection, form: &ModAddForm) -> Result<Self, Error> {
|
||||
use schema::mod_add::dsl::*;
|
||||
insert_into(mod_add)
|
||||
.values(form)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
|
||||
fn update(conn: &PgConnection, from_id: i32, form: &ModAddForm) -> Result<Self, Error> {
|
||||
use schema::mod_add::dsl::*;
|
||||
diesel::update(mod_add.find(from_id))
|
||||
.set(form)
|
||||
.get_result::<Self>(conn)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use establish_connection;
|
||||
use super::*;
|
||||
use actions::user::*;
|
||||
use actions::post::*;
|
||||
use actions::community::*;
|
||||
use actions::comment::*;
|
||||
// use Crud;
|
||||
#[test]
|
||||
fn test_crud() {
|
||||
let conn = establish_connection();
|
||||
|
||||
let new_mod = UserForm {
|
||||
name: "the mod".into(),
|
||||
fedi_name: "rrf".into(),
|
||||
preferred_username: None,
|
||||
password_encrypted: "nope".into(),
|
||||
email: None,
|
||||
admin: None,
|
||||
banned: None,
|
||||
updated: None
|
||||
};
|
||||
|
||||
let inserted_mod = User_::create(&conn, &new_mod).unwrap();
|
||||
|
||||
let new_user = UserForm {
|
||||
name: "jim2".into(),
|
||||
fedi_name: "rrf".into(),
|
||||
preferred_username: None,
|
||||
password_encrypted: "nope".into(),
|
||||
email: None,
|
||||
admin: None,
|
||||
banned: None,
|
||||
updated: None
|
||||
};
|
||||
|
||||
let inserted_user = User_::create(&conn, &new_user).unwrap();
|
||||
|
||||
let new_community = CommunityForm {
|
||||
name: "mod_community".to_string(),
|
||||
title: "nada".to_owned(),
|
||||
description: None,
|
||||
category_id: 1,
|
||||
creator_id: inserted_user.id,
|
||||
removed: None,
|
||||
updated: None
|
||||
};
|
||||
|
||||
let inserted_community = Community::create(&conn, &new_community).unwrap();
|
||||
|
||||
let new_post = PostForm {
|
||||
name: "A test post thweep".into(),
|
||||
url: None,
|
||||
body: None,
|
||||
creator_id: inserted_user.id,
|
||||
community_id: inserted_community.id,
|
||||
removed: None,
|
||||
locked: None,
|
||||
updated: None
|
||||
};
|
||||
|
||||
let inserted_post = Post::create(&conn, &new_post).unwrap();
|
||||
|
||||
let comment_form = CommentForm {
|
||||
content: "A test comment".into(),
|
||||
creator_id: inserted_user.id,
|
||||
post_id: inserted_post.id,
|
||||
removed: None,
|
||||
parent_id: None,
|
||||
updated: None
|
||||
};
|
||||
|
||||
let inserted_comment = Comment::create(&conn, &comment_form).unwrap();
|
||||
|
||||
// Now the actual tests
|
||||
|
||||
// remove post
|
||||
let mod_remove_post_form = ModRemovePostForm {
|
||||
mod_user_id: inserted_mod.id,
|
||||
post_id: inserted_post.id,
|
||||
reason: None,
|
||||
removed: None,
|
||||
};
|
||||
let inserted_mod_remove_post = ModRemovePost::create(&conn, &mod_remove_post_form).unwrap();
|
||||
let read_moderator_remove_post = ModRemovePost::read(&conn, inserted_mod_remove_post.id).unwrap();
|
||||
let expected_moderator_remove_post = ModRemovePost {
|
||||
id: inserted_mod_remove_post.id,
|
||||
post_id: inserted_post.id,
|
||||
mod_user_id: inserted_mod.id,
|
||||
reason: None,
|
||||
removed: Some(true),
|
||||
when_: inserted_mod_remove_post.when_,
|
||||
};
|
||||
|
||||
// lock post
|
||||
|
||||
let mod_lock_post_form = ModLockPostForm {
|
||||
mod_user_id: inserted_mod.id,
|
||||
post_id: inserted_post.id,
|
||||
locked: None,
|
||||
};
|
||||
let inserted_mod_lock_post = ModLockPost::create(&conn, &mod_lock_post_form).unwrap();
|
||||
let read_moderator_lock_post = ModLockPost::read(&conn, inserted_mod_lock_post.id).unwrap();
|
||||
let expected_moderator_lock_post = ModLockPost {
|
||||
id: inserted_mod_lock_post.id,
|
||||
post_id: inserted_post.id,
|
||||
mod_user_id: inserted_mod.id,
|
||||
locked: Some(true),
|
||||
when_: inserted_mod_lock_post.when_,
|
||||
};
|
||||
|
||||
// comment
|
||||
|
||||
let mod_remove_comment_form = ModRemoveCommentForm {
|
||||
mod_user_id: inserted_mod.id,
|
||||
comment_id: inserted_comment.id,
|
||||
reason: None,
|
||||
removed: None,
|
||||
};
|
||||
let inserted_mod_remove_comment = ModRemoveComment::create(&conn, &mod_remove_comment_form).unwrap();
|
||||
let read_moderator_remove_comment = ModRemoveComment::read(&conn, inserted_mod_remove_comment.id).unwrap();
|
||||
let expected_moderator_remove_comment = ModRemoveComment {
|
||||
id: inserted_mod_remove_comment.id,
|
||||
comment_id: inserted_comment.id,
|
||||
mod_user_id: inserted_mod.id,
|
||||
reason: None,
|
||||
removed: Some(true),
|
||||
when_: inserted_mod_remove_comment.when_,
|
||||
};
|
||||
|
||||
// community
|
||||
|
||||
let mod_remove_community_form = ModRemoveCommunityForm {
|
||||
mod_user_id: inserted_mod.id,
|
||||
community_id: inserted_community.id,
|
||||
reason: None,
|
||||
removed: None,
|
||||
expires: None,
|
||||
};
|
||||
let inserted_mod_remove_community = ModRemoveCommunity::create(&conn, &mod_remove_community_form).unwrap();
|
||||
let read_moderator_remove_community = ModRemoveCommunity::read(&conn, inserted_mod_remove_community.id).unwrap();
|
||||
let expected_moderator_remove_community = ModRemoveCommunity {
|
||||
id: inserted_mod_remove_community.id,
|
||||
community_id: inserted_community.id,
|
||||
mod_user_id: inserted_mod.id,
|
||||
reason: None,
|
||||
removed: Some(true),
|
||||
expires: None,
|
||||
when_: inserted_mod_remove_community.when_,
|
||||
};
|
||||
|
||||
// ban from community
|
||||
|
||||
let mod_ban_from_community_form = ModBanFromCommunityForm {
|
||||
mod_user_id: inserted_mod.id,
|
||||
other_user_id: inserted_user.id,
|
||||
community_id: inserted_community.id,
|
||||
reason: None,
|
||||
banned: None,
|
||||
expires: None,
|
||||
};
|
||||
let inserted_mod_ban_from_community = ModBanFromCommunity::create(&conn, &mod_ban_from_community_form).unwrap();
|
||||
let read_moderator_ban_from_community = ModBanFromCommunity::read(&conn, inserted_mod_ban_from_community.id).unwrap();
|
||||
let expected_moderator_ban_from_community = ModBanFromCommunity {
|
||||
id: inserted_mod_ban_from_community.id,
|
||||
community_id: inserted_community.id,
|
||||
mod_user_id: inserted_mod.id,
|
||||
other_user_id: inserted_user.id,
|
||||
reason: None,
|
||||
banned: Some(true),
|
||||
expires: None,
|
||||
when_: inserted_mod_ban_from_community.when_,
|
||||
};
|
||||
|
||||
// ban
|
||||
|
||||
let mod_ban_form = ModBanForm {
|
||||
mod_user_id: inserted_mod.id,
|
||||
other_user_id: inserted_user.id,
|
||||
reason: None,
|
||||
banned: None,
|
||||
expires: None,
|
||||
};
|
||||
let inserted_mod_ban = ModBan::create(&conn, &mod_ban_form).unwrap();
|
||||
let read_moderator_ban = ModBan::read(&conn, inserted_mod_ban.id).unwrap();
|
||||
let expected_moderator_ban = ModBan {
|
||||
id: inserted_mod_ban.id,
|
||||
mod_user_id: inserted_mod.id,
|
||||
other_user_id: inserted_user.id,
|
||||
reason: None,
|
||||
banned: Some(true),
|
||||
expires: None,
|
||||
when_: inserted_mod_ban.when_,
|
||||
};
|
||||
|
||||
// mod add community
|
||||
|
||||
let mod_add_community_form = ModAddCommunityForm {
|
||||
mod_user_id: inserted_mod.id,
|
||||
other_user_id: inserted_user.id,
|
||||
community_id: inserted_community.id,
|
||||
removed: None,
|
||||
};
|
||||
let inserted_mod_add_community = ModAddCommunity::create(&conn, &mod_add_community_form).unwrap();
|
||||
let read_moderator_add_community = ModAddCommunity::read(&conn, inserted_mod_add_community.id).unwrap();
|
||||
let expected_moderator_add_community = ModAddCommunity {
|
||||
id: inserted_mod_add_community.id,
|
||||
community_id: inserted_community.id,
|
||||
mod_user_id: inserted_mod.id,
|
||||
other_user_id: inserted_user.id,
|
||||
removed: Some(false),
|
||||
when_: inserted_mod_add_community.when_,
|
||||
};
|
||||
|
||||
// mod add
|
||||
|
||||
let mod_add_form = ModAddForm {
|
||||
mod_user_id: inserted_mod.id,
|
||||
other_user_id: inserted_user.id,
|
||||
removed: None,
|
||||
};
|
||||
let inserted_mod_add = ModAdd::create(&conn, &mod_add_form).unwrap();
|
||||
let read_moderator_add = ModAdd::read(&conn, inserted_mod_add.id).unwrap();
|
||||
let expected_moderator_add = ModAdd {
|
||||
id: inserted_mod_add.id,
|
||||
mod_user_id: inserted_mod.id,
|
||||
other_user_id: inserted_user.id,
|
||||
removed: Some(false),
|
||||
when_: inserted_mod_add.when_,
|
||||
};
|
||||
|
||||
ModRemovePost::delete(&conn, inserted_mod_remove_post.id).unwrap();
|
||||
ModLockPost::delete(&conn, inserted_mod_lock_post.id).unwrap();
|
||||
ModRemoveComment::delete(&conn, inserted_mod_remove_comment.id).unwrap();
|
||||
ModRemoveCommunity::delete(&conn, inserted_mod_remove_community.id).unwrap();
|
||||
ModBanFromCommunity::delete(&conn, inserted_mod_ban_from_community.id).unwrap();
|
||||
ModBan::delete(&conn, inserted_mod_ban.id).unwrap();
|
||||
ModAddCommunity::delete(&conn, inserted_mod_add_community.id).unwrap();
|
||||
ModAdd::delete(&conn, inserted_mod_add.id).unwrap();
|
||||
|
||||
Comment::delete(&conn, inserted_comment.id).unwrap();
|
||||
Post::delete(&conn, inserted_post.id).unwrap();
|
||||
Community::delete(&conn, inserted_community.id).unwrap();
|
||||
User_::delete(&conn, inserted_user.id).unwrap();
|
||||
User_::delete(&conn, inserted_mod.id).unwrap();
|
||||
|
||||
assert_eq!(expected_moderator_remove_post, read_moderator_remove_post);
|
||||
assert_eq!(expected_moderator_lock_post, read_moderator_lock_post);
|
||||
assert_eq!(expected_moderator_remove_comment, read_moderator_remove_comment);
|
||||
assert_eq!(expected_moderator_remove_community, read_moderator_remove_community);
|
||||
assert_eq!(expected_moderator_ban_from_community, read_moderator_ban_from_community);
|
||||
assert_eq!(expected_moderator_ban, read_moderator_ban);
|
||||
assert_eq!(expected_moderator_add_community, read_moderator_add_community);
|
||||
assert_eq!(expected_moderator_add, read_moderator_add);
|
||||
}
|
||||
}
|
@ -0,0 +1,427 @@
|
||||
extern crate diesel;
|
||||
use diesel::*;
|
||||
use diesel::result::Error;
|
||||
use serde::{Deserialize, 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, Deserialize,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>,
|
||||
limit: Option<i64>,
|
||||
page: Option<i64>) -> Result<Vec<Self>, Error> {
|
||||
use actions::moderator_views::mod_remove_post_view::dsl::*;
|
||||
let mut query = mod_remove_post_view.into_boxed();
|
||||
|
||||
let page = page.unwrap_or(1);
|
||||
let limit = limit.unwrap_or(10);
|
||||
let offset = limit * (page - 1);
|
||||
|
||||
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, Deserialize,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>,
|
||||
limit: Option<i64>,
|
||||
page: Option<i64>) -> Result<Vec<Self>, Error> {
|
||||
use actions::moderator_views::mod_lock_post_view::dsl::*;
|
||||
let mut query = mod_lock_post_view.into_boxed();
|
||||
|
||||
let page = page.unwrap_or(1);
|
||||
let limit = limit.unwrap_or(10);
|
||||
let offset = limit * (page - 1);
|
||||
|
||||
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, Deserialize,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>,
|
||||
limit: Option<i64>,
|
||||
page: Option<i64>) -> Result<Vec<Self>, Error> {
|
||||
use actions::moderator_views::mod_remove_comment_view::dsl::*;
|
||||
let mut query = mod_remove_comment_view.into_boxed();
|
||||
|
||||
let page = page.unwrap_or(1);
|
||||
let limit = limit.unwrap_or(10);
|
||||
let offset = limit * (page - 1);
|
||||
|
||||
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, Deserialize,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>,
|
||||
limit: Option<i64>,
|
||||
page: Option<i64>) -> Result<Vec<Self>, Error> {
|
||||
use actions::moderator_views::mod_remove_community_view::dsl::*;
|
||||
let mut query = mod_remove_community_view.into_boxed();
|
||||
|
||||
let page = page.unwrap_or(1);
|
||||
let limit = limit.unwrap_or(10);
|
||||
let offset = limit * (page - 1);
|
||||
|
||||
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, Deserialize,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>,
|
||||
limit: Option<i64>,
|
||||
page: Option<i64>) -> Result<Vec<Self>, Error> {
|
||||
use actions::moderator_views::mod_ban_from_community_view::dsl::*;
|
||||
let mut query = mod_ban_from_community_view.into_boxed();
|
||||
|
||||
let page = page.unwrap_or(1);
|
||||
let limit = limit.unwrap_or(10);
|
||||
let offset = limit * (page - 1);
|
||||
|
||||
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, Deserialize,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>,
|
||||
limit: Option<i64>,
|
||||
page: Option<i64>) -> Result<Vec<Self>, Error> {
|
||||
use actions::moderator_views::mod_ban_view::dsl::*;
|
||||
let mut query = mod_ban_view.into_boxed();
|
||||
|
||||
let page = page.unwrap_or(1);
|
||||
let limit = limit.unwrap_or(10);
|
||||
let offset = limit * (page - 1);
|
||||
|
||||
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, Deserialize,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>,
|
||||
limit: Option<i64>,
|
||||
page: Option<i64>) -> Result<Vec<Self>, Error> {
|
||||
use actions::moderator_views::mod_add_community_view::dsl::*;
|
||||
let mut query = mod_add_community_view.into_boxed();
|
||||
|
||||
let page = page.unwrap_or(1);
|
||||
let limit = limit.unwrap_or(10);
|
||||
let offset = limit * (page - 1);
|
||||
|
||||
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, Deserialize,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>,
|
||||
limit: Option<i64>,
|
||||
page: Option<i64>) -> Result<Vec<Self>, Error> {
|
||||
use actions::moderator_views::mod_add_view::dsl::*;
|
||||
let mut query = mod_add_view.into_boxed();
|
||||
|
||||
let page = page.unwrap_or(1);
|
||||
let limit = limit.unwrap_or(10);
|
||||
let offset = limit * (page - 1);
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
@ -0,0 +1,184 @@
|
||||
import { Component } from 'inferno';
|
||||
import { Link } from 'inferno-router';
|
||||
import { Subscription } from "rxjs";
|
||||
import { retryWhen, delay, take } from 'rxjs/operators';
|
||||
import { UserOperation, GetModlogForm, GetModlogResponse, ModRemovePost, ModLockPost, ModRemoveComment, ModRemoveCommunity, ModBanFromCommunity, ModBan, ModAddCommunity, ModAdd } from '../interfaces';
|
||||
import { WebSocketService } from '../services';
|
||||
import { msgOp, addTypeInfo } from '../utils';
|
||||
import { MomentTime } from './moment-time';
|
||||
import * as moment from 'moment';
|
||||
|
||||
interface ModlogState {
|
||||
removed_posts: Array<ModRemovePost>,
|
||||
locked_posts: Array<ModLockPost>,
|
||||
removed_comments: Array<ModRemoveComment>,
|
||||
removed_communities: Array<ModRemoveCommunity>,
|
||||
banned_from_community: Array<ModBanFromCommunity>,
|
||||
banned: Array<ModBan>,
|
||||
added_to_community: Array<ModAddCommunity>,
|
||||
added: Array<ModAdd>,
|
||||
loading: boolean;
|
||||
}
|
||||
|
||||
export class Modlog extends Component<any, ModlogState> {
|
||||
private subscription: Subscription;
|
||||
private emptyState: ModlogState = {
|
||||
removed_posts: [],
|
||||
locked_posts: [],
|
||||
removed_comments: [],
|
||||
removed_communities: [],
|
||||
banned_from_community: [],
|
||||
banned: [],
|
||||
added_to_community: [],
|
||||
added: [],
|
||||
loading: true
|
||||
}
|
||||
|
||||
constructor(props: any, context: any) {
|
||||
super(props, context);
|
||||
this.state = this.emptyState;
|
||||
this.subscription = WebSocketService.Instance.subject
|
||||
.pipe(retryWhen(errors => errors.pipe(delay(3000), take(10))))
|
||||
.subscribe(
|
||||
(msg) => this.parseMessage(msg),
|
||||
(err) => console.error(err),
|
||||
() => console.log('complete')
|
||||
);
|
||||
|
||||
let modlogForm: GetModlogForm = {
|
||||
|
||||
};
|
||||
WebSocketService.Instance.getModlog(modlogForm);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.subscription.unsubscribe();
|
||||
}
|
||||
|
||||
combined() {
|
||||
let combined: Array<{type_: string, data: ModRemovePost | ModLockPost | ModRemoveCommunity}> = [];
|
||||
let removed_posts = addTypeInfo(this.state.removed_posts, "removed_posts");
|
||||
let locked_posts = addTypeInfo(this.state.locked_posts, "locked_posts");
|
||||
let removed_comments = addTypeInfo(this.state.removed_comments, "removed_comments");
|
||||
let removed_communities = addTypeInfo(this.state.removed_communities, "removed_communities");
|
||||
let banned_from_community = addTypeInfo(this.state.banned_from_community, "banned_from_community");
|
||||
let added_to_community = addTypeInfo(this.state.added_to_community, "added_to_community");
|
||||
|
||||
combined.push(...removed_posts);
|
||||
combined.push(...locked_posts);
|
||||
combined.push(...removed_comments);
|
||||
combined.push(...removed_communities);
|
||||
combined.push(...banned_from_community);
|
||||
combined.push(...added_to_community);
|
||||
|
||||
// Sort them by time
|
||||
combined.sort((a, b) => b.data.when_.localeCompare(a.data.when_));
|
||||
|
||||
console.log(combined);
|
||||
|
||||
return (
|
||||
<tbody>
|
||||
{combined.map(i =>
|
||||
<tr>
|
||||
<td><MomentTime data={i.data} /></td>
|
||||
<td><Link to={`/user/${i.data.mod_user_id}`}>{i.data.mod_user_name}</Link></td>
|
||||
<td>
|
||||
{i.type_ == 'removed_posts' &&
|
||||
<>
|
||||
{(i.data as ModRemovePost).removed? 'Removed' : 'Restored'}
|
||||
<span> Post <Link to={`/post/${(i.data as ModRemovePost).post_id}`}>{(i.data as ModRemovePost).post_name}</Link></span>
|
||||
<div>{(i.data as ModRemovePost).reason && ` reason: ${(i.data as ModRemovePost).reason}`}</div>
|
||||
</>
|
||||
}
|
||||
{i.type_ == 'locked_posts' &&
|
||||
<>
|
||||
{(i.data as ModLockPost).locked? 'Locked' : 'Unlocked'}
|
||||
<span> Post <Link to={`/post/${(i.data as ModLockPost).post_id}`}>{(i.data as ModLockPost).post_name}</Link></span>
|
||||
</>
|
||||
}
|
||||
{i.type_ == 'removed_comments' &&
|
||||
<>
|
||||
{(i.data as ModRemoveComment).removed? 'Removed' : 'Restored'}
|
||||
<span> Comment <Link to={`/post/${(i.data as ModRemoveComment).post_id}/comment/${(i.data as ModRemoveComment).comment_id}`}>{(i.data as ModRemoveComment).comment_content}</Link></span>
|
||||
<div>{(i.data as ModRemoveComment).reason && ` reason: ${(i.data as ModRemoveComment).reason}`}</div>
|
||||
</>
|
||||
}
|
||||
{i.type_ == 'removed_communities' &&
|
||||
<>
|
||||
{(i.data as ModRemoveCommunity).removed ? 'Removed' : 'Restored'}
|
||||
<span> Community <Link to={`/community/${i.data.community_id}`}>{i.data.community_name}</Link></span>
|
||||
<div>{(i.data as ModRemoveCommunity).reason && ` reason: ${(i.data as ModRemoveCommunity).reason}`}</div>
|
||||
<div>{(i.data as ModRemoveCommunity).expires && ` expires: ${moment.utc((i.data as ModRemoveCommunity).expires).fromNow()}`}</div>
|
||||
</>
|
||||
}
|
||||
{i.type_ == 'banned_from_community' &&
|
||||
<>
|
||||
<span>{(i.data as ModBanFromCommunity).banned ? 'Banned ' : 'Unbanned '} </span>
|
||||
<span><Link to={`/user/${(i.data as ModBanFromCommunity).other_user_id}`}>{(i.data as ModBanFromCommunity).other_user_name}</Link></span>
|
||||
<div>{(i.data as ModBanFromCommunity).reason && ` reason: ${(i.data as ModBanFromCommunity).reason}`}</div>
|
||||
<div>{(i.data as ModBanFromCommunity).expires && ` expires: ${moment.utc((i.data as ModBanFromCommunity).expires).fromNow()}`}</div>
|
||||
</>
|
||||
}
|
||||
{i.type_ == 'added_to_community' &&
|
||||
<>
|
||||
<span>{(i.data as ModAddCommunity).removed ? 'Removed ' : 'Appointed '} </span>
|
||||
<span><Link to={`/user/${(i.data as ModAddCommunity).other_user_id}`}>{(i.data as ModAddCommunity).other_user_name}</Link></span>
|
||||
<span> as a mod to the community </span>
|
||||
<span><Link to={`/community/${i.data.community_id}`}>{i.data.community_name}</Link></span>
|
||||
</>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
}
|
||||
|
||||
</tbody>
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div class="container">
|
||||
{this.state.loading ?
|
||||
<h4 class=""><svg class="icon icon-spinner spin"><use xlinkHref="#icon-spinner"></use></svg></h4> :
|
||||
<div>
|
||||
<h4>Modlog</h4>
|
||||
<div class="table-responsive">
|
||||
<table id="modlog_table" class="table table-sm table-hover">
|
||||
<thead class="pointer">
|
||||
<tr>
|
||||
<th>Time</th>
|
||||
<th>Mod</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{this.combined()}
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
parseMessage(msg: any) {
|
||||
console.log(msg);
|
||||
let op: UserOperation = msgOp(msg);
|
||||
if (msg.error) {
|
||||
alert(msg.error);
|
||||
return;
|
||||
} else if (op == UserOperation.GetModlog) {
|
||||
let res: GetModlogResponse = msg;
|
||||
this.state.loading = false;
|
||||
this.state.removed_posts = res.removed_posts;
|
||||
this.state.locked_posts = res.locked_posts;
|
||||
this.state.removed_comments = res.removed_comments;
|
||||
this.state.removed_communities = res.removed_communities;
|
||||
this.state.banned_from_community = res.banned_from_community;
|
||||
this.state.added_to_community = res.added_to_community;
|
||||
|
||||
this.setState(this.state);
|
||||
}
|
||||
}
|
||||
}
|
@ -1 +1 @@
|
||||
export let version: string = "v0.0.2-9-g8e5a5d1";
|
||||
export let version: string = "v0.0.2-13-g1bf0dfd";
|
Loading…
Reference in New Issue