-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpermissions.js
37 lines (31 loc) · 987 Bytes
/
permissions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const request = require('request');
const config = require('config');
const apiUrl = config.get('server').get('cmsApiUrl');
function createResponseHandler (process) {
return function responseHandler (error, response) {
if (error) {
process(error);
return;
}
process(response.statusCode === 200);
};
}
function canEditTopicDocument (token, topicId, process) {
if (typeof process !== 'function') {
throw new TypeError(`expected process to be a function, got ${typeof process} instead`);
}
return request.get(
`${apiUrl}Api/Permissions/Topics/${topicId}/Permission/IsAssociatedTo`,
createResponseHandler(process)
).auth(null, null, true, token);
}
function isAllowedToEdit (token, topicId, process) {
return request.get(
`${apiUrl}Api/Permissions/Topics/${topicId}/Permission/IsAllowedToEdit`,
createResponseHandler(process)
).auth(null, null, true, token);
}
module.exports = {
canEditTopicDocument,
isAllowedToEdit
};