-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1914 from ResearchHub/moderation
Adding Moderator view with user_details endpoint
- Loading branch information
Showing
6 changed files
with
113 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import json | ||
from unittest.mock import patch | ||
|
||
from django.test import TestCase | ||
from rest_framework.test import APITestCase | ||
|
||
from paper.openalex_util import process_openalex_works | ||
from paper.related_models.authorship_model import Authorship | ||
from paper.related_models.paper_model import Paper | ||
from reputation.models import Score | ||
from user.models import UserVerification | ||
from user.related_models.author_model import Author | ||
from user.tests.helpers import ( | ||
create_random_authenticated_user, | ||
create_random_default_user, | ||
create_user, | ||
) | ||
from utils.openalex import OpenAlex | ||
from utils.test_helpers import ( | ||
get_authenticated_get_response, | ||
get_authenticated_patch_response, | ||
) | ||
|
||
|
||
class ModeratorTests(APITestCase): | ||
|
||
def test_moderator_can_view_details(self): | ||
self.user = create_user( | ||
email="mod@example.com", | ||
first_name="Moderator", | ||
last_name="mod", | ||
moderator=True, | ||
) | ||
|
||
self.client.force_authenticate(user=self.user) | ||
|
||
url = f"/api/moderator/{self.user.id}/user_details/" | ||
response = self.client.get(url, {}) | ||
self.assertIn("id", response.data) | ||
|
||
def test_non_moderator_cannot_view_details(self): | ||
self.user = create_user( | ||
email="user@example.com", | ||
first_name="Moderator", | ||
last_name="user", | ||
moderator=False, | ||
) | ||
|
||
self.client.force_authenticate(user=self.user) | ||
|
||
url = f"/api/moderator/{self.user.id}/user_details/" | ||
response = self.client.get(url, {}) | ||
self.assertNotIn("id", response.data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from rest_framework.decorators import action | ||
from rest_framework.permissions import AllowAny | ||
from rest_framework.response import Response | ||
from rest_framework.viewsets import ModelViewSet | ||
|
||
from user.permissions import IsModerator, UserIsEditor | ||
from user.serializers import ModeratorUserSerializer | ||
|
||
|
||
class ModeratorView(ModelViewSet): | ||
|
||
@action( | ||
detail=True, methods=["get"], permission_classes=[UserIsEditor | IsModerator] | ||
) | ||
def user_details(self, request, pk=None, **kwargs): | ||
from user.models import User | ||
|
||
user = User.objects.get(id=pk) | ||
serializer = ModeratorUserSerializer(user) | ||
|
||
return Response(serializer.data) |