source: Klonkt/src/routes/admin.js@ 9a00f28

main
Last change on this file since 9a00f28 was 9a00f28, checked in by Robin <roboburr@…>, 7 weeks ago

Fix: test feedback round, cirkels tagline + report details + full i18n

Three findings from Bart's test pass, tied together by the new i18n keys:

  1. The admin tagline said "Solo mode" even with Cirkels (federation) on. Solo-tenancy now distinguishes: apEnabled -> "Cirkels-modus: jouw site, verbonden met de fediverse", else the solo line. New key in nl/en/de.
  1. Reports only showed who reported; now they show the reason and WHICH post. getNotifications resolves the stored objects URIs of a report: our own /ap/notes/<id> become "Over de post: <title>" links under the description; an empty reason renders "Geen reden opgegeven". Other URIs (the actor itself) are skipped, the row already names the account.
  1. Notificaties and Betaalde posts were hardcoded Dutch on an English-configured Klonkt. Everything now goes through t(): the two admin pages (including their client-side status strings, passed via the JSON data block), the admin menu buttons, and the visitor-facing paid pages (gate, passkey, result). Server-side push payloads translate too, using the SITE's content language (fallback KLONKT_DEFAULT_LANG), and the test ping uses the request language. Full nl/en/de dictionaries.

Changed files:
src/services/i18n.js

  • admin.tagline_cirkels, admin.b_paid/b_push/back, notif.report_about/ report_noreason, and the push.*, apaid.*, pgate.*, ppk.*, pres.* blocks in nl/en/de

src/routes/admin.js, src/views/pages/admin.ejs

  • circlesOn (apEnabled) -> cirkels tagline; menu buttons via t()

src/services/ActivityPubService.js

  • report objects resolved to post links; push payloads via i18nT with pushLang(slug) (site language)

src/views/pages/fedi-notifications.ejs

  • report reason fallback + "Over de post" links (+ styles)

src/routes/admin-push.js, src/views/pages/admin-push.ejs

  • pageTitleKey push.t; all copy + JS status strings via t()

src/routes/admin-paid.js, src/views/pages/admin-paid.ejs

  • pageTitleKey apaid.t; all copy via t(), copy-button label via data-attr

src/routes/paid.js

  • pageTitleKey pres.t / ppk.t

src/views/pages/paid-gate.ejs, paid-passkey.ejs, paid-result.ejs

  • visitor copy + JS strings via t()

src/routes/push.js

  • test notification via resolveLang(req)

-robo
Co-Authored-By: Claude Opus 4.8 <noreply@…>

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/**
2 * Admin routes — Phase B stub.
3 * Read-only god-only overview of users / sites / posts.
4 * Real admin dashboard (create/delete sites, manage users, etc.) comes later.
5 */
6
7import express from 'express';
8import db from '../config/database.js';
9import { renderPage } from '../middleware/render.js';
10import { requireAuth } from '../middleware/auth.js';
11import { getTenancy, apEnabled } from '../services/SettingsService.js';
12import { getPrimarySite } from '../middleware/site.js';
13
14const router = express.Router();
15
16// Recent posts from one site, DRAFTS ON TOP, with mode-aware edit/view URLs.
17// Solves the problem that drafts (status != published) were not findable anywhere:
18// the timeline shows only published posts.
19function sitePosts(siteId, siteSlug, tenancy, limit = 60) {
20 const base = tenancy === 'hub' ? `/user/${siteSlug}` : '';
21 return db.prepare(`
22 SELECT slug, title, status, published_at, created_at, updated_at
23 FROM posts WHERE site_id = ?
24 ORDER BY (status != 'published') DESC, COALESCE(updated_at, published_at, created_at) DESC
25 LIMIT ?
26 `).all(siteId, limit).map((p) => ({
27 ...p,
28 isDraft: p.status !== 'published',
29 editUrl: `${base}/posts/${p.slug}/edit`,
30 viewUrl: `${base}/${p.slug}`,
31 }));
32}
33
34router.get('/', requireAuth, (req, res) => {
35 const user = req.session.user;
36
37 // A kijker may view the full (god) admin panel read-only — same as god,
38 // but writing is globally blocked. A regular artist who owns a site gets
39 // a "My Klonkt Hub" dashboard, scoped to their own site. No site -> no admin.
40 if (user.role !== 'god' && user.role !== 'kijker') {
41 const mySite = db.prepare(
42 'SELECT * FROM sites WHERE owner_id = ? ORDER BY created_at ASC LIMIT 1'
43 ).get(user.id);
44 if (!mySite) return res.status(403).send('Geen beheer beschikbaar voor dit account.');
45
46 const mine = {
47 posts: db.prepare("SELECT COUNT(*) AS c FROM posts WHERE site_id = ?").get(mySite.id).c,
48 published: db.prepare("SELECT COUNT(*) AS c FROM posts WHERE site_id = ? AND status = 'published'").get(mySite.id).c,
49 };
50 return renderPage(req, res, 'pages/my-site', {
51 pageTitleKey: 'admin.t_hub',
52 bodyClass: 'on-admin',
53 mySite,
54 mine,
55 posts: sitePosts(mySite.id, mySite.slug, 'hub'), // my-site is hub-only
56 });
57 }
58
59 const tenancy = getTenancy();
60
61 // The primary/main site — in solo THE site, in hub the main site. Provides the
62 // "Appearance" tile with its edit link + the posts/drafts list.
63 const primarySite = getPrimarySite();
64
65 const stats = {
66 users: db.prepare('SELECT COUNT(*) AS c FROM users').get().c,
67 sites: db.prepare('SELECT COUNT(*) AS c FROM sites').get().c,
68 posts: db.prepare('SELECT COUNT(*) AS c FROM posts').get().c,
69 published: db.prepare(
70 "SELECT COUNT(*) AS c FROM posts WHERE status = 'published'"
71 ).get().c,
72 };
73
74 // Sites/users tables are only relevant in hub mode; in solo we skip the query.
75 const sites = tenancy === 'hub' ? db.prepare(`
76 SELECT s.slug, s.title, s.created_at, u.username AS owner_username
77 FROM sites s
78 LEFT JOIN users u ON u.id = s.owner_id
79 ORDER BY s.created_at DESC
80 LIMIT 50
81 `).all() : [];
82
83 const users = tenancy === 'hub' ? db.prepare(`
84 SELECT username, email, role, created_at
85 FROM users
86 ORDER BY created_at DESC
87 LIMIT 50
88 `).all() : [];
89
90 // Posts/drafts of the primary site (in solo = the site; in hub = the admin's
91 // main site). Drafts are listed first so they are easy to find.
92 const posts = primarySite ? sitePosts(primarySite.id, primarySite.slug, tenancy) : [];
93
94 renderPage(req, res, 'pages/admin', {
95 pageTitleKey: 'admin.t_admin',
96 bodyClass: 'on-admin',
97 tenancy,
98 circlesOn: apEnabled(), // solo vs cirkels tagline (federatie aan/uit)
99 primarySite,
100 stats,
101 sites,
102 posts,
103 users,
104 });
105});
106
107// Handleiding — searchable explanation of all admin features. Visible to anyone
108// who may view the admin panel (logged in); purely static help text, nothing sensitive.
109router.get('/handleiding', requireAuth, (req, res) => {
110 renderPage(req, res, 'pages/admin-help', {
111 pageTitleKey: 'admin.t_manual',
112 bodyClass: 'on-admin',
113 tenancy: getTenancy(),
114 });
115});
116
117export default router;
Note: See TracBrowser for help on using the repository browser.