我開始得到相當看起來像這幾個帆政策:帆政策 - 利用變量
...
'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