add a perms utils file

This commit is contained in:
riley
2017-05-18 14:28:43 -06:00
parent ff75b9474a
commit 6deee7cb80
6 changed files with 12 additions and 19 deletions
+1 -1
View File
@@ -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;
});
/**
+1 -4
View File
@@ -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',
+1 -4
View File
@@ -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',
+1 -7
View File
@@ -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;
}
}
};
+8
View File
@@ -0,0 +1,8 @@
const intersection = require('lodash/intersection');
const check = (user, roles) => {
return intersection(roles, user.roles).length > 0;
};
module.exports = {
check
};
-3
View File
@@ -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]}});
}