@@ -129,12 +129,20 @@ export const Utils = {
129
129
* Get a Controller's method's policies
130
130
*/
131
131
getControllerPolicy ( app : FabrixApp , handler , routeMethod , pre = [ ] ) {
132
+ const controller = Utils . getControllerFromHandler ( handler )
133
+
132
134
if ( app . config . get ( 'policies.*.*' ) ) {
133
135
pre = [ ...new Set ( [ ...pre , ...Utils . stringToArray ( app . config . get ( 'policies.*.*' ) ) ] ) ]
134
136
}
135
137
if ( app . config . get ( `policies.*.${ routeMethod } ` ) ) {
136
138
pre = [ ...new Set ( [ ...pre , ...Utils . stringToArray ( app . config . get ( `policies.*.${ routeMethod } ` ) ) ] ) ]
137
139
}
140
+ if ( handler && controller && app . config . get ( `policies.${ controller } .*.*` ) ) {
141
+ pre = [ ...new Set ( [ ...pre , ...Utils . stringToArray ( app . config . get ( `policies.${ controller } .*.*` ) ) ] ) ]
142
+ }
143
+ if ( handler && controller && app . config . get ( `policies.${ controller } .*.${ routeMethod } ` ) ) {
144
+ pre = [ ...new Set ( [ ...pre , ...Utils . stringToArray ( app . config . get ( `policies.${ controller } .*.${ routeMethod } ` ) ) ] ) ]
145
+ }
138
146
if ( handler && app . config . get ( `policies.${ handler } .${ routeMethod } ` ) ) {
139
147
pre = [ ...new Set ( [ ...pre , ...Utils . stringToArray ( app . config . get ( `policies.${ handler } .${ routeMethod } ` ) ) ] ) ]
140
148
}
@@ -172,6 +180,10 @@ export const Utils = {
172
180
return get ( app . controllers , handler )
173
181
} ,
174
182
183
+ getControllerFromHandler ( handler ) {
184
+ return isString ( handler ) ? handler . split ( '.' ) [ 0 ] : handler
185
+ } ,
186
+
175
187
/**
176
188
* Get handler method from a controller.method string path
177
189
*/
@@ -221,20 +233,6 @@ export const Utils = {
221
233
} )
222
234
} ,
223
235
224
- // /**
225
- // *
226
- // */
227
- // getControllerPolicyFromString(app: FabrixApp, handlerString: string) {
228
- // let pre = []
229
- // if (app.config.get('policies.*')) {
230
- // pre.push(Utils.policyStringToArray(app.config.get('policies.*')))
231
- // }
232
- // if (app.config.get(`policies.${handlerString}`)) {
233
- // pre = [...pre, ...Utils.policyStringToArray(app.config.get(`policies.${handlerString}`))]
234
- // }
235
- // return { pre: pre }
236
- // },
237
-
238
236
/**
239
237
* Build a route collection
240
238
*/
0 commit comments