mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-12-23 00:03:09 +02:00
Fix everything (db/encryption, logging etc)
This commit is contained in:
parent
24d5e6d99d
commit
4a48ba635a
@ -67,7 +67,7 @@ model ArchivedUser {
|
||||
}
|
||||
|
||||
model Category {
|
||||
channelName String @default("ticket-{num}")
|
||||
channelName String
|
||||
claiming Boolean @default(false)
|
||||
createdAt DateTime @default(now())
|
||||
description String @db.VarChar(512)
|
||||
|
@ -1,9 +1,7 @@
|
||||
command:
|
||||
log:
|
||||
admin:
|
||||
changes:
|
||||
title: 'Changes'
|
||||
description: 'These were the changes made:'
|
||||
changes: 'Changes'
|
||||
description:
|
||||
joined: '{user} {verb} {targetType}'
|
||||
target:
|
||||
|
@ -60,40 +60,36 @@ async function logAdminEvent(client, {
|
||||
};
|
||||
const channel = client.channels.cache.get(settings.logChannel);
|
||||
if (!channel) return;
|
||||
const embeds = [
|
||||
new MessageEmbed()
|
||||
.setColor('ORANGE')
|
||||
.setAuthor({
|
||||
iconURL: user.avatarURL(),
|
||||
name: user.username,
|
||||
})
|
||||
.setTitle(getMessage('log.admin.title.joined', {
|
||||
...i18nOptions,
|
||||
targetType: getMessage(`log.admin.title.target.${target.type}`),
|
||||
verb: getMessage(`log.admin.verb.${action}`),
|
||||
}))
|
||||
.setDescription(getMessage('log.admin.description.joined', {
|
||||
...i18nOptions,
|
||||
targetType: getMessage(`log.admin.description.target.${target.type}`),
|
||||
verb: getMessage(`log.admin.verb.${action}`),
|
||||
}))
|
||||
.addField(getMessage(`log.admin.title.target.${target.type}`), target.name ?? target.id),
|
||||
];
|
||||
|
||||
return await channel.send({
|
||||
embeds: [
|
||||
if (diff && diff.original) {
|
||||
embeds.push(
|
||||
new MessageEmbed()
|
||||
.setColor('ORANGE')
|
||||
.setAuthor({
|
||||
iconURL: user.avatarURL(),
|
||||
name: user.username,
|
||||
})
|
||||
.setTitle(getMessage('log.admin.title.joined', {
|
||||
...i18nOptions,
|
||||
targetType: getMessage(`log.admin.title.target.${target.type}`),
|
||||
verb: getMessage(`log.admin.verb.${action}`),
|
||||
}))
|
||||
.setDescription(getMessage('log.admin.description.joined', {
|
||||
...i18nOptions,
|
||||
targetType: getMessage(`log.admin.description.target.${target.type}`),
|
||||
verb: getMessage(`log.admin.verb.${action}`),
|
||||
}))
|
||||
.addField(getMessage(`log.admin.title.target.${target.type}`), target.name ?? target.id),
|
||||
// .setFooter({
|
||||
// iconURL: client.guilds.cache.get(guildId).iconURL(),
|
||||
// text: settings.footer,
|
||||
// }),
|
||||
...[
|
||||
diff?.original &&
|
||||
new MessageEmbed()
|
||||
.setColor('ORANGE')
|
||||
.setTitle(getMessage('log.admin.changes.title'))
|
||||
.setDescription(getMessage('log.admin.changes.description'))
|
||||
.setFields(makeDiff(diff)),
|
||||
],
|
||||
],
|
||||
});
|
||||
.setTitle(getMessage('log.admin.changes'))
|
||||
.setFields(makeDiff(diff)),
|
||||
);
|
||||
}
|
||||
|
||||
return await channel.send({ embeds });
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
@ -17,7 +17,7 @@ const fields = [
|
||||
'regex',
|
||||
];
|
||||
const shouldEncrypt = ['create', 'createMany', 'update', 'updateMany', 'upsert'];
|
||||
const shouldDecrypt = ['findUnique', 'findFirst', 'findMany'];
|
||||
// const shouldDecrypt = ['findUnique', 'findFirst', 'findMany'];
|
||||
|
||||
|
||||
|
||||
@ -62,7 +62,8 @@ module.exports = log => {
|
||||
return async (params, next) => {
|
||||
if (params.args.data && shouldEncrypt.includes(params.action)) params.args = encrypt(params.args);
|
||||
let result = await next(params);
|
||||
if (result && shouldDecrypt.includes(params.action)) result = decrypt(result);
|
||||
// if (result && shouldDecrypt.includes(params.action)) result = decrypt(result);
|
||||
if (result) result = decrypt(result);
|
||||
return result;
|
||||
};
|
||||
};
|
@ -1,10 +1,33 @@
|
||||
const { logAdminEvent } = require('../../../../../../lib/logging');
|
||||
|
||||
module.exports.delete = fastify => ({
|
||||
handler: async (req, res) => {
|
||||
/** @type {import('client')} */
|
||||
const client = res.context.config.client;
|
||||
const categoryId = Number(req.params.category);
|
||||
const category = await client.prisma.category.delete({ where: { id: categoryId } });
|
||||
|
||||
logAdminEvent(client, {
|
||||
action: 'delete',
|
||||
guildId: req.params.guild,
|
||||
target: {
|
||||
id: category.id,
|
||||
name: category.name,
|
||||
type: 'category',
|
||||
},
|
||||
userId: req.user.payload.id,
|
||||
});
|
||||
|
||||
return category;
|
||||
},
|
||||
onRequest: [fastify.authenticate, fastify.isAdmin],
|
||||
});
|
||||
|
||||
module.exports.get = fastify => ({
|
||||
handler: async (req, res) => {
|
||||
/** @type {import('client')} */
|
||||
const client = res.context.config.client;
|
||||
|
||||
const categoryId = Number(req.params.category);
|
||||
const category = await client.prisma.category.findUnique({
|
||||
include: {
|
||||
questions: {
|
||||
@ -22,7 +45,7 @@ module.exports.get = fastify => ({
|
||||
},
|
||||
},
|
||||
},
|
||||
where: { id: Number(req.params.category) },
|
||||
where: { id: categoryId },
|
||||
});
|
||||
|
||||
return category;
|
||||
@ -34,12 +57,12 @@ module.exports.patch = fastify => ({
|
||||
handler: async (req, res) => {
|
||||
/** @type {import('client')} */
|
||||
const client = res.context.config.client;
|
||||
|
||||
const categoryId = Number(req.params.category);
|
||||
const user = await client.users.fetch(req.user.payload.id);
|
||||
const guild = client.guilds.cache.get(req.params.guild);
|
||||
const data = req.body;
|
||||
const allow = ['VIEW_CHANNEL', 'READ_MESSAGE_HISTORY', 'SEND_MESSAGES', 'EMBED_LINKS', 'ATTACH_FILES'];
|
||||
const original = req.params.category && await client.prisma.category.findUnique({ where: { id: req.params.category } });
|
||||
const original = req.params.category && await client.prisma.category.findUnique({ where: { id: categoryId } });
|
||||
if (!original) return res.status(404);
|
||||
|
||||
if (!data.discordCategory) {
|
||||
@ -69,7 +92,6 @@ module.exports.patch = fastify => ({
|
||||
|
||||
const category = await client.prisma.category.update({
|
||||
data: {
|
||||
guild: { connect: { id: guild.id } },
|
||||
...data,
|
||||
questions: {
|
||||
upsert: data.questions?.map(q => ({
|
||||
@ -79,6 +101,7 @@ module.exports.patch = fastify => ({
|
||||
})),
|
||||
},
|
||||
},
|
||||
where: { id: categoryId },
|
||||
});
|
||||
|
||||
logAdminEvent(client, {
|
||||
|
@ -69,7 +69,7 @@ module.exports.post = fastify => ({
|
||||
data.discordCategory = channel.id;
|
||||
}
|
||||
|
||||
if (data.channelName === null) data.channelName = undefined;
|
||||
if (!data.channelName) data.channelName = 'ticket-{num}';
|
||||
|
||||
const category = await client.prisma.category.create({
|
||||
data: {
|
||||
|
Loading…
Reference in New Issue
Block a user