mirror of
https://github.com/wassname/talk.git
synced 2026-07-08 04:03:09 +08:00
add a perms utils file
This commit is contained in:
+1
-1
@@ -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,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,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,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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
const intersection = require('lodash/intersection');
|
||||
const check = (user, roles) => {
|
||||
return intersection(roles, user.roles).length > 0;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
check
|
||||
};
|
||||
@@ -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]}});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user