Skip to content

Commit

Permalink
Return 403 if device limit is exceeded
Browse files Browse the repository at this point in the history
  • Loading branch information
gherceg committed Dec 12, 2024
1 parent 6d87fb4 commit c164e3a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion corehq/apps/ota/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from iso8601 import iso8601
from looseversion import LooseVersion
from memoized import memoized
from tastypie.http import HttpTooManyRequests
from tastypie.http import HttpForbidden, HttpTooManyRequests

from casexml.apps.case.cleanup import claim_case, get_first_claims
from casexml.apps.case.fixtures import CaseDBFixture
Expand Down Expand Up @@ -70,9 +70,11 @@
from corehq.util.quickcache import quickcache

from .case_restore import get_case_restore_response
from .const import DEVICES_PER_USER
from .models import DeviceLogRequest, MobileRecoveryMeasure, SerialIdBucket
from .rate_limiter import rate_limit_restore
from .utils import (
can_login_on_device,
demo_user_restore_response,
get_restore_user,
handle_401_response,
Expand All @@ -97,6 +99,11 @@ def restore(request, domain, app_id=None):
if rate_limit_restore(domain):
return HttpTooManyRequests()

if not can_login_on_device(request.couch_user._id, request.GET.get('device_id')):
return HttpForbidden(
_("Your user has exceeded the daily device limit of {limit}.").format(limit=DEVICES_PER_USER)
)

response, timing_context = get_restore_response(
domain, request.couch_user, app_id, **get_restore_params(request, domain))
return response
Expand Down

0 comments on commit c164e3a

Please sign in to comment.