mirror of https://github.com/LemmyNet/lemmy
Merge branch 'moderation'
- Fixes #63 - Fixes #62 - Fixes #61 - Fixes #60 - Fixes #59 - Fixes #57 - Fixes #56 - Fixes #50 - Fixes #49 - Some of #48 - Fixes #45 - Some of #35 - Fixes #29 - Fixes #14pull/722/head
commit
e6542b55d2
@ -1,12 +1,39 @@
|
||||
FROM node:10-jessie as node
|
||||
#If encounter Invalid cross-device error -run on host 'echo N | sudo tee /sys/module/overlay/parameters/metacopy'
|
||||
COPY ui /app/ui
|
||||
RUN cd /app/ui && yarn && yarn build
|
||||
WORKDIR /app/ui
|
||||
RUN yarn
|
||||
RUN yarn build
|
||||
|
||||
FROM rust:1.33 as rust
|
||||
COPY server /app/server
|
||||
|
||||
# create a new empty shell project
|
||||
WORKDIR /app
|
||||
RUN USER=root cargo new server
|
||||
WORKDIR /app/server
|
||||
|
||||
# copy over your manifests
|
||||
COPY server/Cargo.toml server/Cargo.lock ./
|
||||
|
||||
# this build step will cache your dependencies
|
||||
RUN mkdir -p ./src/bin \
|
||||
&& echo 'fn main() { println!("Dummy") }' > ./src/bin/main.rs
|
||||
RUN cargo build --release --bin lemmy
|
||||
RUN ls ./target/release/.fingerprint/
|
||||
RUN rm -r ./target/release/.fingerprint/server-*
|
||||
|
||||
# copy your source tree
|
||||
# RUN rm -rf ./src/
|
||||
COPY server/src ./src/
|
||||
COPY server/migrations ./migrations/
|
||||
|
||||
# build for release
|
||||
RUN cargo build --frozen --release --bin lemmy
|
||||
RUN mv /app/server/target/release/lemmy /app/lemmy
|
||||
|
||||
# The output image
|
||||
# FROM debian:stable-slim
|
||||
# RUN apt-get -y update && apt-get install -y postgresql-client
|
||||
# COPY --from=rust /app/server/target/release/lemmy /app/lemmy
|
||||
COPY --from=node /app/ui/dist /app/dist
|
||||
RUN cd /app/server && cargo build --release
|
||||
RUN mv /app/server/target/release/lemmy /app/
|
||||
WORKDIR /app/
|
||||
EXPOSE 8536
|
||||
|
@ -1 +1,2 @@
|
||||
drop table user_
|
||||
drop table user_ban;
|
||||
drop table user_;
|
||||
|
@ -1,3 +1,5 @@
|
||||
drop view community_view;
|
||||
drop view community_moderator_view;
|
||||
drop view community_follower_view;
|
||||
drop view community_user_ban_view;
|
||||
drop view site_view;
|
||||
|
@ -0,0 +1,8 @@
|
||||
drop table mod_remove_post;
|
||||
drop table mod_lock_post;
|
||||
drop table mod_remove_comment;
|
||||
drop table mod_remove_community;
|
||||
drop table mod_ban;
|
||||
drop table mod_ban_from_community;
|
||||
drop table mod_add;
|
||||
drop table mod_add_community;
|
@ -0,0 +1,76 @@
|
||||
create table mod_remove_post (
|
||||
id serial primary key,
|
||||
mod_user_id int references user_ on update cascade on delete cascade not null,
|
||||
post_id int references post on update cascade on delete cascade not null,
|
||||
reason text,
|
||||
removed boolean default true,
|
||||
when_ timestamp not null default now()
|
||||
);
|
||||
|
||||
create table mod_lock_post (
|
||||
id serial primary key,
|
||||
mod_user_id int references user_ on update cascade on delete cascade not null,
|
||||
post_id int references post on update cascade on delete cascade not null,
|
||||
locked boolean default true,
|
||||
when_ timestamp not null default now()
|
||||
);
|
||||
|
||||
create table mod_remove_comment (
|
||||
id serial primary key,
|
||||
mod_user_id int references user_ on update cascade on delete cascade not null,
|
||||
comment_id int references comment on update cascade on delete cascade not null,
|
||||
reason text,
|
||||
removed boolean default true,
|
||||
when_ timestamp not null default now()
|
||||
);
|
||||
|
||||
create table mod_remove_community (
|
||||
id serial primary key,
|
||||
mod_user_id int references user_ on update cascade on delete cascade not null,
|
||||
community_id int references community on update cascade on delete cascade not null,
|
||||
reason text,
|
||||
removed boolean default true,
|
||||
expires timestamp,
|
||||
when_ timestamp not null default now()
|
||||
);
|
||||
|
||||
-- TODO make sure you can't ban other mods
|
||||
create table mod_ban_from_community (
|
||||
id serial primary key,
|
||||
mod_user_id int references user_ on update cascade on delete cascade not null,
|
||||
other_user_id int references user_ on update cascade on delete cascade not null,
|
||||
community_id int references community on update cascade on delete cascade not null,
|
||||
reason text,
|
||||
banned boolean default true,
|
||||
expires timestamp,
|
||||
when_ timestamp not null default now()
|
||||
);
|
||||
|
||||
create table mod_ban (
|
||||
id serial primary key,
|
||||
mod_user_id int references user_ on update cascade on delete cascade not null,
|
||||
other_user_id int references user_ on update cascade on delete cascade not null,
|
||||
reason text,
|
||||
banned boolean default true,
|
||||
expires timestamp,
|
||||
when_ timestamp not null default now()
|
||||
);
|
||||
|
||||
create table mod_add_community (
|
||||
id serial primary key,
|
||||
mod_user_id int references user_ on update cascade on delete cascade not null,
|
||||
other_user_id int references user_ on update cascade on delete cascade not null,
|
||||
community_id int references community on update cascade on delete cascade not null,
|
||||
removed boolean default false,
|
||||
when_ timestamp not null default now()
|
||||
);
|
||||
|
||||
-- When removed is false that means kicked
|
||||
create table mod_add (
|
||||
id serial primary key,
|
||||
mod_user_id int references user_ on update cascade on delete cascade not null,
|
||||
other_user_id int references user_ on update cascade on delete cascade not null,
|
||||
removed boolean default false,
|
||||
when_ timestamp not null default now()
|
||||
);
|
||||
|
@ -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: false,
|
||||
banned: false,
|
||||
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: false,
|
||||
banned: false,
|
||||
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)
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,36 @@
|
||||
import { Component } from 'inferno';
|
||||
import { Link } from 'inferno-router';
|
||||
import { repoUrl } from '../utils';
|
||||
import { version } from '../version';
|
||||
|
||||
export class Footer extends Component<any, any> {
|
||||
|
||||
|
||||
constructor(props: any, context: any) {
|
||||
super(props, context);
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<nav title={version} class="container navbar navbar-expand-md navbar-light navbar-bg p-0 px-3 my-2">
|
||||
<div className="navbar-collapse">
|
||||
<ul class="navbar-nav ml-auto">
|
||||
<li class="nav-item">
|
||||
<Link class="nav-link" to="/modlog">Modlog</Link>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href={repoUrl}>Contribute</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href={repoUrl}>Code</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href={repoUrl}>About</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,175 @@
|
||||
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 {
|
||||
combined: Array<{type_: string, data: ModRemovePost | ModLockPost | ModRemoveCommunity}>,
|
||||
communityId?: number,
|
||||
communityName?: string,
|
||||
loading: boolean;
|
||||
}
|
||||
|
||||
export class Modlog extends Component<any, ModlogState> {
|
||||
private subscription: Subscription;
|
||||
private emptyState: ModlogState = {
|
||||
combined: [],
|
||||
loading: true,
|
||||
}
|
||||
|
||||
constructor(props: any, context: any) {
|
||||
super(props, context);
|
||||
|
||||
this.state = this.emptyState;
|
||||
this.state.communityId = this.props.match.params.community_id ? Number(this.props.match.params.community_id) : undefined;
|
||||
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 = {
|
||||
community_id: this.state.communityId
|
||||
};
|
||||
WebSocketService.Instance.getModlog(modlogForm);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.subscription.unsubscribe();
|
||||
}
|
||||
|
||||
setCombined(res: GetModlogResponse) {
|
||||
let removed_posts = addTypeInfo(res.removed_posts, "removed_posts");
|
||||
let locked_posts = addTypeInfo(res.locked_posts, "locked_posts");
|
||||
let removed_comments = addTypeInfo(res.removed_comments, "removed_comments");
|
||||
let removed_communities = addTypeInfo(res.removed_communities, "removed_communities");
|
||||
let banned_from_community = addTypeInfo(res.banned_from_community, "banned_from_community");
|
||||
let added_to_community = addTypeInfo(res.added_to_community, "added_to_community");
|
||||
|
||||
this.state.combined.push(...removed_posts);
|
||||
this.state.combined.push(...locked_posts);
|
||||
this.state.combined.push(...removed_comments);
|
||||
this.state.combined.push(...removed_communities);
|
||||
this.state.combined.push(...banned_from_community);
|
||||
this.state.combined.push(...added_to_community);
|
||||
|
||||
if (this.state.communityId && this.state.combined.length > 0) {
|
||||
this.state.communityName = this.state.combined[0].data.community_name;
|
||||
}
|
||||
|
||||
// Sort them by time
|
||||
this.state.combined.sort((a, b) => b.data.when_.localeCompare(a.data.when_));
|
||||
|
||||
this.setState(this.state);
|
||||
}
|
||||
|
||||
combined() {
|
||||
return (
|
||||
<tbody>
|
||||
{this.state.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>
|
||||
{this.state.communityName && <Link className="text-white" to={`/community/${this.state.communityId}`}>/f/{this.state.communityName} </Link>}
|
||||
<span>Modlog</span>
|
||||
</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.setCombined(res);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,147 @@
|
||||
import { Component, linkEvent } from 'inferno';
|
||||
import { Subscription } from "rxjs";
|
||||
import { retryWhen, delay, take } from 'rxjs/operators';
|
||||
import { RegisterForm, LoginResponse, UserOperation } from '../interfaces';
|
||||
import { WebSocketService, UserService } from '../services';
|
||||
import { msgOp } from '../utils';
|
||||
import { SiteForm } from './site-form';
|
||||
|
||||
interface State {
|
||||
userForm: RegisterForm;
|
||||
doneRegisteringUser: boolean;
|
||||
userLoading: boolean;
|
||||
}
|
||||
|
||||
export class Setup extends Component<any, State> {
|
||||
private subscription: Subscription;
|
||||
|
||||
private emptyState: State = {
|
||||
userForm: {
|
||||
username: undefined,
|
||||
password: undefined,
|
||||
password_verify: undefined,
|
||||
admin: true,
|
||||
},
|
||||
doneRegisteringUser: false,
|
||||
userLoading: false,
|
||||
}
|
||||
|
||||
|
||||
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")
|
||||
);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.subscription.unsubscribe();
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-12 offset-lg-3 col-lg-6">
|
||||
<h3>Lemmy Instance Setup</h3>
|
||||
{!this.state.doneRegisteringUser ? this.registerUser() : <SiteForm />}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
registerUser() {
|
||||
return (
|
||||
<form onSubmit={linkEvent(this, this.handleRegisterSubmit)}>
|
||||
<h4>Set up Site Administrator</h4>
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label">Username</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" class="form-control" value={this.state.userForm.username} onInput={linkEvent(this, this.handleRegisterUsernameChange)} required minLength={3} pattern="[a-zA-Z0-9_]+" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label">Email</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="email" class="form-control" placeholder="Optional" value={this.state.userForm.email} onInput={linkEvent(this, this.handleRegisterEmailChange)} minLength={3} />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label">Password</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="password" value={this.state.userForm.password} onInput={linkEvent(this, this.handleRegisterPasswordChange)} class="form-control" required />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label">Verify Password</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="password" value={this.state.userForm.password_verify} onInput={linkEvent(this, this.handleRegisterPasswordVerifyChange)} class="form-control" required />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<div class="col-sm-10">
|
||||
<button type="submit" class="btn btn-secondary">{this.state.userLoading ?
|
||||
<svg class="icon icon-spinner spin"><use xlinkHref="#icon-spinner"></use></svg> : 'Sign Up'}</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
handleRegisterSubmit(i: Setup, event: any) {
|
||||
event.preventDefault();
|
||||
i.state.userLoading = true;
|
||||
i.setState(i.state);
|
||||
event.preventDefault();
|
||||
WebSocketService.Instance.register(i.state.userForm);
|
||||
}
|
||||
|
||||
handleRegisterUsernameChange(i: Setup, event: any) {
|
||||
i.state.userForm.username = event.target.value;
|
||||
i.setState(i.state);
|
||||
}
|
||||
|
||||
handleRegisterEmailChange(i: Setup, event: any) {
|
||||
i.state.userForm.email = event.target.value;
|
||||
i.setState(i.state);
|
||||
}
|
||||
|
||||
handleRegisterPasswordChange(i: Setup, event: any) {
|
||||
i.state.userForm.password = event.target.value;
|
||||
i.setState(i.state);
|
||||
}
|
||||
|
||||
handleRegisterPasswordVerifyChange(i: Setup, event: any) {
|
||||
i.state.userForm.password_verify = event.target.value;
|
||||
i.setState(i.state);
|
||||
}
|
||||
|
||||
parseMessage(msg: any) {
|
||||
let op: UserOperation = msgOp(msg);
|
||||
if (msg.error) {
|
||||
alert(msg.error);
|
||||
this.state.userLoading = false;
|
||||
this.setState(this.state);
|
||||
return;
|
||||
} else if (op == UserOperation.Register) {
|
||||
this.state.userLoading = false;
|
||||
this.state.doneRegisteringUser = true;
|
||||
let res: LoginResponse = msg;
|
||||
UserService.Instance.login(res);
|
||||
console.log(res);
|
||||
this.setState(this.state);
|
||||
} else if (op == UserOperation.CreateSite) {
|
||||
this.props.history.push('/');
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
import { Component, linkEvent } from 'inferno';
|
||||
import { Site, SiteForm as SiteFormI } from '../interfaces';
|
||||
import { WebSocketService } from '../services';
|
||||
import * as autosize from 'autosize';
|
||||
|
||||
interface SiteFormProps {
|
||||
site?: Site; // If a site is given, that means this is an edit
|
||||
onCancel?(): any;
|
||||
}
|
||||
|
||||
interface SiteFormState {
|
||||
siteForm: SiteFormI;
|
||||
loading: boolean;
|
||||
}
|
||||
|
||||
export class SiteForm extends Component<SiteFormProps, SiteFormState> {
|
||||
private emptyState: SiteFormState ={
|
||||
siteForm: {
|
||||
name: null
|
||||
},
|
||||
loading: false
|
||||
}
|
||||
|
||||
constructor(props: any, context: any) {
|
||||
super(props, context);
|
||||
this.state = this.emptyState;
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
autosize(document.querySelectorAll('textarea'));
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<form onSubmit={linkEvent(this, this.handleCreateSiteSubmit)}>
|
||||
<h4>{`${this.props.site ? 'Edit' : 'Name'} your Site`}</h4>
|
||||
<div class="form-group row">
|
||||
<label class="col-12 col-form-label">Name</label>
|
||||
<div class="col-12">
|
||||
<input type="text" class="form-control" value={this.state.siteForm.name} onInput={linkEvent(this, this.handleSiteNameChange)} required minLength={3} />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label class="col-12 col-form-label">Sidebar</label>
|
||||
<div class="col-12">
|
||||
<textarea value={this.state.siteForm.description} onInput={linkEvent(this, this.handleSiteDescriptionChange)} class="form-control" rows={3} />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<div class="col-12">
|
||||
<button type="submit" class="btn btn-secondary mr-2">
|
||||
{this.state.loading ?
|
||||
<svg class="icon icon-spinner spin"><use xlinkHref="#icon-spinner"></use></svg> :
|
||||
this.props.site ? 'Save' : 'Create'}</button>
|
||||
{this.props.site && <button type="button" class="btn btn-secondary" onClick={linkEvent(this, this.handleCancel)}>Cancel</button>}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
handleCreateSiteSubmit(i: SiteForm, event: any) {
|
||||
event.preventDefault();
|
||||
i.state.loading = true;
|
||||
if (i.props.site) {
|
||||
WebSocketService.Instance.editSite(i.state.siteForm);
|
||||
} else {
|
||||
WebSocketService.Instance.createSite(i.state.siteForm);
|
||||
}
|
||||
i.setState(i.state);
|
||||
}
|
||||
|
||||
handleSiteNameChange(i: SiteForm, event: any) {
|
||||
i.state.siteForm.name = event.target.value;
|
||||
i.setState(i.state);
|
||||
}
|
||||
|
||||
handleSiteDescriptionChange(i: SiteForm, event: any) {
|
||||
i.state.siteForm.description = event.target.value;
|
||||
i.setState(i.state);
|
||||
}
|
||||
|
||||
handleCancel(i: SiteForm) {
|
||||
i.props.onCancel();
|
||||
}
|
||||
}
|
@ -1,2 +1,4 @@
|
||||
export const endpoint = `${window.location.hostname}:8536`;
|
||||
export let wsUri = (window.location.protocol=='https:') ? 'wss://' : 'ws://' + endpoint + '/service/ws';
|
||||
let host = `${window.location.hostname}`;
|
||||
let port = `${window.location.port == "4444" ? '8536' : window.location.port}`;
|
||||
let endpoint = `${host}:${port}`;
|
||||
export let wsUri = `${(window.location.protocol=='https:') ? 'wss://' : 'ws://'}${endpoint}/service/ws`;
|
||||
|
@ -0,0 +1 @@
|
||||
export let version: string = "v0.0.2-13-g1bf0dfd";
|
Loading…
Reference in New Issue