Skip to content

Commit a689edd

Browse files
committed
simplify base user lookup
1 parent b9d289d commit a689edd

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

lib/access-context.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ AccessContext.prototype.addPrincipal = function(principalType, principalId, prin
128128
* @returns {*}
129129
*/
130130
AccessContext.prototype.getUserId = function() {
131+
var BaseUser = this.registry.getModel('User');
131132
for (var i = 0; i < this.principals.length; i++) {
132133
var p = this.principals[i];
133134
var isBuiltinPrincipal = p.type === Principal.APP ||
@@ -143,19 +144,9 @@ AccessContext.prototype.getUserId = function() {
143144
// or permit to resolve a valid user model
144145
var userModel = this.registry.findModel(p.type);
145146
if (!userModel) continue;
146-
if (userModel.modelName === 'User') {
147+
if (userModel.prototype instanceof BaseUser) {
147148
return p.id;
148149
}
149-
var modelBase = userModel.definition.settings.base;
150-
while (modelBase) {
151-
// make sure modelBase is a model instance
152-
modelBase = typeof(modelBase === 'string') ? this.registry.findModel(modelBase) : modelBase;
153-
if (modelBase.modelName === 'User') {
154-
return p.id;
155-
}
156-
// iterate on the upper base model
157-
modelBase = modelBase.definition.settings.base;
158-
}
159150
}
160151
return null;
161152
};

0 commit comments

Comments
 (0)