From ee9fa9e3a6ea69fa5d101225a7530df12929aae7 Mon Sep 17 00:00:00 2001 From: Mistium <92952823+Mistium@users.noreply.github.com> Date: Tue, 6 Oct 2026 19:42:27 +0100 Subject: [PATCH] Turn the admin user view into a full account page Users can be filtered to warned or banned, joined this week, under 18 or admins, and found by Rotur ID as well as name. Each row shows admin, standing and under-18 badges and when they joined. Opening someone shows their Rotur ID, plan, last sign-in and sessions, storage, project totals and open reports at a glance, with tabs for an overview (a private admin note, account details, spaces and classes), projects, reports about them and by them, their recent comments, activity, and moderation (standing with its history, ban record, a message, profile comments). The section and user live in the URL, so /admin?section=users&user=name opens straight to someone, and reports and bans link to the person. Errors move into the System group in the sidebar. --- src/community/api.js | 6 +- src/community/pages/Admin.jsx | 21 +- src/community/pages/Admin.module.css | 243 +++++++- src/community/pages/admin/BansSection.jsx | 4 +- src/community/pages/admin/ReportsSection.jsx | 7 +- src/community/pages/admin/UserDetailCard.jsx | 527 +++++++++++++---- src/community/pages/admin/UserManager.jsx | 89 ++- src/community/pages/admin/admin-links.js | 18 + src/community/translations/_sources.json | 542 ++++++++++++------ src/community/translations/en.json | 86 ++- .../unit/community-admin-user-detail.test.jsx | 150 +++++ 11 files changed, 1365 insertions(+), 328 deletions(-) create mode 100644 src/community/pages/admin/admin-links.js create mode 100644 test/unit/community-admin-user-detail.test.jsx diff --git a/src/community/api.js b/src/community/api.js index c3c540a4c1c..0643e5dfd2c 100644 --- a/src/community/api.js +++ b/src/community/api.js @@ -331,13 +331,15 @@ const api = { request('/admin/user/message', {method: 'POST', body: {username, message}}), updateUserProfile: (username, patch) => request('/admin/user/profile', {method: 'POST', body: {username, ...patch}}), + setUserNote: (username, note) => + request('/admin/user/note', {method: 'POST', body: {username, note}}), searchProjects: q => request(`/admin/projects?q=${encodeURIComponent(q)}`), stats: (days = 30) => request(`/admin/stats?days=${encodeURIComponent(days)}`), storage: () => request('/admin/storage'), syncStorage: () => request('/admin/storage/sync', {method: 'POST'}), - users: ({q = '', offset = 0, limit = 30, sort = 'name'} = {}) => request( + users: ({q = '', offset = 0, limit = 30, sort = 'name', filter = ''} = {}) => request( `/admin/users?q=${encodeURIComponent(q)}&offset=${encodeURIComponent(offset)}` + - `&limit=${encodeURIComponent(limit)}&sort=${encodeURIComponent(sort)}` + `&limit=${encodeURIComponent(limit)}&sort=${encodeURIComponent(sort)}&filter=${encodeURIComponent(filter)}` ), extensions: () => request('/admin/extensions', {cache: false}), setExtensionPolicy: (hash, status) => diff --git a/src/community/pages/Admin.jsx b/src/community/pages/Admin.jsx index 030e9aa2a66..54b034bed8d 100644 --- a/src/community/pages/Admin.jsx +++ b/src/community/pages/Admin.jsx @@ -1,6 +1,7 @@ import {useCommunityIntl as useCommunityText} from '../i18n.jsx'; /* eslint-disable max-len */ import React, {useRef, useState} from 'react'; +import {useSearchParams} from 'react-router-dom'; import { Activity, AlertTriangle, Ban, BarChart3, Flag, FolderOpen, HardDrive, Puzzle, ShieldCheck, User } from 'lucide-react'; @@ -29,12 +30,12 @@ const SECTIONS = [ {key: 'overview', label: 'Overview', icon: BarChart3}, {key: 'storage', label: 'Storage and runtime', icon: HardDrive, group: 'System'}, {key: 'activity', label: 'Activity', icon: Activity, group: 'System'}, + {key: 'errors', label: 'Errors', icon: AlertTriangle, group: 'System'}, {key: 'reports', label: 'Reports', icon: Flag, group: 'Moderation'}, {key: 'users', label: 'Users', icon: User, group: 'Moderation'}, {key: 'bans', label: 'Bans', icon: Ban, group: 'Moderation'}, {key: 'projects', label: 'Projects', icon: FolderOpen, group: 'Content'}, {key: 'extensions', label: 'Extensions', icon: Puzzle, group: 'Content'}, - {key: 'errors', label: 'Errors', icon: AlertTriangle, group: 'System'}, {key: 'admins', label: 'Admins', icon: ShieldCheck, group: 'Access'} ]; @@ -43,7 +44,21 @@ const Admin = () => { const {user, loading} = useUser(); const {reports, openErrors, bans, admins, error, setError, load} = useAdminData(user); const [newAdmin, setNewAdmin] = useState(''); - const [active, setActive] = useState('overview'); + const [searchParams, setSearchParams] = useSearchParams(); + const requested = searchParams.get('section'); + const active = SECTIONS.some(section => section.key === requested) ? requested : 'overview'; + const selectedUser = searchParams.get('user') || null; + const setActive = key => { + const params = new URLSearchParams(); + if (key !== 'overview') params.set('section', key); + setSearchParams(params); + }; + const selectUser = name => { + const params = new URLSearchParams(); + params.set('section', 'users'); + if (name) params.set('user', name); + setSearchParams(params); + }; const [dialog, setDialog] = useState(null); const [dialogBusy, setDialogBusy] = useState(false); const [dialogError, setDialogError] = useState(''); @@ -271,7 +286,7 @@ const Admin = () => { {active === 'users' ? (
- +
) : null} diff --git a/src/community/pages/Admin.module.css b/src/community/pages/Admin.module.css index 30f9d4731c2..6d52653e8f8 100644 --- a/src/community/pages/Admin.module.css +++ b/src/community/pages/Admin.module.css @@ -112,10 +112,10 @@ .userToolbar { display: grid; - grid-template-columns: minmax(220px, 1fr) auto auto; + grid-template-columns: minmax(220px, 1fr) auto; gap: 10px; align-items: center; - margin-bottom: 16px; + margin-bottom: 12px; } .pagination { @@ -815,3 +815,242 @@ .storageGrid {grid-template-columns: 1fr;} .userToolbar {grid-template-columns: 1fr;} } + +.badgeWarn { + color: #E5A84B; + background: color-mix(in srgb, #E5A84B 14%, transparent); + border-color: transparent; +} + +.userList, +.flatList { + display: flex; + flex-direction: column; + padding: 2px 16px; + border-radius: var(--radius-sm); + background: var(--bg-card); +} + +.userRow, +.flatRow { + display: flex; + align-items: center; + gap: 12px; + padding: 12px 0; + border-bottom: 1px solid var(--border-soft); +} + +.userRow:last-child, +.flatRow:last-child { + border-bottom: 0; +} + +.userRow:hover .row-title, +.userRow:focus-visible .row-title { + color: var(--accent-strong); +} + +.dossier { + display: flex; + flex-direction: column; + gap: 16px; +} + +.dossier > .backButton { + align-self: flex-start; + margin-bottom: 0; +} + +.dossierHead { + display: flex; + align-items: flex-start; + gap: 16px; + padding: 18px; + border-radius: var(--radius); + background: var(--bg-card); +} + +.dossierIdentity { + display: flex; + flex-direction: column; + gap: 4px; + min-width: 0; + flex: 1; +} + +.dossierName { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 6px; + margin: 0; + font-size: var(--fs-xl); +} + +.dossierName .badge { + margin-inline-start: 0; +} + +.dossierBio { + margin: 4px 0 0; + font-size: var(--fs-sm); + color: var(--text-dim); + white-space: pre-wrap; + overflow-wrap: anywhere; +} + +.idButton { + display: inline-flex; + align-items: center; + gap: 6px; + padding: 2px 8px; + border: 0; + border-radius: var(--radius-2xs); + background: var(--bg-raised); + color: var(--text-dim); + font: inherit; + cursor: pointer; +} + +.idButton code { + font-size: var(--fs-xs); +} + +.idButton:hover { + color: var(--mw-text); +} + +.facts { + display: grid; + grid-template-columns: repeat(3, minmax(0, 1fr)); + gap: 10px; +} + +.fact { + display: flex; + flex-direction: column; + gap: 3px; + min-width: 0; + padding: 14px; + border-radius: var(--radius-sm); + background: var(--bg-card); +} + +.factLabel { + font-size: var(--fs-xs); + color: var(--text-dim); +} + +.factValue { + font-size: var(--fs-lg); + font-weight: 700; + color: var(--mw-text); + overflow-wrap: anywhere; +} + +.factDetail { + font-size: var(--fs-xs); + color: var(--text-faint); +} + +.dossierGrid { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); + gap: 12px; + align-items: start; +} + +.panel { + display: flex; + flex-direction: column; + gap: 10px; + padding: 16px; + border-radius: var(--radius-sm); + background: var(--bg-card); +} + +.panel .flatList { + padding: 0; + background: transparent; +} + +.panelFooter { + display: flex; + align-items: center; + justify-content: space-between; + gap: 10px; +} + +.detailList { + display: grid; + grid-template-columns: auto minmax(0, 1fr); + gap: 8px 16px; + margin: 0; + font-size: var(--fs-sm); +} + +.detailList dt { + color: var(--text-dim); +} + +.detailList dd { + display: flex; + flex-wrap: wrap; + gap: 4px 10px; + margin: 0; + color: var(--mw-text); +} + +.inlineLink { + color: var(--accent-strong); +} + +.mutedLine { + margin: 0; + font-size: var(--fs-sm); + color: var(--text-dim); +} + +.snapshot { + padding: 8px 10px; + border-radius: var(--radius-xs); + background: var(--bg-raised); + font-size: var(--fs-sm); + color: var(--text-dim); + white-space: pre-wrap; + overflow-wrap: anywhere; +} + +.commentText { + font-size: var(--fs-md); + white-space: pre-wrap; + overflow-wrap: anywhere; +} + +.stack { + display: flex; + flex-direction: column; + gap: 20px; +} + +@media (max-width: 620px) { + .facts { + grid-template-columns: repeat(2, minmax(0, 1fr)); + } + + .dossierHead { + flex-wrap: wrap; + } + + .dossierIdentity { + flex-basis: calc(100% - 72px); + } + + .idButton code { + overflow-wrap: anywhere; + } + + .userToolbar { + grid-template-columns: 1fr; + } +} diff --git a/src/community/pages/admin/BansSection.jsx b/src/community/pages/admin/BansSection.jsx index 781c64bba00..b24bcdd79d4 100644 --- a/src/community/pages/admin/BansSection.jsx +++ b/src/community/pages/admin/BansSection.jsx @@ -1,5 +1,6 @@ /* eslint-disable max-len */ import React from 'react'; +import {Link} from 'react-router-dom'; import {useCommunityIntl as useCommunityText} from '../../i18n.jsx'; import {Ban} from 'lucide-react'; import Avatar from '../../components/Avatar.jsx'; @@ -8,6 +9,7 @@ import EmptyState from '../../components/ui/EmptyState.jsx'; import SectionHeading from '../../components/ui/SectionHeading.jsx'; import {timeAgo} from '../../format'; import styles from '../Admin.module.css'; +import {adminUserPath} from './admin-links.js'; // Banned users, with a button to ban someone by name. const BansSection = ({bans, banByName, unban}) => { @@ -31,7 +33,7 @@ const BansSection = ({bans, banByName, unban}) => { size={28} />
- {`@${ban.username}`} + {`@${ban.username}`} {communityText('Banned by @{value1}{value2}', {value1: ban.by, value2: timeAgo(ban.created) ? ` · ${timeAgo(ban.created)} ago` : ''})} {ban.reason ? ` · ${ban.reason}` : ''} diff --git a/src/community/pages/admin/ReportsSection.jsx b/src/community/pages/admin/ReportsSection.jsx index 8f59cbdac15..e812b26b020 100644 --- a/src/community/pages/admin/ReportsSection.jsx +++ b/src/community/pages/admin/ReportsSection.jsx @@ -2,7 +2,7 @@ import React from 'react'; import {Link} from 'react-router-dom'; import {useCommunityIntl as useCommunityText} from '../../i18n.jsx'; -import {Flag} from 'lucide-react'; +import {Flag, UserSearch} from 'lucide-react'; import {projectUrl} from '../../api'; import Button from '../../components/ui/Button.jsx'; import EmptyState from '../../components/ui/EmptyState.jsx'; @@ -11,6 +11,7 @@ import StatusMessage from '../../components/ui/StatusMessage.jsx'; import {timeAgo} from '../../format'; import styles from '../Admin.module.css'; import EvidencePanel from './EvidencePanel.jsx'; +import {adminUserPath} from './admin-links.js'; // The open moderation queue: reports and support requests with their actions. const ReportsSection = ({reports, openCount, replyToSupport, act, warnFromReport, banFromReport}) => { @@ -76,6 +77,10 @@ const ReportsSection = ({reports, openCount, replyToSupport, act, warnFromReport ) : null}
+ {report.type === 'support' || report.subject || report.targetUser || report.type === 'user' ? ( + + ) : null} {report.type === 'support' ? ( ) : null} diff --git a/src/community/pages/admin/UserDetailCard.jsx b/src/community/pages/admin/UserDetailCard.jsx index 57cee17cc69..8995b635933 100644 --- a/src/community/pages/admin/UserDetailCard.jsx +++ b/src/community/pages/admin/UserDetailCard.jsx @@ -1,27 +1,102 @@ /* eslint-disable max-len */ +import PropTypes from 'prop-types'; import React, {useEffect, useRef, useState} from 'react'; import {Link} from 'react-router-dom'; import {useCommunityIntl as useCommunityText} from '../../i18n.jsx'; -import {ArrowLeft, FolderOpen} from 'lucide-react'; +import {getCommunityLocale} from '../../locale.js'; +import { + Activity, ArrowLeft, Copy, ExternalLink, Flag, FolderOpen, Gavel, LayoutDashboard, + MessageSquare, NotebookPen, UserCog +} from 'lucide-react'; import api, {projectUrl} from '../../api'; import Avatar from '../../components/Avatar.jsx'; +import UnderlineTabs from '../../components/UnderlineTabs.jsx'; +import {tabPanelProps} from '../../components/SectionTabs.jsx'; import Button from '../../components/ui/Button.jsx'; +import EmptyState from '../../components/ui/EmptyState.jsx'; import Notice from '../../components/ui/Notice.jsx'; +import SectionHeading from '../../components/ui/SectionHeading.jsx'; import StatusMessage from '../../components/ui/StatusMessage.jsx'; -import {formatBytes} from '../../format'; +import {formatBytes, formatDate, formatDateTime, timeAgo} from '../../format'; import styles from '../Admin.module.css'; import AdminActionDialog from './AdminActionDialog.jsx'; +import {commentLocation} from './admin-links.js'; const STANDING_LEVELS = ['good', 'warning', 'suspended', 'banned']; +const count = value => (Number(value) || 0).toLocaleString(getCommunityLocale()); + +const commentHref = comment => { + const where = commentLocation(comment.key); + const anchor = `#comment-id-${comment.id}`; + if (where.kind === 'project') return `${projectUrl(where.id)}${anchor}`; + if (where.kind === 'profile') return `/users/${where.id}${anchor}`; + if (where.kind === 'space') return `/spaces/${where.id}${anchor}`; + if (where.kind === 'bounty') return `/bounties/${where.id}${anchor}`; + if (where.kind === 'roadmap') return `/roadmap/entry/${where.id}`; + if (where.kind === 'pull') return `/project/${where.id}/pulls/${where.index}`; + return ''; +}; + +const Fact = ({label, value, detail}) => ( +
+ {label} + {value} + {detail ? {detail} : null} +
+); + +Fact.propTypes = { + label: PropTypes.node.isRequired, + value: PropTypes.node, + detail: PropTypes.node +}; + +const ReportList = ({reports, empty, communityText}) => ( + reports.length ? ( +
+ {reports.map(report => ( +
+
+ + {report.category || report.type} + + {report.resolved ? communityText('Closed') : communityText('Open')} + + + + {report.subject && report.subject !== report.reporter ? + communityText('Report on a {value1} by @{value2} about @{value3}', {value1: report.type, value2: report.reporter, value3: report.subject}) : + communityText('Report on a {value1} by @{value2}', {value1: report.type, value2: report.reporter})} + {' · '}{formatDateTime(report.created)} + {report.resolved && report.action ? ` · ${report.action.replace(/_/g, ' ')}${report.resolvedBy ? ` by @${report.resolvedBy}` : ''}` : ''} + + {report.reason ? {report.reason} : null} + {report.snapshot ? {report.snapshot} : null} +
+
+ ))} +
+ ) :

{empty}

+); + +ReportList.propTypes = { + reports: PropTypes.arrayOf(PropTypes.object).isRequired, + empty: PropTypes.node.isRequired, + communityText: PropTypes.func.isRequired +}; + const UserDetailCard = ({username, onBack}) => { const {text: communityText} = useCommunityText(); const [data, setData] = useState(null); const [error, setError] = useState(''); const [note, setNote] = useState(''); + const [tab, setTab] = useState('overview'); const [level, setLevel] = useState('good'); const [reasonText, setReasonText] = useState(''); const [message, setMessage] = useState(''); + const [adminNote, setAdminNote] = useState(''); + const [noteBusy, setNoteBusy] = useState(false); const [dialog, setDialog] = useState(null); const [dialogBusy, setDialogBusy] = useState(false); const [dialogError, setDialogError] = useState(''); @@ -35,6 +110,7 @@ const UserDetailCard = ({username, onBack}) => { setData(null); setError(''); setNote(''); + setTab('overview'); setDialog(null); setDialogError(''); setDialogBusy(false); @@ -43,6 +119,7 @@ const UserDetailCard = ({username, onBack}) => { if (!active) return; setData(result); setLevel((result.standing && result.standing.level) || 'good'); + setAdminNote((result.note && result.note.text) || ''); setReasonText(''); setMessage(''); }) @@ -66,54 +143,43 @@ const UserDetailCard = ({username, onBack}) => { .catch(() => {}); }; - const applyStanding = async () => { - if (!data) return; + const run = async (action, success) => { setError(''); setNote(''); try { - await api.admin.setStanding(data.username, level, reasonText.trim()); - setNote(communityText('Standing updated.')); + await action(); + if (success) setNote(success); refresh(); } catch (e) { setError(e.message || 'Action failed.'); } }; + const applyStanding = () => run( + () => api.admin.setStanding(data.username, level, reasonText.trim()), + communityText('Standing updated.') + ); + const sendMessage = async () => { - if (!data || !message.trim()) return; - setError(''); - setNote(''); - try { - await api.admin.messageUser(data.username, message.trim()); - setNote(communityText('Message sent.')); - setMessage(''); - } catch (e) { - setError(e.message || 'Action failed.'); - } + if (!message.trim()) return; + await run(() => api.admin.messageUser(data.username, message.trim()), communityText('Message sent.')); + setMessage(''); }; - const toggleComments = async () => { - if (!data) return; - setError(''); - setNote(''); - try { - await api.admin.updateUserProfile(data.username, {commentsOff: !data.commentsOff}); - refresh(); - } catch (e) { - setError(e.message || 'Action failed.'); - } + const toggleComments = () => run(() => api.admin.updateUserProfile(data.username, {commentsOff: !data.commentsOff})); + + const saveNote = async () => { + setNoteBusy(true); + await run(() => api.admin.setUserNote(data.username, adminNote.trim()), communityText('Note saved.')); + setNoteBusy(false); }; - const unshareProject = async pid => { - try { - await api.unpublish(pid); - setNote(communityText('Project unshared.')); - refresh(); - } catch (e) { - setError(e.message || 'Could not unshare.'); - } + const copyId = () => { + if (navigator.clipboard && data.userId) navigator.clipboard.writeText(data.userId).catch(() => {}); }; + const unshareProject = pid => run(() => api.unpublish(pid), communityText('Project unshared.')); + const deleteProject = pid => { if (deleteInFlight.current) return; const project = (data.projects || []).find(item => item.id === pid); @@ -149,7 +215,7 @@ const UserDetailCard = ({username, onBack}) => { } }; - if (error) { + if (error && !data) { return (
{error} @@ -162,8 +228,49 @@ const UserDetailCard = ({username, onBack}) => { } if (!data) return {communityText('Loading user details…')}; + const reports = data.reports || {about: [], filed: [], aboutCount: 0, filedCount: 0, openAboutCount: 0}; + const totals = data.totals || {}; + const sessions = data.sessions || {}; + const plan = data.plan || {}; + const standing = data.standing || {level: 'good', history: []}; + const projects = data.projects || []; + const comments = data.comments || []; + const activity = data.activity || []; + const quota = data.quota; + const quotaPct = quota && quota.limit > 0 ? Math.min(100, (quota.used / quota.limit) * 100) : 0; + + const activityText = item => { + const title = item.projectTitle || item.projectId || ''; + if (item.type === 'love') return communityText('Loved {value1}', {value1: title}); + if (item.type === 'favorite') return communityText('Favorited {value1}', {value1: title}); + if (item.type === 'share') return communityText('Shared {value1}', {value1: title}); + if (item.type === 'remix') return communityText('Remixed {value1} as {value2}', {value1: item.parentTitle || item.parentId || '', value2: title}); + if (item.type === 'release') return communityText('Released {value1} of {value2}', {value1: item.version || '', value2: title}); + return item.type; + }; + + const commentPlace = comment => { + const where = commentLocation(comment.key); + if (where.kind === 'project') return communityText('On project {value1}', {value1: where.id}); + if (where.kind === 'profile') return communityText('On the profile of @{value1}', {value1: where.id}); + if (where.kind === 'space') return communityText('In space {value1}', {value1: where.id}); + if (where.kind === 'bounty') return communityText('On bounty {value1}', {value1: where.id}); + if (where.kind === 'roadmap') return communityText('On a roadmap idea'); + if (where.kind === 'pull') return communityText('On pull request {value1} of project {value2}', {value1: where.index, value2: where.id}); + return comment.key; + }; + + const tabs = [ + {key: 'overview', label: communityText('Overview')}, + {key: 'projects', label: <>{communityText('Projects')} {projects.length}}, + {key: 'reports', label: <>{communityText('Reports')} {reports.aboutCount + reports.filedCount}}, + {key: 'comments', label: <>{communityText('Comments')} {comments.length}}, + {key: 'activity', label: communityText('Activity')}, + {key: 'moderation', label: communityText('Moderation')} + ]; + return ( -
+
{ {communityText('Back to list')} -
-
- -
- - {`@${data.username}`} - {data.admin ? {communityText('admin')} : null} - {(data.standing && data.standing.level) || communityText('good')} - - - {communityText('{value1} followers · {value2} following', {value1: data.followerCount || 0, value2: data.followingCount || 0})} - -
-
- -
- - setReasonText(e.target.value)} - /> - +
+ +
+

+ {`@${data.username}`} + {data.admin ? {communityText('Admin')} : null} + {data.banned ? ( + {communityText('Banned')} + ) : standing.level !== 'good' ? ( + {standing.level} + ) : null} + {data.student ? {communityText('Student')} : null} + {data.minor && !data.student ? {communityText('Under 18')} : null} +

+ + {data.userId ? ( + + ) : communityText('No Rotur ID recorded')} + + {data.bio ?

{data.bio}

: null}
- - -
- setMessage(e.target.value)} - /> - +
+
+
- +
+ + + + + + +
- {data.quota ? ( -
- {communityText('Storage')} - - - - - - {communityText('{value1} of {value2}', {value1: formatBytes(data.quota.used), value2: formatBytes(data.quota.limit)})} - - + {error ? {error} : null} + {note ? {note} : null} + + +
+ {tab === 'overview' ? ( +
+
+ +