[FEAT] Automated audit logging (#667)
* WIP event logging - new table for events and new settings view for viewing
* WIP add logging
* UI for log rows
* rename files to Logging to prevent getting gitignore
* add metadata for all logging events and colored badges in logs page
* remove unneeded comment
* cleanup namespace for logging
* clean up backend calls
* update logging to show to => from settings changes
* add logging for invitations, created, deleted, and accepted
* add logging for user created, updated, suspended, or removed
* add logging for workspace deleted
* add logging for chat logs exported
* add logging for API keys, LLM, embedder, vector db, embed chat, and reset button
* modify event logs
* update to event log types
* simplify rendering of event badges
---------
Co-authored-by: timothycarambat <rambat1010@gmail.com>
2024-02-07 00:21:40 +01:00
|
|
|
const { EventLogs } = require("../models/eventLogs");
|
2023-07-25 19:37:04 +02:00
|
|
|
const { Invite } = require("../models/invite");
|
|
|
|
const { User } = require("../models/user");
|
|
|
|
const { reqBody } = require("../utils/http");
|
|
|
|
|
|
|
|
function inviteEndpoints(app) {
|
|
|
|
if (!app) return;
|
|
|
|
|
|
|
|
app.get("/invite/:code", async (request, response) => {
|
|
|
|
try {
|
|
|
|
const { code } = request.params;
|
2023-09-28 23:00:03 +02:00
|
|
|
const invite = await Invite.get({ code });
|
2023-07-25 19:37:04 +02:00
|
|
|
if (!invite) {
|
|
|
|
response.status(200).json({ invite: null, error: "Invite not found." });
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (invite.status !== "pending") {
|
|
|
|
response
|
|
|
|
.status(200)
|
|
|
|
.json({ invite: null, error: "Invite is no longer valid." });
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
response
|
|
|
|
.status(200)
|
|
|
|
.json({ invite: { code, status: invite.status }, error: null });
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
response.sendStatus(500).end();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
app.post("/invite/:code", async (request, response) => {
|
|
|
|
try {
|
|
|
|
const { code } = request.params;
|
2024-01-10 17:42:03 +01:00
|
|
|
const { username, password } = reqBody(request);
|
2023-09-28 23:00:03 +02:00
|
|
|
const invite = await Invite.get({ code });
|
2023-07-25 19:37:04 +02:00
|
|
|
if (!invite || invite.status !== "pending") {
|
|
|
|
response
|
|
|
|
.status(200)
|
|
|
|
.json({ success: false, error: "Invite not found or is invalid." });
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-10 22:18:48 +01:00
|
|
|
const { user, error } = await User.create({
|
2024-01-10 17:42:03 +01:00
|
|
|
username,
|
|
|
|
password,
|
|
|
|
role: "default",
|
2024-01-10 22:18:48 +01:00
|
|
|
});
|
2023-07-25 19:37:04 +02:00
|
|
|
if (!user) {
|
|
|
|
console.error("Accepting invite:", error);
|
|
|
|
response
|
|
|
|
.status(200)
|
|
|
|
.json({ success: false, error: "Could not create user." });
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
await Invite.markClaimed(invite.id, user);
|
[FEAT] Automated audit logging (#667)
* WIP event logging - new table for events and new settings view for viewing
* WIP add logging
* UI for log rows
* rename files to Logging to prevent getting gitignore
* add metadata for all logging events and colored badges in logs page
* remove unneeded comment
* cleanup namespace for logging
* clean up backend calls
* update logging to show to => from settings changes
* add logging for invitations, created, deleted, and accepted
* add logging for user created, updated, suspended, or removed
* add logging for workspace deleted
* add logging for chat logs exported
* add logging for API keys, LLM, embedder, vector db, embed chat, and reset button
* modify event logs
* update to event log types
* simplify rendering of event badges
---------
Co-authored-by: timothycarambat <rambat1010@gmail.com>
2024-02-07 00:21:40 +01:00
|
|
|
await EventLogs.logEvent(
|
|
|
|
"invite_accepted",
|
|
|
|
{
|
|
|
|
username: user.username,
|
|
|
|
},
|
|
|
|
user.id
|
|
|
|
);
|
|
|
|
|
2023-07-25 19:37:04 +02:00
|
|
|
response.status(200).json({ success: true, error: null });
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
response.sendStatus(500).end();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { inviteEndpoints };
|