Skip to content

Commit

Permalink
disabled a bunch of website functionality, such as registation, when …
Browse files Browse the repository at this point in the history
…the current hackathon is over (like now)
  • Loading branch information
jrdbnntt committed Feb 25, 2017
1 parent c3900a5 commit b89d592
Show file tree
Hide file tree
Showing 22 changed files with 36 additions and 5 deletions.
9 changes: 8 additions & 1 deletion api/models/hackathon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions api/views/attendee/assign_wifi_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions api/views/attendee/check_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions api/views/attendee/rsvp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions api/views/hacker/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions api/views/judge/assign_hacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions api/views/judge/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
1 change: 1 addition & 0 deletions api/views/mentor/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
1 change: 1 addition & 0 deletions api/views/mentor/request/claim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions api/views/mentor/request/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions api/views/mentor/request/release_claim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down
5 changes: 4 additions & 1 deletion hackfsu_com/views/generic/api_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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())
8 changes: 5 additions & 3 deletions hackfsu_com/views/generic/page_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 """
Expand Down
1 change: 1 addition & 0 deletions webapp/views/hacks/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@


class HacksPage(PageView):
allowed_after_current_hackathon_ends = False
template_name = 'hacks/index.html'
1 change: 1 addition & 0 deletions webapp/views/help/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


class HelpPage(PageView):
allowed_after_current_hackathon_ends = False
template_name = 'help/index.html'

def work(self, request):
Expand Down
1 change: 1 addition & 0 deletions webapp/views/judge/hack/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down
1 change: 1 addition & 0 deletions webapp/views/judge/index/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
1 change: 1 addition & 0 deletions webapp/views/organize/judging/expo/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
1 change: 1 addition & 0 deletions webapp/views/registration/hacker/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions webapp/views/registration/judge/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions webapp/views/registration/mentor/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
1 change: 1 addition & 0 deletions webapp/views/user/rsvp/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b89d592

Please sign in to comment.