我开始得到相当看起来像这几个帆政策:帆政策 - 利用变量
...
'MyController':{
'some': ['runPassport', 'isLoggedIn', 'ensureTotpOkIfEnabled'],
'action': ['runPassport', 'isLoggedIn', 'ensureTotpOkIfEnabled'],
'here': ['runPassport', 'isLoggedIn', 'ensureTotpOkIfEnabled', 'extra'],
},
....
的问题是重复的。我想要有一个快捷方式,如“userIsAuthenticated”。
我可以声明一个变量
var userIsAuthenticated = ['runPassport', 'isLoggedIn', 'ensureTotpOkIfEnabled'];
....
'MyController':{
'some': userIsAuthenticated,
'action': userIsAuthenticated,
'here': Array.concat(userIsAuthenticated, ['extra'],
},
我的问题是这里的行动。我认为语法很难阅读和容易出错。
我试着写:
'MyController':{
'some': userIsAuthenticated,
'action': userIsAuthenticated,
'here': [userIsAuthenticated, 'extra'],
},
这看上去很美。它可能有效。虽然我明白我得到一个数组有两个项目,第一个项目是一个包含3个项目的数组。
所以,问题是。在Sails中声明这样的策略是否安全?我在手册中找不到任何提及的语法(http://sailsjs.org/documentation/concepts/policies)。有没有其他方法?
好的,谢谢。猜猜没有完美的方式。 – tkarls