UNPKG

wasteful-scope

Version:

OAuth2 scope utilities for the wasteful scope parsing, comparing, merging, etc

111 lines (99 loc) 2.8 kB
'use strict'; module.exports.create = function (vocab) { function wordify(objScope) { var strings = [] ; console.log('[scope perms]'); console.log(objScope.scope); Object.keys(objScope.scope).forEach(function (groupname) { var names = groupname.split(/\./g) , group = objScope.scope[groupname] , unit = names[0] , subgroups = names[1].split(/_/) , subgroup , privs = [] , priv ; subgroups.forEach(function (str, i) { subgroups[i] = str.charAt(0).toUpperCase() + str.slice(1); }); subgroup = subgroups.join(' '); strings.push({ group: 'Use information about the ' + subgroup + ' in your ' + (unit.charAt(0).toUpperCase() + unit.slice(1)) + ' to ' , privs: privs }); if ((group.readable||[]).length) { priv = ''; priv += 'view'; group.readable.forEach(function (perm, i) { if (i === (group.readable.length - 1)) { if (i > 0) { priv += ' and'; } priv += ' ' + vocab[perm]; } else { if (0 === i) { priv += ' ' + vocab[perm]; } else { priv += ', ' + vocab[perm]; } } }); privs.push(priv); } if ((group.writeable||[]).length) { priv = ''; priv += 'view & update'; group.writeable.forEach(function (perm, i) { console.log('1', perm, '2', vocab[perm]); if (i === (group.writeable.length - 1)) { if (i > 0) { priv = priv + ' and'; } priv = priv + ' ' + vocab[perm]; } else { if (0 === i) { priv = priv + ' ' + vocab[perm]; } else { priv = priv + ', ' + vocab[perm]; } } }); privs.push(priv); } if ((group.executable||[]).length) { priv = ''; if (-1 !== group.executable.indexOf('texting') || -1 !== group.executable.indexOf('emailing')) { priv += 'send'; if (-1 !== group.executable.indexOf('texting')) { priv += ' texts'; if (-1 !== group.executable.indexOf('emailing')) { priv += ' &'; } } if (-1 !== group.executable.indexOf('emailing')) { priv += ' emails'; } } if (-1 !== group.executable.indexOf('calling')) { if (priv.length > 5) { priv += ' and'; } priv += ' make calls'; } } if (priv) { privs.push(priv); } }); return strings; } return { wordify: wordify }; };