Fix PersonalNoteAccessPermissions for anonymous user

fixes: #3377
This commit is contained in:
Oskar Hahn 2017-08-31 21:12:39 +02:00
parent 97a1431c32
commit 24b07da7b4
2 changed files with 34 additions and 6 deletions

View File

@ -186,12 +186,15 @@ class PersonalNoteAccessPermissions(BaseAccessPermissions):
full_data = container.get_full_data() if isinstance(container, Collection) else [container.get_full_data()]
# Parse data.
for full in full_data:
if full['user_id'] == user.id:
data = [full]
break
else:
if user is None:
data = []
else:
for full in full_data:
if full['user_id'] == user.id:
data = [full]
break
else:
data = []
# Reduce result to a single item or None if it was not a collection at
# the beginning of the method.

View File

@ -1,6 +1,9 @@
from unittest import TestCase
from openslides.users.access_permissions import UserAccessPermissions
from openslides.users.access_permissions import (
PersonalNoteAccessPermissions,
UserAccessPermissions,
)
from openslides.utils.collection import CollectionElement
@ -37,3 +40,25 @@ class UserGetProjectorDataTest(TestCase):
'is_present': False,
'is_committee': False,
})
class TestPersonalNoteAccessPermissions(TestCase):
def test_get_restricted_data(self):
ap = PersonalNoteAccessPermissions()
rd = ap.get_restricted_data(
CollectionElement.from_values(
'users/personal_note',
1,
full_data={'user_id': 1}),
CollectionElement.from_values('users/user', 5, full_data={}))
self.assertEqual(rd, None)
def test_get_restricted_data_for_anonymous(self):
ap = PersonalNoteAccessPermissions()
rd = ap.get_restricted_data(
CollectionElement.from_values(
'users/personal_note',
1,
full_data={'user_id': 1}),
None)
self.assertEqual(rd, None)