hritikm15 commited on
Commit
16ed560
Β·
verified Β·
1 Parent(s): 4d90a52

Pest: require district selection + restore B2B auth gate

Browse files
Files changed (1) hide show
  1. api.py +11 -3
api.py CHANGED
@@ -875,9 +875,17 @@ def pest_risk(req: PestRiskRequest, user: _Opt[str] = Depends(_get_current_user)
875
  import datetime
876
  t0 = time.perf_counter()
877
 
878
- # State-only pest queries are allowed for the farmer-facing portal.
879
- # B2B value comes from comparative dashboards + alerts + APIs, not from
880
- # gating single state lookups.
 
 
 
 
 
 
 
 
881
 
882
  month = req.month or datetime.datetime.now().month
883
  year = req.year or datetime.datetime.now().year
 
875
  import datetime
876
  t0 = time.perf_counter()
877
 
878
+ # ── B2B aggregate guard ────────────────────────────────────────────────────
879
+ # State-only queries (no district) return state-wide aggregates β€” those are
880
+ # the high-value bulk views B2B clients pay for. Require auth. Single-block
881
+ # queries (with district) stay open for retail / consumer demo use.
882
+ if not req.district and user is None:
883
+ raise HTTPException(
884
+ status_code=401,
885
+ detail="State-only pest aggregates require B2B authentication. "
886
+ "POST /auth/token to get a token, or supply 'district' for "
887
+ "a single-block lookup.",
888
+ )
889
 
890
  month = req.month or datetime.datetime.now().month
891
  year = req.year or datetime.datetime.now().year