From 62e8e4c5c57bf43e80d9fd478b91d02b3822c4ab Mon Sep 17 00:00:00 2001 From: riley Date: Tue, 16 May 2017 10:15:43 -0600 Subject: [PATCH] change how constants are exposed --- perms/index.js | 3 ++- perms/mutationReducer.js | 27 +++++++++++---------------- perms/queryReducer.js | 31 +++++++++++++------------------ perms/rootReducer.js | 3 +-- 4 files changed, 27 insertions(+), 37 deletions(-) diff --git a/perms/index.js b/perms/index.js index c9b29ea85..b2baf00ec 100644 --- a/perms/index.js +++ b/perms/index.js @@ -8,7 +8,8 @@ const reducers = [ mutations.reducer ]; -const allPermissions = [...root.constants, ...queries.constants, ...mutations.constants]; +// 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, initialState) => { return perms.every(perm => { diff --git a/perms/mutationReducer.js b/perms/mutationReducer.js index 75eb22400..7e3c1b3cd 100644 --- a/perms/mutationReducer.js +++ b/perms/mutationReducer.js @@ -3,23 +3,18 @@ const check = (user, roles) => { return !!intersection(roles, user.roles).length; }; -const CREATE_COMMENT = 'CREATE_COMMENT'; -const CREATE_ACTION = 'CREATE_ACTION'; -const DELETE_ACTION = 'DELETE_ACTION'; -const EDIT_NAME = 'EDIT_NAME'; -const SET_USER_STATUS = 'SET_USER_STATUS'; -const SUSPEND_USER = 'SUSPEND_USER'; -const SET_COMMENT_STATUS = 'SET_COMMENT_STATUS'; -const ADD_COMMENT_TAG = 'ADD_COMMENT_TAG'; -const REMOVE_COMMENT_TAG = 'REMOVE_COMMENT_TAG'; -const UPDATE_CONFIG = 'UPDATE_CONFIG'; - module.exports = { - constants: [ - CREATE_COMMENT, CREATE_ACTION, DELETE_ACTION, EDIT_NAME, SET_USER_STATUS, - SUSPEND_USER, SET_COMMENT_STATUS, ADD_COMMENT_TAG, REMOVE_COMMENT_TAG, UPDATE_CONFIG - ], - reducer: (user, perm, context, initialState) => { + CREATE_COMMENT: 'CREATE_COMMENT', + CREATE_ACTION: 'CREATE_ACTION', + DELETE_ACTION: 'DELETE_ACTION', + EDIT_NAME: 'EDIT_NAME', + SET_USER_STATUS: 'SET_USER_STATUS', + SUSPEND_USER: 'SUSPEND_USER', + SET_COMMENT_STATUS: 'SET_COMMENT_STATUS', + ADD_COMMENT_TAG: 'ADD_COMMENT_TAG', + REMOVE_COMMENT_TAG: 'REMOVE_COMMENT_TAG', + UPDATE_CONFIG: 'UPDATE_CONFIG', + reducer: function (user, perm, context, initialState) { switch (perm) { case 'muation:createComment': return true; diff --git a/perms/queryReducer.js b/perms/queryReducer.js index b80a61ea7..9e97c8ec4 100644 --- a/perms/queryReducer.js +++ b/perms/queryReducer.js @@ -3,31 +3,26 @@ const check = (user, roles) => { return !!intersection(roles, user.roles).length; }; -const SEARCH_ASSETS = 'SEARCH_ASSETS'; -const SEARCH_OTHER_USERS = 'SEARCH_OTHER_USERS'; -const SEARCH_ACTIONS = 'SEARCH_ACTIONS'; -const SEARCH_NON_NULL_OR_ACCEPTED_COMMENTS = 'SEARCH_NON_NULL_OR_ACCEPTED_COMMENTS'; -const SEARCH_OTHERS_COMMENTS = 'SEARCH_OTHERS_COMMENTS'; -const SEARCH_COMMENT_METRICS = 'SEARCH_COMMENT_METRICS'; - module.exports = { - constants: [ - SEARCH_ASSETS, SEARCH_OTHER_USERS, SEARCH_ACTIONS, SEARCH_NON_NULL_OR_ACCEPTED_COMMENTS, - SEARCH_OTHERS_COMMENTS, SEARCH_COMMENT_METRICS - ], - reducer: (perm, user, context, initialState) => { + SEARCH_ASSETS: 'SEARCH_ASSETS', + SEARCH_OTHER_USERS: 'SEARCH_OTHER_USERS', + SEARCH_ACTIONS: 'SEARCH_ACTIONS', + SEARCH_NON_NULL_OR_ACCEPTED_COMMENTS: 'SEARCH_NON_NULL_OR_ACCEPTED_COMMENTS', + SEARCH_OTHERS_COMMENTS: 'SEARCH_OTHERS_COMMENTS', + SEARCH_COMMENT_METRICS: 'SEARCH_COMMENT_METRICS', + reducer: function (perm, user, context, initialState) { switch (perm) { - case SEARCH_ASSETS: + case this.SEARCH_ASSETS: return check(user, ['ADMIN', 'MODERATOR']); - case SEARCH_OTHER_USERS: + case this.SEARCH_OTHER_USERS: return check(user, ['ADMIN', 'MODERATOR']); - case SEARCH_ACTIONS: + case this.SEARCH_ACTIONS: return check(user, ['ADMIN', 'MODERATOR']); - case SEARCH_NON_NULL_OR_ACCEPTED_COMMENTS: + case this.SEARCH_NON_NULL_OR_ACCEPTED_COMMENTS: return check(user, ['ADMIN', 'MODERATOR']); - case SEARCH_OTHERS_COMMENTS: + case this.SEARCH_OTHERS_COMMENTS: return check(user, ['ADMIN', 'MODERATOR']); - case SEARCH_COMMENT_METRICS: + case this.SEARCH_COMMENT_METRICS: return check(user, ['ADMIN', 'MODERATOR']); default: return initialState; diff --git a/perms/rootReducer.js b/perms/rootReducer.js index b46b6e82a..e8552c765 100644 --- a/perms/rootReducer.js +++ b/perms/rootReducer.js @@ -1,6 +1,5 @@ module.exports = { - constants: [], - reducer: (perm, user, context, initialState) => { + reducer: function (perm, user, context, initialState) { // this runs before everything if (user.status === 'BANNED') {