2016-07-24 17:47:34 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// ENiGMA½
|
2022-06-05 20:04:25 +00:00
|
|
|
const checkAcs = require('./acs_parser.js').parse;
|
|
|
|
const Log = require('./logger.js').log;
|
2016-07-24 17:47:34 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// deps
|
2022-06-05 20:04:25 +00:00
|
|
|
const assert = require('assert');
|
|
|
|
const _ = require('lodash');
|
2016-07-24 17:47:34 +00:00
|
|
|
|
|
|
|
class ACS {
|
2018-12-28 17:39:41 +00:00
|
|
|
constructor(subject) {
|
|
|
|
this.subject = subject;
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 03:30:00 +00:00
|
|
|
static get Defaults() {
|
|
|
|
return {
|
2022-06-05 20:04:25 +00:00
|
|
|
MessageConfRead: 'GM[users]', // list/read
|
|
|
|
MessageConfWrite: 'GM[users]', // post/write
|
2019-09-16 03:30:00 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
MessageAreaRead: 'GM[users]', // list/read; requires parent conf read
|
|
|
|
MessageAreaWrite: 'GM[users]', // post/write; requires parent conf write
|
2019-09-16 03:30:00 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
FileAreaRead: 'GM[users]', // list
|
|
|
|
FileAreaWrite: 'GM[sysops]', // upload
|
|
|
|
FileAreaDownload: 'GM[users]', // download
|
2019-09-16 03:30:00 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
check(acs, scope, defaultAcs) {
|
|
|
|
acs = acs ? acs[scope] : defaultAcs;
|
|
|
|
acs = acs || defaultAcs;
|
|
|
|
try {
|
2022-06-05 20:04:25 +00:00
|
|
|
return checkAcs(acs, { subject: this.subject });
|
|
|
|
} catch (e) {
|
|
|
|
Log.warn({ exception: e, acs: acs }, 'Exception caught checking ACS');
|
2018-06-22 05:15:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// Message Conferences & Areas
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
|
|
|
hasMessageConfRead(conf) {
|
|
|
|
return this.check(conf.acs, 'read', ACS.Defaults.MessageConfRead);
|
|
|
|
}
|
|
|
|
|
2019-09-16 03:30:00 +00:00
|
|
|
hasMessageConfWrite(conf) {
|
|
|
|
return this.check(conf.acs, 'write', ACS.Defaults.MessageConfWrite);
|
|
|
|
}
|
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
hasMessageAreaRead(area) {
|
|
|
|
return this.check(area.acs, 'read', ACS.Defaults.MessageAreaRead);
|
|
|
|
}
|
|
|
|
|
2019-09-16 03:30:00 +00:00
|
|
|
hasMessageAreaWrite(area) {
|
|
|
|
return this.check(area.acs, 'write', ACS.Defaults.MessageAreaWrite);
|
|
|
|
}
|
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// File Base / Areas
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
|
|
|
hasFileAreaRead(area) {
|
|
|
|
return this.check(area.acs, 'read', ACS.Defaults.FileAreaRead);
|
|
|
|
}
|
|
|
|
|
|
|
|
hasFileAreaWrite(area) {
|
2019-09-16 03:30:00 +00:00
|
|
|
// :TODO: create 'upload' alias?
|
2018-06-22 05:15:04 +00:00
|
|
|
return this.check(area.acs, 'write', ACS.Defaults.FileAreaWrite);
|
|
|
|
}
|
|
|
|
|
|
|
|
hasFileAreaDownload(area) {
|
|
|
|
return this.check(area.acs, 'download', ACS.Defaults.FileAreaDownload);
|
|
|
|
}
|
|
|
|
|
2018-08-04 17:49:44 +00:00
|
|
|
hasMenuModuleAccess(modInst) {
|
|
|
|
const acs = _.get(modInst, 'menuConfig.config.acs');
|
2022-06-05 20:04:25 +00:00
|
|
|
if (!_.isString(acs)) {
|
|
|
|
return true; // no ACS check req.
|
2018-08-04 17:49:44 +00:00
|
|
|
}
|
|
|
|
try {
|
2022-06-05 20:04:25 +00:00
|
|
|
return checkAcs(acs, { subject: this.subject });
|
|
|
|
} catch (e) {
|
|
|
|
Log.warn({ exception: e, acs: acs }, 'Exception caught checking ACS');
|
2018-08-04 17:49:44 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-08 13:42:15 +00:00
|
|
|
matches(acs) {
|
|
|
|
return checkAcs(acs, {subject: this.subject});
|
|
|
|
}
|
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
getConditionalValue(condArray, memberName) {
|
2022-06-05 20:04:25 +00:00
|
|
|
if (!Array.isArray(condArray)) {
|
2018-06-23 03:26:46 +00:00
|
|
|
// no cond array, just use the value
|
2018-06-22 05:15:04 +00:00
|
|
|
return condArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(_.isString(memberName));
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
const matchCond = condArray.find(cond => {
|
|
|
|
if (_.has(cond, 'acs')) {
|
2018-06-22 05:15:04 +00:00
|
|
|
try {
|
2022-06-05 20:04:25 +00:00
|
|
|
return checkAcs(cond.acs, { subject: this.subject });
|
|
|
|
} catch (e) {
|
|
|
|
Log.warn(
|
|
|
|
{ exception: e, acs: cond },
|
|
|
|
'Exception caught checking ACS'
|
|
|
|
);
|
2018-06-22 05:15:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
2022-06-05 20:04:25 +00:00
|
|
|
return true; // no ACS check req.
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
if (matchCond) {
|
2018-06-22 05:15:04 +00:00
|
|
|
return matchCond[memberName];
|
|
|
|
}
|
|
|
|
}
|
2016-07-24 17:47:34 +00:00
|
|
|
}
|
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
module.exports = ACS;
|