Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/community/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,14 @@ const api = {
bans: () => request('/admin/bans'),
ban: (username, reason) => request('/admin/ban', {method: 'POST', body: {username, reason}}),
unban: username => request('/admin/unban', {method: 'POST', body: {username}}),
shadowBans: () => request('/admin/shadowbans', {cache: false}),
shadowBan: (username, reason) => request('/admin/shadowban', {method: 'POST', body: {username, reason}}),
liftShadowBan: username => request('/admin/unshadowban', {method: 'POST', body: {username}}),
hideProject: (id, reason) => request(`/admin/projects/${id}/hide`, {method: 'POST', body: {reason}}),
restoreProject: id => request(`/admin/projects/${id}/restore`, {method: 'POST'}),
shadowBanProject: (id, reason) =>
request(`/admin/projects/${id}/shadowban`, {method: 'POST', body: {reason}}),
liftProjectShadowBan: id => request(`/admin/projects/${id}/unshadowban`, {method: 'POST'}),
getUser: username => request(`/admin/user?username=${encodeURIComponent(username)}`),
setStanding: (username, level, reason) =>
request('/admin/standing', {method: 'POST', body: {username, level, reason}}),
Expand Down
2 changes: 1 addition & 1 deletion src/community/notification-preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const setNotificationPreferences = preferences => {
};

const categoryForNotification = type => {
if (['standing', 'moderation', 'news', 'report_update'].includes(type)) return 'system';
if (['standing', 'moderation', 'project_hidden', 'project_restored', 'news', 'report_update'].includes(type)) return 'system';
if (['purchase', 'donation', 'cosmetic_gift', 'item_received', 'item_sold', 'item_purchased'].includes(type)) return 'economy';
if (['remix', 'contribution', 'project_feedback', 'project_review', 'roadmap_comment', 'space_project', 'space_comment', 'space_curator_invite', 'space_curator_accepted', 'space_curator_declined', 'space_curator_removed', 'release'].includes(type)) return 'projects';
return 'social';
Expand Down
15 changes: 14 additions & 1 deletion src/community/notification-text.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {isMilestoneNotification, milestoneLink, milestoneText} from './milestone
// Shared by the notifications page and the Home preview so both describe and
// link notifications the same way.

export const SYSTEM_TYPES = ['standing', 'moderation', 'news', 'report_update'];
export const SYSTEM_TYPES = ['standing', 'moderation', 'project_hidden', 'project_restored', 'news', 'report_update'];

export const GROUP_TYPES = [
'group_invite',
Expand Down Expand Up @@ -138,6 +138,7 @@ const reportOutcome = (action, t) => {
case 'warn_user': return t('Your report was actioned with a warning.');
case 'ban_user': return t('Your report was actioned with a ban.');
case 'unshare_project': return t('Your report was actioned; the project was unshared.');
case 'hide_project': return t('Your report was actioned; the project was hidden.');
default: return t('Your report was reviewed.');
}
};
Expand Down Expand Up @@ -223,6 +224,18 @@ export const describeNotification = (n, t, actor) => {
case 'standing': return n.reason ?
t('Your account standing is now {level}: {reason}', {level: strong(n.level), reason: n.reason}) :
t('Your account standing is now {level}.', {level: strong(n.level)});
case 'project_hidden':
if (project) {
return n.reason ?
t('A moderator hid {project}: {reason}', {project, reason: n.reason}) :
t('A moderator hid {project}.', {project});
}
return n.reason ?
t('A moderator hid your project: {reason}', {reason: n.reason}) :
t('A moderator hid your project.');
case 'project_restored': return project ?
t('A moderator restored {project}.', {project}) :
t('A moderator restored your project.');
case 'moderation': return n.message ?
t.plain(n.message) :
t('A moderator sent you a message.');
Expand Down
78 changes: 76 additions & 2 deletions src/community/pages/Admin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {useCommunityIntl as useCommunityText} from '../i18n.jsx';
import React, {useRef, useState} from 'react';
import {useSearchParams} from 'react-router-dom';
import {
Activity, AlertTriangle, Ban, BarChart3, Flag, FolderOpen, HardDrive, Puzzle, ShieldCheck, User
Activity, AlertTriangle, Ban, BarChart3, EyeOff, Flag, FolderOpen, Ghost, HardDrive, Puzzle, ShieldCheck, User
} from 'lucide-react';
import api from '../api';
import {useUser} from '../UserContext.jsx';
Expand All @@ -23,6 +23,7 @@ import ExtensionManager from './admin/ExtensionManager.jsx';
import ErrorManager from './admin/ErrorManager.jsx';
import ReportsSection from './admin/ReportsSection.jsx';
import BansSection from './admin/BansSection.jsx';
import ShadowBansSection from './admin/ShadowBansSection.jsx';
import AdminsSection from './admin/AdminsSection.jsx';
import useAdminData from './admin/use-admin-data.js';

Expand All @@ -42,7 +43,7 @@ const SECTIONS = [
const Admin = () => {
const {text: communityText} = useCommunityText();
const {user, loading} = useUser();
const {reports, openErrors, bans, admins, error, setError, load} = useAdminData(user);
const {reports, openErrors, bans, shadowBans, admins, error, setError, load} = useAdminData(user);
const [newAdmin, setNewAdmin] = useState('');
const [searchParams, setSearchParams] = useSearchParams();
const requested = searchParams.get('section');
Expand Down Expand Up @@ -93,6 +94,20 @@ const Admin = () => {
});
};

const hideFromReport = report => {
setDialogError('');
setDialog({
kind: 'hide-report',
report,
title: communityText('Hide this project?'),
description: communityText('The project becomes private and its creator can\'t share it again until an admin restores it. They get a notification with your reason.'),
action: communityText('Hide project'),
danger: true,
fields: [{key: 'reason', label: communityText('Reason for the creator'), value: '', multiline: true, maxLength: 1000}],
icon: EyeOff
});
};

const warnFromReport = report => {
setDialogError('');
setDialog({
Expand Down Expand Up @@ -137,6 +152,22 @@ const Admin = () => {
});
};

const shadowBanByName = () => {
setDialogError('');
setDialog({
kind: 'shadow-ban-user',
title: communityText('Shadow ban a user'),
description: communityText('Their projects, comments and profile leave every list for everyone else. They are not told and still see everything as normal.'),
action: communityText('Shadow ban'),
danger: true,
fields: [
{key: 'username', label: communityText('Username'), value: '', maxLength: 80},
{key: 'reason', label: communityText('Private note for admins'), value: '', multiline: true, maxLength: 1000}
],
icon: Ghost
});
};

const updateDialogField = (key, value) => {
setDialog(current => ({
...current,
Expand All @@ -154,6 +185,14 @@ const Admin = () => {
setDialogError(communityText('Enter a reply.'));
return;
}
if (dialog.kind === 'hide-report' && !values.reason) {
setDialogError(communityText('Tell the creator why their project is hidden.'));
return;
}
if (dialog.kind === 'shadow-ban-user' && !values.username) {
setDialogError(communityText('Enter a username.'));
return;
}
if (dialog.kind === 'warn-report' && !values.reason) {
setDialogError(communityText('Enter a warning reason.'));
return;
Expand All @@ -170,6 +209,9 @@ const Admin = () => {
await api.admin.messageUser(dialog.report.reporter, values.message);
await api.admin.reportAction(dialog.report.id, 'dismiss');
window.dispatchEvent(new Event('mw:reports-updated'));
} else if (dialog.kind === 'hide-report') {
await api.admin.reportAction(dialog.report.id, 'hide_project', values.reason);
window.dispatchEvent(new Event('mw:reports-updated'));
} else if (dialog.kind === 'warn-report') {
await api.admin.reportAction(dialog.report.id, 'warn_user', values.reason);
window.dispatchEvent(new Event('mw:reports-updated'));
Expand All @@ -178,6 +220,8 @@ const Admin = () => {
window.dispatchEvent(new Event('mw:reports-updated'));
} else if (dialog.kind === 'ban-user') {
await api.admin.ban(values.username, values.reason);
} else if (dialog.kind === 'shadow-ban-user') {
await api.admin.shadowBan(values.username, values.reason);
}
setDialog(null);
load();
Expand All @@ -199,6 +243,26 @@ const Admin = () => {
}
};

const liftShadowBan = async username => {
try {
setError('');
await api.admin.liftShadowBan(username);
load();
} catch (e) {
setError(e.message || 'Could not lift that shadow ban.');
}
};

const liftProjectShadowBan = async id => {
try {
setError('');
await api.admin.liftProjectShadowBan(id);
load();
} catch (e) {
setError(e.message || 'Could not lift that shadow ban.');
}
};

const addAdmin = async () => {
const name = newAdmin.trim();
if (!name) return;
Expand Down Expand Up @@ -279,6 +343,7 @@ const Admin = () => {
openCount={openCount}
replyToSupport={replyToSupport}
act={act}
hideFromReport={hideFromReport}
warnFromReport={warnFromReport}
banFromReport={banFromReport}
/>
Expand Down Expand Up @@ -316,6 +381,15 @@ const Admin = () => {
/>
) : null}

{active === 'bans' ? (
<ShadowBansSection
shadowBans={shadowBans}
shadowBanByName={shadowBanByName}
liftUser={liftShadowBan}
liftProject={liftProjectShadowBan}
/>
) : null}

{active === 'admins' ? (
<AdminsSection
admins={admins}
Expand Down
3 changes: 3 additions & 0 deletions src/community/pages/Admin.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
}

.content {
display: flex;
flex-direction: column;
gap: 40px;
min-width: 0;
}

Expand Down
1 change: 1 addition & 0 deletions src/community/pages/MyStuff.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const trashPurgeConfirmation = project => ({
});

const visibilityLabel = project => {
if (project.moderationHidden) return 'Hidden by a moderator';
if (project.contributionOnly) return 'Contribution only';
const v = project.visibility || (project.shared ? 'public' : 'private');
if (v === 'public') return 'Shared';
Expand Down
2 changes: 2 additions & 0 deletions src/community/pages/Notifications.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ const TYPE_STYLE = {
donation: {icon: Coins, color: '#e0a63c'},
standing: {icon: ShieldAlert, color: '#e35d6a'},
moderation: {icon: ShieldAlert, color: '#e35d6a'},
project_hidden: {icon: ShieldAlert, color: '#e35d6a'},
project_restored: {icon: ShieldAlert, color: '#3fae6a'},
news: {icon: Megaphone, color: '#9a6ff0'},
report_update: {icon: Flag, color: '#e35d6a'},
contribution: {icon: GitPullRequest, color: '#4c8dff'},
Expand Down
17 changes: 17 additions & 0 deletions src/community/pages/Project.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import ProjectHeader from './project/ProjectHeader.jsx';
import ForkSetupModal from './project/ForkSetupModal.jsx';
import PlayerPrompts from './project/PlayerPrompts.jsx';
import ProjectNotices from './project/ProjectNotices.jsx';
import ProjectModerationDialog from './admin/ProjectModerationDialog.jsx';
import ProjectStage from './project/ProjectStage.jsx';
import ProjectActivity from './project/ProjectActivity.jsx';

Expand Down Expand Up @@ -86,6 +87,7 @@ const Project = () => {
const [savingTitle, setSavingTitle] = useState(false);
const [thumbnailStatus, setThumbnailStatus] = useState('idle');
const [reporting, setReporting] = useState(false);
const [moderation, setModeration] = useState(null);
const [copied, setCopied] = useState(false);
const [collectionOpen, setCollectionOpen] = useState(false);
const thumbInput = useRef(null);
Expand Down Expand Up @@ -718,8 +720,21 @@ const Project = () => {
menuReport={menuReport}
setActionError={setActionError}
setDeleteConfirm={setDeleteConfirm}
openModeration={setModeration}
/>

{user && user.isAdmin ? (
<ProjectModerationDialog
kind={moderation}
project={project}
onClose={() => setModeration(null)}
onDone={() => {
setModeration(null);
load();
}}
/>
) : null}

{collectionOpen ? <CollectionSaveModal project={project} onClose={() => setCollectionOpen(false)} /> : null}

{deleteConfirm ? (
Expand Down Expand Up @@ -802,6 +817,8 @@ const Project = () => {
projectThemeApplied={projectThemeApplied}
revertTheme={revertTheme}
setRevertTheme={setRevertTheme}
isAdmin={Boolean(user && user.isAdmin)}
openModeration={setModeration}
/>

<div className={styles.stageRow}>
Expand Down
53 changes: 35 additions & 18 deletions src/community/pages/admin/ProjectManager.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import StatusMessage from '../../components/ui/StatusMessage.jsx';
import useLatest from '../../use-latest.js';
import styles from '../Admin.module.css';
import AdminActionDialog from './AdminActionDialog.jsx';
import ProjectModerationDialog from './ProjectModerationDialog.jsx';

const ProjectManager = () => {
const {text: communityText} = useCommunityText();
Expand All @@ -22,6 +23,7 @@ const ProjectManager = () => {
const [dialog, setDialog] = useState(null);
const [dialogError, setDialogError] = useState('');
const [dialogBusy, setDialogBusy] = useState(false);
const [moderation, setModeration] = useState(null);
const actionInFlight = useRef(false);
const beginSearch = useLatest();

Expand All @@ -41,22 +43,20 @@ const ProjectManager = () => {
search('');
}, [search]);

const unshare = async id => {
const moderate = (kind, project) => {
if (actionInFlight.current) return;
const releaseAction = () => {
actionInFlight.current = false;
};
actionInFlight.current = true;
try {
setError('');
await api.unpublish(id);
setNote(communityText('Project unshared.'));
search(query);
} catch (e) {
setError(e.message || 'Could not unshare that project.');
} finally {
releaseAction();
}
setError('');
setNote('');
setModeration({kind, project});
};

const moderationDone = kind => {
setModeration(null);
if (kind === 'hide') setNote(communityText('Project hidden. Its creator was told why.'));
else if (kind === 'restore') setNote(communityText('Project restored.'));
else if (kind === 'shadow') setNote(communityText('Project shadow banned.'));
else setNote(communityText('Shadow ban lifted.'));
search(query);
};

const remove = id => {
Expand Down Expand Up @@ -106,6 +106,12 @@ const ProjectManager = () => {
}}
onConfirm={confirmRemove}
/>
<ProjectModerationDialog
kind={moderation ? moderation.kind : null}
project={moderation ? moderation.project : null}
onClose={() => setModeration(null)}
onDone={moderationDone}
/>
<SectionHeading icon={FolderOpen} title={communityText('Projects')} />
<div className={styles.addAdmin}>
<input
Expand Down Expand Up @@ -133,15 +139,26 @@ const ProjectManager = () => {
<div className={styles.rowInfo}>
<span className={styles.rowTitle}>
<Link to={projectUrl(project)}>{project.title || project.id}</Link>
{project.moderationHidden ? <span className={`${styles.badge} ${styles.badgeWarn}`}>{communityText('Hidden')}</span> : null}
{project.projectShadowBanned ? <span className={`${styles.badge} ${styles.badgeWarn}`}>{communityText('Shadow banned')}</span> : null}
{project.ownerShadowBanned ? <span className={`${styles.badge} ${styles.badgeWarn}`}>{communityText('Creator shadow banned')}</span> : null}
{project.ownerBanned ? <span className={`${styles.badge} ${styles.badgeDanger}`}>{communityText('Creator banned')}</span> : null}
</span>
<span className={styles.rowMeta}>
{communityText('by @{value1} · {value2}', {value1: project.owner, value2: project.shared ? communityText('Shared') : communityText('Unshared')})}
</span>
</div>
<div className={styles.rowActions}>
{project.shared ? (
<Button onClick={() => unshare(project.id)}>{communityText('Unshare')}</Button>
) : null}
{project.moderationHidden ? (
<Button onClick={() => moderate('restore', project)}>{communityText('Restore')}</Button>
) : (
<Button onClick={() => moderate('hide', project)}>{communityText('Hide')}</Button>
)}
{project.projectShadowBanned ? (
<Button onClick={() => moderate('unshadow', project)}>{communityText('Lift shadow ban')}</Button>
) : (
<Button onClick={() => moderate('shadow', project)}>{communityText('Shadow ban')}</Button>
)}
<Button variant="danger" onClick={() => remove(project.id)}>{communityText('Delete')}</Button>
</div>
</div>
Expand Down
Loading
Loading