Skip to content

Commit

Permalink
Merge pull request #167 from willemarcel/develop
Browse files Browse the repository at this point in the history
fix bug in AoIs with hide_whitelist filter
  • Loading branch information
willemarcel authored Dec 13, 2018
2 parents 9497acd + 0b8c2e9 commit 5766e07
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 4 deletions.
4 changes: 2 additions & 2 deletions osmchadjango/supervise/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class AreaOfInterest(models.Model):
def __str__(self):
return '{} by {}'.format(self.name, self.user.username)

def changesets(self):
def changesets(self, request=None):
"""Return the changesets that match the filters, including the geometry
of the AreaOfInterest.
"""
qs = ChangesetFilter(self.filters).qs
qs = ChangesetFilter(self.filters, request=request).qs
if self.geometry is not None:
return qs.filter(
bbox__intersects=self.geometry
Expand Down
97 changes: 96 additions & 1 deletion osmchadjango/supervise/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from ...changeset.tests.modelfactories import (
ChangesetFactory, HarmfulChangesetFactory, GoodChangesetFactory,
SuspicionReasonsFactory, TagFactory
SuspicionReasonsFactory, TagFactory, UserWhitelistFactory
)
from ...users.models import User
from ..models import AreaOfInterest, BlacklistedUser
Expand Down Expand Up @@ -638,6 +638,101 @@ def test_aoi_with_in_bbox_filter(self):
self.assertEqual(response.data['count'], 51)
self.assertEqual(len(response.data['features']), 50)

def test_aoi_with_hide_whitelist_filter(self):
aoi = AreaOfInterest.objects.create(
name='Another place in the world',
user=self.user,
filters={
'editor': 'Potlatch 2',
'hide_whitelist': 'True'
},
)
UserWhitelistFactory(user=self.user, whitelist_user='test')
ChangesetFactory()
ChangesetFactory(user='other_user', uid='333')
ChangesetFactory(user='another_user', uid='4333')

self.client.login(username=self.user.username, password='password')
response = self.client.get(
reverse('supervise:aoi-list-changesets', args=[aoi.pk])
)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['count'], 2)
self.assertEqual(len(response.data['features']), 2)

def test_aoi_with_false_hide_whitelist_filter(self):
aoi = AreaOfInterest.objects.create(
name='Another place in the world',
user=self.user,
filters={
'editor': 'Potlatch 2',
'hide_whitelist': 'False'
},
)
UserWhitelistFactory(user=self.user, whitelist_user='test')
ChangesetFactory()
ChangesetFactory(user='other_user', uid='333')
ChangesetFactory(user='another_user', uid='4333')

self.client.login(username=self.user.username, password='password')
response = self.client.get(
reverse('supervise:aoi-list-changesets', args=[aoi.pk])
)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['count'], 3)
self.assertEqual(len(response.data['features']), 3)

def test_aoi_with_blacklist_filter(self):
aoi = AreaOfInterest.objects.create(
name='Another place in the world',
user=self.user,
filters={
'editor': 'Potlatch 2',
'blacklist': 'True'
},
)
BlacklistedUser.objects.create(
username='test',
uid='123123',
added_by=self.user,
)
ChangesetFactory()
ChangesetFactory(user='other_user', uid='333')
ChangesetFactory(user='another_user', uid='4333')
self.client.login(username=self.user.username, password='password')
response = self.client.get(
reverse('supervise:aoi-list-changesets', args=[aoi.pk])
)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['count'], 1)
self.assertEqual(len(response.data['features']), 1)

def test_aoi_with_false_blacklist_filter(self):
aoi = AreaOfInterest.objects.create(
name='Another place in the world',
user=self.user,
filters={
'editor': 'Potlatch 2',
'blacklist': 'False'
},
)
BlacklistedUser.objects.create(
username='test',
uid='123123',
added_by=self.user,
)
ChangesetFactory()
ChangesetFactory(user='other_user', uid='333')
ChangesetFactory(user='another_user', uid='4333')

self.client.login(username=self.user.username, password='password')
response = self.client.get(
reverse('supervise:aoi-list-changesets', args=[aoi.pk])
)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['count'], 3)
self.assertEqual(len(response.data['features']), 3)

def test_aoi_changesets_feed_view(self):
ChangesetFactory(bbox=Polygon(((10, 10), (10, 11), (11, 11), (10, 10))))
ChangesetFactory(
Expand Down
3 changes: 2 additions & 1 deletion osmchadjango/supervise/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
ChangesetSerializer, ChangesetSerializerToStaff, ChangesetStatsSerializer
)
from ..changeset.views import StandardResultsSetPagination
from ..changeset.filters import ChangesetFilter
from .models import AreaOfInterest, BlacklistedUser
from .serializers import (
AreaOfInterestSerializer, BlacklistSerializer,
Expand Down Expand Up @@ -182,7 +183,7 @@ def get_serializer_class(self):
return ChangesetSerializer

def list(self, request, *args, **kwargs):
queryset = self.get_object().changesets().select_related(
queryset = self.get_object().changesets(request).select_related(
'check_user'
).prefetch_related('tags', 'reasons')

Expand Down

0 comments on commit 5766e07

Please sign in to comment.