Skip to content

Commit

Permalink
fix: Disable DB gateways (#2374)
Browse files Browse the repository at this point in the history
* fix: Disable logging in, verifying, resetting password and registering

* Disable anonymisation cron job view
  • Loading branch information
faucomte97 authored Nov 1, 2024
1 parent ec52caa commit e9212f6
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 70 deletions.
80 changes: 47 additions & 33 deletions portal/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,53 +223,63 @@
),
url(r"^$", home, name="home"),
url(r"^home-learning", home_learning, name="home-learning"),
url(r"^register_form", register_view, name="register"),
url(
r"^register_form",
# register_view,
home,
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()),
# # 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,
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()),
# 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,
name="student_login",
),
url(
r"^login/student/$",
StudentClassCodeView.as_view(),
# StudentClassCodeView.as_view(),
home,
name="student_login_access_code",
),
url(
r"^u/(?P<user_id>[0-9]+)/(?P<login_id>[a-z0-9]+)/$",
student_direct_login,
# student_direct_login,
home,
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()),
# ratelimit(
# group=RATELIMIT_LOGIN_GROUP,
# key="post:username",
# method=RATELIMIT_METHOD,
# rate=RATELIMIT_LOGIN_RATE,
# block=True,
# is_teacher=False,
# )(IndependentStudentLoginView.as_view()),
home,
name="independent_student_login",
),
url(r"^login_form", old_login_form_redirect, name="old_login_form"),
Expand All @@ -290,17 +300,20 @@
),
url(
rf"^verify_email/(?P<token>{JWT_REGEX})/$",
verify_email,
# verify_email,
home,
name="verify_email",
),
url(
r"^user/password/reset/student/$",
student_password_reset,
# student_password_reset,
home,
name="student_password_reset",
),
url(
r"^user/password/reset/teacher/$",
teacher_password_reset,
# teacher_password_reset,
home,
name="teacher_password_reset",
),
url(
Expand All @@ -310,7 +323,8 @@
),
url(
r"^user/password/reset/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$",
password_reset_check_and_confirm,
# password_reset_check_and_confirm,
home,
name="password_reset_check_and_confirm",
),
url(
Expand Down
72 changes: 36 additions & 36 deletions portal/views/cron/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion portal/views/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit e9212f6

Please sign in to comment.