Skip to content

Commit 0dc8ffe

Browse files
committed
Refactor: Calculate the user role once before iterating through the reviews list
1 parent 66bf690 commit 0dc8ffe

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/common/helper.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -560,25 +560,25 @@ function * postToBusApi (payload) {
560560
* @param {Object} authUser The authenticated user details
561561
*/
562562
function cleanseReviews (reviews, authUser) {
563-
const cleansedReviews = []
564-
563+
// Not a machine user
565564
if (!authUser.scopes) {
566-
_.forEach(reviews, (review) => {
567-
const admin = _.filter(authUser.roles, role => role.toLowerCase() === 'Administrator'.toLowerCase())
568-
const copilot = _.filter(authUser.roles, role => role.toLowerCase() === 'Copilot'.toLowerCase())
565+
const admin = _.filter(authUser.roles, role => role.toLowerCase() === 'Administrator'.toLowerCase())
566+
const copilot = _.filter(authUser.roles, role => role.toLowerCase() === 'Copilot'.toLowerCase())
569567

570-
// User is neither admin nor copilot
571-
if (admin.length === 0 && copilot.length === 0) {
572-
_.unset(review, 'metadata')
573-
}
568+
// User is neither admin nor copilot
569+
if (admin.length === 0 && copilot.length === 0) {
570+
const cleansedReviews = []
574571

575-
cleansedReviews.push(review)
576-
})
572+
_.forEach(reviews, (review) => {
573+
_.unset(review, 'metadata')
574+
cleansedReviews.push(review)
575+
})
577576

578-
return cleansedReviews
579-
} else {
580-
return reviews
577+
return cleansedReviews
578+
}
581579
}
580+
581+
return reviews
582582
}
583583

584584
module.exports = {

0 commit comments

Comments
 (0)