2016-07-24 17:47:34 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// ENiGMA½
|
|
|
|
const checkAcs = require('./acs_parser.js').parse;
|
2016-08-30 03:01:51 +00:00
|
|
|
const Log = require('./logger.js').log;
|
2016-07-24 17:47:34 +00:00
|
|
|
|
|
|
|
// deps
|
|
|
|
const assert = require('assert');
|
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
|
|
class ACS {
|
|
|
|
constructor(client) {
|
|
|
|
this.client = client;
|
|
|
|
}
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2016-07-24 17:47:34 +00:00
|
|
|
check(acs, scope, defaultAcs) {
|
|
|
|
acs = acs ? acs[scope] : defaultAcs;
|
|
|
|
acs = acs || defaultAcs;
|
2016-08-30 03:01:51 +00:00
|
|
|
try {
|
|
|
|
return checkAcs(acs, { client : this.client } );
|
|
|
|
} catch(e) {
|
|
|
|
Log.warn( { exception : e, acs : acs }, 'Exception caught checking ACS');
|
|
|
|
return false;
|
2018-01-15 19:22:11 +00:00
|
|
|
}
|
2016-07-24 17:47:34 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 01:58:56 +00:00
|
|
|
//
|
|
|
|
// Message Conferences & Areas
|
|
|
|
//
|
2016-07-24 17:47:34 +00:00
|
|
|
hasMessageConfRead(conf) {
|
|
|
|
return this.check(conf.acs, 'read', ACS.Defaults.MessageConfRead);
|
|
|
|
}
|
|
|
|
|
|
|
|
hasMessageAreaRead(area) {
|
|
|
|
return this.check(area.acs, 'read', ACS.Defaults.MessageAreaRead);
|
|
|
|
}
|
|
|
|
|
2016-12-07 01:58:56 +00:00
|
|
|
//
|
|
|
|
// File Base / Areas
|
|
|
|
//
|
2016-09-29 03:54:25 +00:00
|
|
|
hasFileAreaRead(area) {
|
|
|
|
return this.check(area.acs, 'read', ACS.Defaults.FileAreaRead);
|
|
|
|
}
|
|
|
|
|
2016-12-31 21:50:29 +00:00
|
|
|
hasFileAreaWrite(area) {
|
|
|
|
return this.check(area.acs, 'write', ACS.Defaults.FileAreaWrite);
|
|
|
|
}
|
|
|
|
|
2016-12-07 01:58:56 +00:00
|
|
|
hasFileAreaDownload(area) {
|
|
|
|
return this.check(area.acs, 'download', ACS.Defaults.FileAreaDownload);
|
|
|
|
}
|
|
|
|
|
2016-07-24 17:47:34 +00:00
|
|
|
getConditionalValue(condArray, memberName) {
|
2018-06-14 02:54:17 +00:00
|
|
|
if(!Array.isArray(condArray)) {
|
|
|
|
// no cond array, just use the value
|
|
|
|
return condArray;
|
|
|
|
}
|
|
|
|
|
2016-07-24 17:47:34 +00:00
|
|
|
assert(_.isString(memberName));
|
|
|
|
|
|
|
|
const matchCond = condArray.find( cond => {
|
|
|
|
if(_.has(cond, 'acs')) {
|
2016-08-30 03:01:51 +00:00
|
|
|
try {
|
|
|
|
return checkAcs(cond.acs, { client : this.client } );
|
|
|
|
} catch(e) {
|
|
|
|
Log.warn( { exception : e, acs : cond }, 'Exception caught checking ACS');
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-24 17:47:34 +00:00
|
|
|
} else {
|
|
|
|
return true; // no acs check req.
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if(matchCond) {
|
|
|
|
return matchCond[memberName];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ACS.Defaults = {
|
|
|
|
MessageAreaRead : 'GM[users]',
|
|
|
|
MessageConfRead : 'GM[users]',
|
2016-09-29 03:54:25 +00:00
|
|
|
|
|
|
|
FileAreaRead : 'GM[users]',
|
2016-12-31 21:50:29 +00:00
|
|
|
FileAreaWrite : 'GM[sysops]',
|
2016-12-07 01:58:56 +00:00
|
|
|
FileAreaDownload : 'GM[users]',
|
2016-07-24 17:47:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = ACS;
|