[profiles][ban] save profile snapshots for reports and bans

This commit is contained in:
Andrea 2021-12-18 22:37:26 +01:00
parent feb08abfe9
commit 2edb167a00
4 changed files with 18 additions and 5 deletions

View File

@ -0,0 +1,7 @@
-- Up
ALTER TABLE users ADD COLUMN banSnapshot TEXT NULL;
ALTER TABLE reports ADD COLUMN snapshot TEXT NULL;
-- Down

View File

@ -7,6 +7,7 @@ import {calculateStats, statsFile} from '../../src/stats';
import fs from 'fs'; import fs from 'fs';
import { caches } from "../../src/cache"; import { caches } from "../../src/cache";
import mailer from "../../src/mailer"; import mailer from "../../src/mailer";
import {profilesSnapshot} from "./profile";
const router = Router(); const router = Router();
@ -155,7 +156,8 @@ router.post('/admin/ban/:username', handleErrorAsync(async (req, res) => {
UPDATE users UPDATE users
SET bannedReason = ${req.body.reason}, SET bannedReason = ${req.body.reason},
bannedTerms = ${req.body.terms.join(',')}, bannedTerms = ${req.body.terms.join(',')},
bannedBy = ${req.user.id} bannedBy = ${req.user.id},
banSnapshot = ${await profilesSnapshot(req.db, normalise(req.params.username))}
WHERE id = ${user.id} WHERE id = ${user.id}
`); `);
mailer(user.email, 'ban', {reason: req.body.reason}); mailer(user.email, 'ban', {reason: req.body.reason});

View File

@ -43,7 +43,7 @@ const verifyLinks = (links, authenticators) => {
return verifiedLinks; return verifiedLinks;
} }
const fetchProfiles = async (db, username, self, isAdmin) => { const fetchProfiles = async (db, username, self) => {
const profiles = await db.all(SQL` const profiles = await db.all(SQL`
SELECT profiles.* SELECT profiles.*
FROM profiles FROM profiles
@ -88,6 +88,10 @@ const fetchProfiles = async (db, username, self, isAdmin) => {
return p; return p;
}; };
export const profilesSnapshot = async (db, username) => {
return JSON.stringify(await fetchProfiles(db, username, true), null, 4);
}
const susRegexes = fs.readFileSync(__dirname + '/../../sus.txt').toString('utf-8').split('\n').filter(x => !!x); const susRegexes = fs.readFileSync(__dirname + '/../../sus.txt').toString('utf-8').split('\n').filter(x => !!x);
function* isSuspicious(profile) { function* isSuspicious(profile) {
@ -288,8 +292,8 @@ router.post('/profile/report/:username', handleErrorAsync(async (req, res) => {
} }
await req.db.get(SQL` await req.db.get(SQL`
INSERT INTO reports (id, userId, reporterId, isAutomatic, comment, isHandled) INSERT INTO reports (id, userId, reporterId, isAutomatic, comment, isHandled, snapshot)
VALUES (${ulid()}, ${user.id}, ${req.user.id}, 0, ${req.body.comment}, 0); VALUES (${ulid()}, ${user.id}, ${req.user.id}, 0, ${req.body.comment}, 0, ${await profilesSnapshot(req.db, normalise(req.params.username))});
`); `);
return res.json('OK'); return res.json('OK');

View File

@ -21,7 +21,7 @@ const normalise = s => s.trim().toLowerCase();
const isSpam = (email) => { const isSpam = (email) => {
const noDots = email.replace(/\./g, ''); const noDots = email.replace(/\./g, '');
return noDots === 'javierfranciscotmp@gmailcom' return noDots === 'javierfranciscotmp@gmailcom'
|| noDots === 'leahmarykathryntmp@gmail.com' || noDots === 'leahmarykathryntmp@gmailcom'
|| email.includes('dogazu') || email.includes('dogazu')
|| email.includes('narodowcy.net') || email.includes('narodowcy.net')
|| email.length > 128; || email.length > 128;