Forum: search, muting members, archived topics, the public threads in the sitemap
- Search (/forum/kereses, the magnifier in the forum bar): thread titles
and posts the viewer may read, Hungarian stems and word beginnings
without accents ("alvas" finds "alvásban"), one result per thread with
the matching words marked.
- Muting a member (post menu, profile; the list in the settings): their
threads leave the lists, their posts fold up, their replies and mentions
no longer count or send e-mails. They are not told.
- The admin archives a topic (Moderálás → Témák): it stays readable but
takes no new threads or replies, and folds away on the front page.
- The public topics and threads are in the sitemap; the forum's own pages
are kept from robots.
- A reply e-mail goes to the one answered, also on the second level.
- Migration 0043 also prepares charts attached to a forum question.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -1130,3 +1130,82 @@ async fn answers_to_the_member(pool: PgPool) {
|
||||
assert_eq!(app.get("/v1/forum/nav", Some(&bea)).await["replies"], 0);
|
||||
assert_eq!(answers(app.get("/v1/forum/replies", Some(&bea)).await).len(), 2, "the list stays");
|
||||
}
|
||||
|
||||
#[sqlx::test(migrator = "db::MIGRATOR")]
|
||||
async fn search_mutes_and_archived_topics(pool: PgPool) {
|
||||
let app = TestApp::new(pool);
|
||||
let anna = app.member("anna@example.com", "Csendesvíz", &["user"]).await;
|
||||
let bea = app.member("bea@example.com", "Holdfény", &["user"]).await;
|
||||
let admin = app.member("admin@example.com", "Gazda", &["user", "admin"]).await;
|
||||
let found = |v: Value| -> Vec<i64> {
|
||||
let mut ids: Vec<i64> =
|
||||
v["results"].as_array().unwrap().iter().map(|r| r["thread"]["id"].as_i64().unwrap()).collect();
|
||||
ids.sort();
|
||||
ids
|
||||
};
|
||||
|
||||
// Search: word beginnings without accents, titles, and only what one may read.
|
||||
let sleep = app.thread(&anna, "torzsasztal", "Nehezen alszom").await;
|
||||
app.reply(&bea, sleep, "Nekem az esti séták segítettek az alvásban.", None).await;
|
||||
let hidden = app.thread(&anna, "ami-a-szivemen-van", "Alvászavar titokban").await;
|
||||
assert_eq!(found(app.get("/v1/forum/search?q=alvas", None).await), vec![sleep], "a visitor: public topics");
|
||||
assert_eq!(found(app.get("/v1/forum/search?q=alv%C3%A1s", Some(&anna)).await), vec![sleep, hidden]);
|
||||
let hit = app.get("/v1/forum/search?q=s%C3%A9t%C3%A1k", None).await;
|
||||
assert!(hit["results"][0]["snippet"].as_str().unwrap().contains("⟦séták⟧"), "{hit}");
|
||||
assert!(found(app.get("/v1/forum/search?q=a", None).await).is_empty(), "too short");
|
||||
let map = app.get("/v1/forum/sitemap", None).await;
|
||||
let mapped: Vec<i64> = map["threads"].as_array().unwrap().iter().map(|t| t["id"].as_i64().unwrap()).collect();
|
||||
assert_eq!(mapped, vec![sleep], "public threads only");
|
||||
|
||||
// Muting Bea: her threads leave Anna's lists, her posts fold up, her
|
||||
// answers stop counting, and search leaves her out. She is not told.
|
||||
let soups = app.thread(&bea, "torzsasztal", "Téli levesek").await;
|
||||
assert_eq!(app.get("/v1/forum/nav", Some(&anna)).await["replies"], 1);
|
||||
let (status, _) = app.call("PUT", "/v1/forum/members/Holdf%C3%A9ny/mute", Some(&anna), Value::Null).await;
|
||||
assert_eq!(status, StatusCode::NO_CONTENT);
|
||||
let listed = app.get("/v1/forum/topics/torzsasztal", Some(&anna)).await;
|
||||
assert!(listed["threads"].as_array().unwrap().iter().all(|t| t["id"] != soups));
|
||||
let thread = app.get(&format!("/v1/forum/threads/{sleep}"), Some(&anna)).await;
|
||||
assert_eq!(thread["posts"][1]["muted"], true);
|
||||
assert_eq!(app.get("/v1/forum/nav", Some(&anna)).await["replies"], 0);
|
||||
assert!(found(app.get("/v1/forum/search?q=s%C3%A9t%C3%A1k", Some(&anna)).await).is_empty());
|
||||
assert_eq!(app.get("/v1/forum/me/mutes", Some(&anna)).await["muted"][0]["nickname"], "Holdfény");
|
||||
assert_eq!(app.get("/v1/forum/members/Holdf%C3%A9ny", Some(&anna)).await["member"]["muted"], true);
|
||||
assert_eq!(app.get(&format!("/v1/forum/threads/{sleep}"), Some(&bea)).await["posts"][0]["muted"], false);
|
||||
let (status, _) = app.call("PUT", "/v1/forum/members/Csendesv%C3%ADz/mute", Some(&anna), Value::Null).await;
|
||||
assert_eq!(status, StatusCode::BAD_REQUEST, "not oneself");
|
||||
let (status, _) = app.call("DELETE", "/v1/forum/members/Holdf%C3%A9ny/mute", Some(&anna), Value::Null).await;
|
||||
assert_eq!(status, StatusCode::NO_CONTENT);
|
||||
assert_eq!(app.get("/v1/forum/nav", Some(&anna)).await["replies"], 1);
|
||||
|
||||
// Archiving the topic: readable, but nothing new; brought back, it works again.
|
||||
let (status, _) =
|
||||
app.call("PATCH", "/v1/forum/topics/torzsasztal", Some(&admin), json!({ "archived": true })).await;
|
||||
assert_eq!(status, StatusCode::NO_CONTENT);
|
||||
let topic = app.get("/v1/forum/topics/torzsasztal", Some(&anna)).await;
|
||||
assert_eq!(topic["topic"]["archived"], true);
|
||||
let thread = app.get(&format!("/v1/forum/threads/{sleep}"), Some(&anna)).await;
|
||||
assert_eq!(thread["access"]["can_reply"], false);
|
||||
assert_eq!(thread["thread"]["topic"]["archived"], true);
|
||||
let (status, _) = app
|
||||
.call("POST", &format!("/v1/forum/threads/{sleep}/posts"), Some(&bea), json!({ "body": "Még egy szó." }))
|
||||
.await;
|
||||
assert_eq!(status, StatusCode::FORBIDDEN);
|
||||
let (status, _) = app
|
||||
.call(
|
||||
"POST",
|
||||
"/v1/forum/threads",
|
||||
Some(&anna),
|
||||
json!({ "topic": "torzsasztal", "title": "Új", "body": "Szia" }),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(status, StatusCode::BAD_REQUEST);
|
||||
let home = app.get("/v1/forum/home", Some(&anna)).await;
|
||||
let archived = home["topics"].as_array().unwrap().iter().find(|t| t["slug"] == "torzsasztal").unwrap();
|
||||
assert_eq!(archived["archived"], true);
|
||||
let (status, _) =
|
||||
app.call("PATCH", "/v1/forum/topics/torzsasztal", Some(&anna), json!({ "archived": false })).await;
|
||||
assert_eq!(status, StatusCode::FORBIDDEN, "admins only");
|
||||
app.call("PATCH", "/v1/forum/topics/torzsasztal", Some(&admin), json!({ "archived": false })).await;
|
||||
app.reply(&bea, sleep, "Még egy szó.", None).await;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user