From 0362184d0965ef1c9cfac267f2e31ca2bd895a2b Mon Sep 17 00:00:00 2001 From: Ahmed Bera Pay Date: Wed, 20 Dec 2023 00:34:50 +0300 Subject: [PATCH 1/2] Update update_content_status Updated to query banning users with their usernames instead of querying by ID. --- project/backend/api/tests.py | 2 +- project/backend/api/views.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/project/backend/api/tests.py b/project/backend/api/tests.py index b566bd81..a39fdba8 100644 --- a/project/backend/api/tests.py +++ b/project/backend/api/tests.py @@ -955,7 +955,7 @@ def test_update_question_status(self): def test_update_user_status(self): url = reverse('update_content_status') - data = {'context': 'user', 'content_id': self.basic_user.id, 'hide': False} + data = {'context': 'user', 'content_id': self.basic_user.user.username, 'hide': False} response = self.client.put(url, data, format='json') diff --git a/project/backend/api/views.py b/project/backend/api/views.py index 5a39db29..d6c21ca2 100644 --- a/project/backend/api/views.py +++ b/project/backend/api/views.py @@ -1410,8 +1410,9 @@ def update_content_status(request): return Response(NodeViewQuestionSerializer(question).data, status=200) elif context == 'user': - user = BasicUser.objects.filter(pk=content_id) + user = User.objects.filter(username=content_id) if user.count() > 0: + user = BasicUser.objects.filter(user=user.first()) user = user.first() user.user.is_active = hide user.save() From 23aacc088ed43f2c1bad590da27f89835a3d153c Mon Sep 17 00:00:00 2001 From: Ahmed Bera Pay Date: Wed, 20 Dec 2023 01:39:01 +0300 Subject: [PATCH 2/2] Update views.py Added id field to response of get_profile Reversed changes for username check --- project/backend/api/tests.py | 3 ++- project/backend/api/views.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/project/backend/api/tests.py b/project/backend/api/tests.py index a39fdba8..8ad9668a 100644 --- a/project/backend/api/tests.py +++ b/project/backend/api/tests.py @@ -329,6 +329,7 @@ def test_get_user_profile(self): data = {'mail':'test@example.com'} response = self.client.get(self.get_profile_url, data, format="json") self.assertEqual(response.status_code,200) + self.assertEqual(response.json()['id'], 1) self.assertEqual(response.json()['name'],'User') self.assertEqual(response.json()['surname'], 'Test') self.assertEqual(response.json()['bio'], 'Hello') @@ -955,7 +956,7 @@ def test_update_question_status(self): def test_update_user_status(self): url = reverse('update_content_status') - data = {'context': 'user', 'content_id': self.basic_user.user.username, 'hide': False} + data = {'context': 'user', 'content_id': self.basic_user.id, 'hide': False} response = self.client.put(url, data, format='json') diff --git a/project/backend/api/views.py b/project/backend/api/views.py index d6c21ca2..86d23b7c 100644 --- a/project/backend/api/views.py +++ b/project/backend/api/views.py @@ -355,7 +355,8 @@ def get_profile(request): if Admin.objects.filter(id=basic_user.id).exists(): user_type = 'admin' - return JsonResponse({'name':user.first_name, + return JsonResponse({'id': user.id, + 'name':user.first_name, 'surname':user.last_name, 'orcid': orcid, 'bio':basic_user.bio, @@ -1410,9 +1411,8 @@ def update_content_status(request): return Response(NodeViewQuestionSerializer(question).data, status=200) elif context == 'user': - user = User.objects.filter(username=content_id) + user = BasicUser.objects.filter(pk=content_id) if user.count() > 0: - user = BasicUser.objects.filter(user=user.first()) user = user.first() user.user.is_active = hide user.save()