Skip to content

Commit 44256d1

Browse files
authored
Merge pull request #405 from Peppermint-Lab/next
next
2 parents b4c66de + c835045 commit 44256d1

File tree

48 files changed

+8649
-2042
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+8649
-2042
lines changed

apps/api/package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
"@types/bcrypt": "^5.0.0",
1818
"@types/email-reply-parser": "^1",
1919
"@types/formidable": "^3.4.5",
20+
"@types/imap": "^0.8.42",
2021
"@types/jsonwebtoken": "^8.5.8",
22+
"@types/mailparser": "^3.4.5",
2123
"@types/node": "^17.0.23",
2224
"@types/nodemailer": "^6.4.14",
2325
"@types/passport-local": "^1.0.35",
@@ -30,18 +32,19 @@
3032
"dependencies": {
3133
"@azure/identity": "^4.5.0",
3234
"@fastify/cookie": "^9.0.4",
33-
"@fastify/cors": "^8.3.0",
35+
"@fastify/cors": "^10.0.1",
3436
"@fastify/multipart": "^8.2.0",
3537
"@fastify/rate-limit": "^9.0.0",
3638
"@fastify/session": "^10.4.0",
37-
"@fastify/swagger": "^8.10.0",
39+
"@fastify/swagger": "^9.2.0",
40+
"@fastify/swagger-ui": "^5.1.0",
3841
"@prisma/client": "5.6.0",
3942
"add": "^2.0.6",
4043
"axios": "^1.5.0",
4144
"bcrypt": "^5.0.1",
4245
"dotenv": "^16.0.0",
4346
"email-reply-parser": "^1.8.1",
44-
"fastify": "4.22.2",
47+
"fastify": "5.1",
4548
"fastify-formidable": "^3.0.2",
4649
"fastify-multer": "^2.0.3",
4750
"formidable": "^3.5.1",

apps/api/src/controllers/config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ export function configRoutes(fastify: FastifyInstance) {
229229
});
230230
});
231231
}
232+
233+
reply.send({
234+
success: true,
235+
active: false,
236+
});
232237
}
233238
);
234239

apps/api/src/controllers/data.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
2+
import { requirePermission } from "../lib/roles";
23
import { prisma } from "../prisma";
34

45
export function dataRoutes(fastify: FastifyInstance) {
56
// Get total count of all tickets
67
fastify.get(
78
"/api/v1/data/tickets/all",
8-
9+
{
10+
preHandler: requirePermission(["issue::read"]),
11+
},
912
async (request: FastifyRequest, reply: FastifyReply) => {
1013
const result = await prisma.ticket.count({
1114
where: { hidden: false },
@@ -18,7 +21,9 @@ export function dataRoutes(fastify: FastifyInstance) {
1821
// Get total count of all completed tickets
1922
fastify.get(
2023
"/api/v1/data/tickets/completed",
21-
24+
{
25+
preHandler: requirePermission(["issue::read"]),
26+
},
2227
async (request: FastifyRequest, reply: FastifyReply) => {
2328
const result = await prisma.ticket.count({
2429
where: { isComplete: true, hidden: false },
@@ -31,7 +36,9 @@ export function dataRoutes(fastify: FastifyInstance) {
3136
// Get total count of all open tickets
3237
fastify.get(
3338
"/api/v1/data/tickets/open",
34-
39+
{
40+
preHandler: requirePermission(["issue::read"]),
41+
},
3542
async (request: FastifyRequest, reply: FastifyReply) => {
3643
const result = await prisma.ticket.count({
3744
where: { isComplete: false, hidden: false },
@@ -44,7 +51,9 @@ export function dataRoutes(fastify: FastifyInstance) {
4451
// Get total of all unsassigned tickets
4552
fastify.get(
4653
"/api/v1/data/tickets/unassigned",
47-
54+
{
55+
preHandler: requirePermission(["issue::read"]),
56+
},
4857
async (request: FastifyRequest, reply: FastifyReply) => {
4958
const result = await prisma.ticket.count({
5059
where: { userId: null, hidden: false, isComplete: false },
@@ -53,4 +62,15 @@ export function dataRoutes(fastify: FastifyInstance) {
5362
reply.send({ count: result });
5463
}
5564
);
65+
66+
// Get all logs
67+
fastify.get(
68+
"/api/v1/data/logs",
69+
async (request: FastifyRequest, reply: FastifyReply) => {
70+
const logs = await import("fs/promises").then((fs) =>
71+
fs.readFile("logs.log", "utf-8")
72+
);
73+
reply.send({ logs: logs });
74+
}
75+
);
5676
}

apps/api/src/controllers/notebook.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
22
import { track } from "../lib/hog";
3+
import { requirePermission } from "../lib/roles";
34
import { checkSession } from "../lib/session";
45
import { prisma } from "../prisma";
56

@@ -19,7 +20,9 @@ export function notebookRoutes(fastify: FastifyInstance) {
1920
// Create a new entry
2021
fastify.post(
2122
"/api/v1/notebook/note/create",
22-
23+
{
24+
preHandler: requirePermission(["document::create"]),
25+
},
2326
async (request: FastifyRequest, reply: FastifyReply) => {
2427
const { content, title }: any = request.body;
2528
const user = await checkSession(request);
@@ -43,7 +46,9 @@ export function notebookRoutes(fastify: FastifyInstance) {
4346
// Get all entries
4447
fastify.get(
4548
"/api/v1/notebooks/all",
46-
49+
{
50+
preHandler: requirePermission(["document::read"]),
51+
},
4752
async (request: FastifyRequest, reply: FastifyReply) => {
4853
const user = await checkSession(request);
4954

@@ -58,7 +63,9 @@ export function notebookRoutes(fastify: FastifyInstance) {
5863
// Get a single entry
5964
fastify.get(
6065
"/api/v1/notebooks/note/:id",
61-
66+
{
67+
preHandler: requirePermission(["document::read"]),
68+
},
6269
async (request: FastifyRequest, reply: FastifyReply) => {
6370
const user = await checkSession(request);
6471

@@ -75,14 +82,17 @@ export function notebookRoutes(fastify: FastifyInstance) {
7582
// Delete an entry
7683
fastify.delete(
7784
"/api/v1/notebooks/note/:id",
85+
{
86+
preHandler: requirePermission(["document::delete"]),
87+
},
7888
async (request: FastifyRequest, reply: FastifyReply) => {
7989
const user = await checkSession(request);
8090
const { id }: any = request.params;
8191

8292
await prisma.notes.delete({
83-
where: {
93+
where: {
8494
id: id,
85-
userId: user!.id
95+
userId: user!.id,
8696
},
8797
});
8898

@@ -95,15 +105,18 @@ export function notebookRoutes(fastify: FastifyInstance) {
95105
// Update an entry
96106
fastify.put(
97107
"/api/v1/notebooks/note/:id/update",
108+
{
109+
preHandler: requirePermission(["document::update"]),
110+
},
98111
async (request: FastifyRequest, reply: FastifyReply) => {
99112
const user = await checkSession(request);
100113
const { id }: any = request.params;
101114
const { content, title }: any = request.body;
102115

103116
await prisma.notes.update({
104-
where: {
117+
where: {
105118
id: id,
106-
userId: user!.id
119+
userId: user!.id,
107120
},
108121
data: {
109122
title: title,

0 commit comments

Comments
 (0)