diff --git a/posthog/models/remote_config.py b/posthog/models/remote_config.py index e37f15d7a2997..2599857cc2939 100644 --- a/posthog/models/remote_config.py +++ b/posthog/models/remote_config.py @@ -68,10 +68,10 @@ def build_config(self): # NOTE: Let's try and keep this tidy! Follow the styling of the values already here... config = { "token": team.api_token, - "supported_compression": ["gzip", "gzip-js"], - "has_feature_flags": FeatureFlag.objects.filter(team=team, active=True, deleted=False).count() > 0, - "capture_dead_clicks": bool(team.capture_dead_clicks), - "capture_performance": ( + "supportedCompression": ["gzip", "gzip-js"], + "hasFeatureFlags": FeatureFlag.objects.filter(team=team, active=True, deleted=False).count() > 0, + "captureDeadClicks": bool(team.capture_dead_clicks), + "capturePerformance": ( { "network_timing": bool(team.capture_performance_opt_in), "web_vitals": bool(team.autocapture_web_vitals_opt_in), @@ -81,7 +81,7 @@ def build_config(self): else False ), "autocapture_opt_out": bool(team.autocapture_opt_out), - "autocapture_exceptions": ( + "autocaptureExceptions": ( { "endpoint": "/e/", } @@ -92,7 +92,7 @@ def build_config(self): } if str(team.id) not in (settings.ELEMENT_CHAIN_AS_STRING_EXCLUDED_TEAMS or []): - config["elements_chain_as_string"] = True + config["elementsChainAsString"] = True # MARK: Session Recording session_recording_config_response: bool | dict = False @@ -136,7 +136,7 @@ def build_config(self): "canvasQuality": "0.4" if record_canvas else None, } ) - config["session_recording"] = session_recording_config_response + config["sessionRecording"] = session_recording_config_response # MARK: Quota limiting if settings.EE_AVAILABLE: @@ -151,8 +151,8 @@ def build_config(self): ) if team.api_token in limited_tokens_recordings: - config["quota_limited"] = ["recordings"] - config["session_recording"] = False + config["quotaLimited"] = ["recordings"] + config["sessionRecording"] = False config["surveys"] = True if team.surveys_opt_in else False config["heatmaps"] = True if team.heatmaps_opt_in else False @@ -160,7 +160,7 @@ def build_config(self): default_identified_only = team.pk >= int(settings.DEFAULT_IDENTIFIED_ONLY_TEAM_ID_MIN) except Exception: default_identified_only = False - config["default_identified_only"] = bool(default_identified_only) + config["defaultIdentifiedOnly"] = bool(default_identified_only) # MARK: Site apps - we want to eventually inline the JS but that will come later site_apps = [] @@ -171,7 +171,7 @@ def build_config(self): except Exception: pass - config["site_apps"] = site_apps + config["siteApps"] = site_apps return config diff --git a/posthog/models/test/test_hog_function.py b/posthog/models/test/test_hog_function.py index 7cbc441e083df..04f6294f37212 100644 --- a/posthog/models/test/test_hog_function.py +++ b/posthog/models/test/test_hog_function.py @@ -278,7 +278,8 @@ def test_hog_functions_reload_on_team_saved(self): {"key": "$pageview", "operator": "regex", "value": "test"}, ] # 1 update team, 1 load hog functions, 1 update hog functions - with self.assertNumQueries(3): + # 4 unrelated due to RemoteConfig refresh + with self.assertNumQueries(3 + 4): self.team.save() hog_function_1.refresh_from_db() hog_function_2.refresh_from_db() diff --git a/posthog/models/test/test_remote_config.py b/posthog/models/test/test_remote_config.py index 67780870d948d..cfe66d48d8e6b 100644 --- a/posthog/models/test/test_remote_config.py +++ b/posthog/models/test/test_remote_config.py @@ -37,26 +37,22 @@ def test_creates_remote_config_immediately(self): "token": "phc_12345", "surveys": False, "heatmaps": False, + "siteApps": [], "analytics": {"endpoint": "/i/v0/e/"}, - "site_apps": [], - "has_feature_flags": False, - "session_recording": False, + "hasFeatureFlags": False, + "sessionRecording": False, + "captureDeadClicks": False, + "capturePerformance": {"web_vitals": False, "network_timing": True, "web_vitals_allowed_metrics": None}, "autocapture_opt_out": False, - "capture_dead_clicks": False, - "capture_performance": { - "web_vitals": False, - "network_timing": True, - "web_vitals_allowed_metrics": None, - }, - "supported_compression": ["gzip", "gzip-js"], - "autocapture_exceptions": False, - "default_identified_only": False, - "elements_chain_as_string": True, + "supportedCompression": ["gzip", "gzip-js"], + "autocaptureExceptions": False, + "defaultIdentifiedOnly": False, + "elementsChainAsString": True, } ) def test_indicates_if_feature_flags_exist(self): - assert not self.remote_config.config["has_feature_flags"] + assert not self.remote_config.config["hasFeatureFlags"] flag = FeatureFlag.objects.create( team=self.team, @@ -67,29 +63,29 @@ def test_indicates_if_feature_flags_exist(self): deleted=True, ) - assert not self.remote_config.config["has_feature_flags"] + assert not self.remote_config.config["hasFeatureFlags"] flag.active = False flag.deleted = False flag.save() self.remote_config.refresh_from_db() - assert not self.remote_config.config["has_feature_flags"] + assert not self.remote_config.config["hasFeatureFlags"] flag.active = True flag.deleted = False flag.save() self.remote_config.refresh_from_db() - assert self.remote_config.config["has_feature_flags"] + assert self.remote_config.config["hasFeatureFlags"] def test_capture_dead_clicks_toggle(self): self.team.capture_dead_clicks = True self.team.save() self.remote_config.refresh_from_db() - assert self.remote_config.config["capture_dead_clicks"] + assert self.remote_config.config["captureDeadClicks"] def test_capture_performance_toggle(self): self.team.capture_performance_opt_in = True self.team.save() self.remote_config.refresh_from_db() - assert self.remote_config.config["capture_performance"]["network_timing"] + assert self.remote_config.config["capturePerformance"]["network_timing"] def test_autocapture_opt_out_toggle(self): self.team.autocapture_opt_out = True @@ -101,14 +97,14 @@ def test_autocapture_exceptions_toggle(self): self.team.autocapture_exceptions_opt_in = True self.team.save() self.remote_config.refresh_from_db() - assert self.remote_config.config["autocapture_exceptions"] == {"endpoint": "/e/"} + assert self.remote_config.config["autocaptureExceptions"] == {"endpoint": "/e/"} def test_session_recording_sample_rate(self): self.team.session_recording_opt_in = True self.team.session_recording_sample_rate = Decimal("0.5") self.team.save() self.remote_config.refresh_from_db() - assert self.remote_config.config["session_recording"]["sampleRate"] == "0.50" + assert self.remote_config.config["sessionRecording"]["sampleRate"] == "0.50" class TestRemoteConfigSync(_RemoteConfigBase): @@ -143,7 +139,7 @@ def test_renders_js_including_config(self): assert js == snapshot( """\ (function() { - window._POSTHOG_CONFIG = {"token": "phc_12345", "surveys": false, "heatmaps": false, "analytics": {"endpoint": "/i/v0/e/"}, "site_apps": [], "has_feature_flags": false, "session_recording": false, "autocapture_opt_out": false, "capture_dead_clicks": false, "capture_performance": {"web_vitals": false, "network_timing": true, "web_vitals_allowed_metrics": null}, "supported_compression": ["gzip", "gzip-js"], "autocapture_exceptions": false, "default_identified_only": false, "elements_chain_as_string": true}; + window._POSTHOG_CONFIG = {"token": "phc_12345", "surveys": false, "heatmaps": false, "siteApps": [], "analytics": {"endpoint": "/i/v0/e/"}, "hasFeatureFlags": false, "sessionRecording": false, "captureDeadClicks": false, "capturePerformance": {"web_vitals": false, "network_timing": true, "web_vitals_allowed_metrics": null}, "autocapture_opt_out": false, "supportedCompression": ["gzip", "gzip-js"], "autocaptureExceptions": false, "defaultIdentifiedOnly": false, "elementsChainAsString": true}; window._POSTHOG_SITE_APPS = []; })();\ """ @@ -187,7 +183,7 @@ def test_renders_js_including_site_apps(self): assert js == snapshot( """\ (function() { - window._POSTHOG_CONFIG = {"token": "phc_12345", "surveys": false, "heatmaps": false, "analytics": {"endpoint": "/i/v0/e/"}, "site_apps": [], "has_feature_flags": false, "session_recording": false, "autocapture_opt_out": false, "capture_dead_clicks": false, "capture_performance": {"web_vitals": false, "network_timing": true, "web_vitals_allowed_metrics": null}, "supported_compression": ["gzip", "gzip-js"], "autocapture_exceptions": false, "default_identified_only": false, "elements_chain_as_string": true}; + window._POSTHOG_CONFIG = {"token": "phc_12345", "surveys": false, "heatmaps": false, "siteApps": [], "analytics": {"endpoint": "/i/v0/e/"}, "hasFeatureFlags": false, "sessionRecording": false, "captureDeadClicks": false, "capturePerformance": {"web_vitals": false, "network_timing": true, "web_vitals_allowed_metrics": null}, "autocapture_opt_out": false, "supportedCompression": ["gzip", "gzip-js"], "autocaptureExceptions": false, "defaultIdentifiedOnly": false, "elementsChainAsString": true}; window._POSTHOG_SITE_APPS = [{ token: 'tokentoken', load: function(posthog) { (function () { return { inject: (data) => console.log('injected!', data)}; })().inject({ config:{}, posthog:posthog }) } },{ token: 'tokentoken', load: function(posthog) { (function () { return { inject: (data) => console.log('injected 2!', data)}; })().inject({ config:{}, posthog:posthog }) } },{ token: 'tokentoken', load: function(posthog) { (function () { return { inject: (data) => console.log('injected but disabled!', data)}; })().inject({ config:{}, posthog:posthog }) } }]; })();\ """ diff --git a/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr b/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr index fb63b5473790c..6e2662eae4931 100644 --- a/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr +++ b/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr @@ -640,12 +640,12 @@ LEFT OUTER JOIN "posthog_organizationmembership" ON ("ee_accesscontrol"."organization_member_id" = "posthog_organizationmembership"."id") WHERE (("ee_accesscontrol"."organization_member_id" IS NULL AND "ee_accesscontrol"."resource" = 'project' - AND "ee_accesscontrol"."resource_id" = '435' + AND "ee_accesscontrol"."resource_id" = '440' AND "ee_accesscontrol"."role_id" IS NULL AND "ee_accesscontrol"."team_id" = 99999) OR ("posthog_organizationmembership"."user_id" = 99999 AND "ee_accesscontrol"."resource" = 'project' - AND "ee_accesscontrol"."resource_id" = '435' + AND "ee_accesscontrol"."resource_id" = '440' AND "ee_accesscontrol"."role_id" IS NULL AND "ee_accesscontrol"."team_id" = 99999) OR ("ee_accesscontrol"."organization_member_id" IS NULL @@ -1690,12 +1690,12 @@ LEFT OUTER JOIN "posthog_organizationmembership" ON ("ee_accesscontrol"."organization_member_id" = "posthog_organizationmembership"."id") WHERE (("ee_accesscontrol"."organization_member_id" IS NULL AND "ee_accesscontrol"."resource" = 'project' - AND "ee_accesscontrol"."resource_id" = '442' + AND "ee_accesscontrol"."resource_id" = '447' AND "ee_accesscontrol"."role_id" IS NULL AND "ee_accesscontrol"."team_id" = 99999) OR ("posthog_organizationmembership"."user_id" = 99999 AND "ee_accesscontrol"."resource" = 'project' - AND "ee_accesscontrol"."resource_id" = '442' + AND "ee_accesscontrol"."resource_id" = '447' AND "ee_accesscontrol"."role_id" IS NULL AND "ee_accesscontrol"."team_id" = 99999) OR ("ee_accesscontrol"."organization_member_id" IS NULL @@ -2445,12 +2445,12 @@ LEFT OUTER JOIN "posthog_organizationmembership" ON ("ee_accesscontrol"."organization_member_id" = "posthog_organizationmembership"."id") WHERE (("ee_accesscontrol"."organization_member_id" IS NULL AND "ee_accesscontrol"."resource" = 'project' - AND "ee_accesscontrol"."resource_id" = '442' + AND "ee_accesscontrol"."resource_id" = '447' AND "ee_accesscontrol"."role_id" IS NULL AND "ee_accesscontrol"."team_id" = 99999) OR ("posthog_organizationmembership"."user_id" = 99999 AND "ee_accesscontrol"."resource" = 'project' - AND "ee_accesscontrol"."resource_id" = '442' + AND "ee_accesscontrol"."resource_id" = '447' AND "ee_accesscontrol"."role_id" IS NULL AND "ee_accesscontrol"."team_id" = 99999) OR ("ee_accesscontrol"."organization_member_id" IS NULL @@ -3136,12 +3136,12 @@ LEFT OUTER JOIN "posthog_organizationmembership" ON ("ee_accesscontrol"."organization_member_id" = "posthog_organizationmembership"."id") WHERE (("ee_accesscontrol"."organization_member_id" IS NULL AND "ee_accesscontrol"."resource" = 'project' - AND "ee_accesscontrol"."resource_id" = '442' + AND "ee_accesscontrol"."resource_id" = '447' AND "ee_accesscontrol"."role_id" IS NULL AND "ee_accesscontrol"."team_id" = 99999) OR ("posthog_organizationmembership"."user_id" = 99999 AND "ee_accesscontrol"."resource" = 'project' - AND "ee_accesscontrol"."resource_id" = '442' + AND "ee_accesscontrol"."resource_id" = '447' AND "ee_accesscontrol"."role_id" IS NULL AND "ee_accesscontrol"."team_id" = 99999) OR ("ee_accesscontrol"."organization_member_id" IS NULL @@ -3890,12 +3890,12 @@ LEFT OUTER JOIN "posthog_organizationmembership" ON ("ee_accesscontrol"."organization_member_id" = "posthog_organizationmembership"."id") WHERE (("ee_accesscontrol"."organization_member_id" IS NULL AND "ee_accesscontrol"."resource" = 'project' - AND "ee_accesscontrol"."resource_id" = '442' + AND "ee_accesscontrol"."resource_id" = '447' AND "ee_accesscontrol"."role_id" IS NULL AND "ee_accesscontrol"."team_id" = 99999) OR ("posthog_organizationmembership"."user_id" = 99999 AND "ee_accesscontrol"."resource" = 'project' - AND "ee_accesscontrol"."resource_id" = '442' + AND "ee_accesscontrol"."resource_id" = '447' AND "ee_accesscontrol"."role_id" IS NULL AND "ee_accesscontrol"."team_id" = 99999) OR ("ee_accesscontrol"."organization_member_id" IS NULL @@ -4608,12 +4608,12 @@ LEFT OUTER JOIN "posthog_organizationmembership" ON ("ee_accesscontrol"."organization_member_id" = "posthog_organizationmembership"."id") WHERE (("ee_accesscontrol"."organization_member_id" IS NULL AND "ee_accesscontrol"."resource" = 'project' - AND "ee_accesscontrol"."resource_id" = '442' + AND "ee_accesscontrol"."resource_id" = '447' AND "ee_accesscontrol"."role_id" IS NULL AND "ee_accesscontrol"."team_id" = 99999) OR ("posthog_organizationmembership"."user_id" = 99999 AND "ee_accesscontrol"."resource" = 'project' - AND "ee_accesscontrol"."resource_id" = '442' + AND "ee_accesscontrol"."resource_id" = '447' AND "ee_accesscontrol"."role_id" IS NULL AND "ee_accesscontrol"."team_id" = 99999) OR ("ee_accesscontrol"."organization_member_id" IS NULL @@ -5408,12 +5408,12 @@ LEFT OUTER JOIN "posthog_organizationmembership" ON ("ee_accesscontrol"."organization_member_id" = "posthog_organizationmembership"."id") WHERE (("ee_accesscontrol"."organization_member_id" IS NULL AND "ee_accesscontrol"."resource" = 'project' - AND "ee_accesscontrol"."resource_id" = '442' + AND "ee_accesscontrol"."resource_id" = '447' AND "ee_accesscontrol"."role_id" IS NULL AND "ee_accesscontrol"."team_id" = 99999) OR ("posthog_organizationmembership"."user_id" = 99999 AND "ee_accesscontrol"."resource" = 'project' - AND "ee_accesscontrol"."resource_id" = '442' + AND "ee_accesscontrol"."resource_id" = '447' AND "ee_accesscontrol"."role_id" IS NULL AND "ee_accesscontrol"."team_id" = 99999) OR ("ee_accesscontrol"."organization_member_id" IS NULL @@ -5673,12 +5673,12 @@ LEFT OUTER JOIN "posthog_organizationmembership" ON ("ee_accesscontrol"."organization_member_id" = "posthog_organizationmembership"."id") WHERE (("ee_accesscontrol"."organization_member_id" IS NULL AND "ee_accesscontrol"."resource" = 'project' - AND "ee_accesscontrol"."resource_id" = '442' + AND "ee_accesscontrol"."resource_id" = '447' AND "ee_accesscontrol"."role_id" IS NULL AND "ee_accesscontrol"."team_id" = 99999) OR ("posthog_organizationmembership"."user_id" = 99999 AND "ee_accesscontrol"."resource" = 'project' - AND "ee_accesscontrol"."resource_id" = '442' + AND "ee_accesscontrol"."resource_id" = '447' AND "ee_accesscontrol"."role_id" IS NULL AND "ee_accesscontrol"."team_id" = 99999) OR ("ee_accesscontrol"."organization_member_id" IS NULL @@ -6107,12 +6107,12 @@ LEFT OUTER JOIN "posthog_organizationmembership" ON ("ee_accesscontrol"."organization_member_id" = "posthog_organizationmembership"."id") WHERE (("ee_accesscontrol"."organization_member_id" IS NULL AND "ee_accesscontrol"."resource" = 'project' - AND "ee_accesscontrol"."resource_id" = '442' + AND "ee_accesscontrol"."resource_id" = '447' AND "ee_accesscontrol"."role_id" IS NULL AND "ee_accesscontrol"."team_id" = 99999) OR ("posthog_organizationmembership"."user_id" = 99999 AND "ee_accesscontrol"."resource" = 'project' - AND "ee_accesscontrol"."resource_id" = '442' + AND "ee_accesscontrol"."resource_id" = '447' AND "ee_accesscontrol"."role_id" IS NULL AND "ee_accesscontrol"."team_id" = 99999) OR ("ee_accesscontrol"."organization_member_id" IS NULL @@ -6573,12 +6573,12 @@ LEFT OUTER JOIN "posthog_organizationmembership" ON ("ee_accesscontrol"."organization_member_id" = "posthog_organizationmembership"."id") WHERE (("ee_accesscontrol"."organization_member_id" IS NULL AND "ee_accesscontrol"."resource" = 'project' - AND "ee_accesscontrol"."resource_id" = '442' + AND "ee_accesscontrol"."resource_id" = '447' AND "ee_accesscontrol"."role_id" IS NULL AND "ee_accesscontrol"."team_id" = 99999) OR ("posthog_organizationmembership"."user_id" = 99999 AND "ee_accesscontrol"."resource" = 'project' - AND "ee_accesscontrol"."resource_id" = '442' + AND "ee_accesscontrol"."resource_id" = '447' AND "ee_accesscontrol"."role_id" IS NULL AND "ee_accesscontrol"."team_id" = 99999) OR ("ee_accesscontrol"."organization_member_id" IS NULL @@ -7267,12 +7267,12 @@ LEFT OUTER JOIN "posthog_organizationmembership" ON ("ee_accesscontrol"."organization_member_id" = "posthog_organizationmembership"."id") WHERE (("ee_accesscontrol"."organization_member_id" IS NULL AND "ee_accesscontrol"."resource" = 'project' - AND "ee_accesscontrol"."resource_id" = '442' + AND "ee_accesscontrol"."resource_id" = '447' AND "ee_accesscontrol"."role_id" IS NULL AND "ee_accesscontrol"."team_id" = 99999) OR ("posthog_organizationmembership"."user_id" = 99999 AND "ee_accesscontrol"."resource" = 'project' - AND "ee_accesscontrol"."resource_id" = '442' + AND "ee_accesscontrol"."resource_id" = '447' AND "ee_accesscontrol"."role_id" IS NULL AND "ee_accesscontrol"."team_id" = 99999) OR ("ee_accesscontrol"."organization_member_id" IS NULL @@ -8018,12 +8018,12 @@ LEFT OUTER JOIN "posthog_organizationmembership" ON ("ee_accesscontrol"."organization_member_id" = "posthog_organizationmembership"."id") WHERE (("ee_accesscontrol"."organization_member_id" IS NULL AND "ee_accesscontrol"."resource" = 'project' - AND "ee_accesscontrol"."resource_id" = '442' + AND "ee_accesscontrol"."resource_id" = '447' AND "ee_accesscontrol"."role_id" IS NULL AND "ee_accesscontrol"."team_id" = 99999) OR ("posthog_organizationmembership"."user_id" = 99999 AND "ee_accesscontrol"."resource" = 'project' - AND "ee_accesscontrol"."resource_id" = '442' + AND "ee_accesscontrol"."resource_id" = '447' AND "ee_accesscontrol"."role_id" IS NULL AND "ee_accesscontrol"."team_id" = 99999) OR ("ee_accesscontrol"."organization_member_id" IS NULL