access controls: promisification

`getPadAccess()` (src/node/padaccess.js) is now "promise only", resolving to
`true` or `false` as appropriate, and throwing an exception if there's an
error.

The two call sites (padreadonly.js and importexport.js) updated to match.
This commit is contained in:
Ray Bellis 2019-01-23 16:29:36 +00:00
parent 34fdaa4e8c
commit d5d28717c4
3 changed files with 39 additions and 70 deletions

View file

@ -1,17 +1,20 @@
var ERR = require("async-stacktrace");
var securityManager = require('./db/SecurityManager');
// checks for padAccess
module.exports = function (req, res, callback) {
securityManager.checkAccess(req.params.pad, req.cookies.sessionID, req.cookies.token, req.cookies.password, function(err, accessObj) {
if (ERR(err, callback)) return;
module.exports = async function (req, res) {
try {
let accessObj = await securityManager.checkAccess(req.params.pad, req.cookies.sessionID, req.cookies.token, req.cookies.password);
if (accessObj.accessStatus === "grant") {
// there is access, continue
callback();
return true;
} else {
// no access
res.status(403).send("403 - Can't touch this");
return false;
}
});
} catch (err) {
// @TODO - send internal server error here?
throw err;
}
}