Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default permission class to IsAuthenticated & made required changes #2268

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions care/abdm/api/viewsets/abha.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from rest_framework.decorators import action
from rest_framework.generics import get_object_or_404
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet

Expand All @@ -14,7 +13,6 @@ class AbhaViewSet(GenericViewSet):
serializer_class = AbhaSerializer
model = AbhaNumber
queryset = AbhaNumber.objects.all()
permission_classes = (IsAuthenticated,)

def get_abha_object(self):
queryset = get_patient_queryset(self.request.user)
Expand Down
21 changes: 6 additions & 15 deletions care/abdm/api/viewsets/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from django.core.cache import cache
from rest_framework import status
from rest_framework.generics import GenericAPIView, get_object_or_404
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response

from care.abdm.utils.api_call import AbdmGateway
Expand All @@ -19,7 +18,6 @@


class OnFetchView(GenericAPIView):
permission_classes = (IsAuthenticated,)
authentication_classes = [ABDMAuthentication]

def post(self, request, *args, **kwargs):
Expand All @@ -41,7 +39,6 @@ def post(self, request, *args, **kwargs):


class OnInitView(GenericAPIView):
permission_classes = (IsAuthenticated,)
authentication_classes = [ABDMAuthentication]

def post(self, request, *args, **kwargs):
Expand All @@ -53,7 +50,6 @@ def post(self, request, *args, **kwargs):


class OnConfirmView(GenericAPIView):
permission_classes = (IsAuthenticated,)
authentication_classes = [ABDMAuthentication]

def post(self, request, *args, **kwargs):
Expand Down Expand Up @@ -86,7 +82,6 @@ def post(self, request, *args, **kwargs):


class AuthNotifyView(GenericAPIView):
permission_classes = (IsAuthenticated,)
authentication_classes = [ABDMAuthentication]

def post(self, request, *args, **kwargs):
Expand All @@ -104,15 +99,13 @@ def post(self, request, *args, **kwargs):


class OnAddContextsView(GenericAPIView):
permission_classes = (IsAuthenticated,)
authentication_classes = [ABDMAuthentication]

def post(self, request, *args, **kwargs):
return Response({}, status=status.HTTP_202_ACCEPTED)


class DiscoverView(GenericAPIView):
permission_classes = (IsAuthenticated,)
authentication_classes = [ABDMAuthentication]

def post(self, request, *args, **kwargs):
Expand Down Expand Up @@ -181,7 +174,6 @@ def post(self, request, *args, **kwargs):


class LinkInitView(GenericAPIView):
permission_classes = (IsAuthenticated,)
authentication_classes = [ABDMAuthentication]

def post(self, request, *args, **kwargs):
Expand All @@ -201,7 +193,6 @@ def post(self, request, *args, **kwargs):


class LinkConfirmView(GenericAPIView):
permission_classes = (IsAuthenticated,)
authentication_classes = [ABDMAuthentication]

def post(self, request, *args, **kwargs):
Expand Down Expand Up @@ -235,7 +226,6 @@ def post(self, request, *args, **kwargs):


class NotifyView(GenericAPIView):
permission_classes = (IsAuthenticated,)
authentication_classes = [ABDMAuthentication]

def post(self, request, *args, **kwargs):
Expand All @@ -253,7 +243,6 @@ def post(self, request, *args, **kwargs):


class RequestDataView(GenericAPIView):
permission_classes = (IsAuthenticated,)
authentication_classes = [ABDMAuthentication]

def post(self, request, *args, **kwargs):
Expand Down Expand Up @@ -345,10 +334,12 @@ def post(self, request, *args, **kwargs):
],
"consent_id": data["hiRequest"]["consent"]["id"],
"transaction_id": data["transactionId"],
"session_status": "TRANSFERRED"
if data_transfer_response
and data_transfer_response.status_code == 202
else "FAILED",
"session_status": (
"TRANSFERRED"
if data_transfer_response
and data_transfer_response.status_code == 202
else "FAILED"
),
"care_contexts": list(
map(
lambda context: {"id": context["careContextReference"]},
Expand Down
3 changes: 0 additions & 3 deletions care/abdm/api/viewsets/consent.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from rest_framework import status
from rest_framework.decorators import action
from rest_framework.mixins import ListModelMixin, RetrieveModelMixin
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet

Expand Down Expand Up @@ -45,7 +44,6 @@ class ConsentViewSet(GenericViewSet, ListModelMixin, RetrieveModelMixin):
serializer_class = ConsentRequestSerializer
model = ConsentRequest
queryset = ConsentRequest.objects.all()
permission_classes = (IsAuthenticated,)
filter_backends = (filters.DjangoFilterBackend,)
filterset_class = ConsentRequestFilter

Expand Down Expand Up @@ -142,7 +140,6 @@ def fetch(self, request, pk):


class ConsentCallbackViewSet(GenericViewSet):
permission_classes = (IsAuthenticated,)
authentication_classes = [ABDMAuthentication]

def consent_request__on_init(self, request):
Expand Down
3 changes: 0 additions & 3 deletions care/abdm/api/viewsets/health_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from django.db.models import Q
from rest_framework import status
from rest_framework.decorators import action
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet

Expand All @@ -20,7 +19,6 @@


class HealthInformationViewSet(GenericViewSet):
permission_classes = (IsAuthenticated,)

def retrieve(self, request, pk):
files = FileUpload.objects.filter(
Expand Down Expand Up @@ -83,7 +81,6 @@ def request(self, request, pk):


class HealthInformationCallbackViewSet(GenericViewSet):
permission_classes = (IsAuthenticated,)
authentication_classes = [ABDMAuthentication]

def health_information__hiu__on_request(self, request):
Expand Down
26 changes: 15 additions & 11 deletions care/abdm/api/viewsets/healthid.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from rest_framework.decorators import action
from rest_framework.exceptions import ValidationError
from rest_framework.mixins import CreateModelMixin
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet

Expand Down Expand Up @@ -39,7 +38,6 @@
class ABDMHealthIDViewSet(GenericViewSet, CreateModelMixin):
base_name = "healthid"
model = AbhaNumber
permission_classes = (IsAuthenticated,)

@extend_schema(
operation_id="generate_aadhaar_otp",
Expand Down Expand Up @@ -497,15 +495,21 @@ def add_care_context(self, request, *args, **kwargs):
AbdmGateway().fetch_modes(
{
"healthId": consultation.patient.abha_number.health_id,
"name": request.data["name"]
if "name" in request.data
else consultation.patient.abha_number.name,
"gender": request.data["gender"]
if "gender" in request.data
else consultation.patient.abha_number.gender,
"dateOfBirth": request.data["dob"]
if "dob" in request.data
else str(consultation.patient.abha_number.date_of_birth),
"name": (
request.data["name"]
if "name" in request.data
else consultation.patient.abha_number.name
),
"gender": (
request.data["gender"]
if "gender" in request.data
else consultation.patient.abha_number.gender
),
"dateOfBirth": (
request.data["dob"]
if "dob" in request.data
else str(consultation.patient.abha_number.date_of_birth)
),
"consultationId": consultation_id,
# "authMode": "DIRECT",
"purpose": "LINK",
Expand Down
2 changes: 0 additions & 2 deletions care/abdm/api/viewsets/hip.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from rest_framework import status
from rest_framework.decorators import action
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet

Expand All @@ -16,7 +15,6 @@


class HipViewSet(GenericViewSet):
permission_classes = (IsAuthenticated,)
authentication_classes = [ABDMAuthentication]

def get_linking_token(self, data):
Expand Down
3 changes: 0 additions & 3 deletions care/abdm/api/viewsets/patients.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from django.db.models import Q
from rest_framework import status
from rest_framework.decorators import action
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet

Expand All @@ -17,7 +16,6 @@


class PatientsViewSet(GenericViewSet):
permission_classes = (IsAuthenticated,)

@action(detail=False, methods=["POST"])
def find(self, request):
Expand Down Expand Up @@ -57,7 +55,6 @@ def find(self, request):


class PatientsCallbackViewSet(GenericViewSet):
permission_classes = (IsAuthenticated,)
authentication_classes = [ABDMAuthentication]

def patients__on_find(self, request):
Expand Down
3 changes: 0 additions & 3 deletions care/abdm/api/viewsets/status.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from rest_framework import status
from rest_framework.generics import GenericAPIView
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response

from care.abdm.models import AbhaNumber
Expand All @@ -10,7 +9,6 @@


class NotifyView(GenericAPIView):
permission_classes = (IsAuthenticated,)
authentication_classes = [ABDMAuthentication]

def post(self, request, *args, **kwargs):
Expand All @@ -29,7 +27,6 @@ def post(self, request, *args, **kwargs):


class SMSOnNotifyView(GenericAPIView):
permission_classes = (IsAuthenticated,)
authentication_classes = [ABDMAuthentication]

def post(self, request, *args, **kwargs):
Expand Down
3 changes: 0 additions & 3 deletions care/facility/api/viewsets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
RetrieveModelMixin,
UpdateModelMixin,
)
from rest_framework.permissions import IsAuthenticated
from rest_framework.viewsets import GenericViewSet

from care.facility.api.viewsets.mixins.access import UserAccessMixin
Expand All @@ -19,5 +18,3 @@ class FacilityBaseViewset(
GenericViewSet,
):
"""Base class for all endpoints related to Faclity model."""

permission_classes = (IsAuthenticated,)
2 changes: 0 additions & 2 deletions care/facility/api/viewsets/ambulance.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
RetrieveModelMixin,
UpdateModelMixin,
)
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet

Expand Down Expand Up @@ -49,7 +48,6 @@ class AmbulanceViewSet(
DestroyModelMixin,
GenericViewSet,
):
permission_classes = (IsAuthenticated,)
serializer_class = AmbulanceSerializer
queryset = Ambulance.objects.filter(deleted=False).select_related(
"primary_district", "secondary_district", "third_district"
Expand Down
7 changes: 2 additions & 5 deletions care/facility/api/viewsets/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class AssetPublicViewSet(GenericViewSet):
queryset = Asset.objects.all()
serializer_class = AssetSerializer
lookup_field = "external_id"
permission_classes = []

def retrieve(self, request, *args, **kwargs):
key = "asset:" + kwargs["external_id"]
Expand All @@ -207,6 +208,7 @@ class AssetPublicQRViewSet(GenericViewSet):
queryset = Asset.objects.all()
serializer_class = AssetSerializer
lookup_field = "qr_code_id"
permission_classes = []

def retrieve(self, request, *args, **kwargs):
qr_code_id = kwargs["qr_code_id"]
Expand All @@ -227,7 +229,6 @@ def retrieve(self, request, *args, **kwargs):
class AvailabilityViewSet(ListModelMixin, RetrieveModelMixin, GenericViewSet):
queryset = AvailabilityRecord.objects.all()
serializer_class = AvailabilityRecordSerializer
permission_classes = (IsAuthenticated,)

def get_queryset(self):
facility_queryset = get_facility_queryset(self.request.user)
Expand Down Expand Up @@ -280,7 +281,6 @@ class AssetViewSet(
lookup_field = "external_id"
filter_backends = (filters.DjangoFilterBackend, drf_filters.SearchFilter)
search_fields = ["name", "serial_number", "qr_code_id"]
permission_classes = [IsAuthenticated]
filterset_class = AssetFilter

def get_queryset(self):
Expand Down Expand Up @@ -422,7 +422,6 @@ def operate_assets(self, request, *args, **kwargs):
class AssetRetrieveConfigViewSet(ListModelMixin, GenericViewSet):
queryset = Asset.objects.all()
authentication_classes = [MiddlewareAuthentication]
permission_classes = [IsAuthenticated]
serializer_class = AssetConfigSerializer

@extend_schema(
Expand Down Expand Up @@ -549,8 +548,6 @@ class AssetServiceViewSet(
)
serializer_class = AssetServiceSerializer

permission_classes = (IsAuthenticated,)

lookup_field = "external_id"

filter_backends = (filters.DjangoFilterBackend,)
Expand Down
5 changes: 3 additions & 2 deletions care/facility/api/viewsets/bed.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
RetrieveModelMixin,
UpdateModelMixin,
)
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet

Expand Down Expand Up @@ -71,7 +70,6 @@ class BedViewSet(
serializer_class = BedSerializer
lookup_field = "external_id"
filter_backends = (filters.DjangoFilterBackend, drf_filters.SearchFilter)
permission_classes = [IsAuthenticated]
search_fields = ["name"]
filterset_class = BedFilter

Expand Down Expand Up @@ -166,6 +164,7 @@ class AssetBedViewSet(
filter_backends = (filters.DjangoFilterBackend,)
filterset_class = AssetBedFilter
lookup_field = "external_id"
permission_classes = []

def get_queryset(self):
user = self.request.user
Expand Down Expand Up @@ -210,6 +209,7 @@ class PatientAssetBedViewSet(ListModelMixin, GenericViewSet):
"bed__name",
"created_date",
]
permission_classes = []

def get_queryset(self):
user = self.request.user
Expand Down Expand Up @@ -250,6 +250,7 @@ class ConsultationBedViewSet(
filter_backends = (filters.DjangoFilterBackend,)
filterset_class = ConsultationBedFilter
lookup_field = "external_id"
permission_classes = []

def get_queryset(self):
user = self.request.user
Expand Down
Loading