Forum: founders are the first fifteen; the admin can take or give the badge
The site has few members yet, some of them test accounts: the badge goes to the first fifteen, and the admin can take it from a test account on its profile (the place goes to the next newcomer) or give it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
-- "Alapító tag": the first hundred members (in the order they chose a
|
||||
-- nickname) keep the badge for good, however many come after them.
|
||||
-- "Alapító tag": the first fifteen members (in the order they chose a
|
||||
-- nickname) keep the badge for good. The admin can take it from a test
|
||||
-- account or give it; a freed place goes to the next newcomer.
|
||||
ALTER TABLE forum.members ADD COLUMN founder boolean NOT NULL DEFAULT false;
|
||||
UPDATE forum.members SET founder = true
|
||||
WHERE user_id IN (SELECT user_id FROM forum.members ORDER BY created_at, user_id LIMIT 100);
|
||||
WHERE user_id IN (SELECT user_id FROM forum.members ORDER BY created_at, user_id LIMIT 15);
|
||||
|
||||
@@ -17,7 +17,7 @@ use crate::error::{ApiError, ApiResult};
|
||||
use crate::text;
|
||||
|
||||
/// The first this many members get the "Alapító tag" badge for good.
|
||||
const FOUNDERS: i64 = 100;
|
||||
pub const FOUNDERS: i64 = 15;
|
||||
|
||||
/// A nickname may change once in this many days (spelling fixes that keep the
|
||||
/// same folded form any time).
|
||||
|
||||
@@ -91,6 +91,7 @@ pub fn router(state: Arc<AppState>) -> Router {
|
||||
.route("/v1/forum/members/search", get(mentions::search))
|
||||
.route("/v1/forum/members/{nickname}", get(members::profile))
|
||||
.route("/v1/forum/members/{nickname}/mute", put(mutes::mute).delete(mutes::unmute))
|
||||
.route("/v1/forum/members/{nickname}/founder", put(mutes::set_founder))
|
||||
.route("/v1/forum/me/mutes", get(mutes::list))
|
||||
.route("/v1/forum/members/{nickname}/ban", post(moderation::ban).delete(moderation::unban))
|
||||
.route("/v1/forum/mod/log", get(moderation::log))
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
//! muter's lists, their posts fold up (one click shows them), their replies
|
||||
//! and mentions no longer notify, and they drop out of "Most itt vannak".
|
||||
//! The muted member is not told, and can still be reported.
|
||||
//! (Also here: the admin's switch for the "Alapító tag" badge.)
|
||||
|
||||
use axum::Json;
|
||||
use axum::extract::{Path, State};
|
||||
@@ -65,3 +66,29 @@ pub async fn list(State(state): St, viewer: Viewer) -> ApiResult<Json<Value>> {
|
||||
muted.sort_by(|a, b| a["nickname"].as_str().cmp(&b["nickname"].as_str()));
|
||||
Ok(Json(json!({ "muted": muted })))
|
||||
}
|
||||
|
||||
/// The admin takes the "Alapító tag" badge from a member (a test account) or
|
||||
/// gives it; a place taken away goes to the next newcomer.
|
||||
pub async fn set_founder(
|
||||
State(state): St,
|
||||
viewer: Viewer,
|
||||
WithRejection(Path(nickname), _): WithRejection<Path<String>, ApiError>,
|
||||
WithRejection(axum::Json(req), _): WithRejection<axum::Json<FounderChange>, ApiError>,
|
||||
) -> ApiResult<StatusCode> {
|
||||
viewer.require_user()?;
|
||||
if !viewer.is_admin() {
|
||||
return Err(ApiError::Forbidden("Ezt csak az admin teheti meg.".into()));
|
||||
}
|
||||
let target = member_id(&state, &nickname).await?;
|
||||
sqlx::query("UPDATE forum.members SET founder = $2 WHERE user_id = $1")
|
||||
.bind(target)
|
||||
.bind(req.founder)
|
||||
.execute(&state.db)
|
||||
.await?;
|
||||
Ok(StatusCode::NO_CONTENT)
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct FounderChange {
|
||||
founder: bool,
|
||||
}
|
||||
|
||||
@@ -1316,16 +1316,18 @@ async fn a_question_about_ones_chart(pool: PgPool) {
|
||||
}
|
||||
|
||||
#[sqlx::test(migrator = "db::MIGRATOR")]
|
||||
async fn the_first_hundred_are_founders(pool: PgPool) {
|
||||
async fn the_first_fifteen_are_founders(pool: PgPool) {
|
||||
let app = TestApp::new(pool);
|
||||
let anna = app.member("anna@example.com", "Csendesvíz", &["user"]).await;
|
||||
// Ninety-nine more founders already (made up), then Bea comes too late.
|
||||
let admin = app.member("admin@example.com", "Gondnok", &["admin"]).await;
|
||||
// Thirteen more founders already (made up): fifteen in all, then Bea comes too late.
|
||||
sqlx::query(
|
||||
"WITH u AS (INSERT INTO users (id, email, display_name) \
|
||||
SELECT gen_random_uuid(), 'f' || n || '@example.invalid', 'F' FROM generate_series(1, 99) n \
|
||||
SELECT gen_random_uuid(), 'f' || n || '@example.invalid', 'F' FROM generate_series(1, 13) n \
|
||||
RETURNING id, email) \
|
||||
INSERT INTO forum.members (user_id, nickname, nickname_key, avatar, founder) \
|
||||
SELECT id, 'Alapito ' || email, 'alapito ' || email, 'hold-ejkek', true FROM u",
|
||||
SELECT id, 'Alapito' || split_part(email, '@', 1), \
|
||||
translate('alapito' || split_part(email, '@', 1), 'i10', 'llo'), 'hold-ejkek', true FROM u",
|
||||
)
|
||||
.execute(&app.pool)
|
||||
.await
|
||||
@@ -1336,4 +1338,15 @@ async fn the_first_hundred_are_founders(pool: PgPool) {
|
||||
let shown = app.get(&format!("/v1/forum/threads/{thread}"), None).await;
|
||||
assert_eq!(shown["posts"][0]["author"]["founder"], true);
|
||||
assert_eq!(shown["posts"][1]["author"]["founder"], false);
|
||||
|
||||
// The admin takes it from a test account: the next newcomer gets the place.
|
||||
let uri = "/v1/forum/members/Alapitof1/founder";
|
||||
let (status, _) = app.call("PUT", uri, Some(&anna), json!({ "founder": false })).await;
|
||||
assert_eq!(status, StatusCode::FORBIDDEN);
|
||||
let (status, _) = app.call("PUT", uri, Some(&admin), json!({ "founder": false })).await;
|
||||
assert_eq!(status, StatusCode::NO_CONTENT);
|
||||
let cili = app.member("cili@example.com", "Zöldág", &["user"]).await;
|
||||
app.reply(&cili, thread, "Sziasztok!", None).await;
|
||||
let shown = app.get(&format!("/v1/forum/threads/{thread}"), None).await;
|
||||
assert_eq!(shown["posts"][2]["author"]["founder"], true);
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ export default async function PrivacyPage() {
|
||||
Fórumprofilod: az álneved (a korábbiakat 90 napig, hogy más ne vehesse fel), az avatarod vagy a
|
||||
feltöltött saját képed (kicsinyítve, a kép rejtett adatai, például a helyszín nélkül), a
|
||||
bemutatkozásod, a képletedből megosztott jegyek, hogy önkéntes kísérő vagy-e, a Támogató
|
||||
jelvény (ha bekapcsolod, mások látják, hogy vásároltál), hogy az első száz tag közé tartozol-e
|
||||
jelvény (ha bekapcsolod, mások látják, hogy vásároltál), hogy az első tizenöt tag közé tartozol-e
|
||||
(Alapító tag), a láthatatlan mód és az e-mail-értesítések beállítása
|
||||
</td>
|
||||
<td>Részvétel a fórumon; a jegyek megosztása és a jelvények a saját döntésed</td>
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
"use client";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
|
||||
import { api, errorText } from "@/lib/api";
|
||||
|
||||
/** The admin's switch for the "Alapító tag" badge (e.g. off for a test account; the place goes to the next newcomer). */
|
||||
export function FounderToggle({ nickname, founder }: { nickname: string; founder: boolean }) {
|
||||
const router = useRouter();
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
return (
|
||||
<div className="fmute">
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-sm btn-ghost"
|
||||
disabled={busy}
|
||||
onClick={async () => {
|
||||
if (
|
||||
founder &&
|
||||
!window.confirm(`Elveszed ${nickname} Alapító tag jelvényét? A helyét a következő új tag kapja.`)
|
||||
)
|
||||
return;
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
await api(`/forum/members/${encodeURIComponent(nickname)}/founder`, {
|
||||
method: "PUT",
|
||||
body: { founder: !founder },
|
||||
});
|
||||
router.refresh();
|
||||
} catch (e) {
|
||||
setError(errorText(e));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{founder ? "Alapító tag jelvény elvétele" : "Alapító tag jelvény megadása"}
|
||||
</button>
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -8,8 +8,10 @@ import { Badge, RankBadge } from "@/components/forum/Badges";
|
||||
import { PostBody } from "@/components/forum/PostBody";
|
||||
import { type MemberProfile, ago, banText, threadHref } from "@/lib/forum";
|
||||
import { forumGet } from "@/lib/forumServer";
|
||||
import { getMe } from "@/lib/server";
|
||||
|
||||
import { BanPanel } from "./BanPanel";
|
||||
import { FounderToggle } from "./FounderToggle";
|
||||
import { MuteButton } from "./MuteButton";
|
||||
import { RequestPanel } from "./RequestPanel";
|
||||
|
||||
@@ -37,6 +39,7 @@ export default async function MemberPage({ params }: Props) {
|
||||
if (!res.ok) notFound();
|
||||
const { member, recent, viewer } = res.data;
|
||||
const a = member.author;
|
||||
const admin = viewer.logged_in ? ((await getMe())?.user.roles.includes("admin") ?? false) : false;
|
||||
const signs = signsText(a.signs);
|
||||
const since = new Date(member.created_at).toLocaleDateString("hu-HU", { year: "numeric", month: "long" });
|
||||
return (
|
||||
@@ -73,6 +76,7 @@ export default async function MemberPage({ params }: Props) {
|
||||
</Link>
|
||||
)}
|
||||
{viewer.member && !member.own && <MuteButton nickname={a.nickname} muted={member.muted} />}
|
||||
{admin && <FounderToggle nickname={a.nickname} founder={a.founder ?? false} />}
|
||||
{viewer.moderator && !member.own && !a.moderator && (
|
||||
<BanPanel
|
||||
nickname={a.nickname}
|
||||
|
||||
@@ -85,7 +85,7 @@ const DATA: [string, string, string][] = [
|
||||
"Legitimate interest (Art. 6(1)(f))",
|
||||
],
|
||||
[
|
||||
"Your forum profile: your nickname (earlier ones for 90 days, so nobody else can take them), your avatar or the picture you uploaded (made smaller, without its hidden data such as the location), introduction, the signs of your chart you share, whether you are a volunteer companion (Kísérő), the Támogató (supporter) badge (if you switch it on, others see that you bought something), whether you were among the first hundred members (Alapító tag – founder), the invisible mode and your e-mail notification settings",
|
||||
"Your forum profile: your nickname (earlier ones for 90 days, so nobody else can take them), your avatar or the picture you uploaded (made smaller, without its hidden data such as the location), introduction, the signs of your chart you share, whether you are a volunteer companion (Kísérő), the Támogató (supporter) badge (if you switch it on, others see that you bought something), whether you were among the first fifteen members (Alapító tag – founder), the invisible mode and your e-mail notification settings",
|
||||
"Taking part in the forum; sharing the signs and the badges is your choice",
|
||||
"Performance of the contract",
|
||||
],
|
||||
|
||||
@@ -60,7 +60,7 @@ const BADGES: Record<BadgeKind, { label: string; title: string; icon: React.Reac
|
||||
// A sprout: there from the beginning.
|
||||
founder: {
|
||||
label: "Alapító tag",
|
||||
title: "A fórum első száz tagja közül való",
|
||||
title: "A fórum első tizenöt tagja közül való",
|
||||
icon: (
|
||||
<>
|
||||
<path d="M12 20.5V11" />
|
||||
|
||||
Reference in New Issue
Block a user