From 909ab434a043ea50e00c65e709f39bb4802b2cc9 Mon Sep 17 00:00:00 2001 From: GregoryHorvath Date: Fri, 29 May 2020 13:51:58 +0200 Subject: [PATCH 1/3] Commenting out the FR changes, add visibility --- api/drf_views.py | 11 +++-- api/models.py | 24 +++++----- api/serializers.py | 2 +- api/test_views.py | 116 ++++++++++++++++++++++----------------------- 4 files changed, 77 insertions(+), 76 deletions(-) diff --git a/api/drf_views.py b/api/drf_views.py index 687f5129f..e874494d2 100644 --- a/api/drf_views.py +++ b/api/drf_views.py @@ -251,8 +251,8 @@ class EventViewset(viewsets.ReadOnlyModelViewSet): def get_queryset(self): if self.action == 'mini_events': return Event.objects.filter(parent_event__isnull=True).prefetch_related('dtype') - - return Event.get_for(self.request.user).filter(parent_event__isnull=True) + return Event.objects.filter(parent_event__isnull=True) + # return Event.get_for(self.request.user).filter(parent_event__isnull=True) def get_serializer_class(self): if self.action == 'mini_events': @@ -264,14 +264,15 @@ def get_serializer_class(self): # Overwrite 'retrieve' because by default we filter to only non-merged Emergencies in 'get_queryset()' def retrieve(self, request, pk=None, *args, **kwargs): - filters if pk: try: - instance = Event.get_for(request.user).get(pk=pk) + instance = Event.objects.get(pk=pk) + # instance = Event.get_for(request.user).get(pk=pk) except Exception: raise Http404 elif kwargs['slug']: - instance = Event.get_for(request.user).filter(slug=kwargs['slug']).first() + instance = Event.objects.filter(slug=kwargs['slug']).first() + # instance = Event.get_for(request.user).filter(slug=kwargs['slug']).first() if not instance: raise Http404 else: diff --git a/api/models.py b/api/models.py index ed89978e2..606cc7c17 100644 --- a/api/models.py +++ b/api/models.py @@ -314,10 +314,10 @@ class Meta: verbose_name = 'Emergency' verbose_name_plural = 'Emergencies' - @staticmethod - def get_for(user): - field_report_pretech = Prefetch('field_reports', queryset=FieldReport.get_for(user)) - return Event.objects.prefetch_related(field_report_pretech) + # @staticmethod + # def get_for(user): + # field_report_pretech = Prefetch('field_reports', queryset=FieldReport.get_for(user)) + # return Event.objects.prefetch_related(field_report_pretech) def start_date(self): """ Get start date of first appeal """ @@ -789,14 +789,14 @@ class FieldReport(models.Model): class Meta: ordering = ('-created_at', '-updated_at',) - @staticmethod - def get_for(user): - filters = models.Q(visibility=VisibilityChoices.PUBLIC) - if user.is_authenticated: - filters = models.Q(visibility__in=[VisibilityChoices.MEMBERSHIP, VisibilityChoices.PUBLIC]) - if is_user_ifrc(user): - filters = models.Q() - return FieldReport.objects.filter(filters) + # @staticmethod + # def get_for(user): + # filters = models.Q(visibility=VisibilityChoices.PUBLIC) + # if user.is_authenticated: + # filters = models.Q(visibility__in=[VisibilityChoices.MEMBERSHIP, VisibilityChoices.PUBLIC]) + # if is_user_ifrc(user): + # filters = models.Q() + # return FieldReport.objects.filter(filters) def save(self, *args, **kwargs): # On save, is report_date or start_date is not set, set it to now. diff --git a/api/serializers.py b/api/serializers.py index c2130fcb0..036b3ab58 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -164,7 +164,7 @@ class MiniFieldReportSerializer(serializers.ModelSerializer): class Meta: model = FieldReport fields = ( - 'summary', 'status', 'description', 'contacts', 'created_at', 'updated_at', 'report_date', 'id', 'is_covid_report', + 'summary', 'status', 'description', 'contacts', 'created_at', 'updated_at', 'report_date', 'id', 'is_covid_report', 'visibility', 'num_injured', 'num_dead', 'num_missing', 'num_affected', 'num_displaced', 'num_assisted', 'num_localstaff', 'num_volunteers', 'num_expats_delegates', 'gov_num_injured', 'gov_num_dead', 'gov_num_missing', 'gov_num_affected', 'gov_num_displaced', 'gov_num_assisted', 'other_num_injured', 'other_num_dead', 'other_num_missing', 'other_num_affected', 'other_num_displaced', 'other_num_assisted', diff --git a/api/test_views.py b/api/test_views.py index 1c7ca381c..cbba2cb21 100644 --- a/api/test_views.py +++ b/api/test_views.py @@ -182,71 +182,71 @@ def test_country_snippet_visibility(self): self.client.force_authenticate(user=None) -class FieldReportsVisibilityTestCase(APITestCase): - fixtures = ['DisasterTypes',] - def setUp(self): - user = User.objects.create(username='foo') - User.objects.create_superuser(username='bar', email='foo@bar.com', password='12345678') - event = models.Event.objects.create( - dtype=models.DisasterType.objects.get(pk=1), - name='test event for FRs', - disaster_start_date=datetime.now() - ) - models.FieldReport.objects.create( - dtype=models.DisasterType.objects.get(pk=1), - summary='membership field report', - bulletin='3', - visibility=1, # MEMBERSHIP - dref='2', - user=user, - event_id=event.id, - ) - models.FieldReport.objects.create( - dtype=models.DisasterType.objects.get(pk=1), - summary='ifrc field report', - bulletin='3', - visibility=2, # IFRC - dref='2', - user=user, - event_id=event.id, - ) - models.FieldReport.objects.create( - dtype=models.DisasterType.objects.get(pk=1), - summary='public field report', - bulletin='3', - visibility=3, # PUBLIC - dref='2', - user=user, - event_id=event.id, - ) +# class FieldReportsVisibilityTestCase(APITestCase): +# fixtures = ['DisasterTypes',] +# def setUp(self): +# user = User.objects.create(username='foo') +# User.objects.create_superuser(username='bar', email='foo@bar.com', password='12345678') +# event = models.Event.objects.create( +# dtype=models.DisasterType.objects.get(pk=1), +# name='test event for FRs', +# disaster_start_date=datetime.now() +# ) +# models.FieldReport.objects.create( +# dtype=models.DisasterType.objects.get(pk=1), +# summary='membership field report', +# bulletin='3', +# visibility=1, # MEMBERSHIP +# dref='2', +# user=user, +# event_id=event.id, +# ) +# models.FieldReport.objects.create( +# dtype=models.DisasterType.objects.get(pk=1), +# summary='ifrc field report', +# bulletin='3', +# visibility=2, # IFRC +# dref='2', +# user=user, +# event_id=event.id, +# ) +# models.FieldReport.objects.create( +# dtype=models.DisasterType.objects.get(pk=1), +# summary='public field report', +# bulletin='3', +# visibility=3, # PUBLIC +# dref='2', +# user=user, +# event_id=event.id, +# ) - def test_field_reports_visibility(self): - user = User.objects.get(username='foo') - user2 = User.objects.get(username='bar') +# def test_field_reports_visibility(self): +# user = User.objects.get(username='foo') +# user2 = User.objects.get(username='bar') - # perform the request without a user - # this user should see FRs with PUBLIC visibility - response = self.client.get('/api/v2/event/6') - response = json.loads(response.content) +# # perform the request without a user +# # this user should see FRs with PUBLIC visibility +# response = self.client.get('/api/v2/event/6') +# response = json.loads(response.content) - self.assertEqual(len(response['field_reports']), 1) - self.assertEqual(response['field_reports'][0]['summary'], 'public field report') +# self.assertEqual(len(response['field_reports']), 1) +# self.assertEqual(response['field_reports'][0]['summary'], 'public field report') - # perform the request with an authenticated user - # this user should see FRs with MEMBERSHIP and PUBLIC visibility - self.client.force_authenticate(user=user) - response = self.client.get('/api/v2/event/6') - response = json.loads(response.content) +# # perform the request with an authenticated user +# # this user should see FRs with MEMBERSHIP and PUBLIC visibility +# self.client.force_authenticate(user=user) +# response = self.client.get('/api/v2/event/6') +# response = json.loads(response.content) - self.assertEqual(len(response['field_reports']), 2) +# self.assertEqual(len(response['field_reports']), 2) - # perform the request with a superuser - # this user should see all FRs - self.client.force_authenticate(user=user2) - response = self.client.get('/api/v2/event/6') - response = json.loads(response.content) +# # perform the request with a superuser +# # this user should see all FRs +# self.client.force_authenticate(user=user2) +# response = self.client.get('/api/v2/event/6') +# response = json.loads(response.content) - self.assertEqual(len(response['field_reports']), 3) +# self.assertEqual(len(response['field_reports']), 3) class ActionTestCase(APITestCase): From b9dca74a9dff222020ffae46ed34ecacad187d92 Mon Sep 17 00:00:00 2001 From: GregoryHorvath Date: Fri, 29 May 2020 14:19:48 +0200 Subject: [PATCH 2/3] Added 'is_superuser' to serializer --- api/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/serializers.py b/api/serializers.py index 036b3ab58..257ebed0c 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -256,7 +256,7 @@ class UserSerializer(serializers.ModelSerializer): subscription = MiniSubscriptionSerializer(many=True) class Meta: model = User - fields = ('id', 'username', 'first_name', 'last_name', 'email', 'profile', 'subscription',) + fields = ('id', 'username', 'first_name', 'last_name', 'email', 'profile', 'subscription', 'is_superuser',) def update(self, instance, validated_data): if 'profile' in validated_data: From b1efad5cb4df2fe793b45a1cd5e610766976383f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Horv=C3=A1th=20Gergely?= Date: Tue, 2 Jun 2020 09:01:41 +0200 Subject: [PATCH 3/3] Increase version to 282 --- CHANGELOG.md | 8 +++++++- main/__init__.py | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bfdc81fee..407f2391d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Unreleased +## 1.1.282 + +### Added + - Minor backend fixes for 4.3.5 + ## 1.1.281 ### Added @@ -1183,7 +1188,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## 0.1.20 -[Unreleased]: https://github.com/IFRCGo/go-api/compare/1.2.281...HEAD +[Unreleased]: https://github.com/IFRCGo/go-api/compare/1.2.282...HEAD +[1.2.282]: https://github.com/IFRCGo/go-api/compare/1.2.281...1.1.282 [1.2.281]: https://github.com/IFRCGo/go-api/compare/1.2.280...1.1.281 [1.2.280]: https://github.com/IFRCGo/go-api/compare/1.2.279...1.1.280 [1.2.279]: https://github.com/IFRCGo/go-api/compare/1.2.278...1.1.279 diff --git a/main/__init__.py b/main/__init__.py index c095b0051..66386c809 100644 --- a/main/__init__.py +++ b/main/__init__.py @@ -1 +1 @@ -__version__ = '1.1.281' +__version__ = '1.1.282'