Skip to content
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
14 changes: 3 additions & 11 deletions api/event/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,13 @@
from django.db.models import Prefetch

from api.models import EventDateTimeslot, EventWeekdayTimeslot, UrlCode, UserEvent
from api.settings import (
MAX_EVENT_DAYS,
RAND_URL_CODE_ATTEMPTS,
RAND_URL_CODE_LENGTH,
URL_CODE_EXP_SECONDS,
)
from api.settings import MAX_EVENT_DAYS, RAND_URL_CODE_ATTEMPTS, RAND_URL_CODE_LENGTH


def check_code_available(code):
try:
existing_code = UrlCode.objects.get(url_code=code)
if existing_code.last_used >= datetime.now() - timedelta(
seconds=URL_CODE_EXP_SECONDS
):
return False
UrlCode.objects.get(url_code=code)
return False
except UrlCode.DoesNotExist:
pass

Expand Down
10 changes: 2 additions & 8 deletions api/event/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,7 @@ def create_date_event(request):
duration=duration,
time_zone=time_zone,
)
# Here we trust the code checking logic from before instead of checking again
UrlCode.objects.update_or_create(
url_code=url_code, defaults={"user_event": new_event}
)
UrlCode.objects.create(url_code=url_code, user_event=new_event)
# Create timeslot objects
EventDateTimeslot.objects.bulk_create(
[
Expand Down Expand Up @@ -179,10 +176,7 @@ def create_week_event(request):
duration=duration,
time_zone=time_zone,
)
# Here we trust the code checking logic from before instead of checking again
UrlCode.objects.update_or_create(
url_code=url_code, defaults={"user_event": new_event}
)
UrlCode.objects.create(url_code=url_code, user_event=new_event)
# Create timeslot objects
deduplicated_timeslots = set(
(js_weekday(ts.weekday()), ts.time()) for ts in timeslots
Expand Down
12 changes: 0 additions & 12 deletions api/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from api.models import (
PasswordResetToken,
UnverifiedUserAccount,
UrlCode,
UserAccount,
UserSession,
)
Expand All @@ -15,7 +14,6 @@
LONG_SESS_EXP_SECONDS,
PWD_RESET_EXP_SECONDS,
SESS_EXP_SECONDS,
URL_CODE_EXP_SECONDS,
)


Expand Down Expand Up @@ -63,15 +61,6 @@ def password_reset_token_cleanup():
).delete()


def url_code_cleanup():
"""
Removes expired event URL codes.
"""
UrlCode.objects.filter(
last_used__lt=datetime.now() - timedelta(seconds=URL_CODE_EXP_SECONDS)
).delete()


@shared_task
def daily_duties():
"""
Expand All @@ -82,4 +71,3 @@ def daily_duties():
guest_cleanup()
unverified_user_cleanup()
password_reset_token_cleanup()
url_code_cleanup()
Loading