Skip to content

Commit a2c36b0

Browse files
author
Lasim
committed
refactor: Replace permission checks with global admin requirement in global settings route
1 parent da94544 commit a2c36b0

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

services/backend/src/routes/db/setup.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ async function setupDbHandler(
7171

7272
// Fastify has already validated the request body using our Zod schema
7373
// If we reach here, request.body is guaranteed to be valid
74-
const { type } = request.body;
7574

7675
// Determine DB path based on environment
7776
const isTestEnv = process.env.NODE_ENV === 'test';

services/backend/src/routes/globalSettings/index.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ZodError, z } from 'zod';
33
import { zodToJsonSchema } from 'zod-to-json-schema';
44
import { GlobalSettingsService } from '../../services/globalSettingsService';
55
import { validateEncryption } from '../../utils/encryption'; // Static import
6-
import { requirePermission } from '../../middleware/roleMiddleware';
6+
import { requireGlobalAdmin } from '../../middleware/roleMiddleware';
77
import {
88
CreateGlobalSettingSchema,
99
UpdateGlobalSettingSchema,
@@ -114,7 +114,7 @@ export default async function globalSettingsRoute(fastify: FastifyInstance) {
114114
})
115115
}
116116
},
117-
preHandler: requirePermission('settings.view'),
117+
preHandler: requireGlobalAdmin(),
118118
}, async (request: FastifyRequest, reply: FastifyReply) => {
119119
try {
120120
const groupsWithSettings = await GlobalSettingsService.getAllGroupsWithSettings();
@@ -157,7 +157,7 @@ export default async function globalSettingsRoute(fastify: FastifyInstance) {
157157
})
158158
}
159159
},
160-
preHandler: requirePermission('settings.view'),
160+
preHandler: requireGlobalAdmin(),
161161
}, async (request: FastifyRequest, reply: FastifyReply) => {
162162
try {
163163
const settings = await GlobalSettingsService.getAll();
@@ -208,7 +208,7 @@ export default async function globalSettingsRoute(fastify: FastifyInstance) {
208208
})
209209
}
210210
},
211-
preHandler: requirePermission('settings.view'),
211+
preHandler: requireGlobalAdmin(),
212212
}, async (request, reply) => {
213213
try {
214214
const { key } = request.params;
@@ -272,7 +272,7 @@ export default async function globalSettingsRoute(fastify: FastifyInstance) {
272272
})
273273
}
274274
},
275-
preHandler: requirePermission('settings.edit'),
275+
onRequest: requireGlobalAdmin(),
276276
}, async (request, reply) => {
277277
try {
278278
// Fastify has already validated request.body using CreateGlobalSettingSchema
@@ -362,7 +362,7 @@ export default async function globalSettingsRoute(fastify: FastifyInstance) {
362362
})
363363
}
364364
},
365-
preHandler: requirePermission('settings.edit'),
365+
preHandler: requireGlobalAdmin(),
366366
}, async (request, reply) => {
367367
try {
368368
const { key } = request.params;
@@ -434,7 +434,7 @@ export default async function globalSettingsRoute(fastify: FastifyInstance) {
434434
})
435435
}
436436
},
437-
preHandler: requirePermission('settings.delete'),
437+
preHandler: requireGlobalAdmin(),
438438
}, async (request, reply) => {
439439
try {
440440
const { key } = request.params;
@@ -491,7 +491,7 @@ export default async function globalSettingsRoute(fastify: FastifyInstance) {
491491
})
492492
}
493493
},
494-
preHandler: requirePermission('settings.view'),
494+
preHandler: requireGlobalAdmin(),
495495
}, async (request, reply) => {
496496
try {
497497
const { groupId } = request.params;
@@ -536,7 +536,7 @@ export default async function globalSettingsRoute(fastify: FastifyInstance) {
536536
})
537537
}
538538
},
539-
preHandler: requirePermission('settings.view'),
539+
preHandler: requireGlobalAdmin(),
540540
}, async (request, reply) => {
541541
try {
542542
const categories = await GlobalSettingsService.getCategories();
@@ -588,7 +588,7 @@ export default async function globalSettingsRoute(fastify: FastifyInstance) {
588588
})
589589
}
590590
},
591-
preHandler: requirePermission('settings.view'),
591+
preHandler: requireGlobalAdmin(),
592592
}, async (request, reply) => {
593593
try {
594594
// Fastify has already validated request.body using SearchGlobalSettingsSchema
@@ -654,7 +654,7 @@ export default async function globalSettingsRoute(fastify: FastifyInstance) {
654654
})
655655
}
656656
},
657-
preHandler: requirePermission('settings.edit'),
657+
onRequest: requireGlobalAdmin(),
658658
}, async (request, reply) => {
659659
try {
660660
// Fastify has already validated request.body using BulkGlobalSettingsSchema
@@ -738,7 +738,7 @@ export default async function globalSettingsRoute(fastify: FastifyInstance) {
738738
})
739739
}
740740
},
741-
preHandler: requirePermission('settings.view'),
741+
preHandler: requireGlobalAdmin(),
742742
}, async (request, reply) => {
743743
try {
744744
// const { validateEncryption } = await import('@src/utils/encryption'); // Removed dynamic import

0 commit comments

Comments
 (0)