0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-28 09:16:49 +01:00
posthog/ee/api
Rick Marron 258cd32f54
chore(api): meter rate limit on team (#12006)
## Problem

Take 2 on [this PR](https://github.com/PostHog/posthog/pull/11993#event-7470261128). The problem is that our rate limits should be based on `team_id` instead of an API key, and the last PR didn't handle views that didn't have a `team_id`.

## Changes

* Moves the rate_limit to be based on the `team_id` when possible
* Handles views that don't have a team_id
* Ensures the enabling/disabling of rate limits applies to all rate_limit classes (it used to only apply to the default classes)

and

* moves enabling the rate limit to an instance setting
* and adds a team id allow list for bypassing the rate limit
* and a simple cache which I think stops us hammering the reading of the infrequently changing settings

👉 *Stay up-to-date with [PostHog coding conventions](https://posthog.com/docs/contribute/coding-conventions) for a smoother review.*

## How did you test this code?

Added tests for the new cases:
* Rate limit works across a team - not just on an individual user.
* Rate limits work on views without a `team_id`
* Disabling the rate limits works


Co-authored-by: Paul D'Ambra <paul@posthog.com>
2022-10-18 09:01:07 +01:00
..
test chore(api): meter rate limit on team (#12006) 2022-10-18 09:01:07 +01:00
__init__.py
authentication.py
dashboard_collaborator.py
debug_ch_queries.py
ee_event_definition.py
ee_property_definition.py
explicit_team_member.py
hooks.py
integration.py
license.py
subscription.py