* Initial work on moving to JSON configured Message Areas (vs ID's in SQLite). This will be applied to user groups, and other types as well such that JSON can simply be edited in config.json
* Hopefully better/proper merge of config.js + config.json => config
This commit is contained in:
parent
ec70cc8caa
commit
35de0a2487
|
@ -31,7 +31,15 @@ function init(configPath, cb) {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function mergeWithDefaultConfig(configJson, callback) {
|
function mergeWithDefaultConfig(configJson, callback) {
|
||||||
var mergedConfig = _.defaultsDeep(configJson, getDefaultConfig());
|
//var mergedConfig = _.defaultsDeep(configJson, getDefaultConfig());
|
||||||
|
var mergedConfig = _.merge(getDefaultConfig(), configJson, function mergeCustomizer(conf1, conf2) {
|
||||||
|
// Arrays should always concat
|
||||||
|
if(_.isArray(conf1)) {
|
||||||
|
// :TODO: look for collisions & override dupes
|
||||||
|
return conf1.concat(conf2);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
callback(null, mergedConfig);
|
callback(null, mergedConfig);
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -67,6 +75,7 @@ function getDefaultConfig() {
|
||||||
passwordMax : 128,
|
passwordMax : 128,
|
||||||
requireActivation : true, // require SysOp activation?
|
requireActivation : true, // require SysOp activation?
|
||||||
invalidUsernames : [],
|
invalidUsernames : [],
|
||||||
|
|
||||||
defaultGroups : [ 'users' ]
|
defaultGroups : [ 'users' ]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -113,6 +122,12 @@ function getDefaultConfig() {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
messages : {
|
||||||
|
areas : [
|
||||||
|
{ name : "private_mail", desc : "Private Email", groups : [ "users" ] }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
networks : {
|
networks : {
|
||||||
/*
|
/*
|
||||||
networkName : { // e.g. fidoNet
|
networkName : { // e.g. fidoNet
|
||||||
|
|
|
@ -2,15 +2,59 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var msgDb = require('./database.js').dbs.message;
|
var msgDb = require('./database.js').dbs.message;
|
||||||
|
var Config = require('./config.js').config;
|
||||||
|
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
|
|
||||||
exports.getAvailableMessageAreas = getAvailableMessageAreas;
|
exports.getAvailableMessageAreas = getAvailableMessageAreas;
|
||||||
exports.changeCurrentArea = changeCurrentArea;
|
exports.changeMessageArea = changeMessageArea;
|
||||||
|
|
||||||
// :TODO: need total / new + other stats
|
function getAvailableMessageAreas() {
|
||||||
|
return Config.messages.areas;
|
||||||
|
}
|
||||||
|
|
||||||
|
function changeMessageArea(client, areaName, cb) {
|
||||||
|
|
||||||
|
async.waterfall(
|
||||||
|
[
|
||||||
|
function getArea(callback) {
|
||||||
|
var availAreas = getAvailableMessageAreas();
|
||||||
|
|
||||||
|
areaName = areaName.toLowerCase(); // always lookup lowercase
|
||||||
|
var index = _.findIndex(availAreas, function pred(a) {
|
||||||
|
return a.name === areaName;
|
||||||
|
});
|
||||||
|
|
||||||
|
if(index > -1) {
|
||||||
|
callback(null, availAreas[index]);
|
||||||
|
} else {
|
||||||
|
callback(new Error('Invalid message area'));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function validateAccess(area, callback) {
|
||||||
|
// :TODO: validate user has access to |area| -- must belong to group(s) specified
|
||||||
|
callback(null, area);
|
||||||
|
},
|
||||||
|
function changeArea(area, callback) {
|
||||||
|
client.user.persistProperties( { message_area_name : area.name, message_area_desc : area.desc }, function persisted(err) {
|
||||||
|
callback(err, area);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
],
|
||||||
|
function complete(err, area) {
|
||||||
|
if(!err) {
|
||||||
|
client.log.info( area, 'Current message area changed');
|
||||||
|
} else {
|
||||||
|
client.log.warn( { area : area, error : err.message }, 'Could not change message area');
|
||||||
|
}
|
||||||
|
|
||||||
|
cb(err);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
/*
|
||||||
function getAvailableMessageAreas(cb) {
|
function getAvailableMessageAreas(cb) {
|
||||||
var areas = []; // { areaId, name, groupIds[] }
|
var areas = []; // { areaId, name, groupIds[] }
|
||||||
|
|
||||||
|
@ -59,7 +103,6 @@ function getAvailableMessageAreas(cb) {
|
||||||
cb(err, areas);
|
cb(err, areas);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeCurrentArea(client, areaId, cb) {
|
function changeCurrentArea(client, areaId, cb) {
|
||||||
|
@ -105,3 +148,4 @@ function changeCurrentArea(client, areaId, cb) {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
*/
|
|
@ -331,7 +331,8 @@ User.prototype.persistProperty = function(propName, propValue, cb) {
|
||||||
User.prototype.persistProperties = function(properties, cb) {
|
User.prototype.persistProperties = function(properties, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
// :TODO: should probably add/update live properties
|
// update live props
|
||||||
|
_.merge(this.properties, properties);
|
||||||
|
|
||||||
var stmt = userDb.prepare(
|
var stmt = userDb.prepare(
|
||||||
'REPLACE INTO user_property (user_id, prop_name, prop_value) ' +
|
'REPLACE INTO user_property (user_id, prop_name, prop_value) ' +
|
||||||
|
|
|
@ -30,11 +30,26 @@ function MessageAreaListModule(options) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.entryFormat = this.entryFormat || '( {areaId} ) - {name}';
|
this.entryFormat = this.entryFormat || '( {index} ) - {desc}';
|
||||||
|
|
||||||
this.menuMethods = {
|
this.menuMethods = {
|
||||||
changeArea : function(formData, extraArgs) {
|
changeArea : function(formData, extraArgs) {
|
||||||
if(1 === formData.submitId) {
|
if(1 === formData.submitId) {
|
||||||
|
var areaName = self.messageAreas[formData.value.area].name;
|
||||||
|
|
||||||
|
messageArea.changeMessageArea(self.client, areaName, function areaChanged(err) {
|
||||||
|
if(err) {
|
||||||
|
self.client.term.pipeWrite('\n|00Cannot change area: ' + err.message + '\n');
|
||||||
|
|
||||||
|
setTimeout(function timeout() {
|
||||||
|
self.client.gotoMenuModule( { name : self.menuConfig.fallback } );
|
||||||
|
}, 1000);
|
||||||
|
} else {
|
||||||
|
self.client.gotoMenuModule( { name : self.menuConfig.fallback } );
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
var areaId = self.messageAreas[formData.value.area].areaId;
|
var areaId = self.messageAreas[formData.value.area].areaId;
|
||||||
|
|
||||||
messageArea.changeCurrentArea(self.client, areaId, function areaChanged(err) {
|
messageArea.changeCurrentArea(self.client, areaId, function areaChanged(err) {
|
||||||
|
@ -48,6 +63,7 @@ function MessageAreaListModule(options) {
|
||||||
self.client.gotoMenuModule( { name : self.menuConfig.fallback } );
|
self.client.gotoMenuModule( { name : self.menuConfig.fallback } );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -59,11 +75,19 @@ require('util').inherits(MessageAreaListModule, MenuModule);
|
||||||
MessageAreaListModule.prototype.enter = function(client) {
|
MessageAreaListModule.prototype.enter = function(client) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
self.messageAreas = messageArea.getAvailableMessageAreas();
|
||||||
|
|
||||||
|
console.log(self.messageAreas)
|
||||||
|
|
||||||
|
MessageAreaListModule.super_.prototype.enter.call(self, client);
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
messageArea.getAvailableMessageAreas(function fetched(err, areas) {
|
messageArea.getAvailableMessageAreas(function fetched(err, areas) {
|
||||||
self.messageAreas = areas;
|
self.messageAreas = areas;
|
||||||
|
|
||||||
MessageAreaListModule.super_.prototype.enter.call(self, client);
|
MessageAreaListModule.super_.prototype.enter.call(self, client);
|
||||||
});
|
});*/
|
||||||
};
|
};
|
||||||
|
|
||||||
MessageAreaListModule.prototype.mciReady = function(mciData, cb) {
|
MessageAreaListModule.prototype.mciReady = function(mciData, cb) {
|
||||||
|
@ -91,14 +115,23 @@ MessageAreaListModule.prototype.mciReady = function(mciData, cb) {
|
||||||
function populateAreaListView(callback) {
|
function populateAreaListView(callback) {
|
||||||
var areaListView = vc.getView(1);
|
var areaListView = vc.getView(1);
|
||||||
|
|
||||||
|
/*
|
||||||
var areaList = [];
|
var areaList = [];
|
||||||
self.messageAreas.forEach(function entry(msgArea) {
|
self.messageAreas.forEach(function entry(msgArea) {
|
||||||
// :TODO: depending on options, filter out private, local user to user, etc. area IDs
|
// :TODO: depending on options, filter out private, local user to user, etc. area IDs
|
||||||
// :TODO: dep. on options, filter out areas that current user does not have access to
|
// :TODO: dep. on options, filter out areas that current user does not have access to
|
||||||
areaList.push(strUtil.format(self.entryFormat, msgArea));
|
areaList.push(strUtil.format(self.entryFormat, msgArea));
|
||||||
});
|
});*/
|
||||||
|
|
||||||
areaListView.setItems(areaList);
|
var areaListItems = [];
|
||||||
|
for(var i = 0; i < self.messageAreas.length; ++i) {
|
||||||
|
areaListItems.push(strUtil.format(
|
||||||
|
self.entryFormat,
|
||||||
|
{ index : i, name : self.messageAreas[i].name, desc : self.messageAreas[i].desc })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
areaListView.setItems(areaListItems);
|
||||||
areaListView.redraw();
|
areaListView.redraw();
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in New Issue