mirror of
https://github.com/wassname/talk.git
synced 2026-09-09 11:38:08 +08:00
replaced eslint:recommended with prettier
This commit is contained in:
@@ -4,8 +4,4 @@ const mutation = require('./mutation');
|
||||
const query = require('./query');
|
||||
const subscription = require('./subscription');
|
||||
|
||||
module.exports = merge(...[
|
||||
mutation,
|
||||
query,
|
||||
subscription,
|
||||
]);
|
||||
module.exports = merge(...[mutation, query, subscription]);
|
||||
|
||||
@@ -8,5 +8,5 @@ module.exports = {
|
||||
SUBSCRIBE_ALL_USER_SUSPENDED: 'SUBSCRIBE_ALL_USER_SUSPENDED',
|
||||
SUBSCRIBE_ALL_USER_BANNED: 'SUBSCRIBE_ALL_USER_BANNED',
|
||||
SUBSCRIBE_ALL_USERNAME_REJECTED: 'SUBSCRIBE_ALL_USERNAME_REJECTED',
|
||||
SUBSCRIBE_ALL_USERNAME_APPROVED: 'SUBSCRIBE_ALL_USERNAME_APPROVED'
|
||||
SUBSCRIBE_ALL_USERNAME_APPROVED: 'SUBSCRIBE_ALL_USERNAME_APPROVED',
|
||||
};
|
||||
|
||||
+12
-11
@@ -11,18 +11,19 @@ const constantsArray = Object.keys(constants);
|
||||
* @param {Array<String>} perms the array of permissions that the user must have
|
||||
* in order to succeed
|
||||
*/
|
||||
const findGrant = (user, perms) => perms.every((perm) => {
|
||||
for (let key in reducers) {
|
||||
const reducer = reducers[key];
|
||||
const grant = reducer(user, perm);
|
||||
const findGrant = (user, perms) =>
|
||||
perms.every(perm => {
|
||||
for (let key in reducers) {
|
||||
const reducer = reducers[key];
|
||||
const grant = reducer(user, perm);
|
||||
|
||||
if (typeof grant !== 'undefined' && grant !== null) {
|
||||
return grant;
|
||||
if (typeof grant !== 'undefined' && grant !== null) {
|
||||
return grant;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
/**
|
||||
* returns true, false, or null depending on whether the user has those permissions
|
||||
@@ -33,8 +34,8 @@ const findGrant = (user, perms) => perms.every((perm) => {
|
||||
* @return {Boolean}
|
||||
*/
|
||||
module.exports = (user, ...perms) => {
|
||||
if (perms.some((perm) => !constantsArray.includes(perm))) {
|
||||
const missingPerms = perms.filter((perm) => !constantsArray.includes(perm));
|
||||
if (perms.some(perm => !constantsArray.includes(perm))) {
|
||||
const missingPerms = perms.filter(perm => !constantsArray.includes(perm));
|
||||
throw new Error(`${missingPerms.join(' ')} are not valid permissions.`);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,15 +4,13 @@ const subscription = require('./subscription');
|
||||
|
||||
module.exports = [
|
||||
(user /* , perm*/) => {
|
||||
|
||||
// If a user is banned or currently suspended, then they aren't allowed to
|
||||
// do anything.
|
||||
if (user.banned || user.suspended) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
(user) => {
|
||||
|
||||
user => {
|
||||
// System users can do everything!
|
||||
if (user.system === true) {
|
||||
return true;
|
||||
|
||||
+30
-31
@@ -1,43 +1,42 @@
|
||||
const {check} = require('../utils');
|
||||
const { check } = require('../utils');
|
||||
const types = require('../constants');
|
||||
|
||||
module.exports = (user, perm) => {
|
||||
switch (perm) {
|
||||
case types.CHANGE_USERNAME:
|
||||
return user.status.username.status === 'REJECTED';
|
||||
case types.CHANGE_USERNAME:
|
||||
return user.status.username.status === 'REJECTED';
|
||||
|
||||
case types.SET_USERNAME:
|
||||
return user.status.username.status === 'UNSET';
|
||||
case types.SET_USERNAME:
|
||||
return user.status.username.status === 'UNSET';
|
||||
|
||||
case types.CREATE_COMMENT:
|
||||
case types.CREATE_ACTION:
|
||||
case types.DELETE_ACTION:
|
||||
case types.EDIT_COMMENT:
|
||||
case types.CREATE_COMMENT:
|
||||
case types.CREATE_ACTION:
|
||||
case types.DELETE_ACTION:
|
||||
case types.EDIT_COMMENT:
|
||||
// Anyone can do these things if they aren't suspended, banned, or blocked
|
||||
// as they're editing their username.
|
||||
return !['UNSET', 'REJECTED'].includes(user.status.username.status);
|
||||
|
||||
// Anyone can do these things if they aren't suspended, banned, or blocked
|
||||
// as they're editing their username.
|
||||
return !['UNSET', 'REJECTED'].includes(user.status.username.status);
|
||||
case types.ADD_COMMENT_TAG:
|
||||
case types.REMOVE_COMMENT_TAG:
|
||||
return check(user, ['ADMIN', 'MODERATOR', 'STAFF']);
|
||||
|
||||
case types.ADD_COMMENT_TAG:
|
||||
case types.REMOVE_COMMENT_TAG:
|
||||
return check(user, ['ADMIN', 'MODERATOR', 'STAFF']);
|
||||
case types.SET_COMMENT_STATUS:
|
||||
case types.SET_USER_USERNAME_STATUS:
|
||||
case types.SET_USER_BAN_STATUS:
|
||||
case types.SET_USER_SUSPENSION_STATUS:
|
||||
case types.UPDATE_ASSET_SETTINGS:
|
||||
case types.UPDATE_ASSET_STATUS:
|
||||
return check(user, ['ADMIN', 'MODERATOR']);
|
||||
|
||||
case types.SET_COMMENT_STATUS:
|
||||
case types.SET_USER_USERNAME_STATUS:
|
||||
case types.SET_USER_BAN_STATUS:
|
||||
case types.SET_USER_SUSPENSION_STATUS:
|
||||
case types.UPDATE_ASSET_SETTINGS:
|
||||
case types.UPDATE_ASSET_STATUS:
|
||||
return check(user, ['ADMIN', 'MODERATOR']);
|
||||
case types.UPDATE_CONFIG:
|
||||
case types.UPDATE_SETTINGS:
|
||||
case types.UPDATE_USER_ROLES:
|
||||
case types.CREATE_TOKEN:
|
||||
case types.REVOKE_TOKEN:
|
||||
return check(user, ['ADMIN']);
|
||||
|
||||
case types.UPDATE_CONFIG:
|
||||
case types.UPDATE_SETTINGS:
|
||||
case types.UPDATE_USER_ROLES:
|
||||
case types.CREATE_TOKEN:
|
||||
case types.REVOKE_TOKEN:
|
||||
return check(user, ['ADMIN']);
|
||||
|
||||
default:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
+16
-16
@@ -1,22 +1,22 @@
|
||||
const {check} = require('../utils');
|
||||
const { check } = require('../utils');
|
||||
const types = require('../constants');
|
||||
|
||||
module.exports = (user, perm) => {
|
||||
switch (perm) {
|
||||
case types.SEARCH_ASSETS:
|
||||
case types.SEARCH_OTHER_USERS:
|
||||
case types.SEARCH_ACTIONS:
|
||||
case types.SEARCH_NON_NULL_OR_ACCEPTED_COMMENTS:
|
||||
case types.SEARCH_OTHERS_COMMENTS:
|
||||
return check(user, ['ADMIN', 'MODERATOR']);
|
||||
case types.SEARCH_COMMENT_STATUS_HISTORY:
|
||||
case types.VIEW_USER_STATUS:
|
||||
case types.VIEW_PROTECTED_SETTINGS:
|
||||
case types.VIEW_USER_ROLE:
|
||||
return check(user, ['ADMIN', 'MODERATOR']);
|
||||
case types.LIST_OWN_TOKENS:
|
||||
return check(user, ['ADMIN']);
|
||||
default:
|
||||
break;
|
||||
case types.SEARCH_ASSETS:
|
||||
case types.SEARCH_OTHER_USERS:
|
||||
case types.SEARCH_ACTIONS:
|
||||
case types.SEARCH_NON_NULL_OR_ACCEPTED_COMMENTS:
|
||||
case types.SEARCH_OTHERS_COMMENTS:
|
||||
return check(user, ['ADMIN', 'MODERATOR']);
|
||||
case types.SEARCH_COMMENT_STATUS_HISTORY:
|
||||
case types.VIEW_USER_STATUS:
|
||||
case types.VIEW_PROTECTED_SETTINGS:
|
||||
case types.VIEW_USER_ROLE:
|
||||
return check(user, ['ADMIN', 'MODERATOR']);
|
||||
case types.LIST_OWN_TOKENS:
|
||||
return check(user, ['ADMIN']);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
const {check} = require('../utils');
|
||||
const { check } = require('../utils');
|
||||
const types = require('../constants');
|
||||
|
||||
module.exports = (user, perm) => {
|
||||
switch (perm) {
|
||||
case types.SUBSCRIBE_COMMENT_FLAGGED:
|
||||
case types.SUBSCRIBE_COMMENT_ACCEPTED:
|
||||
case types.SUBSCRIBE_COMMENT_REJECTED:
|
||||
case types.SUBSCRIBE_COMMENT_RESET:
|
||||
case types.SUBSCRIBE_ALL_COMMENT_EDITED:
|
||||
case types.SUBSCRIBE_ALL_COMMENT_ADDED:
|
||||
case types.SUBSCRIBE_ALL_USER_SUSPENDED:
|
||||
case types.SUBSCRIBE_ALL_USER_BANNED:
|
||||
case types.SUBSCRIBE_ALL_USERNAME_REJECTED:
|
||||
case types.SUBSCRIBE_ALL_USERNAME_APPROVED:
|
||||
return check(user, ['ADMIN', 'MODERATOR']);
|
||||
default:
|
||||
break;
|
||||
case types.SUBSCRIBE_COMMENT_FLAGGED:
|
||||
case types.SUBSCRIBE_COMMENT_ACCEPTED:
|
||||
case types.SUBSCRIBE_COMMENT_REJECTED:
|
||||
case types.SUBSCRIBE_COMMENT_RESET:
|
||||
case types.SUBSCRIBE_ALL_COMMENT_EDITED:
|
||||
case types.SUBSCRIBE_ALL_COMMENT_ADDED:
|
||||
case types.SUBSCRIBE_ALL_USER_SUSPENDED:
|
||||
case types.SUBSCRIBE_ALL_USER_BANNED:
|
||||
case types.SUBSCRIBE_ALL_USERNAME_REJECTED:
|
||||
case types.SUBSCRIBE_ALL_USERNAME_APPROVED:
|
||||
return check(user, ['ADMIN', 'MODERATOR']);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
+2
-3
@@ -1,12 +1,11 @@
|
||||
|
||||
/**
|
||||
* check will ensure that the user has the desired roles.
|
||||
*
|
||||
* @param {Object} user user being checked for roles
|
||||
* @param {Array<String>} roles roles to check that the user has
|
||||
*/
|
||||
const check = (user, roles) => roles.some((role) => role === user.role);
|
||||
const check = (user, roles) => roles.some(role => role === user.role);
|
||||
|
||||
module.exports = {
|
||||
check
|
||||
check,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user