Skip to content

Commit

Permalink
Merge branch 'master' into sort-imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Twixes committed Nov 22, 2023
2 parents 44e90da + f1427f5 commit 1c235fa
Show file tree
Hide file tree
Showing 164 changed files with 7,523 additions and 1,780 deletions.
13 changes: 11 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {
},
ecmaVersion: 2018,
sourceType: 'module',
project: 'tsconfig.json'
project: 'tsconfig.json',
},
plugins: [
'prettier',
Expand Down Expand Up @@ -124,6 +124,11 @@ module.exports = {
importNames: ['Tooltip'],
message: 'Please use Tooltip from @posthog/lemon-ui instead.',
},
{
name: 'antd',
importNames: ['Alert'],
message: 'Please use LemonBanner from @posthog/lemon-ui instead.',
},
],
},
],
Expand Down Expand Up @@ -243,6 +248,10 @@ module.exports = {
element: 'a',
message: 'use <Link> instead',
},
{
element: 'Alert',
message: 'use <LemonBanner> instead',
},
],
},
],
Expand All @@ -266,7 +275,7 @@ module.exports = {
rules: {
// The below complains needlessly about expect(api.createInvite).toHaveBeenCalledWith(...)
'@typescript-eslint/unbound-method': 'off',
}
},
},
{
files: ['*Type.ts', '*Type.tsx'], // Kea typegen output
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ jobs:
frontend:
# Avoid running frontend tests for irrelevant changes
# NOTE: we are at risk of missing a dependency here.
- 'bin/*'
- frontend/*
- 'bin/**'
- 'frontend/**'
# Make sure we run if someone is explicitly change the workflow
- .github/workflows/ci-frontend.yml
# various JS config files
Expand Down
1 change: 1 addition & 0 deletions .stylelintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
// CSS Color Module Level 3 says currentColor, Level 4 candidate says currentcolor
// Sticking to Level 3 for now
camelCaseSvgKeywords: true,
ignoreKeywords: ['BlinkMacSystemFont'], // BlinkMacSystemFont MUST have this particular casing
},
],
// Sadly Safari only started supporting the range syntax of media queries in 2023, so let's switch to that
Expand Down
3 changes: 3 additions & 0 deletions cypress/e2e/featureFlags.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('Feature Flags', () => {
cy.get('[data-attr=save-feature-flag]').first().click()

// after save there should be a delete button
cy.get('[data-attr="more-button"]').click()
cy.get('button[data-attr="delete-feature-flag"]').should('have.text', 'Delete feature flag')

// make sure the data is there as expected after a page reload!
Expand Down Expand Up @@ -83,11 +84,13 @@ describe('Feature Flags', () => {
cy.get('[data-attr=save-feature-flag]').first().click()

// after save there should be a delete button
cy.get('[data-attr="more-button"]').click()
cy.get('button[data-attr="delete-feature-flag"]').should('have.text', 'Delete feature flag')

cy.clickNavMenu('featureflags')
cy.get('[data-attr=feature-flag-table]').should('contain', name)
cy.get(`[data-row-key=${name}]`).contains(name).click()
cy.get('[data-attr="more-button"]').click()
cy.get('[data-attr=delete-feature-flag]').click()
cy.get('.Toastify').contains('Undo').should('be.visible')
})
Expand Down
6 changes: 5 additions & 1 deletion ee/api/feature_flag_role_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ def has_permission(self, request, view):
return True
try:
feature_flag: FeatureFlag = FeatureFlag.objects.get(id=view.parents_query_dict["feature_flag_id"])
if feature_flag.created_by.uuid == request.user.uuid:
if (
hasattr(feature_flag, "created_by")
and feature_flag.created_by
and feature_flag.created_by.uuid == request.user.uuid
):
return True
except FeatureFlag.DoesNotExist:
raise exceptions.NotFound("Feature flag not found.")
Expand Down
2 changes: 1 addition & 1 deletion ee/api/test/test_billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from typing import Any, Dict, List
from unittest.mock import MagicMock, patch
from uuid import uuid4
from zoneinfo import ZoneInfo

import jwt
from zoneinfo import ZoneInfo
from dateutil.relativedelta import relativedelta
from django.utils.timezone import now
from freezegun import freeze_time
Expand Down
20 changes: 20 additions & 0 deletions ee/api/test/test_feature_flag_role_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ def test_can_always_add_role_access_if_creator_of_feature_flag(self):
self.assertEqual(flag_role.role.name, self.eng_role.name)
self.assertEqual(flag_role.feature_flag.id, self.feature_flag.id)

def test_role_access_with_deleted_creator_of_feature_flag(self):
OrganizationResourceAccess.objects.create(
resource=OrganizationResourceAccess.Resources.FEATURE_FLAGS,
access_level=OrganizationResourceAccess.AccessLevel.CAN_ONLY_VIEW,
organization=self.organization,
)

flag = FeatureFlag.objects.create(
created_by=None,
team=self.team,
key="flag_role_access_none",
name="Flag role access",
)
self.assertEqual(self.user.role_memberships.count(), 0)
flag_role_access_create_res = self.client.post(
f"/api/projects/@current/feature_flags/{flag.id}/role_access",
{"role_id": self.eng_role.id},
)
self.assertEqual(flag_role_access_create_res.status_code, status.HTTP_403_FORBIDDEN)

def test_cannot_add_role_access_if_feature_flags_access_level_too_low_and_not_creator(self):
OrganizationResourceAccess.objects.create(
resource=OrganizationResourceAccess.Resources.FEATURE_FLAGS,
Expand Down
23 changes: 17 additions & 6 deletions ee/api/test/test_organization.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime as dt
import random
from unittest.mock import ANY, patch
from unittest import mock
from unittest.mock import ANY, call, patch

from freezegun.api import freeze_time
from rest_framework import status
Expand Down Expand Up @@ -104,11 +105,21 @@ def test_delete_last_organization(self, mock_capture):
"Did not return a 404 on trying to delete a nonexistent org",
)

mock_capture.assert_called_once_with(
self.user.distinct_id,
"organization deleted",
organization_props,
groups={"instance": ANY, "organization": str(org_id)},
mock_capture.assert_has_calls(
[
call(
self.user.distinct_id,
"membership level changed",
properties={"new_level": 15, "previous_level": 1},
groups=mock.ANY,
),
call(
self.user.distinct_id,
"organization deleted",
organization_props,
groups={"instance": mock.ANY, "organization": str(org_id)},
),
]
)

def test_no_delete_organization_not_owning(self):
Expand Down
11 changes: 10 additions & 1 deletion ee/billing/billing_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import structlog
from django.utils import timezone
from rest_framework.exceptions import NotAuthenticated
from sentry_sdk import capture_exception

from ee.billing.billing_types import BillingStatus
from ee.billing.quota_limiting import set_org_usage_summary, sync_org_quota_limits
from ee.models import License
from ee.settings import BILLING_SERVICE_URL
from posthog.cloud_utils import get_cached_instance_license
from posthog.models import Organization
from posthog.models.organization import OrganizationUsageInfo
from posthog.models.organization import OrganizationMembership, OrganizationUsageInfo

logger = structlog.get_logger(__name__)

Expand Down Expand Up @@ -114,6 +115,14 @@ def update_billing_distinct_ids(self, organization: Organization) -> None:
distinct_ids = list(organization.members.values_list("distinct_id", flat=True))
self.update_billing(organization, {"distinct_ids": distinct_ids})

def update_billing_customer_email(self, organization: Organization) -> None:
try:
owner_membership = OrganizationMembership.objects.get(organization=organization, level=15)
user = owner_membership.user
self.update_billing(organization, {"org_customer_email": user.email})
except Exception as e:
capture_exception(e)

def deactivate_products(self, organization: Organization, products: str) -> None:
res = requests.get(
f"{BILLING_SERVICE_URL}/api/billing/deactivate?products={products}",
Expand Down
23 changes: 23 additions & 0 deletions ee/billing/test/test_billing_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,26 @@ def test_update_billing_distinct_ids(self, billing_patch_request_mock: MagicMock
BillingManager(license).update_billing_distinct_ids(organization)
assert billing_patch_request_mock.call_count == 1
assert len(billing_patch_request_mock.call_args[1]["json"]["distinct_ids"]) == 2

@patch(
"ee.billing.billing_manager.requests.patch",
return_value=MagicMock(status_code=200, json=MagicMock(return_value={"text": "ok"})),
)
def test_update_billing_customer_email(self, billing_patch_request_mock: MagicMock):
organization = self.organization
license = super(LicenseManager, cast(LicenseManager, License.objects)).create(
key="key123::key123",
plan="enterprise",
valid_until=timezone.datetime(2038, 1, 19, 3, 14, 7),
)
User.objects.create_and_join(
organization=organization,
email="[email protected]",
password=None,
level=OrganizationMembership.Level.OWNER,
)
organization.refresh_from_db()
assert len(organization.members.values_list("distinct_id", flat=True)) == 2 # one exists in the test base
BillingManager(license).update_billing_customer_email(organization)
assert billing_patch_request_mock.call_count == 1
assert billing_patch_request_mock.call_args[1]["json"]["org_customer_email"] == "[email protected]"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# name: ClickhouseTestExperimentSecondaryResults.test_basic_secondary_metric_results
'
/* user_id:132 celery:posthog.celery.sync_insight_caching_state */
/* user_id:131 celery:posthog.celery.sync_insight_caching_state */
SELECT team_id,
date_diff('second', max(timestamp), now()) AS age
FROM events
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.
Binary file modified frontend/__snapshots__/components-networkrequesttiming--basic.png
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.
Binary file modified frontend/__snapshots__/lemon-ui-lemon-banner--closable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/lemon-ui-lemon-banner--dismissable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/lemon-ui-lemon-banner--error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/lemon-ui-lemon-banner--info.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/lemon-ui-lemon-banner--success.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/lemon-ui-lemon-banner--warning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/lemon-ui-lemon-button--as-links.png
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.
Binary file modified frontend/__snapshots__/posthog-3000-navigation--navigation-base.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/scenes-app-batchexports--create-export.png
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.
Binary file modified frontend/__snapshots__/scenes-app-notebooks--bullet-list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/scenes-app-notebooks--empty-notebook.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/scenes-app-notebooks--headings.png
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.
Binary file modified frontend/__snapshots__/scenes-app-notebooks--notebooks-list.png
Binary file modified frontend/__snapshots__/scenes-app-notebooks--numbered-list.png
Binary file modified frontend/__snapshots__/scenes-app-notebooks--text-formats.png
Binary file modified frontend/__snapshots__/scenes-app-pipeline--pipeline-app-logs.png
Binary file modified frontend/__snapshots__/scenes-app-surveys--surveys-list.png
Binary file modified frontend/__snapshots__/scenes-other-login--sso-error.png
Binary file modified frontend/__snapshots__/scenes-other-settings--settings-project.png
Binary file modified frontend/__snapshots__/scenes-other-settings--settings-user.png
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
overflow: hidden;
height: calc(1.2em * (1 - var(--breadcrumbs-compaction-rate)));
box-sizing: content-box;
font-family: var(--font-sans) !important;

> * {
position: absolute;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@
}

.KeyboardShortcut__key {
display: inline-flex;
align-items: center;
justify-content: center;
height: 1.25rem;
min-width: 1.25rem;
padding: 0 0.1875rem;
background: var(--accent-3000);
border-radius: 0.125rem;
border-width: 1px;
background: var(--accent-3000);
color: var(--default);
display: inline-flex;
height: 1.25rem;
justify-content: center;
min-width: 1.25rem;
padding: 0 0.1875rem;
text-transform: capitalize;

.posthog-3000 & {
border-bottom-width: 2px;
border-color: var(--secondary-3000-button-border-hover);
border-radius: 0.25rem;
font-size: 0.625rem;
padding: 0.125rem 0.25rem;
text-transform: uppercase;
}

.KeyboardShortcut--muted > & {
background: none;
color: var(--muted);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Meta } from '@storybook/react'

import { KeyboardShortcut } from './KeyboardShortcut'

const meta: Meta<typeof KeyboardShortcut> = {
title: 'PostHog 3000/Keyboard Shortcut',
component: KeyboardShortcut,
tags: ['autodocs'],
}
export default meta

export const Default = {
args: {
cmd: true,
shift: true,
k: true,
},
}

export const Muted = {
args: {
muted: true,
cmd: true,
shift: true,
k: true,
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ export function KeyboardShortcut({ muted, ...keys }: KeyboardShortcutProps): JSX
) as HotKeyOrModifier[]

return (
<span className={clsx('KeyboardShortcut', muted && 'KeyboardShortcut--muted')}>
<span
className={clsx('KeyboardShortcut KeyboardShortcut__key space-x-0.5', muted && 'KeyboardShortcut--muted')}
>
{sortedKeys.map((key) => (
<span key={key} className="KeyboardShortcut__key">
{KEY_TO_SYMBOL[key] || key}
</span>
<span key={key}>{KEY_TO_SYMBOL[key] || key}</span>
))}
</span>
)
Expand Down
Loading

0 comments on commit 1c235fa

Please sign in to comment.