Skip to content

Commit

Permalink
Merge pull request #2269 from IFRCGo/fix/permission-issue-ops
Browse files Browse the repository at this point in the history
Fix Guest user permission issue in operational learning api
  • Loading branch information
szabozoltan69 authored Sep 18, 2024
2 parents ed657d4 + 0124074 commit 7b46711
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 11 additions & 3 deletions api/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def test_guest_user_permission(self):
"/api/v2/language/",
f"/api/v2/language/{id}/",
"/api/v2/event/",
"/api/v2/ops-learning/",
f"/api/v2/ops-learning/{id}/",
]

go_post_apis = [
Expand All @@ -73,6 +75,7 @@ def test_guest_user_permission(self):
"/api/v2/per-file/multiple/",
"/api/v2/per-prioritization/",
"/api/v2/per-work-plan/",
"/api/v2/ops-learning/",
"/api/v2/project/",
"/api/v2/dref-files/",
"/api/v2/dref-files/multiple/",
Expand All @@ -98,8 +101,6 @@ def test_guest_user_permission(self):
f"/api/v2/flash-update/{id}/",
"/api/v2/local-units/",
f"/api/v2/local-units/{id}/",
"/api/v2/ops-learning/",
f"/api/v2/ops-learning/{id}/",
f"/api/v2/pdf-export/{id}/",
"/api/v2/per-assessment/",
f"/api/v2/per-assessment/{id}/",
Expand Down Expand Up @@ -138,7 +139,6 @@ def test_guest_user_permission(self):
]

go_post_apis_req_additional_perm = [
"/api/v2/ops-learning/",
"/api/v2/per-overview/",
f"/api/v2/user/{id}/accepted_license_terms/",
]
Expand Down Expand Up @@ -167,6 +167,14 @@ def _failure_check(response, check_json_error_code=True):
_success_check(event_pub_response)
self.assertEqual(len(event_pub_response.json()["results"]), 1)

# Unauthenticated user should be able to view operational learning
ops_learning_response = self.client.get("/api/v2/ops-learning/")
_success_check(ops_learning_response)

# Unauthenticated user should not be able to do post operations in operational learning
ops_learning_response = self.client.post("/api/v2/ops-learning/", json=body)
_failure_check(ops_learning_response, check_json_error_code=False)

# authenticate guest user
self.authenticate(user=self.guest_user)

Expand Down
4 changes: 2 additions & 2 deletions per/drf_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from api.models import Country
from deployments.models import SectorTag
from main.permissions import DenyGuestUserPermission
from main.permissions import DenyGuestUserMutationPermission, DenyGuestUserPermission
from main.utils import SpreadSheetContentNegotiation
from per.filter_set import (
PerDocumentFilter,
Expand Down Expand Up @@ -708,7 +708,7 @@ class OpsLearningViewset(viewsets.ModelViewSet):
"""

queryset = OpsLearning.objects.all()
permission_classes = [DenyGuestUserPermission, OpsLearningPermission]
permission_classes = [DenyGuestUserMutationPermission, OpsLearningPermission]
filterset_class = OpsLearningFilter
search_fields = (
"learning",
Expand Down

0 comments on commit 7b46711

Please sign in to comment.