| 1 |
1 |
|
use crate::harness::TestHarness;
|
|
2 |
+ |
use mt_core::types::BanType;
|
| 2 |
3 |
|
|
| 3 |
4 |
|
// Auto-hide threshold tests
|
| 4 |
5 |
|
|
| 474 |
475 |
|
assert_eq!(resp.status.as_u16(), 403, "Flagging own post should be 403");
|
| 475 |
476 |
|
}
|
| 476 |
477 |
|
|
|
478 |
+ |
// Flagging gates on write-level access, not read-level. A user who cannot post
|
|
479 |
+ |
// must not be able to flag either, since enough flags trip the auto-hide
|
|
480 |
+ |
// threshold on someone else's post. Both cases below passed under the old
|
|
481 |
+ |
// `check_community_access` gate, which saw neither platform suspension nor mute.
|
|
482 |
+ |
|
|
483 |
+ |
#[tokio::test]
|
|
484 |
+ |
async fn platform_suspended_user_cannot_flag() {
|
|
485 |
+ |
let mut h = TestHarness::new().await;
|
|
486 |
+ |
let author_id = h.login_as("suspflagauthor").await;
|
|
487 |
+ |
let comm_id = h.create_community("Test", "test").await;
|
|
488 |
+ |
let cat_id = h.create_category(comm_id, "General", "general").await;
|
|
489 |
+ |
h.add_membership(author_id, comm_id, "member").await;
|
|
490 |
+ |
|
|
491 |
+ |
let thread_id = h
|
|
492 |
+ |
.create_thread_with_post(cat_id, author_id, "Suspended Flag", "Content")
|
|
493 |
+ |
.await;
|
|
494 |
+ |
|
|
495 |
+ |
let flagger_id = h.login_as("suspflagger").await;
|
|
496 |
+ |
h.add_membership(flagger_id, comm_id, "member").await;
|
|
497 |
+ |
|
|
498 |
+ |
mt_db::mutations::suspend_user(&h.db, flagger_id, Some("test"))
|
|
499 |
+ |
.await
|
|
500 |
+ |
.unwrap();
|
|
501 |
+ |
|
|
502 |
+ |
let posts = mt_db::queries::list_posts_in_thread(&h.db, thread_id)
|
|
503 |
+ |
.await
|
|
504 |
+ |
.unwrap();
|
|
505 |
+ |
let post_id = posts[0].id;
|
|
506 |
+ |
|
|
507 |
+ |
let flag_url = format!("/p/test/general/{thread_id}/posts/{post_id}/flag");
|
|
508 |
+ |
let resp = h.client.post_form(&flag_url, "reason=spam").await;
|
|
509 |
+ |
assert_eq!(
|
|
510 |
+ |
resp.status.as_u16(),
|
|
511 |
+ |
403,
|
|
512 |
+ |
"A platform-suspended user must not be able to flag"
|
|
513 |
+ |
);
|
|
514 |
+ |
|
|
515 |
+ |
let has_flag = mt_db::queries::has_user_flagged_post(&h.db, post_id, flagger_id)
|
|
516 |
+ |
.await
|
|
517 |
+ |
.unwrap();
|
|
518 |
+ |
assert!(!has_flag, "No flag row should have been written");
|
|
519 |
+ |
}
|
|
520 |
+ |
|
|
521 |
+ |
#[tokio::test]
|
|
522 |
+ |
async fn muted_user_cannot_flag() {
|
|
523 |
+ |
let mut h = TestHarness::new().await;
|
|
524 |
+ |
let author_id = h.login_as("muteflagauthor").await;
|
|
525 |
+ |
let comm_id = h.create_community("Test", "test").await;
|
|
526 |
+ |
let cat_id = h.create_category(comm_id, "General", "general").await;
|
|
527 |
+ |
h.add_membership(author_id, comm_id, "member").await;
|
|
528 |
+ |
|
|
529 |
+ |
let thread_id = h
|
|
530 |
+ |
.create_thread_with_post(cat_id, author_id, "Muted Flag", "Content")
|
|
531 |
+ |
.await;
|
|
532 |
+ |
|
|
533 |
+ |
let flagger_id = h.login_as("muteflagger").await;
|
|
534 |
+ |
h.add_membership(flagger_id, comm_id, "member").await;
|
|
535 |
+ |
|
|
536 |
+ |
mt_db::mutations::create_community_ban(
|
|
537 |
+ |
&h.db,
|
|
538 |
+ |
comm_id,
|
|
539 |
+ |
flagger_id,
|
|
540 |
+ |
author_id,
|
|
541 |
+ |
BanType::Mute,
|
|
542 |
+ |
Some("test"),
|
|
543 |
+ |
None,
|
|
544 |
+ |
)
|
|
545 |
+ |
.await
|
|
546 |
+ |
.unwrap();
|
|
547 |
+ |
|
|
548 |
+ |
let posts = mt_db::queries::list_posts_in_thread(&h.db, thread_id)
|
|
549 |
+ |
.await
|
|
550 |
+ |
.unwrap();
|
|
551 |
+ |
let post_id = posts[0].id;
|
|
552 |
+ |
|
|
553 |
+ |
let flag_url = format!("/p/test/general/{thread_id}/posts/{post_id}/flag");
|
|
554 |
+ |
let resp = h.client.post_form(&flag_url, "reason=spam").await;
|
|
555 |
+ |
assert_eq!(
|
|
556 |
+ |
resp.status.as_u16(),
|
|
557 |
+ |
403,
|
|
558 |
+ |
"A muted user must not be able to flag"
|
|
559 |
+ |
);
|
|
560 |
+ |
|
|
561 |
+ |
let has_flag = mt_db::queries::has_user_flagged_post(&h.db, post_id, flagger_id)
|
|
562 |
+ |
.await
|
|
563 |
+ |
.unwrap();
|
|
564 |
+ |
assert!(!has_flag, "No flag row should have been written");
|
|
565 |
+ |
}
|
|
566 |
+ |
|
| 477 |
567 |
|
#[tokio::test]
|
| 478 |
568 |
|
async fn mod_dismiss_flag() {
|
| 479 |
569 |
|
let mut h = TestHarness::new().await;
|