Skip to content

Commit

Permalink
fix: Revert "fix: Disable DB gateways (#2374)"
Browse files Browse the repository at this point in the history
This reverts commit e9212f6.
  • Loading branch information
faucomte97 committed Nov 2, 2024
1 parent 27ac724 commit 1f7ec61
Showing 3 changed files with 70 additions and 84 deletions.
80 changes: 33 additions & 47 deletions portal/urls.py
Original file line number Diff line number Diff line change
@@ -223,63 +223,53 @@
),
url(r"^$", home, name="home"),
url(r"^home-learning", home_learning, name="home-learning"),
url(
r"^register_form",
# register_view,
home,
name="register",
),
url(r"^register_form", register_view, name="register"),
url(
r"^login/teacher/$",
# # The ratelimit decorator checks how often a POST request is performed on that view.
# # It checks against the username value specifically. If the number of requests
# # exceeds the specified rate, then the user will be blocked (if block = True).
# ratelimit(
# group=RATELIMIT_LOGIN_GROUP,
# key="post:auth-username",
# method=RATELIMIT_METHOD,
# rate=RATELIMIT_LOGIN_RATE,
# block=True,
# )(TeacherLoginView.as_view()),
home,
# The ratelimit decorator checks how often a POST request is performed on that view.
# It checks against the username value specifically. If the number of requests
# exceeds the specified rate, then the user will be blocked (if block = True).
ratelimit(
group=RATELIMIT_LOGIN_GROUP,
key="post:auth-username",
method=RATELIMIT_METHOD,
rate=RATELIMIT_LOGIN_RATE,
block=True,
)(TeacherLoginView.as_view()),
name="teacher_login",
),
url(
rf"^login/student/(?P<access_code>{ACCESS_CODE_REGEX})/(?:(?P<login_type>classform)/)?$",
# ratelimit(
# group=RATELIMIT_LOGIN_GROUP,
# key=school_student_key,
# method=RATELIMIT_METHOD,
# rate=RATELIMIT_LOGIN_RATE_SCHOOL_STUDENT,
# block=True,
# is_teacher=False,
# )(StudentLoginView.as_view()),
home,
ratelimit(
group=RATELIMIT_LOGIN_GROUP,
key=school_student_key,
method=RATELIMIT_METHOD,
rate=RATELIMIT_LOGIN_RATE_SCHOOL_STUDENT,
block=True,
is_teacher=False,
)(StudentLoginView.as_view()),
name="student_login",
),
url(
r"^login/student/$",
# StudentClassCodeView.as_view(),
home,
StudentClassCodeView.as_view(),
name="student_login_access_code",
),
url(
r"^u/(?P<user_id>[0-9]+)/(?P<login_id>[a-z0-9]+)/$",
# student_direct_login,
home,
student_direct_login,
name="student_direct_login",
),
url(
r"^login/independent/$",
# ratelimit(
# group=RATELIMIT_LOGIN_GROUP,
# key="post:username",
# method=RATELIMIT_METHOD,
# rate=RATELIMIT_LOGIN_RATE,
# block=True,
# is_teacher=False,
# )(IndependentStudentLoginView.as_view()),
home,
ratelimit(
group=RATELIMIT_LOGIN_GROUP,
key="post:username",
method=RATELIMIT_METHOD,
rate=RATELIMIT_LOGIN_RATE,
block=True,
is_teacher=False,
)(IndependentStudentLoginView.as_view()),
name="independent_student_login",
),
url(r"^login_form", old_login_form_redirect, name="old_login_form"),
@@ -300,20 +290,17 @@
),
url(
rf"^verify_email/(?P<token>{JWT_REGEX})/$",
# verify_email,
home,
verify_email,
name="verify_email",
),
url(
r"^user/password/reset/student/$",
# student_password_reset,
home,
student_password_reset,
name="student_password_reset",
),
url(
r"^user/password/reset/teacher/$",
# teacher_password_reset,
home,
teacher_password_reset,
name="teacher_password_reset",
),
url(
@@ -323,8 +310,7 @@
),
url(
r"^user/password/reset/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$",
# password_reset_check_and_confirm,
home,
password_reset_check_and_confirm,
name="password_reset_check_and_confirm",
),
url(
72 changes: 36 additions & 36 deletions portal/views/cron/user.py
Original file line number Diff line number Diff line change
@@ -172,42 +172,42 @@ def get(self, request):

class AnonymiseUnverifiedAccounts(CronMixin, APIView):
def get(self, request):
# user_count = User.objects.filter(is_active=True).count()
#
# teacher_queryset, independent_student_queryset = get_unverified_users(
# USER_DELETE_UNVERIFIED_ACCOUNT_DAYS,
# same_day=False,
# )
# teacher_count = teacher_queryset.count()
# indy_count = independent_student_queryset.count()
#
# user_queryset = teacher_queryset.union(independent_student_queryset)
#
# for user in user_queryset.iterator(chunk_size=100):
# try:
# anonymise(user)
# except Exception as ex:
# logging.error(f"Failed to anonymise user with id: {user.id}")
# logging.exception(ex)
#
# user_count -= User.objects.filter(is_active=True).count()
# logging.info(f"{user_count} unverified users anonymised.")
#
# activity_today = DailyActivity.objects.get_or_create(
# date=datetime.now().date()
# )[0]
# activity_today.anonymised_unverified_teachers = teacher_count
# activity_today.anonymised_unverified_independents = indy_count
# activity_today.save()
#
# TotalActivity.objects.update(
# anonymised_unverified_teachers=F("anonymised_unverified_teachers")
# + teacher_count,
# anonymised_unverified_independents=F(
# "anonymised_unverified_independents"
# )
# + indy_count,
# )
user_count = User.objects.filter(is_active=True).count()

teacher_queryset, independent_student_queryset = get_unverified_users(
USER_DELETE_UNVERIFIED_ACCOUNT_DAYS,
same_day=False,
)
teacher_count = teacher_queryset.count()
indy_count = independent_student_queryset.count()

user_queryset = teacher_queryset.union(independent_student_queryset)

for user in user_queryset.iterator(chunk_size=100):
try:
anonymise(user)
except Exception as ex:
logging.error(f"Failed to anonymise user with id: {user.id}")
logging.exception(ex)

user_count -= User.objects.filter(is_active=True).count()
logging.info(f"{user_count} unverified users anonymised.")

activity_today = DailyActivity.objects.get_or_create(
date=datetime.now().date()
)[0]
activity_today.anonymised_unverified_teachers = teacher_count
activity_today.anonymised_unverified_independents = indy_count
activity_today.save()

TotalActivity.objects.update(
anonymised_unverified_teachers=F("anonymised_unverified_teachers")
+ teacher_count,
anonymised_unverified_independents=F(
"anonymised_unverified_independents"
)
+ indy_count,
)

return Response()

2 changes: 1 addition & 1 deletion portal/views/home.py
Original file line number Diff line number Diff line change
@@ -255,7 +255,7 @@ def coding_club(request):

def download_student_pack(request, student_pack_type):
if request.method == "POST":
# count_student_pack_downloads_click(int(student_pack_type))
count_student_pack_downloads_click(int(student_pack_type))
link = cloud_storage("club_packs/PrimaryCodingClub.zip")
return redirect(link)

0 comments on commit 1f7ec61

Please sign in to comment.