#217 overview of suspicious profiles

This commit is contained in:
Avris 2021-06-16 16:48:24 +02:00
parent fb689e2f6c
commit 94f4f4f961
3 changed files with 80 additions and 1 deletions

View File

@ -0,0 +1,5 @@
-- Up
ALTER TABLE users ADD COLUMN suspiciousChecked TINYINT NOT NULL DEFAULT 0;
-- Down

View File

@ -84,6 +84,36 @@
<ChartSet name="users" :data="stats.users.chart" init="cumulative"/> <ChartSet name="users" :data="stats.users.chart" init="cumulative"/>
<section v-if="$isGranted('users') && suspiciousUsers.length > 0">
<h3>
<Icon v="siren-on"/>
Suspicious accounts
</h3>
<Table :data="suspiciousUsers" columns="2">
<template v-slot:row="s"><template v-if="s">
<td>
<LocaleLink :link="`/@${s.el.username}`" :locale="s.el.locale">
{{s.el.username}}
<span class="badge bg-light text-dark">{{s.el.locale}}</span>
</LocaleLink>
</td>
<td>
<a href="#" class="badge bg-light text-success border border-success float-end"
@click.prevent="checkedSuspicious(s.el.id)"
>
<Icon v="thumbs-up"/>
I checked the profile, it's OK.
</a>
</td>
</template></template>
<template v-slot:empty>
<Icon v="search"/>
<T>nouns.empty</T>
</template>
</Table>
</section>
<section v-for="(locale, k) in stats.locales" :key="k"> <section v-for="(locale, k) in stats.locales" :key="k">
<details class="border mb-3" open> <details class="border mb-3" open>
<summary class="bg-light p-3"> <summary class="bg-light p-3">
@ -150,13 +180,18 @@
}, },
async asyncData({ app, store }) { async asyncData({ app, store }) {
let stats = { users: {}}; let stats = { users: {}};
try { try {
stats = await app.$axios.$get(`/admin/stats`); stats = await app.$axios.$get(`/admin/stats`);
} catch {} } catch {}
let suspiciousUsers = [];
try {
suspiciousUsers = await app.$axios.$get(`/admin/suspicious`);
} catch {}
return { return {
stats, stats,
suspiciousUsers,
}; };
}, },
methods: { methods: {
@ -165,6 +200,11 @@
this.users = await this.$axios.$get(`/admin/users`); this.users = await this.$axios.$get(`/admin/users`);
} }
}, },
async checkedSuspicious(id) {
await this.$confirm('Are you sure you want to mark this profile as not suspicious?', 'success');
await this.$post(`/admin/suspicious/checked/${id}`);
this.suspiciousUsers = this.suspiciousUsers.filter(u => u.id !== id);
},
}, },
computed: { computed: {
visibleUsers() { visibleUsers() {

View File

@ -133,4 +133,38 @@ router.post('/admin/ban/:username', handleErrorAsync(async (req, res) => {
return res.json(true); return res.json(true);
})); }));
router.get('/admin/suspicious', handleErrorAsync(async (req, res) => {
if (!req.isGranted('users')) {
return res.status(401).json({error: 'Unauthorised'});
}
return res.json(await req.db.all(SQL`
SELECT users.id, users.username, profiles.locale FROM profiles
LEFT JOIN users ON profiles.userId = users.id
WHERE users.suspiciousChecked != 1
AND users.bannedReason IS NULL
AND (
lower(customFlags) LIKE '%super%'
OR lower(description) LIKE '%super%'
OR lower(customFlags) LIKE '%phobe%'
OR lower(description) LIKE '%phobe%'
)
ORDER BY users.id DESC
`));
}));
router.post('/admin/suspicious/checked/:id', handleErrorAsync(async (req, res) => {
if (!req.isGranted('users')) {
return res.status(401).json({error: 'Unauthorised'});
}
await req.db.get(SQL`
UPDATE users
SET suspiciousChecked = 1
WHERE id=${req.params.id}
`);
return res.json(true);
}));
export default router; export default router;