Skip to content

Commit 7671ae4

Browse files
authored
add username to discord audit log (#109)
1 parent 7ceeffe commit 7671ae4

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/api/functions/discord.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const urlRegex = /https:\/\/[a-z0-9\.-]+\/calendar\?id=([a-f0-9-]+)/;
2727
export const updateDiscord = async (
2828
smClient: SecretsManagerClient,
2929
event: IUpdateDiscord,
30+
actor: string,
3031
isDelete: boolean = false,
3132
logger: FastifyBaseLogger,
3233
): Promise<null | GuildScheduledEventCreateOptions> => {
@@ -90,6 +91,7 @@ export const updateDiscord = async (
9091
entityMetadata: {
9192
location,
9293
},
94+
reason: `${existingMetadata ? "Modified" : "Created"} by ${actor}.`,
9395
};
9496

9597
if (existingMetadata) {

src/api/routes/events.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
DatabaseInsertError,
1919
DiscordEventError,
2020
NotFoundError,
21+
UnauthenticatedError,
2122
ValidationError,
2223
} from "../../common/errors/index.js";
2324
import { randomUUID } from "crypto";
@@ -236,6 +237,9 @@ const eventsPlugin: FastifyPluginAsync = async (fastify, _options) => {
236237
},
237238
},
238239
async (request, reply) => {
240+
if (!request.username) {
241+
throw new UnauthenticatedError({ message: "Username not found." });
242+
}
239243
try {
240244
let originalEvent;
241245
const userProvidedId = (
@@ -281,6 +285,7 @@ const eventsPlugin: FastifyPluginAsync = async (fastify, _options) => {
281285
await updateDiscord(
282286
fastify.secretsManagerClient,
283287
entry,
288+
request.username,
284289
false,
285290
request.log,
286291
);
@@ -360,6 +365,9 @@ const eventsPlugin: FastifyPluginAsync = async (fastify, _options) => {
360365
},
361366
async (request: FastifyRequest<EventDeleteRequest>, reply) => {
362367
const id = request.params.id;
368+
if (!request.username) {
369+
throw new UnauthenticatedError({ message: "Username not found." });
370+
}
363371
try {
364372
await fastify.dynamoClient.send(
365373
new DeleteItemCommand({
@@ -370,6 +378,7 @@ const eventsPlugin: FastifyPluginAsync = async (fastify, _options) => {
370378
await updateDiscord(
371379
fastify.secretsManagerClient,
372380
{ id } as IUpdateDiscord,
381+
request.username,
373382
true,
374383
request.log,
375384
);

0 commit comments

Comments
 (0)