Commit 0c2faf3f authored by Gergely Ujvari's avatar Gergely Ujvari Committed by ujvari

Introduce isPrivate for permissions service

parent a807c8e5
......@@ -82,7 +82,7 @@ AnnotationController = [
# @returns {boolean} True if the annotation is private to the current user.
###
this.isPrivate = ->
model.user and angular.equals(model.permissions?.read or [], [model.user])
permissions.isPrivate model.permissions, model.user
###*
# @ngdoc method
......
......@@ -53,6 +53,18 @@ class Permissions
isPublic: (permissions) ->
GROUP_WORLD in (permissions?.read or [])
###*
# @ngdoc method
# @name permissions#isPrivate
#
# @param {Object} permissions
# @param {String} user
#
# @returns {boolean} True if the annotation is private to the user.
###
isPrivate: (permissions, user) ->
user and angular.equals(permissions?.read or [], [user])
###*
# @ngdoc method
# @name permissions#permits
......
......@@ -58,6 +58,22 @@ describe 'h', ->
permission.read = ['one', 'two', 'three']
assert.isFalse(permissions.isPublic(permission))
describe 'isPrivate', ->
it 'returns true if the given user is in the permissions', ->
user = 'acct:angry@birds.com'
permission = {read: [user]}
assert.isTrue(permissions.isPrivate(permission, user))
it 'returns false if another user is in the permissions', ->
users = ['acct:angry@birds.com', 'acct:angry@joe.com']
permission = {read: users}
assert.isFalse(permissions.isPrivate(permission, 'acct:angry@birds.com'))
it 'returns false if different user in the permissions', ->
user = 'acct:angry@joe.com'
permission = {read: ['acct:angry@birds.com']}
assert.isFalse(permissions.isPrivate(permission, user))
describe 'permits', ->
it 'returns true when annotation has no permissions', ->
annotation = {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment