1 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};
4 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
5 #[table_name="mod_remove_post"]
6 pub struct ModRemovePost {
10 pub reason: Option<String>,
11 pub removed: Option<bool>,
12 pub when_: chrono::NaiveDateTime,
15 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
16 #[table_name="mod_remove_post"]
17 pub struct ModRemovePostForm {
20 pub reason: Option<String>,
21 pub removed: Option<bool>,
24 impl Crud<ModRemovePostForm> for ModRemovePost {
25 fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
26 use schema::mod_remove_post::dsl::*;
27 mod_remove_post.find(from_id)
31 fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
32 use schema::mod_remove_post::dsl::*;
33 diesel::delete(mod_remove_post.find(from_id))
37 fn create(conn: &PgConnection, form: &ModRemovePostForm) -> Result<Self, Error> {
38 use schema::mod_remove_post::dsl::*;
39 insert_into(mod_remove_post)
41 .get_result::<Self>(conn)
44 fn update(conn: &PgConnection, from_id: i32, form: &ModRemovePostForm) -> Result<Self, Error> {
45 use schema::mod_remove_post::dsl::*;
46 diesel::update(mod_remove_post.find(from_id))
48 .get_result::<Self>(conn)
54 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
55 #[table_name="mod_lock_post"]
56 pub struct ModLockPost {
60 pub locked: Option<bool>,
61 pub when_: chrono::NaiveDateTime,
64 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
65 #[table_name="mod_lock_post"]
66 pub struct ModLockPostForm {
69 pub locked: Option<bool>,
72 impl Crud<ModLockPostForm> for ModLockPost {
73 fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
74 use schema::mod_lock_post::dsl::*;
75 mod_lock_post.find(from_id)
79 fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
80 use schema::mod_lock_post::dsl::*;
81 diesel::delete(mod_lock_post.find(from_id))
85 fn create(conn: &PgConnection, form: &ModLockPostForm) -> Result<Self, Error> {
86 use schema::mod_lock_post::dsl::*;
87 insert_into(mod_lock_post)
89 .get_result::<Self>(conn)
92 fn update(conn: &PgConnection, from_id: i32, form: &ModLockPostForm) -> Result<Self, Error> {
93 use schema::mod_lock_post::dsl::*;
94 diesel::update(mod_lock_post.find(from_id))
96 .get_result::<Self>(conn)
100 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
101 #[table_name="mod_remove_comment"]
102 pub struct ModRemoveComment {
104 pub mod_user_id: i32,
106 pub reason: Option<String>,
107 pub removed: Option<bool>,
108 pub when_: chrono::NaiveDateTime,
111 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
112 #[table_name="mod_remove_comment"]
113 pub struct ModRemoveCommentForm {
114 pub mod_user_id: i32,
116 pub reason: Option<String>,
117 pub removed: Option<bool>,
120 impl Crud<ModRemoveCommentForm> for ModRemoveComment {
121 fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
122 use schema::mod_remove_comment::dsl::*;
123 mod_remove_comment.find(from_id)
127 fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
128 use schema::mod_remove_comment::dsl::*;
129 diesel::delete(mod_remove_comment.find(from_id))
133 fn create(conn: &PgConnection, form: &ModRemoveCommentForm) -> Result<Self, Error> {
134 use schema::mod_remove_comment::dsl::*;
135 insert_into(mod_remove_comment)
137 .get_result::<Self>(conn)
140 fn update(conn: &PgConnection, from_id: i32, form: &ModRemoveCommentForm) -> Result<Self, Error> {
141 use schema::mod_remove_comment::dsl::*;
142 diesel::update(mod_remove_comment.find(from_id))
144 .get_result::<Self>(conn)
148 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
149 #[table_name="mod_remove_community"]
150 pub struct ModRemoveCommunity {
152 pub mod_user_id: i32,
153 pub community_id: i32,
154 pub reason: Option<String>,
155 pub removed: Option<bool>,
156 pub expires: Option<chrono::NaiveDateTime>,
157 pub when_: chrono::NaiveDateTime,
160 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
161 #[table_name="mod_remove_community"]
162 pub struct ModRemoveCommunityForm {
163 pub mod_user_id: i32,
164 pub community_id: i32,
165 pub reason: Option<String>,
166 pub removed: Option<bool>,
167 pub expires: Option<chrono::NaiveDateTime>,
170 impl Crud<ModRemoveCommunityForm> for ModRemoveCommunity {
171 fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
172 use schema::mod_remove_community::dsl::*;
173 mod_remove_community.find(from_id)
177 fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
178 use schema::mod_remove_community::dsl::*;
179 diesel::delete(mod_remove_community.find(from_id))
183 fn create(conn: &PgConnection, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
184 use schema::mod_remove_community::dsl::*;
185 insert_into(mod_remove_community)
187 .get_result::<Self>(conn)
190 fn update(conn: &PgConnection, from_id: i32, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
191 use schema::mod_remove_community::dsl::*;
192 diesel::update(mod_remove_community.find(from_id))
194 .get_result::<Self>(conn)
198 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
199 #[table_name="mod_ban_from_community"]
200 pub struct ModBanFromCommunity {
202 pub mod_user_id: i32,
203 pub other_user_id: i32,
204 pub community_id: i32,
205 pub reason: Option<String>,
206 pub banned: Option<bool>,
207 pub expires: Option<chrono::NaiveDateTime>,
208 pub when_: chrono::NaiveDateTime,
211 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
212 #[table_name="mod_ban_from_community"]
213 pub struct ModBanFromCommunityForm {
214 pub mod_user_id: i32,
215 pub other_user_id: i32,
216 pub community_id: i32,
217 pub reason: Option<String>,
218 pub banned: Option<bool>,
219 pub expires: Option<chrono::NaiveDateTime>,
222 impl Crud<ModBanFromCommunityForm> for ModBanFromCommunity {
223 fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
224 use schema::mod_ban_from_community::dsl::*;
225 mod_ban_from_community.find(from_id)
229 fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
230 use schema::mod_ban_from_community::dsl::*;
231 diesel::delete(mod_ban_from_community.find(from_id))
235 fn create(conn: &PgConnection, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
236 use schema::mod_ban_from_community::dsl::*;
237 insert_into(mod_ban_from_community)
239 .get_result::<Self>(conn)
242 fn update(conn: &PgConnection, from_id: i32, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
243 use schema::mod_ban_from_community::dsl::*;
244 diesel::update(mod_ban_from_community.find(from_id))
246 .get_result::<Self>(conn)
251 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
252 #[table_name="mod_ban"]
255 pub mod_user_id: i32,
256 pub other_user_id: i32,
257 pub reason: Option<String>,
258 pub banned: Option<bool>,
259 pub expires: Option<chrono::NaiveDateTime>,
260 pub when_: chrono::NaiveDateTime,
263 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
264 #[table_name="mod_ban"]
265 pub struct ModBanForm {
266 pub mod_user_id: i32,
267 pub other_user_id: i32,
268 pub reason: Option<String>,
269 pub banned: Option<bool>,
270 pub expires: Option<chrono::NaiveDateTime>,
273 impl Crud<ModBanForm> for ModBan {
274 fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
275 use schema::mod_ban::dsl::*;
276 mod_ban.find(from_id)
280 fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
281 use schema::mod_ban::dsl::*;
282 diesel::delete(mod_ban.find(from_id))
286 fn create(conn: &PgConnection, form: &ModBanForm) -> Result<Self, Error> {
287 use schema::mod_ban::dsl::*;
290 .get_result::<Self>(conn)
293 fn update(conn: &PgConnection, from_id: i32, form: &ModBanForm) -> Result<Self, Error> {
294 use schema::mod_ban::dsl::*;
295 diesel::update(mod_ban.find(from_id))
297 .get_result::<Self>(conn)
301 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
302 #[table_name="mod_add_community"]
303 pub struct ModAddCommunity {
305 pub mod_user_id: i32,
306 pub other_user_id: i32,
307 pub community_id: i32,
308 pub removed: Option<bool>,
309 pub when_: chrono::NaiveDateTime,
312 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
313 #[table_name="mod_add_community"]
314 pub struct ModAddCommunityForm {
315 pub mod_user_id: i32,
316 pub other_user_id: i32,
317 pub community_id: i32,
318 pub removed: Option<bool>,
321 impl Crud<ModAddCommunityForm> for ModAddCommunity {
322 fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
323 use schema::mod_add_community::dsl::*;
324 mod_add_community.find(from_id)
328 fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
329 use schema::mod_add_community::dsl::*;
330 diesel::delete(mod_add_community.find(from_id))
334 fn create(conn: &PgConnection, form: &ModAddCommunityForm) -> Result<Self, Error> {
335 use schema::mod_add_community::dsl::*;
336 insert_into(mod_add_community)
338 .get_result::<Self>(conn)
341 fn update(conn: &PgConnection, from_id: i32, form: &ModAddCommunityForm) -> Result<Self, Error> {
342 use schema::mod_add_community::dsl::*;
343 diesel::update(mod_add_community.find(from_id))
345 .get_result::<Self>(conn)
349 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
350 #[table_name="mod_add"]
353 pub mod_user_id: i32,
354 pub other_user_id: i32,
355 pub removed: Option<bool>,
356 pub when_: chrono::NaiveDateTime,
359 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
360 #[table_name="mod_add"]
361 pub struct ModAddForm {
362 pub mod_user_id: i32,
363 pub other_user_id: i32,
364 pub removed: Option<bool>,
367 impl Crud<ModAddForm> for ModAdd {
368 fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
369 use schema::mod_add::dsl::*;
370 mod_add.find(from_id)
374 fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
375 use schema::mod_add::dsl::*;
376 diesel::delete(mod_add.find(from_id))
380 fn create(conn: &PgConnection, form: &ModAddForm) -> Result<Self, Error> {
381 use schema::mod_add::dsl::*;
384 .get_result::<Self>(conn)
387 fn update(conn: &PgConnection, from_id: i32, form: &ModAddForm) -> Result<Self, Error> {
388 use schema::mod_add::dsl::*;
389 diesel::update(mod_add.find(from_id))
391 .get_result::<Self>(conn)
398 use super::super::user::*;
399 use super::super::post::*;
400 use super::super::community::*;
401 use super::super::comment::*;
405 let conn = establish_connection();
407 let new_mod = UserForm {
408 name: "the mod".into(),
409 fedi_name: "rrf".into(),
410 preferred_username: None,
411 password_encrypted: "nope".into(),
418 let inserted_mod = User_::create(&conn, &new_mod).unwrap();
420 let new_user = UserForm {
422 fedi_name: "rrf".into(),
423 preferred_username: None,
424 password_encrypted: "nope".into(),
431 let inserted_user = User_::create(&conn, &new_user).unwrap();
433 let new_community = CommunityForm {
434 name: "mod_community".to_string(),
435 title: "nada".to_owned(),
438 creator_id: inserted_user.id,
444 let inserted_community = Community::create(&conn, &new_community).unwrap();
446 let new_post = PostForm {
447 name: "A test post thweep".into(),
450 creator_id: inserted_user.id,
451 community_id: inserted_community.id,
458 let inserted_post = Post::create(&conn, &new_post).unwrap();
460 let comment_form = CommentForm {
461 content: "A test comment".into(),
462 creator_id: inserted_user.id,
463 post_id: inserted_post.id,
471 let inserted_comment = Comment::create(&conn, &comment_form).unwrap();
473 // Now the actual tests
476 let mod_remove_post_form = ModRemovePostForm {
477 mod_user_id: inserted_mod.id,
478 post_id: inserted_post.id,
482 let inserted_mod_remove_post = ModRemovePost::create(&conn, &mod_remove_post_form).unwrap();
483 let read_moderator_remove_post = ModRemovePost::read(&conn, inserted_mod_remove_post.id).unwrap();
484 let expected_moderator_remove_post = ModRemovePost {
485 id: inserted_mod_remove_post.id,
486 post_id: inserted_post.id,
487 mod_user_id: inserted_mod.id,
490 when_: inserted_mod_remove_post.when_,
495 let mod_lock_post_form = ModLockPostForm {
496 mod_user_id: inserted_mod.id,
497 post_id: inserted_post.id,
500 let inserted_mod_lock_post = ModLockPost::create(&conn, &mod_lock_post_form).unwrap();
501 let read_moderator_lock_post = ModLockPost::read(&conn, inserted_mod_lock_post.id).unwrap();
502 let expected_moderator_lock_post = ModLockPost {
503 id: inserted_mod_lock_post.id,
504 post_id: inserted_post.id,
505 mod_user_id: inserted_mod.id,
507 when_: inserted_mod_lock_post.when_,
512 let mod_remove_comment_form = ModRemoveCommentForm {
513 mod_user_id: inserted_mod.id,
514 comment_id: inserted_comment.id,
518 let inserted_mod_remove_comment = ModRemoveComment::create(&conn, &mod_remove_comment_form).unwrap();
519 let read_moderator_remove_comment = ModRemoveComment::read(&conn, inserted_mod_remove_comment.id).unwrap();
520 let expected_moderator_remove_comment = ModRemoveComment {
521 id: inserted_mod_remove_comment.id,
522 comment_id: inserted_comment.id,
523 mod_user_id: inserted_mod.id,
526 when_: inserted_mod_remove_comment.when_,
531 let mod_remove_community_form = ModRemoveCommunityForm {
532 mod_user_id: inserted_mod.id,
533 community_id: inserted_community.id,
538 let inserted_mod_remove_community = ModRemoveCommunity::create(&conn, &mod_remove_community_form).unwrap();
539 let read_moderator_remove_community = ModRemoveCommunity::read(&conn, inserted_mod_remove_community.id).unwrap();
540 let expected_moderator_remove_community = ModRemoveCommunity {
541 id: inserted_mod_remove_community.id,
542 community_id: inserted_community.id,
543 mod_user_id: inserted_mod.id,
547 when_: inserted_mod_remove_community.when_,
550 // ban from community
552 let mod_ban_from_community_form = ModBanFromCommunityForm {
553 mod_user_id: inserted_mod.id,
554 other_user_id: inserted_user.id,
555 community_id: inserted_community.id,
560 let inserted_mod_ban_from_community = ModBanFromCommunity::create(&conn, &mod_ban_from_community_form).unwrap();
561 let read_moderator_ban_from_community = ModBanFromCommunity::read(&conn, inserted_mod_ban_from_community.id).unwrap();
562 let expected_moderator_ban_from_community = ModBanFromCommunity {
563 id: inserted_mod_ban_from_community.id,
564 community_id: inserted_community.id,
565 mod_user_id: inserted_mod.id,
566 other_user_id: inserted_user.id,
570 when_: inserted_mod_ban_from_community.when_,
575 let mod_ban_form = ModBanForm {
576 mod_user_id: inserted_mod.id,
577 other_user_id: inserted_user.id,
582 let inserted_mod_ban = ModBan::create(&conn, &mod_ban_form).unwrap();
583 let read_moderator_ban = ModBan::read(&conn, inserted_mod_ban.id).unwrap();
584 let expected_moderator_ban = ModBan {
585 id: inserted_mod_ban.id,
586 mod_user_id: inserted_mod.id,
587 other_user_id: inserted_user.id,
591 when_: inserted_mod_ban.when_,
596 let mod_add_community_form = ModAddCommunityForm {
597 mod_user_id: inserted_mod.id,
598 other_user_id: inserted_user.id,
599 community_id: inserted_community.id,
602 let inserted_mod_add_community = ModAddCommunity::create(&conn, &mod_add_community_form).unwrap();
603 let read_moderator_add_community = ModAddCommunity::read(&conn, inserted_mod_add_community.id).unwrap();
604 let expected_moderator_add_community = ModAddCommunity {
605 id: inserted_mod_add_community.id,
606 community_id: inserted_community.id,
607 mod_user_id: inserted_mod.id,
608 other_user_id: inserted_user.id,
609 removed: Some(false),
610 when_: inserted_mod_add_community.when_,
615 let mod_add_form = ModAddForm {
616 mod_user_id: inserted_mod.id,
617 other_user_id: inserted_user.id,
620 let inserted_mod_add = ModAdd::create(&conn, &mod_add_form).unwrap();
621 let read_moderator_add = ModAdd::read(&conn, inserted_mod_add.id).unwrap();
622 let expected_moderator_add = ModAdd {
623 id: inserted_mod_add.id,
624 mod_user_id: inserted_mod.id,
625 other_user_id: inserted_user.id,
626 removed: Some(false),
627 when_: inserted_mod_add.when_,
630 ModRemovePost::delete(&conn, inserted_mod_remove_post.id).unwrap();
631 ModLockPost::delete(&conn, inserted_mod_lock_post.id).unwrap();
632 ModRemoveComment::delete(&conn, inserted_mod_remove_comment.id).unwrap();
633 ModRemoveCommunity::delete(&conn, inserted_mod_remove_community.id).unwrap();
634 ModBanFromCommunity::delete(&conn, inserted_mod_ban_from_community.id).unwrap();
635 ModBan::delete(&conn, inserted_mod_ban.id).unwrap();
636 ModAddCommunity::delete(&conn, inserted_mod_add_community.id).unwrap();
637 ModAdd::delete(&conn, inserted_mod_add.id).unwrap();
639 Comment::delete(&conn, inserted_comment.id).unwrap();
640 Post::delete(&conn, inserted_post.id).unwrap();
641 Community::delete(&conn, inserted_community.id).unwrap();
642 User_::delete(&conn, inserted_user.id).unwrap();
643 User_::delete(&conn, inserted_mod.id).unwrap();
645 assert_eq!(expected_moderator_remove_post, read_moderator_remove_post);
646 assert_eq!(expected_moderator_lock_post, read_moderator_lock_post);
647 assert_eq!(expected_moderator_remove_comment, read_moderator_remove_comment);
648 assert_eq!(expected_moderator_remove_community, read_moderator_remove_community);
649 assert_eq!(expected_moderator_ban_from_community, read_moderator_ban_from_community);
650 assert_eq!(expected_moderator_ban, read_moderator_ban);
651 assert_eq!(expected_moderator_add_community, read_moderator_add_community);
652 assert_eq!(expected_moderator_add, read_moderator_add);