Skip to content

Commit 2a3f1e0

Browse files
author
Tom Kirkpatrick
committed
Minor cleanup and better debugging
1 parent 89b7bbd commit 2a3f1e0

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = function loopbackComponentAccess(app, options) {
2929

3030
// Set up model opertion hooks.
3131
if (options.applyToStatic) {
32-
accessUtils.setupModels();
32+
accessUtils.setupFilters();
3333
}
3434

3535
// TODO: Create Group Access model automatically if one hasn't been specified

lib/utils.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module.exports = class AccessUtils {
4949
/**
5050
* Add operation hooks to limit access.
5151
*/
52-
setupModels() {
52+
setupFilters() {
5353
const models = [ this.options.groupModel ].concat(this.getGroupContentModels());
5454

5555
models.forEach(modelName => {
@@ -298,14 +298,13 @@ module.exports = class AccessUtils {
298298
this.app.loopback.getCurrentContext().set('groupAccessApplied', true);
299299

300300
/**
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)
303302
*/
304303
if (!this.options.applyToStatic) {
305-
if (!context || !context.model || !context.modelId) {
304+
if (!context || !modelClass || !modelId) {
306305
process.nextTick(() => {
307306
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));
309308
cb(null, false);
310309
});
311310
return cb.promise;
@@ -319,7 +318,7 @@ module.exports = class AccessUtils {
319318
}
320319

321320
/**
322-
* More complex application that also covers static methods.
321+
* More complex application that also covers static methods. (EXPERIMENTAL)
323322
*/
324323
Promise.join(this.getCurrentGroupId(context), this.getTargetGroupId(context),
325324
(currentGroupId, targetGroupId) => {
@@ -402,6 +401,7 @@ module.exports = class AccessUtils {
402401

403402
// Is the modelClass GroupModel or a subclass of GroupModel?
404403
if (this.isGroupModel(modelClass)) {
404+
debug('Access to Group Model %s attempted', modelId);
405405
this.hasRoleInGroup(userId, roleId, modelId)
406406
.then(res => cb(null, res));
407407
return cb.promise;
@@ -452,7 +452,7 @@ module.exports = class AccessUtils {
452452
.then(count => {
453453
const res = count > 0;
454454

455-
debug(`user ${userId} has role ${role} in group ${group}: ${res}`);
455+
debug(`User ${userId} ${res ? 'HAS' : 'DOESNT HAVE'} ${role} role in group ${group}`);
456456
cb(null, res);
457457
});
458458
return cb.promise;

0 commit comments

Comments
 (0)