Skip to content

Commit

Permalink
Add admin panel for localunit snapshot and restrict mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
susilnem committed Dec 12, 2024
1 parent 8398de6 commit 9ffc327
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
9 changes: 3 additions & 6 deletions local_units/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from django.core.exceptions import ValidationError
from reversion_compare.admin import CompareVersionAdmin

from dref.admin import ReadOnlyMixin

from .models import (
Affiliation,
BloodService,
Expand Down Expand Up @@ -66,7 +68,7 @@ def save_model(self, request, obj, form, change):


@admin.register(LocalUnitChangeRequest)
class LocalUnitChangeRequestAdmin(admin.ModelAdmin):
class LocalUnitChangeRequestAdmin(ReadOnlyMixin, admin.ModelAdmin):
autocomplete_fields = (
"local_unit",
"triggered_by",
Expand All @@ -82,11 +84,6 @@ class LocalUnitChangeRequestAdmin(admin.ModelAdmin):
"status",
"current_validator",
)
readonly_fields = (
"previous_data",
"rejected_data",
"rejected_reason",
)
ordering = ("id",)

def get_queryset(self, request):
Expand Down
3 changes: 2 additions & 1 deletion local_units/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ def test_deprecate_local_unit(self):

# Test for validation
response = self.client.post(url, data=data)
self.assert_400(response)
self.assert_404(response)

self.client.force_authenticate(self.root_user)
# test revert deprecate
data = {}
url = f"/api/v2/local-units/{local_unit_obj.id}/revert-deprecate/"
Expand Down
5 changes: 3 additions & 2 deletions local_units/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.utils import timezone
from django.shortcuts import get_object_or_404
from drf_spectacular.utils import extend_schema
from rest_framework import permissions, response, status, views, viewsets
from rest_framework.decorators import action
Expand Down Expand Up @@ -238,11 +239,11 @@ def deprecate(self, request, pk=None):
detail=True,
methods=["post"],
url_path="revert-deprecate",
permission_classes=[permissions.IsAuthenticated, DenyGuestUserPermission],
permission_classes=[permissions.IsAuthenticated, ValidateLocalUnitPermission, DenyGuestUserPermission],
)
def revert_deprecate(self, request, pk=None):
"""Revert the deprecate local unit object."""
local_unit = self.get_object()
local_unit = get_object_or_404(LocalUnit, pk=pk)
local_unit.is_deprecated = False
local_unit.deprecated_reason = None
local_unit.deprecated_reason_overview = ""
Expand Down

0 comments on commit 9ffc327

Please sign in to comment.