Commit 4fca244c authored by Nelson GONCALVES's avatar Nelson GONCALVES
Browse files

Account for getAuthorName returning a promise

parent 454f39e4
......@@ -169,8 +169,6 @@ async function padRightsForUser(id, userId) {
return result;
}
var ticket = null;
exports.authenticate = async function (hook_name, context, cb) {
laclasseLogger.info('authenticate');
......@@ -183,7 +181,6 @@ exports.authenticate = async function (hook_name, context, cb) {
return cb([false]);
}
ticket = context.req.query.ticket;
const user = await serviceValidate(context.req.query.ticket, getServiceURL(context.req));
if(!user) return cb([false]);
// User authenticated, save off some information needed for authorization
......@@ -224,12 +221,16 @@ exports.handleMessage = async function (hook_name, {message, client}) {
if (!session || !user || !user.display_name) return;
// Update author name if needed
await authorManager.getAuthor4Token(message.token).then(function (author) {
if(authorManager.getAuthorName(author) !== user.display_name) {
authorManager.setAuthorName(author, client.client.request.session.user.display_name);
}
}).catch(function (error) {
laclasseLogger.error('handleMessage: could not get authorid for token %s', message.token, error);
});
const author = await authorManager.getAuthor4Token(message.token);
if(!author) {
laclasseLogger.error('handleMessage: could not get authorid for token %s', message.token, author);
return;
}
const oldAuthorName = await authorManager.getAuthorName(author);
// laclasseLogger.info("oldAuthorName for: ",author,oldAuthorName);
if( oldAuthorName !== user.display_name) {
// laclasseLogger.info("Setting authorname for :",author,user.display_name);
authorManager.setAuthorName(author, user.display_name);
}
}
};
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment