@@ -129,12 +129,20 @@ export const Utils = {
129129 * Get a Controller's method's policies
130130 */
131131 getControllerPolicy ( app : FabrixApp , handler , routeMethod , pre = [ ] ) {
132+ const controller = Utils . getControllerFromHandler ( handler )
133+
132134 if ( app . config . get ( 'policies.*.*' ) ) {
133135 pre = [ ...new Set ( [ ...pre , ...Utils . stringToArray ( app . config . get ( 'policies.*.*' ) ) ] ) ]
134136 }
135137 if ( app . config . get ( `policies.*.${ routeMethod } ` ) ) {
136138 pre = [ ...new Set ( [ ...pre , ...Utils . stringToArray ( app . config . get ( `policies.*.${ routeMethod } ` ) ) ] ) ]
137139 }
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+ }
138146 if ( handler && app . config . get ( `policies.${ handler } .${ routeMethod } ` ) ) {
139147 pre = [ ...new Set ( [ ...pre , ...Utils . stringToArray ( app . config . get ( `policies.${ handler } .${ routeMethod } ` ) ) ] ) ]
140148 }
@@ -172,6 +180,10 @@ export const Utils = {
172180 return get ( app . controllers , handler )
173181 } ,
174182
183+ getControllerFromHandler ( handler ) {
184+ return isString ( handler ) ? handler . split ( '.' ) [ 0 ] : handler
185+ } ,
186+
175187 /**
176188 * Get handler method from a controller.method string path
177189 */
@@ -221,20 +233,6 @@ export const Utils = {
221233 } )
222234 } ,
223235
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-
238236 /**
239237 * Build a route collection
240238 */
0 commit comments