私は、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'
}
SuperUser でログインすると、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