Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Production release v24.21.0 #2179

Merged
merged 20 commits into from
May 20, 2024
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ee2f148
Update max_length for phone numbers to adhere to ITU-T E.164 standard…
bodhish May 12, 2024
cc0413a
Adds support for doctors and nurses discussions threads in Discussion…
rithviknishad May 12, 2024
3253194
Allow `audio/mp4` by default (#2094)
sainak May 12, 2024
3d79333
Bump Dependencies (#2143)
vigneshhari May 12, 2024
f86293f
Vigneshhari/bump dependencies (#2145)
vigneshhari May 12, 2024
5be2e00
Skip creating event group if all fields are null (#2134)
sainak May 13, 2024
4a5bacb
ABDM M3 (#1829)
khavinshankar May 13, 2024
b46c9d4
Increase area of specialisation in doctors (#2102)
rash-27 May 14, 2024
6ed4494
Added discharge patient filters (#2124)
shivankacker May 14, 2024
a5171a8
converted investigation and investigation group data into JSON (#1912)
DraKen0009 May 15, 2024
7726678
Drops support for cloning previous log update (#2127)
rithviknishad May 15, 2024
50b2a12
Change devcontainer make up command to run after start (#2146)
shivankacker May 15, 2024
ae7ef82
Removes unused `current_health` field from Daily Rounds (#2162)
rithviknishad May 15, 2024
23abce0
Display users list based on user access limitation (#1742)
GokulramGHV May 15, 2024
a2052f2
adds missing merge migrations (#2169)
rithviknishad May 15, 2024
653c079
Store critical care daily round changes in events (#2170)
sainak May 16, 2024
57986ea
Removes unused field `temperature_measured_at` from Daily Rounds (#2171)
rithviknishad May 16, 2024
7c4b853
Merge pull request #2172 from coronasafe/develop
gigincg May 16, 2024
89078bc
make rate limit messages user friendly (#2174)
khavinshankar May 17, 2024
0d2cdc0
Merge pull request #2175 from coronasafe/develop
gigincg May 17, 2024
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
Prev Previous commit
Next Next commit
make rate limit messages user friendly (#2174)
khavinshankar authored May 17, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 89078bc9ba0ff65a0a6629b698355d1661591627
27 changes: 21 additions & 6 deletions care/abdm/api/viewsets/consent.py
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
from care.utils.queryset.facility import get_facility_queryset
from config.auth_views import CaptchaRequiredException
from config.authentication import ABDMAuthentication
from config.ratelimit import ratelimit
from config.ratelimit import USER_READABLE_RATE_LIMIT_TIME, ratelimit

logger = logging.getLogger(__name__)

@@ -62,7 +62,10 @@ def create(self, request):
request, "consent__create", [serializer.validated_data["patient_abha"]]
):
raise CaptchaRequiredException(
detail={"status": 429, "detail": "Too Many Requests Provide Captcha"},
detail={
"status": 429,
"detail": f"Request limit reached. Try after {USER_READABLE_RATE_LIMIT_TIME}",
},
code=status.HTTP_429_TOO_MANY_REQUESTS,
)

@@ -91,7 +94,10 @@ def create(self, request):
def status(self, request, pk):
if ratelimit(request, "consent__status", [pk]):
raise CaptchaRequiredException(
detail={"status": 429, "detail": "Too Many Requests Provide Captcha"},
detail={
"status": 429,
"detail": f"Request limit reached. Try after {USER_READABLE_RATE_LIMIT_TIME}",
},
code=status.HTTP_429_TOO_MANY_REQUESTS,
)

@@ -112,7 +118,10 @@ def status(self, request, pk):
def fetch(self, request, pk):
if ratelimit(request, "consent__fetch", [pk]):
raise CaptchaRequiredException(
detail={"status": 429, "detail": "Too Many Requests Provide Captcha"},
detail={
"status": 429,
"detail": f"Request limit reached. Try after {USER_READABLE_RATE_LIMIT_TIME}",
},
code=status.HTTP_429_TOO_MANY_REQUESTS,
)

@@ -134,7 +143,10 @@ def fetch(self, request, pk):
def list(self, request, *args, **kwargs):
if ratelimit(request, "consent__list", [request.user.username]):
raise CaptchaRequiredException(
detail={"status": 429, "detail": "Too Many Requests Provide Captcha"},
detail={
"status": 429,
"detail": f"Request limit reached. Try after {USER_READABLE_RATE_LIMIT_TIME}",
},
code=status.HTTP_429_TOO_MANY_REQUESTS,
)

@@ -143,7 +155,10 @@ def list(self, request, *args, **kwargs):
def retrieve(self, request, *args, **kwargs):
if ratelimit(request, "consent__retrieve", [kwargs["pk"]]):
raise CaptchaRequiredException(
detail={"status": 429, "detail": "Too Many Requests Provide Captcha"},
detail={
"status": 429,
"detail": f"Request limit reached. Try after {USER_READABLE_RATE_LIMIT_TIME}",
},
code=status.HTTP_429_TOO_MANY_REQUESTS,
)

12 changes: 9 additions & 3 deletions care/abdm/api/viewsets/health_information.py
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
from care.facility.models.file_upload import FileUpload
from config.auth_views import CaptchaRequiredException
from config.authentication import ABDMAuthentication
from config.ratelimit import ratelimit
from config.ratelimit import USER_READABLE_RATE_LIMIT_TIME, ratelimit

logger = logging.getLogger(__name__)

@@ -25,7 +25,10 @@ class HealthInformationViewSet(GenericViewSet):
def retrieve(self, request, pk):
if ratelimit(request, "health_information__retrieve", [pk]):
raise CaptchaRequiredException(
detail={"status": 429, "detail": "Too Many Requests Provide Captcha"},
detail={
"status": 429,
"detail": f"Request limit reached. Try after {USER_READABLE_RATE_LIMIT_TIME}",
},
code=status.HTTP_429_TOO_MANY_REQUESTS,
)

@@ -66,7 +69,10 @@ def retrieve(self, request, pk):
def request(self, request, pk):
if ratelimit(request, "health_information__request", [pk]):
raise CaptchaRequiredException(
detail={"status": 429, "detail": "Too Many Requests Provide Captcha"},
detail={
"status": 429,
"detail": f"Request limit reached. Try after {USER_READABLE_RATE_LIMIT_TIME}",
},
code=status.HTTP_429_TOO_MANY_REQUESTS,
)

87 changes: 69 additions & 18 deletions care/abdm/api/viewsets/healthid.py
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@
from care.facility.models.patient import PatientConsultation, PatientRegistration
from care.utils.queryset.patient import get_patient_queryset
from config.auth_views import CaptchaRequiredException
from config.ratelimit import ratelimit
from config.ratelimit import USER_READABLE_RATE_LIMIT_TIME, ratelimit

logger = logging.getLogger(__name__)

@@ -53,7 +53,10 @@ def generate_aadhaar_otp(self, request):

if ratelimit(request, "generate_aadhaar_otp", [data["aadhaar"]]):
raise CaptchaRequiredException(
detail={"status": 429, "detail": "Too Many Requests Provide Captcha"},
detail={
"status": 429,
"detail": f"Request limit reached. Try after {USER_READABLE_RATE_LIMIT_TIME}",
},
code=status.HTTP_429_TOO_MANY_REQUESTS,
)

@@ -75,7 +78,10 @@ def resend_aadhaar_otp(self, request):

if ratelimit(request, "resend_aadhaar_otp", [data["txnId"]]):
raise CaptchaRequiredException(
detail={"status": 429, "detail": "Too Many Requests Provide Captcha"},
detail={
"status": 429,
"detail": f"Request limit reached. Try after {USER_READABLE_RATE_LIMIT_TIME}",
},
code=status.HTTP_429_TOO_MANY_REQUESTS,
)

@@ -97,7 +103,10 @@ def verify_aadhaar_otp(self, request):

if ratelimit(request, "verify_aadhaar_otp", [data["txnId"]]):
raise CaptchaRequiredException(
detail={"status": 429, "detail": "Too Many Requests Provide Captcha"},
detail={
"status": 429,
"detail": f"Request limit reached. Try after {USER_READABLE_RATE_LIMIT_TIME}",
},
code=status.HTTP_429_TOO_MANY_REQUESTS,
)

@@ -121,7 +130,10 @@ def generate_mobile_otp(self, request):

if ratelimit(request, "generate_mobile_otp", [data["txnId"]]):
raise CaptchaRequiredException(
detail={"status": 429, "detail": "Too Many Requests Provide Captcha"},
detail={
"status": 429,
"detail": f"Request limit reached. Try after {USER_READABLE_RATE_LIMIT_TIME}",
},
code=status.HTTP_429_TOO_MANY_REQUESTS,
)

@@ -143,7 +155,10 @@ def verify_mobile_otp(self, request):

if ratelimit(request, "verify_mobile_otp", [data["txnId"]]):
raise CaptchaRequiredException(
detail={"status": 429, "detail": "Too Many Requests Provide Captcha"},
detail={
"status": 429,
"detail": f"Request limit reached. Try after {USER_READABLE_RATE_LIMIT_TIME}",
},
code=status.HTTP_429_TOO_MANY_REQUESTS,
)

@@ -207,7 +222,10 @@ def create_health_id(self, request):

if ratelimit(request, "create_health_id", [data["txnId"]]):
raise CaptchaRequiredException(
detail={"status": 429, "detail": "Too Many Requests Provide Captcha"},
detail={
"status": 429,
"detail": f"Request limit reached. Try after {USER_READABLE_RATE_LIMIT_TIME}",
},
code=status.HTTP_429_TOO_MANY_REQUESTS,
)

@@ -269,7 +287,10 @@ def search_by_health_id(self, request):
request, "search_by_health_id", [data["healthId"]], increment=False
):
raise CaptchaRequiredException(
detail={"status": 429, "detail": "Too Many Requests Provide Captcha"},
detail={
"status": 429,
"detail": f"Request limit reached. Try after {USER_READABLE_RATE_LIMIT_TIME}",
},
code=status.HTTP_429_TOO_MANY_REQUESTS,
)

@@ -284,7 +305,10 @@ def get_abha_card(self, request):

if ratelimit(request, "get_abha_card", [data["patient"]], increment=False):
raise CaptchaRequiredException(
detail={"status": 429, "detail": "Too Many Requests Provide Captcha"},
detail={
"status": 429,
"detail": f"Request limit reached. Try after {USER_READABLE_RATE_LIMIT_TIME}",
},
code=status.HTTP_429_TOO_MANY_REQUESTS,
)

@@ -320,7 +344,10 @@ def link_via_qr(self, request):

if ratelimit(request, "link_via_qr", [data["hidn"]], increment=False):
raise CaptchaRequiredException(
detail={"status": 429, "detail": "Too Many Requests Provide Captcha"},
detail={
"status": 429,
"detail": f"Request limit reached. Try after {USER_READABLE_RATE_LIMIT_TIME}",
},
code=status.HTTP_429_TOO_MANY_REQUESTS,
)

@@ -410,7 +437,10 @@ def get_new_linking_token(self, request):

if ratelimit(request, "get_new_linking_token", [data["patient"]]):
raise CaptchaRequiredException(
detail={"status": 429, "detail": "Too Many Requests Provide Captcha"},
detail={
"status": 429,
"detail": f"Request limit reached. Try after {USER_READABLE_RATE_LIMIT_TIME}",
},
code=status.HTTP_429_TOO_MANY_REQUESTS,
)

@@ -448,7 +478,10 @@ def add_care_context(self, request, *args, **kwargs):

if ratelimit(request, "add_care_context", [consultation_id]):
raise CaptchaRequiredException(
detail={"status": 429, "detail": "Too Many Requests Provide Captcha"},
detail={
"status": 429,
"detail": f"Request limit reached. Try after {USER_READABLE_RATE_LIMIT_TIME}",
},
code=status.HTTP_429_TOO_MANY_REQUESTS,
)

@@ -499,7 +532,10 @@ def patient_sms_notify(self, request, *args, **kwargs):

if ratelimit(request, "patient_sms_notify", [patient_id]):
raise CaptchaRequiredException(
detail={"status": 429, "detail": "Too Many Requests Provide Captcha"},
detail={
"status": 429,
"detail": f"Request limit reached. Try after {USER_READABLE_RATE_LIMIT_TIME}",
},
code=status.HTTP_429_TOO_MANY_REQUESTS,
)

@@ -545,7 +581,10 @@ def auth_init(self, request):

if ratelimit(request, "auth_init", [data["healthid"]]):
raise CaptchaRequiredException(
detail={"status": 429, "detail": "Too Many Requests Provide Captcha"},
detail={
"status": 429,
"detail": f"Request limit reached. Try after {USER_READABLE_RATE_LIMIT_TIME}",
},
code=status.HTTP_429_TOO_MANY_REQUESTS,
)

@@ -567,7 +606,10 @@ def confirm_with_aadhaar_otp(self, request):

if ratelimit(request, "confirm_with_aadhaar_otp", [data["txnId"]]):
raise CaptchaRequiredException(
detail={"status": 429, "detail": "Too Many Requests Provide Captcha"},
detail={
"status": 429,
"detail": f"Request limit reached. Try after {USER_READABLE_RATE_LIMIT_TIME}",
},
code=status.HTTP_429_TOO_MANY_REQUESTS,
)

@@ -620,7 +662,10 @@ def confirm_with_mobile_otp(self, request):

if ratelimit(request, "confirm_with_mobile_otp", [data["txnId"]]):
raise CaptchaRequiredException(
detail={"status": 429, "detail": "Too Many Requests Provide Captcha"},
detail={
"status": 429,
"detail": f"Request limit reached. Try after {USER_READABLE_RATE_LIMIT_TIME}",
},
code=status.HTTP_429_TOO_MANY_REQUESTS,
)

@@ -672,7 +717,10 @@ def confirm_with_demographics(self, request):

if ratelimit(request, "confirm_with_demographics", [data["txnId"]]):
raise CaptchaRequiredException(
detail={"status": 429, "detail": "Too Many Requests Provide Captcha"},
detail={
"status": 429,
"detail": f"Request limit reached. Try after {USER_READABLE_RATE_LIMIT_TIME}",
},
code=status.HTTP_429_TOO_MANY_REQUESTS,
)

@@ -696,7 +744,10 @@ def check_and_generate_mobile_otp(self, request):

if ratelimit(request, "check_and_generate_mobile_otp", [data["txnId"]]):
raise CaptchaRequiredException(
detail={"status": 429, "detail": "Too Many Requests Provide Captcha"},
detail={
"status": 429,
"detail": f"Request limit reached. Try after {USER_READABLE_RATE_LIMIT_TIME}",
},
code=status.HTTP_429_TOO_MANY_REQUESTS,
)

7 changes: 5 additions & 2 deletions care/abdm/api/viewsets/patients.py
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
from care.utils.notification_handler import send_webpush
from config.auth_views import CaptchaRequiredException
from config.authentication import ABDMAuthentication
from config.ratelimit import ratelimit
from config.ratelimit import USER_READABLE_RATE_LIMIT_TIME, ratelimit


class PatientsViewSet(GenericViewSet):
@@ -25,7 +25,10 @@ def find(self, request):

if ratelimit(request, "patients__find", [identifier]):
raise CaptchaRequiredException(
detail={"status": 429, "detail": "Too Many Requests Provide Captcha"},
detail={
"status": 429,
"detail": f"Request limit reached. Try after {USER_READABLE_RATE_LIMIT_TIME}",
},
code=status.HTTP_429_TOO_MANY_REQUESTS,
)

24 changes: 24 additions & 0 deletions config/ratelimit.py
Original file line number Diff line number Diff line change
@@ -56,3 +56,27 @@ def ratelimit(
return False

return False


def get_user_readable_rate_limit_time(rate_limit):
if not rate_limit:
return "1 second"

requests, time = rate_limit.split("/")

time_unit_map = {
"s": "second(s)",
"m": "minute(s)",
"h": "hour(s)",
"d": "day(s)",
}

time_value = time[:-1]
time_unit = time[-1]

return f"{time_value or 1} {time_unit_map.get(time_unit, 'second(s)')}"


USER_READABLE_RATE_LIMIT_TIME = get_user_readable_rate_limit_time(
settings.DJANGO_RATE_LIMIT
)