Skip to content

Commit

Permalink
Merge branch 'master' into dn-chore/one-timestamp-format
Browse files Browse the repository at this point in the history
  • Loading branch information
daibhin committed Apr 22, 2024
2 parents 303cd67 + eb3f8be commit 2e6fb8b
Show file tree
Hide file tree
Showing 179 changed files with 1,624 additions and 863 deletions.
29 changes: 20 additions & 9 deletions .github/workflows/ci-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ jobs:
- name: Check formatting
run: |
ruff format --exclude posthog/hogql/grammar --check --diff .
ruff format --check --diff .
- name: Add Problem Matcher
run: echo "::add-matcher::.github/mypy-problem-matcher.json"
Expand Down Expand Up @@ -197,22 +197,33 @@ jobs:
sudo apt-get update
sudo apt-get install libxml2-dev libxmlsec1-dev libxmlsec1-openssl
- name: Install python dependencies
run: |
uv pip install --system -r requirements.txt -r requirements-dev.txt
# First running migrations from master, to simulate the real-world scenario

- uses: actions/checkout@v3
- name: Checkout master
uses: actions/checkout@v3
with:
ref: master

- name: Run migrations up to master
- name: Install python dependencies for master
run: |
# We need to ensure we have requirements for the master branch
# now also, so we can run migrations up to master.
uv pip install --system -r requirements.txt -r requirements-dev.txt
- name: Run migrations up to master
run: |
python manage.py migrate
- uses: actions/checkout@v3
# Now we can consider this PR's migrations

- name: Checkout this PR
uses: actions/checkout@v3

- name: Install python dependencies for this PR
run: |
uv pip install --system -r requirements.txt -r requirements-dev.txt
- name: Run migrations for this PR
run: |
python manage.py migrate
- name: Check migrations
run: |
Expand Down
4 changes: 2 additions & 2 deletions bin/deploy-hobby
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ curl -o /dev/null -L --header "Content-Type: application/json" -d "{
\"properties\": {\"domain\": \"${DOMAIN}\"},
\"type\": \"capture\",
\"event\": \"magic_curl_install_start\"
}" https://app.posthog.com/batch/ &> /dev/null
}" https://us.i.posthog.com/batch/ &> /dev/null

# update apt cache
echo "Grabbing latest apt caches"
Expand Down Expand Up @@ -223,7 +223,7 @@ curl -o /dev/null -L --header "Content-Type: application/json" -d "{
\"properties\": {\"domain\": \"${DOMAIN}\"},
\"type\": \"capture\",
\"event\": \"magic_curl_install_complete\"
}" https://app.posthog.com/batch/ &> /dev/null
}" https://us.i.posthog.com/batch/ &> /dev/null
echo ""
echo "To stop the stack run 'docker-compose stop'"
echo "To start the stack again run 'docker-compose start'"
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/auto-redirect.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Redirect to other subdomain if logged in', () => {

cy.visit(`/login?next=${redirect_path}`)

cy.setCookie('ph_current_instance', `"app.posthog.com"`)
cy.setCookie('ph_current_instance', `"us.posthog.com"`)
cy.setCookie('is-logged-in', '1')
cy.reload()

Expand Down
12 changes: 9 additions & 3 deletions ee/clickhouse/queries/event_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,19 @@ def __init__(
should_join_distinct_ids=False,
should_join_persons=False,
# Extra events/person table columns to fetch since parent query needs them
extra_fields: List[ColumnName] = [],
extra_event_properties: List[PropertyName] = [],
extra_person_fields: List[ColumnName] = [],
extra_fields: Optional[List[ColumnName]] = None,
extra_event_properties: Optional[List[PropertyName]] = None,
extra_person_fields: Optional[List[ColumnName]] = None,
override_aggregate_users_by_distinct_id: Optional[bool] = None,
person_on_events_mode: PersonsOnEventsMode = PersonsOnEventsMode.disabled,
**kwargs,
) -> None:
if extra_person_fields is None:
extra_person_fields = []
if extra_event_properties is None:
extra_event_properties = []
if extra_fields is None:
extra_fields = []
super().__init__(
filter=filter,
team=team,
Expand Down
4 changes: 2 additions & 2 deletions ee/clickhouse/queries/funnels/funnel_correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,9 +868,9 @@ def get_partial_event_contingency_tables(self) -> Tuple[List[EventContingencyTab

# Get the total success/failure counts from the results
results = [result for result in results_with_total if result[0] != self.TOTAL_IDENTIFIER]
_, success_total, failure_total = [
_, success_total, failure_total = next(
result for result in results_with_total if result[0] == self.TOTAL_IDENTIFIER
][0]
)

# Add a little structure, and keep it close to the query definition so it's
# obvious what's going on with result indices.
Expand Down
4 changes: 3 additions & 1 deletion ee/clickhouse/queries/test/test_cohort_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ def _make_event_sequence(
interval_days,
period_event_counts,
event="$pageview",
properties={},
properties=None,
):
if properties is None:
properties = {}
for period_index, event_count in enumerate(period_event_counts):
for i in range(event_count):
_create_event(
Expand Down
2 changes: 1 addition & 1 deletion ee/clickhouse/views/test/test_clickhouse_retention.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ def test_can_specify_breakdown_event_property_and_retrieve_people(self):
),
)

chrome_cohort = [cohort for cohort in retention["result"] if cohort["label"] == "Chrome"][0]
chrome_cohort = next(cohort for cohort in retention["result"] if cohort["label"] == "Chrome")
people_url = chrome_cohort["values"][0]["people_url"]
people_response = self.client.get(people_url)
assert people_response.status_code == 200
Expand Down
3 changes: 2 additions & 1 deletion ee/models/license.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class License(models.Model):
]

ENTERPRISE_PLAN = "enterprise"
ENTERPRISE_FEATURES = SCALE_FEATURES + [
ENTERPRISE_FEATURES = [
*SCALE_FEATURES,
AvailableFeature.ADVANCED_PERMISSIONS,
AvailableFeature.PROJECT_BASED_PERMISSIONING,
AvailableFeature.SAML,
Expand Down
4 changes: 3 additions & 1 deletion ee/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Django settings for PostHog Enterprise Edition.
"""

import os
from typing import Dict, List

Expand All @@ -15,7 +16,8 @@
}

# SSO
AUTHENTICATION_BACKENDS = AUTHENTICATION_BACKENDS + [
AUTHENTICATION_BACKENDS = [
*AUTHENTICATION_BACKENDS,
"ee.api.authentication.MultitenantSAMLAuth",
"social_core.backends.google.GoogleOAuth2",
]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion frontend/src/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% include "head.html" %}

<script>
!function (t, e) { var o, n, p, r; e.__SV || (window.posthog = e, e._i = [], e.init = function (i, s, a) { function g(t, e) { var o = e.split("."); 2 == o.length && (t = t[o[0]], e = o[1]), t[e] = function () { t.push([e].concat(Array.prototype.slice.call(arguments, 0))) } } (p = t.createElement("script")).type = "text/javascript", p.async = !0, p.src = s.api_host + "/static/array.js", (r = t.getElementsByTagName("script")[0]).parentNode.insertBefore(p, r); var u = e; for (void 0 !== a ? u = e[a] = [] : a = "posthog", u.people = u.people || [], u.toString = function (t) { var e = "posthog"; return "posthog" !== a && (e += "." + a), t || (e += " (stub)"), e }, u.people.toString = function () { return u.toString(1) + ".people (stub)" }, o = "capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags".split(" "), n = 0; n < o.length; n++)g(u, o[n]); e._i.push([i, s, a]) }, e.__SV = 1) }(document, window.posthog || []);
!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host.replace(".i.posthog.com","-assets.i.posthog.com")+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags getFeatureFlag getFeatureFlagPayload reloadFeatureFlags group updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures getActiveMatchingSurveys getSurveys onSessionId".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
posthog.init({{ js_posthog_api_key | safe}}, { api_host: {{ js_posthog_host | safe}}, persistence: 'localStorage+cookie'})
</script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const sidePanelDocsLogic = kea<sidePanelDocsLogicType>([
}

if (event.data.type === 'external-navigation') {
// This should only be triggered for app|eu.posthog.com links
// This should only be triggered for us|eu.posthog.com links
actions.handleExternalUrl(event.data.url)
return
}
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/lib/components/Cards/InsightCard/TopHeading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ export function TopHeading({ insight }: { insight: InsightModel }): JSX.Element
}
}

const defaultDateRange = query == undefined || isInsightQueryNode(query) ? 'Last 7 days' : null
const dateText = dateFilterToText(date_from, date_to, defaultDateRange)
let dateText: string | null = null
if (insightType?.name !== 'Retention') {
const defaultDateRange = query == undefined || isInsightQueryNode(query) ? 'Last 7 days' : null
dateText = dateFilterToText(date_from, date_to, defaultDateRange)
}
return (
<>
<span title={insightType?.description}>{insightType?.name}</span>
Expand Down
22 changes: 15 additions & 7 deletions frontend/src/lib/components/JSSnippet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ import { CodeSnippet, Language } from 'lib/components/CodeSnippet'
import { apiHostOrigin } from 'lib/utils/apiHost'
import { teamLogic } from 'scenes/teamLogic'

export function JSSnippet(): JSX.Element {
export function useJsSnippet(indent = 0): string {
const { currentTeam } = useValues(teamLogic)

return (
<CodeSnippet language={Language.HTML}>{`<script>
!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags getFeatureFlag getFeatureFlagPayload reloadFeatureFlags group updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures getActiveMatchingSurveys getSurveys onSessionId".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
posthog.init('${currentTeam?.api_token}',{api_host:'${apiHostOrigin()}'})
</script>`}</CodeSnippet>
)
return [
'<script>',
` !function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host.replace(".i.posthog.com","-assets.i.posthog.com")+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags getFeatureFlag getFeatureFlagPayload reloadFeatureFlags group updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures getActiveMatchingSurveys getSurveys onSessionId".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);`,
` posthog.init('${currentTeam?.api_token}',{api_host:'${apiHostOrigin()}'})`,
'</script>',
]
.map((x) => ' '.repeat(indent) + x)
.join('\n')
}

export function JSSnippet(): JSX.Element {
const snippet = useJsSnippet()

return <CodeSnippet language={Language.HTML}>{snippet}</CodeSnippet>
}
20 changes: 11 additions & 9 deletions frontend/src/lib/components/PropertyIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import {
IconWeb,
IconWindows,
} from 'lib/lemon-ui/icons'
import { Tooltip } from 'lib/lemon-ui/Tooltip'
import { HTMLAttributes, ReactNode } from 'react'
import { forwardRef, HTMLAttributes, Ref } from 'react'
import { countryCodeToFlag } from 'scenes/insights/views/WorldMap'

const osIcons = {
Expand Down Expand Up @@ -66,12 +65,13 @@ interface PropertyIconProps {
property: string
value?: string
className?: string
noTooltip?: boolean
onClick?: HTMLAttributes<HTMLDivElement>['onClick']
tooltipTitle?: (property: string, value?: string) => ReactNode // Tooltip title will default to `value`
}

export function PropertyIcon({ property, value, className, noTooltip, tooltipTitle }: PropertyIconProps): JSX.Element {
export const PropertyIcon = forwardRef(function PropertyIcon(
{ property, value, className }: PropertyIconProps,
ref: Ref<HTMLDivElement>
): JSX.Element {
if (!property || !(property in PROPERTIES_ICON_MAP)) {
return <></>
}
Expand All @@ -86,7 +86,9 @@ export function PropertyIcon({ property, value, className, noTooltip, tooltipTit
icon = countryCodeToFlag(value)
}

const content = <div className={clsx('inline-flex items-center', className)}>{icon}</div>

return noTooltip ? content : <Tooltip title={tooltipTitle?.(property, value) ?? value}>{content}</Tooltip>
}
return (
<div ref={ref} className={clsx('inline-flex items-center', className)}>
{icon}
</div>
)
})
7 changes: 5 additions & 2 deletions frontend/src/lib/utils/apiHost.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
export function apiHostOrigin(): string {
let apiHost = window.location.origin
// similar to https://github.com/PostHog/posthog-js/blob/b79315b7a4fa0caded7026bda2fec01defb0ba73/src/posthog-core.ts#L1742

if (apiHost === 'https://us.posthog.com') {
apiHost = 'https://app.posthog.com'
apiHost = 'https://us.i.posthog.com'
} else if (apiHost === 'https://eu.posthog.com') {
apiHost = 'https://eu.i.posthog.com'
}

return apiHost
}
3 changes: 2 additions & 1 deletion frontend/src/scenes/data-warehouse/new/sourceWizardLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([
}),
listeners(({ actions, values }) => ({
onBack: () => {
if (values.currentStep <= 2) {
if (values.currentStep <= 1) {
actions.selectConnector(null)
}
},
Expand Down Expand Up @@ -447,6 +447,7 @@ export const sourceWizardLogic = kea<sourceWizardLogicType>([
})
lemonToast.success('New Data Resource Created')
actions.setSourceId(id)
actions.resetSourceConnectionDetails()
actions.onNext()
} catch (e: any) {
lemonToast.error(e.data?.message ?? e.message)
Expand Down
Loading

0 comments on commit 2e6fb8b

Please sign in to comment.