Skip to content

Commit 7edd144

Browse files
committed
Hide review metadata for non-admin non-copilot users in listSubmissions
1 parent b335e5c commit 7edd144

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/common/helper.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,28 @@ function * postToBusApi (payload) {
554554
yield busApiClient.postEvent(payload)
555555
}
556556

557+
/**
558+
* Function to remove metadata details from reviews for members who shouldn't see them
559+
* @param {Array} reviews
560+
* @param {Array} roles
561+
*/
562+
function cleanseReviews (reviews, roles) {
563+
const cleansedReviews = []
564+
565+
_.forEach(reviews, (review) => {
566+
const admin = _.filter(roles, role => role === 'Administrator')
567+
const copilot = _.filter(roles, role => role === 'Copilot')
568+
569+
// User is neither admin nor copilot
570+
if (admin.length === 0 && copilot.length === 0) {
571+
_.unset(review, 'metadata')
572+
}
573+
574+
cleansedReviews.push(review)
575+
})
576+
return cleansedReviews
577+
}
578+
557579
module.exports = {
558580
wrapExpress,
559581
autoWrapExpress,
@@ -566,5 +588,6 @@ module.exports = {
566588
checkGetAccess,
567589
checkReviewGetAccess,
568590
downloadFile,
569-
postToBusApi
591+
postToBusApi,
592+
cleanseReviews
570593
}

src/controllers/SubmissionController.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Submission Controller
33
*/
44

5+
const _ = require('lodash')
56
const SubmissionService = require('../services/SubmissionService')
67
const helper = require('../common/helper')
78

@@ -38,6 +39,12 @@ function * downloadSubmission (req, res) {
3839
*/
3940
function * listSubmissions (req, res) {
4041
const data = yield SubmissionService.listSubmissions(req.query)
42+
data.rows = _.map(data.rows, (submission) => {
43+
if (submission.review) {
44+
submission.review = helper.cleanseReviews(submission.review, req.authUser.roles)
45+
}
46+
return submission
47+
})
4148
helper.setPaginationHeaders(req, res, data)
4249
}
4350

0 commit comments

Comments
 (0)