merge master

This commit is contained in:
riley
2017-05-16 16:33:41 -06:00
219 changed files with 3845 additions and 1847 deletions
+7 -9
View File
@@ -11,13 +11,13 @@ const reducers = [
// this will make 'reducer' a key in this array. hm.
const allPermissions = [...Object.keys(root), ...Object.keys(queries), ...Object.keys(mutations)];
const findGrant = (user, perms, context) => {
const findGrant = (user, perms) => {
return perms.every(perm => {
return perms.every((perm) => {
for (let key in reducers) {
const reducer = reducers[key];
const grant = reducer.checkRoles(user, perm, context);
const grant = reducer.checkRoles(user, perm);
if (grant !== null && typeof grant !== 'undefined') {
return grant;
@@ -36,18 +36,16 @@ const findGrant = (user, perms, context) => {
* @param {String/Array} perms a string an array of strings which are the names of the permissions
* @return {Boolean}
*/
module.exports = (user, context, ...perms) => {
module.exports = (user, ...perms) => {
// make sure all the passed permissions are not typos
const missingPerms = perms.filter(perm => {
const missingPerms = perms.filter((perm) => {
return allPermissions.indexOf(perm) === -1;
});
if (missingPerms.length) {
// not sure if this is working.
if (missingPerms.length > 0) {
throw new Error(`${missingPerms.join(' ')} are not valid permissions.`);
}
return findGrant(user, perms, context);
return findGrant(user, perms);
};