Skip to content

Commit

Permalink
Merge pull request #974 from OneCommunityGlobal/Jingyi_create/edit/de…
Browse files Browse the repository at this point in the history
…lete_badges_permission

Jingyi create/edit/delete badges permission
  • Loading branch information
one-community authored Jun 23, 2024
2 parents 2ab7527 + 985d2ea commit 74da28a
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/controllers/badgeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,21 @@ const badgeController = function (Badge) {
const cache = cacheClosure();

const getAllBadges = async function (req, res) {
console.log(req.body.requestor);
if (!(await helper.hasPermission(req.body.requestor, 'seeBadges'))) {
console.log('in if statement');
console.log(req.body.requestor); // Retain logging from development branch for debugging

// Check if the user has any of the following permissions
if (
!(await helper.hasPermission(req.body.requestor, 'seeBadges')) &&
!(await helper.hasPermission(req.body.requestor, 'assignBadges')) &&
!(await helper.hasPermission(req.body.requestor, 'createBadges')) &&
!(await helper.hasPermission(req.body.requestor, 'updateBadges')) &&
!(await helper.hasPermission(req.body.requestor, 'deleteBadges'))
) {
console.log('in if statement'); // Retain logging from development branch for debugging
res.status(403).send('You are not authorized to view all badge data.');
return;
}

// Add cache to reduce database query and optimize performance
if (cache.hasCache('allBadges')) {
res.status(200).send(cache.getCache('allBadges'));
Expand Down

0 comments on commit 74da28a

Please sign in to comment.