【发布时间】:2015-02-26 00:37:10
【问题描述】:
我在sails.js、SuperUser、Admin、User 和 SuOrAdmin 中有 4 个策略以及带有蓝图控制器的 3 个模型,这是策略配置:
'*': 'SuperUser',
User:{
'*': 'SuOrAdmin',
findOne: 'User'
},
Empresa:{
'*': 'SuperUser',
findOne: 'Admin',
findOne: 'User'
},
Noticia:{
'*': 'SuOrAdmin',
find: 'User',
findOne: 'User'
}
当我使用超级用户登录时,我可以对除 Noticia 的 find 方法之外的所有模型进行 CRUD,但是当我使用管理员登录时,我可以对 Noticia 模型进行 CRUD,这是 SuOrAdmin 策略:
module.exports = function(req, res, next) {
// User is allowed, proceed to the next policy,
// or if this is the last policy, the controller
if ( (req.session.user && req.session.user.admin) || (req.session.SuperUser) ) {
return next();
}
// User is not allowed
// (default res.forbidden() behavior can be overridden in `config/403.js`)
return res.json(403, {error: 'You are not permitted to perform this action.'});
};
谁能帮帮我,我在这个问题上被困了 2 天。
@mikermcneil
【问题讨论】: