SecurityManager: Don't prefetch values

Prefetching can cause unhandled Promise rejections, and it makes the
code less readable.
This commit is contained in:
Richard Hansen 2022-02-28 04:15:53 -05:00
parent 8053875d45
commit b89ae69202

View file

@ -95,18 +95,13 @@ exports.checkAccess = async (padID, sessionCookie, token, userSettings) => {
return DENY; return DENY;
} }
// start fetching the info we may need const padExists = await padManager.doesPadExist(padID);
const p_sessionAuthorID = sessionManager.findAuthorID(padID.split('$')[0], sessionCookie);
const p_tokenAuthorID = authorManager.getAuthor4Token(token);
const p_padExists = padManager.doesPadExist(padID);
const padExists = await p_padExists;
if (!padExists && !canCreate) { if (!padExists && !canCreate) {
authLogger.debug('access denied: user attempted to create a pad, which is prohibited'); authLogger.debug('access denied: user attempted to create a pad, which is prohibited');
return DENY; return DENY;
} }
const sessionAuthorID = await p_sessionAuthorID; const sessionAuthorID = await sessionManager.findAuthorID(padID.split('$')[0], sessionCookie);
if (settings.requireSession && !sessionAuthorID) { if (settings.requireSession && !sessionAuthorID) {
authLogger.debug('access denied: HTTP API session is required'); authLogger.debug('access denied: HTTP API session is required');
return DENY; return DENY;
@ -114,7 +109,7 @@ exports.checkAccess = async (padID, sessionCookie, token, userSettings) => {
const grant = { const grant = {
accessStatus: 'grant', accessStatus: 'grant',
authorID: (sessionAuthorID != null) ? sessionAuthorID : await p_tokenAuthorID, authorID: sessionAuthorID || await authorManager.getAuthor4Token(token),
}; };
if (!padID.includes('$')) { if (!padID.includes('$')) {