diff --git a/api/models/hackathon.py b/api/models/hackathon.py index b56d5da..be84b02 100644 --- a/api/models/hackathon.py +++ b/api/models/hackathon.py @@ -33,13 +33,20 @@ def __str__(self): else: return self.name - def is_today(self): + def is_today(self) -> bool: """ Returns t/f based on if the hackathon is happening today """ today = timezone.now().date() return (self.start_date <= today) and (today <= self.end_date) + def is_over(self) -> bool: + """ + :return: True if hackathon is over, false if upcoming/happening + """ + today = timezone.now().date() + return self.end_date < today + @admin.register(Hackathon, site=hackfsu_admin) class HackathonAdmin(admin.ModelAdmin): diff --git a/api/views/attendee/assign_wifi_credentials.py b/api/views/attendee/assign_wifi_credentials.py index 3d755e1..d29dd93 100644 --- a/api/views/attendee/assign_wifi_credentials.py +++ b/api/views/attendee/assign_wifi_credentials.py @@ -16,6 +16,7 @@ class RequestForm(forms.Form): class AssignWifiCredentialsView(ApiView): request_form_class = RequestForm + allowed_after_current_hackathon_ends = False access_manager = acl.AccessManager(acl_accept=[acl.group_organizer]) def work(self, request, req, res): diff --git a/api/views/attendee/check_in.py b/api/views/attendee/check_in.py index c0298ad..8bd1f7c 100644 --- a/api/views/attendee/check_in.py +++ b/api/views/attendee/check_in.py @@ -16,6 +16,7 @@ class RequestForm(forms.Form): class CheckInView(ApiView): request_form_class = RequestForm + allowed_after_current_hackathon_ends = False access_manager = acl.AccessManager(acl_accept=[acl.group_organizer]) def work(self, request, req, res): diff --git a/api/views/attendee/rsvp.py b/api/views/attendee/rsvp.py index e1c997b..171aa80 100644 --- a/api/views/attendee/rsvp.py +++ b/api/views/attendee/rsvp.py @@ -16,6 +16,7 @@ class RequestForm(forms.Form): class RsvpView(ApiView): request_form_class = RequestForm + allowed_after_current_hackathon_ends = False access_manager = acl.AccessManager(acl_accept=[ acl.group_hacker, acl.group_mentor, diff --git a/api/views/hacker/register.py b/api/views/hacker/register.py index ffa4ce6..7b98cde 100644 --- a/api/views/hacker/register.py +++ b/api/views/hacker/register.py @@ -26,6 +26,7 @@ class RequestForm(forms.Form): class RegisterView(ApiView): request_form_class = RequestForm + allowed_after_current_hackathon_ends = False access_manager = acl.AccessManager(acl_accept=[acl.group_user], acl_deny=[acl.group_hacker, acl.group_judge, acl.group_organizer, acl.group_pending_hacker, acl.group_pending_judge, diff --git a/api/views/judge/assign_hacks.py b/api/views/judge/assign_hacks.py index 8aa0be7..4409405 100644 --- a/api/views/judge/assign_hacks.py +++ b/api/views/judge/assign_hacks.py @@ -50,6 +50,7 @@ class ResponseForm(forms.Form): class AssignHacksView(ApiView): request_form_class = RequestForm response_form_class = ResponseForm + allowed_after_current_hackathon_ends = False access_manager = acl.AccessManager(acl_accept=[acl.group_organizer]) def work(self, request, req, res): diff --git a/api/views/judge/register.py b/api/views/judge/register.py index a6f7173..4d346a8 100644 --- a/api/views/judge/register.py +++ b/api/views/judge/register.py @@ -14,6 +14,7 @@ class RequestForm(forms.Form): class RegisterView(ApiView): request_form_class = RequestForm + allowed_after_current_hackathon_ends = False access_manager = acl.AccessManager(acl_accept=[acl.group_user], acl_deny=[acl.group_hacker, acl.group_judge, acl.group_pending_judge, acl.group_pending_hacker]) diff --git a/api/views/mentor/register.py b/api/views/mentor/register.py index ae53c95..322e4e8 100644 --- a/api/views/mentor/register.py +++ b/api/views/mentor/register.py @@ -15,6 +15,7 @@ class RequestForm(forms.Form): class RegisterView(ApiView): + allowed_after_current_hackathon_ends = False request_form_class = RequestForm access_manager = acl.AccessManager(acl_accept=[acl.group_user], acl_deny=[acl.group_mentor, acl.group_pending_mentor]) diff --git a/api/views/mentor/request/claim.py b/api/views/mentor/request/claim.py index df85b05..855bc2e 100644 --- a/api/views/mentor/request/claim.py +++ b/api/views/mentor/request/claim.py @@ -15,6 +15,7 @@ class RequestForm(forms.Form): class ClaimView(ApiView): request_form_class = RequestForm + allowed_after_current_hackathon_ends = False access_manager = acl.AccessManager(acl_accept=[acl.group_mentor]) def work(self, request, req, res): diff --git a/api/views/mentor/request/create.py b/api/views/mentor/request/create.py index 66f58ab..ce5d2b6 100644 --- a/api/views/mentor/request/create.py +++ b/api/views/mentor/request/create.py @@ -23,6 +23,7 @@ class RequestForm(forms.Form): class CreateView(ApiView): + allowed_after_current_hackathon_ends = False request_form_class = RequestForm def authenticate(self, request): diff --git a/api/views/mentor/request/release_claim.py b/api/views/mentor/request/release_claim.py index c828264..6e008e2 100644 --- a/api/views/mentor/request/release_claim.py +++ b/api/views/mentor/request/release_claim.py @@ -14,6 +14,7 @@ class RequestForm(forms.Form): class ReleaseClaimView(ApiView): + allowed_after_current_hackathon_ends = False request_form_class = RequestForm access_manager = acl.AccessManager(acl_accept=[acl.group_mentor]) diff --git a/hackfsu_com/views/generic/api_view.py b/hackfsu_com/views/generic/api_view.py index 52dea09..35e62d5 100644 --- a/hackfsu_com/views/generic/api_view.py +++ b/hackfsu_com/views/generic/api_view.py @@ -13,6 +13,7 @@ from django.utils.translation import ugettext as _ from django.conf import settings from django import forms +from api.models import Hackathon from hackfsu_com.util import acl from hackfsu_com.util.exceptions import InternalServerError, ExternalUserError import logging @@ -29,6 +30,7 @@ class ApiView(View): request_form_class = forms.Form # Override each time response_form_class = forms.Form # Override each time access_manager = acl.AccessManager() + allowed_after_current_hackathon_ends = True def __init__(self, **kwargs): super().__init__(**kwargs) @@ -117,4 +119,5 @@ def work(self, request: HttpRequest, req: dict, res: dict): def authenticate(self, request): """ To be overridden if necessary. Should still be called with super """ - return self.access_manager.check_user(request.user) + return self.access_manager.check_user(request.user) and \ + (self.allowed_after_current_hackathon_ends or not Hackathon.objects.current().is_over()) diff --git a/hackfsu_com/views/generic/page_view.py b/hackfsu_com/views/generic/page_view.py index c49c118..277bff0 100644 --- a/hackfsu_com/views/generic/page_view.py +++ b/hackfsu_com/views/generic/page_view.py @@ -6,12 +6,13 @@ from django.shortcuts import render from django.shortcuts import redirect from hackfsu_com.util import acl - +from api.models import Hackathon class PageView(View): template_name = None context = None access_manager = acl.AccessManager() + allowed_after_current_hackathon_ends = True def __init__(self, **kwargs): super().__init__(**kwargs) @@ -41,8 +42,9 @@ def work(self, request): pass def authenticate(self, request): - """ May be overwritten to add more extensive auth. Should still be called via super """ - return self.access_manager.check_user(request.user) + """ To be overridden if necessary. Should still be called with super """ + return self.access_manager.check_user(request.user) and \ + (self.allowed_after_current_hackathon_ends or not Hackathon.objects.current().is_over()) def get_access_denied_redirect_url(self, request): """ May be overwritten if desired """ diff --git a/webapp/views/hacks/index.py b/webapp/views/hacks/index.py index eba56e4..49e864b 100644 --- a/webapp/views/hacks/index.py +++ b/webapp/views/hacks/index.py @@ -6,4 +6,5 @@ class HacksPage(PageView): + allowed_after_current_hackathon_ends = False template_name = 'hacks/index.html' diff --git a/webapp/views/help/index.py b/webapp/views/help/index.py index 0aeacf4..071b951 100644 --- a/webapp/views/help/index.py +++ b/webapp/views/help/index.py @@ -7,6 +7,7 @@ class HelpPage(PageView): + allowed_after_current_hackathon_ends = False template_name = 'help/index.html' def work(self, request): diff --git a/webapp/views/judge/hack/index.py b/webapp/views/judge/hack/index.py index 99b46d6..7fc8353 100644 --- a/webapp/views/judge/hack/index.py +++ b/webapp/views/judge/hack/index.py @@ -9,6 +9,7 @@ class HackPage(PageView): + allowed_after_current_hackathon_ends = False template_name = 'judge/hack/index.html' access_manager = acl.AccessManager(acl_accept=[acl.group_judge]) diff --git a/webapp/views/judge/index/index.py b/webapp/views/judge/index/index.py index 0e590d0..3f2c06e 100644 --- a/webapp/views/judge/index/index.py +++ b/webapp/views/judge/index/index.py @@ -7,5 +7,6 @@ class IndexPage(PageView): + allowed_after_current_hackathon_ends = False template_name = 'judge/index/index.html' access_manager = acl.AccessManager(acl_accept=[acl.group_judge]) diff --git a/webapp/views/organize/judging/expo/index.py b/webapp/views/organize/judging/expo/index.py index 0127e36..f682dbe 100644 --- a/webapp/views/organize/judging/expo/index.py +++ b/webapp/views/organize/judging/expo/index.py @@ -7,5 +7,6 @@ class ExpoPage(PageView): + allowed_after_current_hackathon_ends = False template_name = 'organize/judging/expo/index.html' access_manager = acl.AccessManager(acl_accept=[acl.group_organizer]) diff --git a/webapp/views/registration/hacker/index.py b/webapp/views/registration/hacker/index.py index 8cd25da..aa9c2e1 100644 --- a/webapp/views/registration/hacker/index.py +++ b/webapp/views/registration/hacker/index.py @@ -7,6 +7,7 @@ class HackerRegistrationPage(PageView): + allowed_after_current_hackathon_ends = False template_name = 'registration/hacker/index.html' access_manager = acl.AccessManager(acl_accept=[acl.group_user], acl_deny=[acl.group_hacker, acl.group_judge, acl.group_organizer, diff --git a/webapp/views/registration/judge/index.py b/webapp/views/registration/judge/index.py index f19fd6c..d13dbe5 100644 --- a/webapp/views/registration/judge/index.py +++ b/webapp/views/registration/judge/index.py @@ -7,6 +7,7 @@ class JudgeRegistrationPage(PageView): + allowed_after_current_hackathon_ends = False template_name = 'registration/judge/index.html' access_manager = acl.AccessManager(acl_accept=[acl.group_user], acl_deny=[acl.group_hacker, acl.group_judge, acl.group_pending_hacker, diff --git a/webapp/views/registration/mentor/index.py b/webapp/views/registration/mentor/index.py index d1952a1..312367f 100644 --- a/webapp/views/registration/mentor/index.py +++ b/webapp/views/registration/mentor/index.py @@ -7,6 +7,7 @@ class MentorRegistrationPage(PageView): + allowed_after_current_hackathon_ends = False template_name = 'registration/mentor/index.html' access_manager = acl.AccessManager(acl_accept=[acl.group_user], acl_deny=[acl.group_mentor, acl.group_pending_mentor]) diff --git a/webapp/views/user/rsvp/index.py b/webapp/views/user/rsvp/index.py index aad8339..d041583 100644 --- a/webapp/views/user/rsvp/index.py +++ b/webapp/views/user/rsvp/index.py @@ -8,6 +8,7 @@ class RsvpPage(PageView): + allowed_after_current_hackathon_ends = False template_name = 'user/rsvp/index.html' access_manager = acl.AccessManager(acl_accept=[ acl.group_hacker,