rename functions to avoid mistakes
the remove fields are not clear enough. we sent notes by mistake to normal users. changing the name and passing role as the argument will avoid these errors
This commit is contained in:
+26
-27
@@ -4,8 +4,7 @@ exports = module.exports = {
|
||||
canAccess,
|
||||
isOperator,
|
||||
accessLevel,
|
||||
removeInternalFields,
|
||||
removeRestrictedFields,
|
||||
pickFields,
|
||||
|
||||
// database crud
|
||||
add,
|
||||
@@ -587,35 +586,35 @@ async function getStorageDir(app) {
|
||||
return path.join(volume.hostPath, app.storageVolumePrefix);
|
||||
}
|
||||
|
||||
function removeCertificateKeys(app) {
|
||||
if (app.certificate) delete app.certificate.key;
|
||||
app.secondaryDomains.forEach(sd => { if (sd.certificate) delete sd.certificate.key; });
|
||||
app.aliasDomains.forEach(ad => { if (ad.certificate) delete ad.certificate.key; });
|
||||
app.redirectDomains.forEach(rd => { if (rd.certificate) delete rd.certificate.key; });
|
||||
}
|
||||
function pickFields(app, accessLevel) {
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
assert.strictEqual(typeof accessLevel, 'string');
|
||||
|
||||
function removeInternalFields(app) {
|
||||
const result = _.pick(app,
|
||||
'id', 'appStoreId', 'installationState', 'error', 'runState', 'health', 'taskId',
|
||||
'subdomain', 'domain', 'fqdn', 'certificate', 'crontab', 'upstreamUri',
|
||||
'accessRestriction', 'manifest', 'portBindings', 'iconUrl', 'memoryLimit', 'cpuQuota', 'operators',
|
||||
'sso', 'debugMode', 'reverseProxyConfig', 'enableBackup', 'creationTime', 'updateTime', 'ts', 'tags',
|
||||
'label', 'notes', 'secondaryDomains', 'redirectDomains', 'aliasDomains', 'devices', 'env', 'enableAutomaticUpdate',
|
||||
'storageVolumeId', 'storageVolumePrefix', 'mounts', 'enableTurn', 'enableRedis', 'checklist',
|
||||
'enableMailbox', 'mailboxDisplayName', 'mailboxName', 'mailboxDomain', 'enableInbox', 'inboxName', 'inboxDomain');
|
||||
if (accessLevel === exports.ACCESS_LEVEL_NONE) return null; // cannot happen!
|
||||
|
||||
removeCertificateKeys(result);
|
||||
return result;
|
||||
}
|
||||
let result;
|
||||
if (accessLevel === exports.ACCESS_LEVEL_USER) {
|
||||
result = _.pick(app,
|
||||
'id', 'appStoreId', 'installationState', 'error', 'runState', 'health', 'taskId', 'accessRestriction',
|
||||
'secondaryDomains', 'redirectDomains', 'aliasDomains', 'sso', 'subdomain', 'domain', 'fqdn', 'certificate',
|
||||
'manifest', 'portBindings', 'iconUrl', 'creationTime', 'ts', 'tags', 'label', 'upstreamUri');
|
||||
} else { // admin or operator
|
||||
result = _.pick(app,
|
||||
'id', 'appStoreId', 'installationState', 'error', 'runState', 'health', 'taskId',
|
||||
'subdomain', 'domain', 'fqdn', 'certificate', 'crontab', 'upstreamUri',
|
||||
'accessRestriction', 'manifest', 'portBindings', 'iconUrl', 'memoryLimit', 'cpuQuota', 'operators',
|
||||
'sso', 'debugMode', 'reverseProxyConfig', 'enableBackup', 'creationTime', 'updateTime', 'ts', 'tags',
|
||||
'label', 'notes', 'secondaryDomains', 'redirectDomains', 'aliasDomains', 'devices', 'env', 'enableAutomaticUpdate',
|
||||
'storageVolumeId', 'storageVolumePrefix', 'mounts', 'enableTurn', 'enableRedis', 'checklist',
|
||||
'enableMailbox', 'mailboxDisplayName', 'mailboxName', 'mailboxDomain', 'enableInbox', 'inboxName', 'inboxDomain');
|
||||
}
|
||||
|
||||
// non-admins can only see these
|
||||
function removeRestrictedFields(app) {
|
||||
const result = _.pick(app,
|
||||
'id', 'appStoreId', 'installationState', 'error', 'runState', 'health', 'taskId', 'accessRestriction',
|
||||
'secondaryDomains', 'redirectDomains', 'aliasDomains', 'sso', 'subdomain', 'domain', 'fqdn', 'certificate',
|
||||
'manifest', 'portBindings', 'iconUrl', 'creationTime', 'ts', 'tags', 'label', 'upstreamUri');
|
||||
// remove private certificate key
|
||||
if (result.certificate) delete result.certificate.key;
|
||||
result.secondaryDomains.forEach(sd => { if (sd.certificate) delete sd.certificate.key; });
|
||||
result.aliasDomains.forEach(ad => { if (ad.certificate) delete ad.certificate.key; });
|
||||
result.redirectDomains.forEach(rd => { if (rd.certificate) delete rd.certificate.key; });
|
||||
|
||||
removeCertificateKeys(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user