diff --git a/models/user.js b/models/user.js index 3d12d49e9..30069abd0 100644 --- a/models/user.js +++ b/models/user.js @@ -163,7 +163,7 @@ UserSchema.index({ * returns true if a commenter is staff */ UserSchema.method('isStaff', function () { - return !!intersection(['ADMIN', 'MODERATOR', 'STAFF'], this.roles).length; + return intersection(['ADMIN', 'MODERATOR', 'STAFF'], this.roles).length !== 0; }); /** diff --git a/perms/mutationReducer.js b/perms/mutationReducer.js index b589bde90..82bc2de42 100644 --- a/perms/mutationReducer.js +++ b/perms/mutationReducer.js @@ -1,7 +1,4 @@ -const intersection = require('lodash/intersection'); -const check = (user, roles) => { - return !!intersection(roles, user.roles).length; -}; +const {check} = require('./utils'); module.exports = { CREATE_COMMENT: 'CREATE_COMMENT', diff --git a/perms/queryReducer.js b/perms/queryReducer.js index 92f1566d5..65a52358a 100644 --- a/perms/queryReducer.js +++ b/perms/queryReducer.js @@ -1,7 +1,4 @@ -const intersection = require('lodash/intersection'); -const check = (user, roles) => { - return !!intersection(roles, user.roles).length; -}; +const {check} = require('./utils'); module.exports = { SEARCH_ASSETS: 'SEARCH_ASSETS', diff --git a/perms/rootReducer.js b/perms/rootReducer.js index 7abf92753..c48fb9c4d 100644 --- a/perms/rootReducer.js +++ b/perms/rootReducer.js @@ -1,15 +1,9 @@ module.exports = { - DUMMY_ROLE: 'DUMMY_ROLE', - checkRoles: function (user, perm) { + checkRoles: function (user /* , perm*/) { // this runs before everything if (user.status === 'BANNED') { return false; } - - switch (perm) { - default: - break; - } } }; diff --git a/perms/utils.js b/perms/utils.js new file mode 100644 index 000000000..e72a49c53 --- /dev/null +++ b/perms/utils.js @@ -0,0 +1,8 @@ +const intersection = require('lodash/intersection'); +const check = (user, roles) => { + return intersection(roles, user.roles).length > 0; +}; + +module.exports = { + check +}; diff --git a/services/users.js b/services/users.js index 09a4f3a55..83a33e6f6 100644 --- a/services/users.js +++ b/services/users.js @@ -389,9 +389,6 @@ module.exports = class UsersService { return Promise.reject(new Error(`role ${role} is not supported`)); } - // 5.11.2017 - Restricting this to a hierarchical system like WordPress - // where you can only set one role at a time. - // I'm not changing the data structure here, because I don't want a migration return UserModel.update({id}, {$set: {roles: [role]}}); }