mirror of
https://github.com/wassname/talk.git
synced 2026-07-18 12:40:13 +08:00
change how constants are exposed
This commit is contained in:
+2
-1
@@ -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 => {
|
||||
|
||||
+11
-16
@@ -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;
|
||||
|
||||
+13
-18
@@ -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;
|
||||
|
||||
@@ -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') {
|
||||
|
||||
Reference in New Issue
Block a user