@@ -49,7 +49,7 @@ module.exports = class AccessUtils {
49
49
/**
50
50
* Add operation hooks to limit access.
51
51
*/
52
- setupModels ( ) {
52
+ setupFilters ( ) {
53
53
const models = [ this . options . groupModel ] . concat ( this . getGroupContentModels ( ) ) ;
54
54
55
55
models . forEach ( modelName => {
@@ -298,14 +298,13 @@ module.exports = class AccessUtils {
298
298
this . app . loopback . getCurrentContext ( ) . set ( 'groupAccessApplied' , true ) ;
299
299
300
300
/**
301
- * Basic application that does not cover static methods.
302
- * Similar to $owner.
301
+ * Basic application that does not cover static methods. Similar to $owner. (RECOMMENDED)
303
302
*/
304
303
if ( ! this . options . applyToStatic ) {
305
- if ( ! context || ! context . model || ! context . modelId ) {
304
+ if ( ! context || ! modelClass || ! modelId ) {
306
305
process . nextTick ( ( ) => {
307
306
debug ( 'Deny access (context: %s, context.model: %s, context.modelId: %s)' ,
308
- Boolean ( context ) , Boolean ( context . model ) , Boolean ( context . modelId ) ) ;
307
+ Boolean ( context ) , Boolean ( modelClass ) , Boolean ( modelId ) ) ;
309
308
cb ( null , false ) ;
310
309
} ) ;
311
310
return cb . promise ;
@@ -319,7 +318,7 @@ module.exports = class AccessUtils {
319
318
}
320
319
321
320
/**
322
- * More complex application that also covers static methods.
321
+ * More complex application that also covers static methods. (EXPERIMENTAL)
323
322
*/
324
323
Promise . join ( this . getCurrentGroupId ( context ) , this . getTargetGroupId ( context ) ,
325
324
( currentGroupId , targetGroupId ) => {
@@ -402,6 +401,7 @@ module.exports = class AccessUtils {
402
401
403
402
// Is the modelClass GroupModel or a subclass of GroupModel?
404
403
if ( this . isGroupModel ( modelClass ) ) {
404
+ debug ( 'Access to Group Model %s attempted' , modelId ) ;
405
405
this . hasRoleInGroup ( userId , roleId , modelId )
406
406
. then ( res => cb ( null , res ) ) ;
407
407
return cb . promise ;
@@ -452,7 +452,7 @@ module.exports = class AccessUtils {
452
452
. then ( count => {
453
453
const res = count > 0 ;
454
454
455
- debug ( `user ${ userId } has role ${ role } in group ${ group } : ${ res } ` ) ;
455
+ debug ( `User ${ userId } ${ res ? 'HAS' : 'DOESNT HAVE' } ${ role } role in group ${ group } ` ) ;
456
456
cb ( null , res ) ;
457
457
} ) ;
458
458
return cb . promise ;
0 commit comments