Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion nodejs/src/controller/web/brainController.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,15 @@ const deleteBrain = catchAsync(async (req, res) => {
return util.failureResponse(_localize('module.deleteError', req, BRAIN), res);
})

const { ROLE_TYPE } = require('../../config/constants/common');

const deleteAllBrain = catchAsync(async (req, res) => {
// Controller-level defense: allow only COMPANY or MANAGER roles
if (!(req.roleCode === ROLE_TYPE.COMPANY || req.roleCode === ROLE_TYPE.COMPANY_MANAGER)) {
res.message = _localize('auth.permission', req);
return util.unAuthorizedRequest(res);
}

const result = await brainService.deleteAllBrain(req);
if (result) {
res.message = _localize('module.delete', req, BRAIN);
Expand Down Expand Up @@ -135,5 +143,5 @@ module.exports = {
restoreBrain,
deleteAllBrain,
workspaceWiseList
}
}

4 changes: 2 additions & 2 deletions nodejs/src/routes/web/brains.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ const router = express.Router();
const brainController = require('../../controller/web/brainController');
const { createBrainKeys, updateBrainKeys, shareBrainKeys, unshareBrainKeys, shareDocKeys } = require('../../utils/validations/brain');
const { partialUpdateKeys } = require('../../utils/validations/common');
const { authentication } = require('../../middleware/authentication');
const { authentication, checkPermission } = require('../../middleware/authentication');
const { checkPromptLimit } = require('../../middleware/promptlimit');

router.post('/create', validate(createBrainKeys), authentication,checkPromptLimit, brainController.createBrain);
router.put('/update/:id', validate(updateBrainKeys), authentication,checkPromptLimit, brainController.updateBrain);
router.get('/:slug', authentication, brainController.getBrain);
router.delete('/delete/:id', authentication, brainController.deleteBrain);
router.delete('/deleteall', authentication, brainController.deleteAllBrain);
router.delete('/deleteall', authentication, checkPermission, brainController.deleteAllBrain).descriptor('brain.delete_all');
router.post('/list', authentication, checkPromptLimit, brainController.getAll);
router.patch('/partial/:slug', validate(partialUpdateKeys), authentication, brainController.partialUpdate);
router.post('/unshare', validate(unshareBrainKeys), authentication, brainController.unShareBrain);
Expand Down