setCollectionOpen(false)} /> : null}
{deleteConfirm ? (
@@ -802,6 +817,8 @@ const Project = () => {
projectThemeApplied={projectThemeApplied}
revertTheme={revertTheme}
setRevertTheme={setRevertTheme}
+ isAdmin={Boolean(user && user.isAdmin)}
+ openModeration={setModeration}
/>
diff --git a/src/community/pages/admin/ProjectManager.jsx b/src/community/pages/admin/ProjectManager.jsx
index 18f7c0370b6..8a42c905793 100644
--- a/src/community/pages/admin/ProjectManager.jsx
+++ b/src/community/pages/admin/ProjectManager.jsx
@@ -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();
@@ -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();
@@ -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 => {
@@ -106,6 +106,12 @@ const ProjectManager = () => {
}}
onConfirm={confirmRemove}
/>
+
setModeration(null)}
+ onDone={moderationDone}
+ />
{
{project.title || project.id}
+ {project.moderationHidden ? {communityText('Hidden')} : null}
+ {project.projectShadowBanned ? {communityText('Shadow banned')} : null}
+ {project.ownerShadowBanned ? {communityText('Creator shadow banned')} : null}
+ {project.ownerBanned ? {communityText('Creator banned')} : null}
{communityText('by @{value1} · {value2}', {value1: project.owner, value2: project.shared ? communityText('Shared') : communityText('Unshared')})}
- {project.shared ? (
- unshare(project.id)}>{communityText('Unshare')}
- ) : null}
+ {project.moderationHidden ? (
+ moderate('restore', project)}>{communityText('Restore')}
+ ) : (
+ moderate('hide', project)}>{communityText('Hide')}
+ )}
+ {project.projectShadowBanned ? (
+ moderate('unshadow', project)}>{communityText('Lift shadow ban')}
+ ) : (
+ moderate('shadow', project)}>{communityText('Shadow ban')}
+ )}
remove(project.id)}>{communityText('Delete')}
diff --git a/src/community/pages/admin/ProjectModerationDialog.jsx b/src/community/pages/admin/ProjectModerationDialog.jsx
new file mode 100644
index 00000000000..38cf413b989
--- /dev/null
+++ b/src/community/pages/admin/ProjectModerationDialog.jsx
@@ -0,0 +1,122 @@
+/* eslint-disable max-len */
+import PropTypes from 'prop-types';
+import React, {useEffect, useRef, useState} from 'react';
+import {Eye, EyeOff, Ghost} from 'lucide-react';
+import {useCommunityIntl as useCommunityText} from '../../i18n.jsx';
+import api from '../../api';
+import AdminActionDialog from './AdminActionDialog.jsx';
+
+const dialogFor = (kind, title, communityText) => {
+ if (kind === 'hide') {
+ return {
+ title: communityText('Hide {value1}?', {value1: title}),
+ 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,
+ icon: EyeOff,
+ fields: [{key: 'reason', label: communityText('Reason for the creator'), value: '', multiline: true, maxLength: 1000}]
+ };
+ }
+ if (kind === 'restore') {
+ return {
+ title: communityText('Restore {value1}?', {value1: title}),
+ description: communityText('The project goes back to how it was shared before it was hidden, and its creator gets a notification.'),
+ action: communityText('Restore project'),
+ icon: Eye
+ };
+ }
+ if (kind === 'shadow') {
+ return {
+ title: communityText('Shadow ban {value1}?', {value1: title}),
+ description: communityText('The project leaves explore, search, profiles and every other list, but its link keeps working. Its creator is not told and still sees it everywhere.'),
+ action: communityText('Shadow ban'),
+ danger: true,
+ icon: Ghost,
+ fields: [{key: 'reason', label: communityText('Private note for admins'), value: '', multiline: true, maxLength: 1000}]
+ };
+ }
+ return {
+ title: communityText('Lift the shadow ban on {value1}?', {value1: title}),
+ description: communityText('The project shows up in lists again.'),
+ action: communityText('Lift shadow ban'),
+ icon: Ghost
+ };
+};
+
+const runAction = (kind, id, reason) => {
+ if (kind === 'hide') return api.admin.hideProject(id, reason);
+ if (kind === 'restore') return api.admin.restoreProject(id);
+ if (kind === 'shadow') return api.admin.shadowBanProject(id, reason);
+ return api.admin.liftProjectShadowBan(id);
+};
+
+const ProjectModerationDialog = ({kind, project, onClose, onDone}) => {
+ const {text: communityText} = useCommunityText();
+ const [dialog, setDialog] = useState(null);
+ const [busy, setBusy] = useState(false);
+ const [error, setError] = useState('');
+ const inFlight = useRef(false);
+
+ useEffect(() => {
+ setError('');
+ setDialog(kind && project ? dialogFor(kind, project.title || project.id, communityText) : null);
+ }, [kind, project && project.id]);
+
+ if (!dialog) return null;
+
+ const updateField = (key, value) => {
+ setError('');
+ setDialog(current => ({
+ ...current,
+ fields: current.fields.map(field => (field.key === key ? {...field, value} : field))
+ }));
+ };
+
+ const confirm = async () => {
+ if (inFlight.current) return;
+ const reason = ((dialog.fields || []).find(field => field.key === 'reason') || {value: ''}).value.trim();
+ if (kind === 'hide' && !reason) {
+ setError(communityText('Tell the creator why their project is hidden.'));
+ return;
+ }
+ const release = () => {
+ inFlight.current = false;
+ };
+ inFlight.current = true;
+ setBusy(true);
+ try {
+ const result = await runAction(kind, project.id, reason);
+ onDone(kind, result && result.project);
+ } catch (e) {
+ setError(e.message || communityText('Could not update this project.'));
+ } finally {
+ release();
+ setBusy(false);
+ }
+ };
+
+ return (
+ {
+ if (!inFlight.current) onClose();
+ }}
+ onConfirm={confirm}
+ />
+ );
+};
+
+ProjectModerationDialog.propTypes = {
+ kind: PropTypes.oneOf(['hide', 'restore', 'shadow', 'unshadow']),
+ project: PropTypes.shape({
+ id: PropTypes.string,
+ title: PropTypes.string
+ }),
+ onClose: PropTypes.func.isRequired,
+ onDone: PropTypes.func.isRequired
+};
+
+export default ProjectModerationDialog;
diff --git a/src/community/pages/admin/ReportsSection.jsx b/src/community/pages/admin/ReportsSection.jsx
index e2434eb17f6..69ac1652555 100644
--- a/src/community/pages/admin/ReportsSection.jsx
+++ b/src/community/pages/admin/ReportsSection.jsx
@@ -14,7 +14,7 @@ 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}) => {
+const ReportsSection = ({reports, openCount, replyToSupport, act, hideFromReport, warnFromReport, banFromReport}) => {
const {text: communityText} = useCommunityText();
return (
@@ -85,7 +85,7 @@ const ReportsSection = ({reports, openCount, replyToSupport, act, warnFromReport
replyToSupport(report)}>{communityText('Reply and close')}
) : null}
{report.type === 'project' ? (
- act(report.id, 'unshare_project')}>{communityText('Unshare')}
+ hideFromReport(report)}>{communityText('Hide project')}
) : null}
{report.type !== 'support' ? (
warnFromReport(report)}>
diff --git a/src/community/pages/admin/ShadowBansSection.jsx b/src/community/pages/admin/ShadowBansSection.jsx
new file mode 100644
index 00000000000..13d2b8a2daa
--- /dev/null
+++ b/src/community/pages/admin/ShadowBansSection.jsx
@@ -0,0 +1,94 @@
+/* eslint-disable max-len */
+import PropTypes from 'prop-types';
+import React from 'react';
+import {Link} from 'react-router-dom';
+import {useCommunityIntl as useCommunityText} from '../../i18n.jsx';
+import {Ghost} from 'lucide-react';
+import {projectUrl} from '../../api';
+import Avatar from '../../components/Avatar.jsx';
+import Button from '../../components/ui/Button.jsx';
+import EmptyState from '../../components/ui/EmptyState.jsx';
+import SectionHeading from '../../components/ui/SectionHeading.jsx';
+import {timeAgoText} from '../../format';
+import styles from '../Admin.module.css';
+import {adminUserPath} from './admin-links.js';
+
+const ShadowBansSection = ({shadowBans, shadowBanByName, liftUser, liftProject}) => {
+ const {text: communityText} = useCommunityText();
+ const users = shadowBans.users || [];
+ const projects = shadowBans.projects || [];
+ const meta = entry => communityText('Shadow banned by @{value1}{value2}', {value1: entry.by, value2: timeAgoText(entry.created) ? ` · ${timeAgoText(entry.created)}` : ''});
+ return (
+
+ {communityText('Shadow ban a user…')} }
+ />
+ {users.length || projects.length ? (
+
+ {users.map(entry => (
+
+
+
+ {`@${entry.username}`}
+
+ {meta(entry)}
+ {entry.reason ? ` · ${entry.reason}` : ''}
+
+
+
+ liftUser(entry.username)}>{communityText('Lift shadow ban')}
+
+
+ ))}
+ {projects.map(entry => (
+
+
+
+ {entry.title || entry.id}
+ {communityText('Project')}
+
+
+ {communityText('by @{value1}', {value1: entry.owner})}
+ {` · ${meta(entry)}`}
+ {entry.reason ? ` · ${entry.reason}` : ''}
+
+
+
+ liftProject(entry.id)}>{communityText('Lift shadow ban')}
+
+
+ ))}
+
+ ) : (
+
+ {communityText('No creators or projects are shadow banned.')}
+
+ )}
+
+ );
+};
+
+ShadowBansSection.propTypes = {
+ shadowBans: PropTypes.shape({
+ users: PropTypes.arrayOf(PropTypes.object),
+ projects: PropTypes.arrayOf(PropTypes.object)
+ }).isRequired,
+ shadowBanByName: PropTypes.func.isRequired,
+ liftUser: PropTypes.func.isRequired,
+ liftProject: PropTypes.func.isRequired
+};
+
+export default ShadowBansSection;
diff --git a/src/community/pages/admin/UserDetailCard.jsx b/src/community/pages/admin/UserDetailCard.jsx
index 82a349b81b0..5170be56497 100644
--- a/src/community/pages/admin/UserDetailCard.jsx
+++ b/src/community/pages/admin/UserDetailCard.jsx
@@ -5,7 +5,7 @@ import {Link} from 'react-router-dom';
import {useCommunityIntl as useCommunityText} from '../../i18n.jsx';
import {getCommunityLocale} from '../../locale.js';
import {
- Activity, ArrowLeft, Copy, ExternalLink, Flag, FolderOpen, Gavel, LayoutDashboard,
+ Activity, ArrowLeft, Copy, ExternalLink, Flag, FolderOpen, Gavel, Ghost, LayoutDashboard,
MessageSquare, NotebookPen, UserCog
} from 'lucide-react';
import api, {projectUrl} from '../../api';
@@ -20,6 +20,7 @@ import StatusMessage from '../../components/ui/StatusMessage.jsx';
import {formatBytes, formatDate, formatDateTime, timeAgoText} from '../../format';
import styles from '../Admin.module.css';
import AdminActionDialog from './AdminActionDialog.jsx';
+import ProjectModerationDialog from './ProjectModerationDialog.jsx';
import {reportTypeLabel, standingLabel} from './labels.js';
import {commentLocation} from './admin-links.js';
@@ -104,6 +105,8 @@ const UserDetailCard = ({username, onBack, onChanged}) => {
const [dialogBusy, setDialogBusy] = useState(false);
const [dialogError, setDialogError] = useState('');
const [busyAction, setBusyAction] = useState('');
+ const [shadowNote, setShadowNote] = useState('');
+ const [moderation, setModeration] = useState(null);
const deleteInFlight = useRef(false);
const actionInFlight = useRef(false);
const currentUsername = useRef(username);
@@ -129,6 +132,8 @@ const UserDetailCard = ({username, onBack, onChanged}) => {
setAdminNote((result.note && result.note.text) || '');
setReasonText('');
setMessage('');
+ setShadowNote('');
+ setModeration(null);
})
.catch(e => {
if (!active) return;
@@ -220,7 +225,23 @@ const UserDetailCard = ({username, onBack, onChanged}) => {
if (navigator.clipboard && data.userId) navigator.clipboard.writeText(data.userId).catch(() => {});
};
- const unshareProject = pid => run(`unshare:${pid}`, () => api.unpublish(pid), communityText('Project unshared.'));
+ const shadowBanned = Boolean(data && data.shadowBan && data.shadowBan.created);
+
+ const toggleShadowBan = async () => {
+ const done = await run(
+ 'shadow',
+ () => (shadowBanned ? api.admin.liftShadowBan(data.username) : api.admin.shadowBan(data.username, shadowNote.trim())),
+ shadowBanned ? communityText('Shadow ban lifted.') : communityText('Shadow banned. They are not told.')
+ );
+ if (done) setShadowNote('');
+ };
+
+ const moderationDone = kind => {
+ setModeration(null);
+ setNote(kind === 'hide' ? communityText('Project hidden. Its creator was told why.') : communityText('Project restored.'));
+ refresh(currentUsername.current);
+ if (onChanged) onChanged();
+ };
const deleteProject = pid => {
if (deleteInFlight.current) return;
@@ -337,6 +358,12 @@ const UserDetailCard = ({username, onBack, onChanged}) => {
}}
onConfirm={confirmDialog}
/>
+ setModeration(null)}
+ onDone={moderationDone}
+ />
{communityText('Back to list')}
@@ -353,6 +380,7 @@ const UserDetailCard = ({username, onBack, onChanged}) => {
) : standing.level !== 'good' ? (
{standingLabel(standing.level, communityText)}
) : null}
+ {shadowBanned ? {communityText('Shadow banned')} : null}
{data.student ? {communityText('Student')} : null}
{data.minor && !data.student ? {communityText('Under 18')} : null}
@@ -472,6 +500,7 @@ const UserDetailCard = ({username, onBack, onChanged}) => {
{project.title || project.id}
{project.shared ? communityText('Shared') : communityText('Not shared')}
+ {project.moderationHidden ? {communityText('Hidden')} : null}
{communityText('{value1} views · {value2} hearts · {value3} · edited {value4}', {
@@ -483,9 +512,11 @@ const UserDetailCard = ({username, onBack, onChanged}) => {
- {project.shared ? (
- unshareProject(project.id)}>{communityText('Unshare')}
- ) : null}
+ {project.moderationHidden ? (
+ setModeration({kind: 'restore', project})}>{communityText('Restore')}
+ ) : (
+ setModeration({kind: 'hide', project})}>{communityText('Hide')}
+ )}
deleteProject(project.id)}>{communityText('Delete')}
@@ -605,6 +636,35 @@ const UserDetailCard = ({username, onBack, onChanged}) => {
) : {communityText('No standing changes recorded.')}
}
+
+
+
+ {communityText('Their projects, comments and profile leave every list for everyone else, and they stop sending notifications. Links still work, and they are not told.')}
+
+ {shadowBanned ? (
+
+ {communityText('Shadow banned by @{value1} on {value2}.', {value1: data.shadowBan.by || '', value2: formatDate(data.shadowBan.created)})}
+ {data.shadowBan.reason ? ` ${data.shadowBan.reason}` : ''}
+
+ ) : (
+ setShadowNote(e.target.value)}
+ />
+ )}
+
+
+ {shadowBanned ? communityText('Lift shadow ban') : communityText('Shadow ban')}
+
+