diff --git a/lib/org.js b/lib/org.js index 5b271d58..4cd92f15 100644 --- a/lib/org.js +++ b/lib/org.js @@ -11,7 +11,6 @@ var auth = require('./auth'); var console = require('./log'); const API_BASE = '/dw/rest/v1'; -const ORG_ALLOWED_READ_PROPERTIES = [ 'id', 'name', 'realms', 'twoFARoles' ]; /** * Helper to capture most-common responses due to errors which occur across resources. In case a well-known issue @@ -93,7 +92,7 @@ function getOrg(org, token, callback) { return ( cand.name === org ); }); if ( filtered.length === 1 ) { - callback(undefined, filterOrg(filtered[0])); + callback(undefined, toExternalOrg(filtered[0])); return; } // report ambiguousness @@ -101,24 +100,21 @@ function getOrg(org, token, callback) { return; } // do the callback with the body - callback(undefined, filterOrg(body.content[0])); + callback(undefined, toExternalOrg(body.content[0])); }); } /** - * Filters properties of the passed org and returns a reduced object containing only - * an allowed list of properties. + * Transforms the API org representation to an external format. Certain properties are + * transformed into an object representation. * * @param {Object} org the original org object - * @return {Object} the filtered org + * @return {Object} the transformed org object */ -function filterOrg(org) { - for (var prop in org) { - if (org.hasOwnProperty(prop) && ORG_ALLOWED_READ_PROPERTIES.indexOf(prop) === -1) { - // delete the property if not allowed to read - delete org[prop]; - } - } +function toExternalOrg(org) { + // always delete some properties + delete org['links']; + return org; } @@ -197,9 +193,12 @@ module.exports.cli = { } // table fields - var data = [['id', 'name','realms','twoFARoles']]; + var data = [['id', 'name','realms','twoFARoles','twoFAEnabled','allowedVerifierTypes','vaasEnabled', + 'sfIdentityFederation']]; for (var i of list) { - data.push([i.id, i.name, i.realms.length, ( i.twoFARoles.length > 0 )]); + var org = toExternalOrg(i); + data.push([org.id, org.name, org.realms.length, org.twoFARoles.length, org.twoFAEnabled, + org.allowedVerifierTypes.length, org.vaasEnabled, org.sfIdentityFederation]); } console.table(data); diff --git a/test/unit/org.js b/test/unit/org.js index 526a8336..3e3e7e1f 100644 --- a/test/unit/org.js +++ b/test/unit/org.js @@ -188,7 +188,7 @@ describe('Tests for lib/org.js', function() { it('properly filters internal properties', function(done) { var org = proxyquire('../../lib/org', { 'request': function (opts, callback) { - callback(undefined, {statusCode: 200}, {content:[{id:1,name:"myorg",internal:'yes'}]}); + callback(undefined, {statusCode: 200}, {content:[{id:1,name:"myorg",links:'yes'}]}); }, './auth': { 'getToken' : () => 'mytoken',