From ac08f000dc74511608b989ce79ae72ee7c03229b Mon Sep 17 00:00:00 2001 From: Florian Aucomte <33633200+faucomte97@users.noreply.github.com> Date: Tue, 19 Sep 2023 00:08:22 +0100 Subject: [PATCH 1/4] fix: Disable ratelimit when value is empty (#2178) * fix: Don't run ratelimit on empty key * Disable on value null --- portal/helpers/ratelimit.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/portal/helpers/ratelimit.py b/portal/helpers/ratelimit.py index 1787e73b9..acf108842 100644 --- a/portal/helpers/ratelimit.py +++ b/portal/helpers/ratelimit.py @@ -161,7 +161,16 @@ def get_usage(request, group=None, fn=None, key=None, rate=None, method=ALL, inc cache_name = getattr(settings, "RATELIMIT_USE_CACHE", "default") cache = caches[cache_name] - cache_key = _make_cache_key(group, window, rate, value, method) + + if value == "": + return { + "count": 0, + "limit": 0, + "should_limit": False, + "time_left": -1, + } + else: + cache_key = _make_cache_key(group, window, rate, value, method) count = None added = cache.add(cache_key, initial_value, period + EXPIRATION_FUDGE) From ed17db762ed21836b9dc58f4753e06ff5552c7c4 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 18 Sep 2023 23:12:29 +0000 Subject: [PATCH 2/4] 6.36.1 Automatically generated by python-semantic-release --- portal/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/portal/__init__.py b/portal/__init__.py index b076d5803..6c6902981 100644 --- a/portal/__init__.py +++ b/portal/__init__.py @@ -1 +1 @@ -__version__ = "6.36.0" +__version__ = "6.36.1" From 015d9025897cf68d8090676cc53abb25a3db59f3 Mon Sep 17 00:00:00 2001 From: Florian Aucomte <33633200+faucomte97@users.noreply.github.com> Date: Tue, 19 Sep 2023 15:02:19 +0100 Subject: [PATCH 3/4] fix: Move postcode helper to common (#2176) --- {portal => cfl_common/common}/helpers/organisation.py | 0 .../common/migrations/0041_populate_gb_counties.py | 2 +- cfl_common/common/models.py | 4 ++-- cfl_common/common/tests/test_models.py | 10 ++++++++++ portal/tests/test_helper_methods.py | 10 ---------- 5 files changed, 13 insertions(+), 13 deletions(-) rename {portal => cfl_common/common}/helpers/organisation.py (100%) diff --git a/portal/helpers/organisation.py b/cfl_common/common/helpers/organisation.py similarity index 100% rename from portal/helpers/organisation.py rename to cfl_common/common/helpers/organisation.py diff --git a/cfl_common/common/migrations/0041_populate_gb_counties.py b/cfl_common/common/migrations/0041_populate_gb_counties.py index 2484c0851..e45f148b3 100644 --- a/cfl_common/common/migrations/0041_populate_gb_counties.py +++ b/cfl_common/common/migrations/0041_populate_gb_counties.py @@ -1,7 +1,7 @@ import pgeocode from django.db import migrations -from portal.helpers.organisation import sanitise_uk_postcode +from ..helpers.organisation import sanitise_uk_postcode class Migration(migrations.Migration): diff --git a/cfl_common/common/models.py b/cfl_common/common/models.py index cacff07af..8813b1fe2 100644 --- a/cfl_common/common/models.py +++ b/cfl_common/common/models.py @@ -1,14 +1,14 @@ -import pgeocode import re from datetime import timedelta from uuid import uuid4 +import pgeocode from django.contrib.auth.models import User from django.db import models from django.utils import timezone from django_countries.fields import CountryField -from portal.helpers.organisation import sanitise_uk_postcode +from .helpers.organisation import sanitise_uk_postcode class UserProfile(models.Model): diff --git a/cfl_common/common/tests/test_models.py b/cfl_common/common/tests/test_models.py index f5168d5b4..d881beb1c 100644 --- a/cfl_common/common/tests/test_models.py +++ b/cfl_common/common/tests/test_models.py @@ -6,6 +6,7 @@ from .utils.organisation import create_organisation_directly, join_teacher_to_organisation from .utils.student import create_independent_student_directly from .utils.teacher import signup_teacher_directly +from ..helpers.organisation import sanitise_uk_postcode class TestModels(TestCase): @@ -90,6 +91,15 @@ def test_school_postcode(self): assert school.county == "" + def test_sanitise_uk_postcode(self): + postcode_with_space = "AL10 9NE" + postcode_without_space = "AL109UL" + invalid_postcode = "123" + + assert sanitise_uk_postcode(postcode_with_space) == "AL10 9NE" # Check it stays the same + assert sanitise_uk_postcode(postcode_without_space) == "AL10 9UL" # Check a space is added + assert sanitise_uk_postcode(invalid_postcode) == "123" # Check nothing happens + def test_daily_activity_serializer(self): daily_activity = DailyActivity() diff --git a/portal/tests/test_helper_methods.py b/portal/tests/test_helper_methods.py index bff476c4f..23482b72c 100644 --- a/portal/tests/test_helper_methods.py +++ b/portal/tests/test_helper_methods.py @@ -2,7 +2,6 @@ from unittest.mock import patch, Mock from portal.helpers.password import is_password_pwned -from portal.helpers.organisation import sanitise_uk_postcode class TestClass: @@ -29,12 +28,3 @@ def test_is_password_pwned__status_code_not_200(self, mock_get): # Assert mock_get.assert_called_once_with(f"https://api.pwnedpasswords.com/range/{sha1_hash[:5]}") assert not result - - def test_sanitise_uk_postcode(self): - postcode_with_space = "AL10 9NE" - postcode_without_space = "AL109UL" - invalid_postcode = "123" - - assert sanitise_uk_postcode(postcode_with_space) == "AL10 9NE" # Check it stays the same - assert sanitise_uk_postcode(postcode_without_space) == "AL10 9UL" # Check a space is added - assert sanitise_uk_postcode(invalid_postcode) == "123" # Check nothing happens From cab82b1325ea9f3f85fdc01d145f3c6af4a16d8a Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 19 Sep 2023 14:05:35 +0000 Subject: [PATCH 4/4] 6.36.2 Automatically generated by python-semantic-release --- portal/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/portal/__init__.py b/portal/__init__.py index 6c6902981..09ed46c59 100644 --- a/portal/__init__.py +++ b/portal/__init__.py @@ -1 +1 @@ -__version__ = "6.36.1" +__version__ = "6.36.2"