[profiles][ban] save profile snapshots for reports and bans
This commit is contained in:
parent
feb08abfe9
commit
2edb167a00
|
@ -0,0 +1,7 @@
|
|||
-- Up
|
||||
|
||||
ALTER TABLE users ADD COLUMN banSnapshot TEXT NULL;
|
||||
ALTER TABLE reports ADD COLUMN snapshot TEXT NULL;
|
||||
|
||||
-- Down
|
||||
|
|
@ -7,6 +7,7 @@ import {calculateStats, statsFile} from '../../src/stats';
|
|||
import fs from 'fs';
|
||||
import { caches } from "../../src/cache";
|
||||
import mailer from "../../src/mailer";
|
||||
import {profilesSnapshot} from "./profile";
|
||||
|
||||
const router = Router();
|
||||
|
||||
|
@ -155,7 +156,8 @@ router.post('/admin/ban/:username', handleErrorAsync(async (req, res) => {
|
|||
UPDATE users
|
||||
SET bannedReason = ${req.body.reason},
|
||||
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}
|
||||
`);
|
||||
mailer(user.email, 'ban', {reason: req.body.reason});
|
||||
|
|
|
@ -43,7 +43,7 @@ const verifyLinks = (links, authenticators) => {
|
|||
return verifiedLinks;
|
||||
}
|
||||
|
||||
const fetchProfiles = async (db, username, self, isAdmin) => {
|
||||
const fetchProfiles = async (db, username, self) => {
|
||||
const profiles = await db.all(SQL`
|
||||
SELECT profiles.*
|
||||
FROM profiles
|
||||
|
@ -88,6 +88,10 @@ const fetchProfiles = async (db, username, self, isAdmin) => {
|
|||
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);
|
||||
|
||||
function* isSuspicious(profile) {
|
||||
|
@ -288,8 +292,8 @@ router.post('/profile/report/:username', handleErrorAsync(async (req, res) => {
|
|||
}
|
||||
|
||||
await req.db.get(SQL`
|
||||
INSERT INTO reports (id, userId, reporterId, isAutomatic, comment, isHandled)
|
||||
VALUES (${ulid()}, ${user.id}, ${req.user.id}, 0, ${req.body.comment}, 0);
|
||||
INSERT INTO reports (id, userId, reporterId, isAutomatic, comment, isHandled, snapshot)
|
||||
VALUES (${ulid()}, ${user.id}, ${req.user.id}, 0, ${req.body.comment}, 0, ${await profilesSnapshot(req.db, normalise(req.params.username))});
|
||||
`);
|
||||
|
||||
return res.json('OK');
|
||||
|
|
|
@ -21,7 +21,7 @@ const normalise = s => s.trim().toLowerCase();
|
|||
const isSpam = (email) => {
|
||||
const noDots = email.replace(/\./g, '');
|
||||
return noDots === 'javierfranciscotmp@gmailcom'
|
||||
|| noDots === 'leahmarykathryntmp@gmail.com'
|
||||
|| noDots === 'leahmarykathryntmp@gmailcom'
|
||||
|| email.includes('dogazu')
|
||||
|| email.includes('narodowcy.net')
|
||||
|| email.length > 128;
|
||||
|
|
Reference in New Issue