mirror of
https://github.com/wassname/talk.git
synced 2026-08-12 12:30:39 +08:00
merge master
This commit is contained in:
+7
-9
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user