Ensure that permission functions work without a user

This commit is contained in:
Piotr Sarnacki 2016-03-22 12:43:19 +01:00
parent e66efc1cbc
commit cbd0c46e37
2 changed files with 12 additions and 9 deletions

View File

@ -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);
}
}

View File

@ -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));
});