mirror of
https://github.com/ae-utbm/sith.git
synced 2025-11-10 05:53:06 +00:00
don't show hidden users in picture identifications
This commit is contained in:
@@ -186,6 +186,29 @@ class TestPictureRelation(TestSas):
|
||||
assert res.status_code == 404
|
||||
assert PeoplePictureRelation.objects.count() == relation_count
|
||||
|
||||
def test_fetch_relations_including_hidden_users(self):
|
||||
"""Test that normal subscribers users cannot see hidden profiles"""
|
||||
picture = self.album_a.children_pictures.last()
|
||||
self.user_a.is_subscriber_viewable = False
|
||||
self.user_a.save()
|
||||
url = reverse("api:picture_identifications", kwargs={"picture_id": picture.id})
|
||||
|
||||
# a normal subscriber user shouldn't see user_a as identified
|
||||
self.client.force_login(subscriber_user.make())
|
||||
response = self.client.get(url)
|
||||
data = {user["user"]["id"] for user in response.json()}
|
||||
assert data == {self.user_b.id, self.user_c.id}
|
||||
|
||||
# an admin should see everyone
|
||||
self.client.force_login(
|
||||
baker.make(
|
||||
User, groups=[Group.objects.get(id=settings.SITH_GROUP_SAS_ADMIN_ID)]
|
||||
)
|
||||
)
|
||||
response = self.client.get(url)
|
||||
data = {user["user"]["id"] for user in response.json()}
|
||||
assert data == {self.user_a.id, self.user_b.id, self.user_c.id}
|
||||
|
||||
|
||||
class TestPictureModeration(TestSas):
|
||||
@classmethod
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import pytest
|
||||
from django.test import TestCase
|
||||
from model_bakery import baker
|
||||
|
||||
from core.baker_recipes import old_subscriber_user, subscriber_user
|
||||
from core.models import User
|
||||
from sas.baker_recipes import picture_recipe
|
||||
from sas.models import Picture
|
||||
from sas.models import PeoplePictureRelation, Picture
|
||||
|
||||
|
||||
class TestPictureQuerySet(TestCase):
|
||||
@@ -44,3 +45,25 @@ class TestPictureQuerySet(TestCase):
|
||||
user.pictures.create(picture=self.pictures[1]) # moderated
|
||||
pictures = list(Picture.objects.viewable_by(user))
|
||||
assert pictures == [self.pictures[1]]
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_identifications_viewable_by_user():
|
||||
picture = baker.make(Picture)
|
||||
identifications = baker.make(
|
||||
PeoplePictureRelation, picture=picture, _quantity=10, _bulk_create=True
|
||||
)
|
||||
identifications[0].user.is_subscriber_viewable = False
|
||||
identifications[0].user.save()
|
||||
|
||||
assert (
|
||||
list(picture.people.viewable_by(old_subscriber_user.make()))
|
||||
== identifications[1:]
|
||||
)
|
||||
assert (
|
||||
list(picture.people.viewable_by(baker.make(User, is_superuser=True)))
|
||||
== identifications
|
||||
)
|
||||
assert list(picture.people.viewable_by(identifications[1].user)) == [
|
||||
identifications[1]
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user