-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
When using the Mongo as the primary datasource, Role.getRoles is unable to retrieve Roles associated with a principal by RoleMapping records (database based roles). The issue looks to be related to common/model/role.js lines 352-380:
var roleMappingModel = this.RoleMapping || loopback.getModelByType(RoleMapping);
context.principals.forEach(function(p) {
// Check against the role mappings
var principalType = p.type || undefined;
var principalId = p.id || undefined;
// Add the role itself
if (principalType === RoleMapping.ROLE && principalId) {
addRole(principalId);
}
if (principalType && principalId) {
// Please find() treat undefined matches all values
inRoleTasks.push(function(done) {
roleMappingModel.find({where: {principalType: principalType,
principalId: principalId}}, function(err, mappings) {
debug('Role mappings found: %s %j', err, mappings);
if (err) {
done && done(err);
return;
}
mappings.forEach(function(m) {
addRole(m.roleId);
});
done && done();
});
});
}
});
Mongo stores the id field of a principal as an ObjectId type while RoleMapping is storing principalId as a string. The query passed to roleMappingModel.find is unable to match an ObjectId to a string, but I'm not sure what the proper resolution here is ...
Metadata
Metadata
Assignees
Labels
No labels