Don't return messages user doesn't have access to!

This commit is contained in:
Bryan Ashby 2019-09-11 21:56:54 -06:00
parent d5268c7b9e
commit 4f6a0b175c
No known key found for this signature in database
GPG Key ID: B49EB437951D2542
1 changed files with 24 additions and 1 deletions

View File

@ -5,6 +5,9 @@
const MenuModule = require('./menu_module.js').MenuModule;
const Message = require('./message.js');
const UserProps = require('./user_property.js');
const {
hasMessageConfAndAreaRead
} = require('./message_area.js');
exports.moduleInfo = {
name : 'My Messages',
@ -30,7 +33,27 @@ exports.getModule = class MyMessagesModule extends MenuModule {
this.client.log.warn( { error : err.message }, 'Error finding messages addressed to current user');
return this.prevMenu();
}
this.messageList = messageList;
//
// We need to filter out messages belonging to conf/areas the user
// doesn't have access to.
//
// Keep a cache around for quick lookup.
//
const acsCache = new Map(); // areaTag:boolean
this.messageList = messageList.filter(msg => {
let cached = acsCache.get(msg.areaTag);
if(false === cached) {
return false;
}
if(true === cached) {
return true;
}
cached = hasMessageConfAndAreaRead(this.client, msg.areaTag);
acsCache.set(msg.areaTag, cached);
return cached;
});
this.finishedLoading();
});
}