Message ACS improvements & minor fixes
+ getSuitableMessageConfAndAreaTags(): Get a suitable conf/area tag pair with priority on defaults + hasMessageConfAndAreaRead() helper + filterMessageAreaTagsByReadACS() helper * Always include confTag/areaTag when fetching a conf or area (convenience) * Fix 'toRemoteUser' assignment in message * Better kick out of message conf/areas users does not have access to
This commit is contained in:
parent
8027a73ea5
commit
dff8e12dcc
|
@ -307,7 +307,7 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
|
||||||
fromUserId : _.get(this.message, 'meta.System.local_from_user_id', localUserIdNotAvail),
|
fromUserId : _.get(this.message, 'meta.System.local_from_user_id', localUserIdNotAvail),
|
||||||
toUserId : _.get(this.message, 'meta.System.local_to_user_id', localUserIdNotAvail),
|
toUserId : _.get(this.message, 'meta.System.local_to_user_id', localUserIdNotAvail),
|
||||||
fromRemoteUser : _.get(this.message, 'meta.System.remote_from_user', remoteUserNotAvail),
|
fromRemoteUser : _.get(this.message, 'meta.System.remote_from_user', remoteUserNotAvail),
|
||||||
toRemoteUser : _.get(this.messgae, 'meta.System.remote_to_user', remoteUserNotAvail),
|
toRemoteUser : _.get(this.message, 'meta.System.remote_to_user', remoteUserNotAvail),
|
||||||
subject : this.message.subject,
|
subject : this.message.subject,
|
||||||
modTimestamp : this.message.modTimestamp.format(modTimestampFormat),
|
modTimestamp : this.message.modTimestamp.format(modTimestampFormat),
|
||||||
msgNum : this.messageIndex + 1,
|
msgNum : this.messageIndex + 1,
|
||||||
|
|
|
@ -26,10 +26,13 @@ exports.getAvailableMessageAreasByConfTag = getAvailableMessageAreasByConfTag;
|
||||||
exports.getSortedAvailMessageAreasByConfTag = getSortedAvailMessageAreasByConfTag;
|
exports.getSortedAvailMessageAreasByConfTag = getSortedAvailMessageAreasByConfTag;
|
||||||
exports.getDefaultMessageConferenceTag = getDefaultMessageConferenceTag;
|
exports.getDefaultMessageConferenceTag = getDefaultMessageConferenceTag;
|
||||||
exports.getDefaultMessageAreaTagByConfTag = getDefaultMessageAreaTagByConfTag;
|
exports.getDefaultMessageAreaTagByConfTag = getDefaultMessageAreaTagByConfTag;
|
||||||
|
exports.getSuitableMessageConfAndAreaTags = getSuitableMessageConfAndAreaTags;
|
||||||
exports.getMessageConferenceByTag = getMessageConferenceByTag;
|
exports.getMessageConferenceByTag = getMessageConferenceByTag;
|
||||||
exports.getMessageAreaByTag = getMessageAreaByTag;
|
exports.getMessageAreaByTag = getMessageAreaByTag;
|
||||||
exports.changeMessageConference = changeMessageConference;
|
exports.changeMessageConference = changeMessageConference;
|
||||||
exports.changeMessageArea = changeMessageArea;
|
exports.changeMessageArea = changeMessageArea;
|
||||||
|
exports.hasMessageConfAndAreaRead = hasMessageConfAndAreaRead;
|
||||||
|
exports.filterMessageAreaTagsByReadACS = filterMessageAreaTagsByReadACS;
|
||||||
exports.tempChangeMessageConfAndArea = tempChangeMessageConfAndArea;
|
exports.tempChangeMessageConfAndArea = tempChangeMessageConfAndArea;
|
||||||
exports.getMessageListForArea = getMessageListForArea;
|
exports.getMessageListForArea = getMessageListForArea;
|
||||||
exports.getNewMessageCountInAreaForUser = getNewMessageCountInAreaForUser;
|
exports.getNewMessageCountInAreaForUser = getNewMessageCountInAreaForUser;
|
||||||
|
@ -185,7 +188,10 @@ function getDefaultMessageAreaTagByConfTag(client, confTag, disableAcsCheck) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultArea = _.findKey(areaPool, (area) => {
|
defaultArea = _.findKey(areaPool, (area, areaTag) => {
|
||||||
|
if(Message.isPrivateAreaTag(areaTag)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return (true === disableAcsCheck || client.acs.hasMessageAreaRead(area));
|
return (true === disableAcsCheck || client.acs.hasMessageAreaRead(area));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -193,8 +199,47 @@ function getDefaultMessageAreaTagByConfTag(client, confTag, disableAcsCheck) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSuitableMessageConfAndAreaTags(client) {
|
||||||
|
//
|
||||||
|
// Attempts to get a pair of suitable conf/area tags:
|
||||||
|
// * Where the client/user has proper ACS to both
|
||||||
|
// * Try to use defaults where possible
|
||||||
|
// * If default conf/area is not an option, use any
|
||||||
|
// that pass ACS.
|
||||||
|
// * Returns a tuple [confTag, areaTag]; areaTag
|
||||||
|
// and possibly confTag may both be set to '' if
|
||||||
|
// if we fail to find something.
|
||||||
|
//
|
||||||
|
let confTag = getDefaultMessageConferenceTag(client);
|
||||||
|
if(!confTag) {
|
||||||
|
return ['', '']; // can't have an area without a conf
|
||||||
|
}
|
||||||
|
|
||||||
|
let areaTag = getDefaultMessageAreaTagByConfTag(client, confTag);
|
||||||
|
if(!areaTag) {
|
||||||
|
// OK, perhaps *any* area in *any* conf?
|
||||||
|
_.forEach(Config().messageConferences, (conf, ct) => {
|
||||||
|
if(!client.acs.hasMessageConfRead(conf)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_.forEach(conf.areas, (area, at) => {
|
||||||
|
if(!_.includes(Message.WellKnownAreaTags, at) && client.acs.hasMessageAreaRead(area)) {
|
||||||
|
confTag = ct;
|
||||||
|
areaTag = at;
|
||||||
|
return false; // stop inner iteration
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if(areaTag) {
|
||||||
|
return false; // stop iteration
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return [confTag, areaTag || ''];
|
||||||
|
}
|
||||||
|
|
||||||
function getMessageConferenceByTag(confTag) {
|
function getMessageConferenceByTag(confTag) {
|
||||||
return Config().messageConferences[confTag];
|
return Object.assign({ confTag }, Config().messageConferences[confTag]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMessageConfTagByAreaTag(areaTag) {
|
function getMessageConfTagByAreaTag(areaTag) {
|
||||||
|
@ -209,17 +254,23 @@ function getMessageAreaByTag(areaTag, optionalConfTag) {
|
||||||
|
|
||||||
// :TODO: this could be cached
|
// :TODO: this could be cached
|
||||||
if(_.isString(optionalConfTag)) {
|
if(_.isString(optionalConfTag)) {
|
||||||
if(_.has(confs, [ optionalConfTag, 'areas', areaTag ])) {
|
if(_.isObject(confs, [ optionalConfTag, 'areas', areaTag ])) {
|
||||||
return confs[optionalConfTag].areas[areaTag];
|
return Object.assign(
|
||||||
|
{
|
||||||
|
areaTag,
|
||||||
|
confTag : optionalConfTag,
|
||||||
|
},
|
||||||
|
confs[optionalConfTag].areas[areaTag]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
// No confTag to work with - we'll have to search through them all
|
// No confTag to work with - we'll have to search through them all
|
||||||
//
|
//
|
||||||
let area;
|
let area;
|
||||||
_.forEach(confs, (v) => {
|
_.forEach(confs, (conf, confTag) => {
|
||||||
if(_.has(v, [ 'areas', areaTag ])) {
|
if(_.isObject(conf, [ 'areas', areaTag ])) {
|
||||||
area = v.areas[areaTag];
|
area = Object.assign({ areaTag, confTag }, conf.areas[areaTag]);
|
||||||
return false; // stop iteration
|
return false; // stop iteration
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -350,6 +401,22 @@ function changeMessageArea(client, areaTag, cb) {
|
||||||
changeMessageAreaWithOptions(client, areaTag, { persist : true }, cb);
|
changeMessageAreaWithOptions(client, areaTag, { persist : true }, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasMessageConfAndAreaRead(client, area) {
|
||||||
|
const conf = getMessageConfTagByAreaTag(area.areaTag);
|
||||||
|
return client.acs.hasMessageConfRead(conf) && client.acs.hasMessageAreaRead(area);
|
||||||
|
}
|
||||||
|
|
||||||
|
function filterMessageAreaTagsByReadACS(client, areaTags) {
|
||||||
|
if(!Array.isArray(areaTags)) {
|
||||||
|
areaTags = [ areaTags ];
|
||||||
|
}
|
||||||
|
|
||||||
|
return areaTags.filter( areaTag => {
|
||||||
|
const area = getMessageAreaByTag(areaTag);
|
||||||
|
return hasMessageConfAndAreaRead(client, area);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function getNewMessageCountInAreaForUser(userId, areaTag, cb) {
|
function getNewMessageCountInAreaForUser(userId, areaTag, cb) {
|
||||||
getMessageAreaLastReadId(userId, areaTag, (err, lastMessageId) => {
|
getMessageAreaLastReadId(userId, areaTag, (err, lastMessageId) => {
|
||||||
lastMessageId = lastMessageId || 0;
|
lastMessageId = lastMessageId || 0;
|
||||||
|
|
|
@ -21,6 +21,7 @@ const {
|
||||||
getMessageAreaByTag,
|
getMessageAreaByTag,
|
||||||
getDefaultMessageConferenceTag,
|
getDefaultMessageConferenceTag,
|
||||||
getDefaultMessageAreaTagByConfTag,
|
getDefaultMessageAreaTagByConfTag,
|
||||||
|
getSuitableMessageConfAndAreaTags,
|
||||||
} = require('./message_area.js');
|
} = require('./message_area.js');
|
||||||
const {
|
const {
|
||||||
getFileAreaByTag,
|
getFileAreaByTag,
|
||||||
|
@ -128,15 +129,6 @@ function userLogin(client, username, password, options, cb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function postLoginPrep(client, cb) {
|
function postLoginPrep(client, cb) {
|
||||||
|
|
||||||
const defaultMsgAreaTag = (confTag) => {
|
|
||||||
return (
|
|
||||||
getDefaultMessageAreaTagByConfTag(client, confTag) ||
|
|
||||||
getDefaultMessageAreaTagByConfTag(client, getDefaultMessageConferenceTag(client)) ||
|
|
||||||
''
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
async.series(
|
async.series(
|
||||||
[
|
[
|
||||||
(callback) => {
|
(callback) => {
|
||||||
|
@ -144,23 +136,20 @@ function postLoginPrep(client, cb) {
|
||||||
// User may (no longer) have read (view) rights to their current
|
// User may (no longer) have read (view) rights to their current
|
||||||
// message, conferences and/or areas. Move them out if so.
|
// message, conferences and/or areas. Move them out if so.
|
||||||
//
|
//
|
||||||
let confTag = client.user.getProperty(UserProps.MessageConfTag);
|
const confTag = client.user.getProperty(UserProps.MessageConfTag);
|
||||||
const conf = getMessageConferenceByTag(confTag) || {};
|
const conf = getMessageConferenceByTag(confTag) || {};
|
||||||
const area = getMessageAreaByTag(client.user.getProperty(UserProps.MessageAreaTag), confTag) || {};
|
const area = getMessageAreaByTag(client.user.getProperty(UserProps.MessageAreaTag), confTag) || {};
|
||||||
|
|
||||||
if(!client.acs.hasMessageConfRead(conf)) {
|
if(!client.acs.hasMessageConfRead(conf) || !client.acs.hasMessageAreaRead(area)) {
|
||||||
confTag = getDefaultMessageConferenceTag(client) || '';
|
// move them out of both area and possibly conf to something suitable, hopefully.
|
||||||
|
const [newConfTag, newAreaTag] = getSuitableMessageConfAndAreaTags(client);
|
||||||
client.user.persistProperties({
|
client.user.persistProperties({
|
||||||
[ UserProps.MessageConfTag ] : confTag,
|
[ UserProps.MessageConfTag ] : newConfTag,
|
||||||
[ UserProps.MessageAreaTag ] : defaultMsgAreaTag(confTag),
|
[ UserProps.MessageAreaTag ] : newAreaTag,
|
||||||
},
|
},
|
||||||
err => {
|
err => {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
});
|
});
|
||||||
} else if (!client.acs.hasMessageAreaRead(area)) {
|
|
||||||
client.user.persistProperty(UserProps.MessageAreaTag, defaultMsgAreaTag(confTag), err => {
|
|
||||||
return callback(err);
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
return callback(null);
|
return callback(null);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue