forked from project-sunbird/sunbird-report-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock.js
More file actions
19 lines (17 loc) · 673 Bytes
/
block.js
File metadata and controls
19 lines (17 loc) · 673 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const _ = require('lodash');
/**
* @description accesspath rule definition for user block location
*
*/
module.exports = {
ruleName: 'block',
isMatch(user, payload) {
payload = Array.isArray(payload) ? payload : [payload];
const userProfileLocation = _.get(user, 'profileLocation') || _.get(user, 'userLocations');
if (!userProfileLocation) return false;
if (!Array.isArray(userProfileLocation)) return false;
const userBlock = _.find(userProfileLocation, location => _.get(location, 'type') === 'block');
if (!(userBlock && ('id' in userBlock))) return false;
return _.some(payload, locationId => locationId === userBlock.id);
}
};