Add unauthenticated role
This commit is contained in:
parent
bee8a3b022
commit
344c74297c
|
@ -135,6 +135,7 @@ Role.once('dataSourceAttached', function () {
|
|||
Role.OWNER = '$owner'; // owner of the object
|
||||
Role.RELATED = "$related"; // any User with a relationship to the object
|
||||
Role.AUTHENTICATED = "$authenticated"; // authenticated user
|
||||
Role.UNAUTHENTICATED = "$unauthenticated"; // authenticated user
|
||||
Role.EVERYONE = "$everyone"; // everyone
|
||||
|
||||
/**
|
||||
|
@ -203,6 +204,12 @@ function isAuthenticated(userId, callback) {
|
|||
});
|
||||
}
|
||||
|
||||
Role.registerResolver(Role.UNAUTHENTICATED, function(role, context, callback) {
|
||||
process.nextTick(function() {
|
||||
callback && callback(null, !context || !context.principalId);
|
||||
});
|
||||
});
|
||||
|
||||
Role.registerResolver(Role.EVERYONE, function (role, context, callback) {
|
||||
process.nextTick(function () {
|
||||
callback && callback(null, true); // Always true
|
||||
|
|
|
@ -129,6 +129,13 @@ describe('role model', function () {
|
|||
assert(!err && !yes);
|
||||
});
|
||||
|
||||
Role.isInRole(Role.UNAUTHENTICATED, {principalType: ACL.USER, principalId: user.id}, function (err, yes) {
|
||||
assert(!err && !yes);
|
||||
});
|
||||
Role.isInRole(Role.UNAUTHENTICATED, {principalType: ACL.USER, principalId: null}, function (err, yes) {
|
||||
assert(!err && yes);
|
||||
});
|
||||
|
||||
Role.isInRole(Role.EVERYONE, {principalType: ACL.USER, principalId: user.id}, function (err, yes) {
|
||||
assert(!err && yes);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue