mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-07-30 22:46:17 +02:00
* 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
4 changed files with 103 additions and 10 deletions
|
@ -2,15 +2,59 @@
|
|||
'use strict';
|
||||
|
||||
var msgDb = require('./database.js').dbs.message;
|
||||
var Config = require('./config.js').config;
|
||||
|
||||
var async = require('async');
|
||||
var _ = require('lodash');
|
||||
var assert = require('assert');
|
||||
|
||||
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) {
|
||||
var areas = []; // { areaId, name, groupIds[] }
|
||||
|
||||
|
@ -59,7 +103,6 @@ function getAvailableMessageAreas(cb) {
|
|||
cb(err, areas);
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function changeCurrentArea(client, areaId, cb) {
|
||||
|
@ -104,4 +147,5 @@ function changeCurrentArea(client, areaId, cb) {
|
|||
cb(err);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
*/
|
Loading…
Add table
Add a link
Reference in a new issue