Ensure that permission functions work without a user
This commit is contained in:
parent
e66efc1cbc
commit
cbd0c46e37
|
@ -1,29 +1,29 @@
|
|||
|
||||
var hasPermission = function(currentUser, repoId) {
|
||||
var hasPermission = function(user, repoId) {
|
||||
var id = parseInt(repoId);
|
||||
var permissions;
|
||||
if (currentUser) {
|
||||
if (permissions = currentUser.get('permissions')) {
|
||||
if (user) {
|
||||
if (permissions = user.get('permissions')) {
|
||||
return permissions.contains(id);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var hasPushPermission = function(currentUser, repoId) {
|
||||
var hasPushPermission = function(user, repoId) {
|
||||
var id = parseInt(repoId);
|
||||
var permissions;
|
||||
if (currentUser) {
|
||||
if (permissions = currentUser.get('pushPermissions')) {
|
||||
if (user) {
|
||||
if (permissions = user.get('pushPermissions')) {
|
||||
return permissions.contains(id);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var hasAdminPermission = function(currentUser, repoId) {
|
||||
var hasAdminPermission = function(user, repoId) {
|
||||
var id = parseInt(repoId);
|
||||
var permissions;
|
||||
if (currentUser) {
|
||||
if (permissions = currentUser.get('adminPermissions')) {
|
||||
if (user) {
|
||||
if (permissions = user.get('adminPermissions')) {
|
||||
return permissions.contains(id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,16 +8,19 @@ test('it checks permissions', function(assert) {
|
|||
let user = Ember.Object.create({permissions: [1]});
|
||||
assert.ok(hasPermission(user, 1));
|
||||
assert.ok(!hasPermission(user, 2));
|
||||
assert.ok(!hasPermission(null, 1));
|
||||
});
|
||||
|
||||
test('it checks push permissions', function(assert) {
|
||||
let user = Ember.Object.create({pushPermissions: [1]});
|
||||
assert.ok(hasPushPermission(user, 1));
|
||||
assert.ok(!hasPushPermission(user, 2));
|
||||
assert.ok(!hasPushPermission(null, 1));
|
||||
});
|
||||
|
||||
test('it checks admin permissions', function(assert) {
|
||||
let user = Ember.Object.create({adminPermissions: [1]});
|
||||
assert.ok(hasAdminPermission(user, 1));
|
||||
assert.ok(!hasAdminPermission(user, 2));
|
||||
assert.ok(!hasAdminPermission(null, 1));
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user