Skip to content

Commit

Permalink
Registration for user with no apcd groups (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
chandra-tacc authored Feb 27, 2025
1 parent 5966440 commit 6ea7601
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
16 changes: 16 additions & 0 deletions apcd_cms/src/apps/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ def dispatch(self, request, *args, **kwargs):
status=500)


class AuthenticatedUserTemplateMixin:
""" API Mixin to restrict access to authenticated users only. """

def dispatch(self, request, *args, **kwargs):
if not request.user.is_authenticated:
return HttpResponseRedirect('/')
return super().dispatch(request, *args, **kwargs)

class APCDAdminAccessTemplateMixin:
""" API Mixin to restrict access to authenticated APCD admins only. """

Expand Down Expand Up @@ -46,6 +54,14 @@ def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)


class AuthenticatedUserAPIMixin:
""" API Mixin to restrict access to authenticated users."""

def dispatch(self, request, *args, **kwargs):
if not request.user.is_authenticated:
return JsonResponse({'error': 'Unauthorized'}, status=403)
return super().dispatch(request, *args, **kwargs)

class APCDAdminAccessAPIMixin:
""" API Mixin to restrict access to authenticated APCD admins only. """

Expand Down
8 changes: 5 additions & 3 deletions apcd_cms/src/apps/registrations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.conf import settings
from django.http import JsonResponse
from django.views.generic import TemplateView
from apps.base.base import BaseAPIView, APCDGroupAccessTemplateMixin, APCDGroupAccessAPIMixin
from apps.base.base import BaseAPIView, AuthenticatedUserTemplateMixin, AuthenticatedUserAPIMixin
from requests.auth import HTTPBasicAuth
import logging
import rt
Expand All @@ -20,11 +20,11 @@
RT_QUEUE = getattr(settings, 'RT_QUEUE', '')


class RegistrationFormTemplate(APCDGroupAccessTemplateMixin, TemplateView):
class RegistrationFormTemplate(AuthenticatedUserTemplateMixin, TemplateView):
template_name = 'registration_form.html'


class RegistrationFormApi(APCDGroupAccessAPIMixin, BaseAPIView):
class RegistrationFormApi(AuthenticatedUserAPIMixin, BaseAPIView):

def get(self, request):
formatted_reg_data = []
Expand All @@ -44,6 +44,8 @@ def get(self, request):
if (request.user.is_authenticated and has_apcd_group(request.user)):
context = {'registration_data': formatted_reg_data, 'renew': renew}
return JsonResponse({'response': context})
else:
return JsonResponse({'error': 'Unauthorized'}, status=403)

def post(self, request):
form = json.loads(request.body)
Expand Down

0 comments on commit 6ea7601

Please sign in to comment.