diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index 37004fe62c96b..2c2a1abda8ed8 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -50,8 +50,8 @@ import { BatchExportRun, UserBasicType, NotebookNodeResource, - ExternalDataStripeResourceCreatePayload, - ExternalDataStripeResource, + ExternalDataStripeSourceCreatePayload, + ExternalDataStripeSource, } from '~/types' import { getCurrentOrganizationId, getCurrentTeamId } from './utils/logics' import { CheckboxValueType } from 'antd/lib/checkbox/Group' @@ -568,9 +568,9 @@ class ApiRequest { return this.batchExportRun(id, runId, teamId).addPathComponent('logs') } - // External Data Resource - public externalDataResources(teamId?: TeamType['id']): ApiRequest { - return this.projectsDetail(teamId).addPathComponent('external_data_resources') + // External Data Source + public externalDataSources(teamId?: TeamType['id']): ApiRequest { + return this.projectsDetail(teamId).addPathComponent('external_data_sources') } // Request finalization @@ -1578,14 +1578,14 @@ const api = { }, }, - externalDataResources: { - async list(): Promise> { - return await new ApiRequest().externalDataResources().get() + externalDataSources: { + async list(): Promise> { + return await new ApiRequest().externalDataSources().get() }, async create( - data: Partial - ): Promise { - return await new ApiRequest().externalDataResources().create({ data }) + data: Partial + ): Promise { + return await new ApiRequest().externalDataSources().create({ data }) }, }, diff --git a/frontend/src/scenes/data-warehouse/external/SourceModal.tsx b/frontend/src/scenes/data-warehouse/external/SourceModal.tsx index 8874be6b1e681..9adef58bfb4c0 100644 --- a/frontend/src/scenes/data-warehouse/external/SourceModal.tsx +++ b/frontend/src/scenes/data-warehouse/external/SourceModal.tsx @@ -9,9 +9,9 @@ import stripeLogo from 'public/stripe-logo.svg' interface SourceModalProps extends LemonModalProps {} export default function SourceModal(props: SourceModalProps): JSX.Element { - const { tableLoading, isExternalDataResourceSubmitting, selectedConnector, isManualLinkFormVisible, connectors } = + const { tableLoading, isExternalDataSourceSubmitting, selectedConnector, isManualLinkFormVisible, connectors } = useValues(sourceModalLogic) - const { selectConnector, toggleManualLinkFormVisible, resetExternalDataResource, resetTable } = + const { selectConnector, toggleManualLinkFormVisible, resetExternalDataSource, resetTable } = useActions(sourceModalLogic) const MenuButton = (config: ConnectorConfigType): JSX.Element => { @@ -29,7 +29,7 @@ export default function SourceModal(props: SourceModalProps): JSX.Element { const onClear = (): void => { selectConnector(null) toggleManualLinkFormVisible(false) - resetExternalDataResource() + resetExternalDataSource() resetTable() } @@ -40,12 +40,7 @@ export default function SourceModal(props: SourceModalProps): JSX.Element { const formToShow = (): JSX.Element => { if (selectedConnector) { return ( -
+ @@ -67,7 +62,7 @@ export default function SourceModal(props: SourceModalProps): JSX.Element { center htmlType="submit" data-attr="source-link" - loading={isExternalDataResourceSubmitting} + loading={isExternalDataSourceSubmitting} > Link diff --git a/frontend/src/scenes/data-warehouse/external/sourceModalLogic.ts b/frontend/src/scenes/data-warehouse/external/sourceModalLogic.ts index 7e7f412fb2434..a902950180adc 100644 --- a/frontend/src/scenes/data-warehouse/external/sourceModalLogic.ts +++ b/frontend/src/scenes/data-warehouse/external/sourceModalLogic.ts @@ -2,7 +2,7 @@ import { actions, connect, kea, path, reducers, selectors, listeners } from 'kea import type { sourceModalLogicType } from './sourceModalLogicType' import { forms } from 'kea-forms' -import { ExternalDataStripeResourceCreatePayload } from '~/types' +import { ExternalDataStripeSourceCreatePayload } from '~/types' import api from 'lib/api' import { lemonToast } from '@posthog/lemon-ui' import { dataWarehouseTableLogic } from '../dataWarehouseTableLogic' @@ -78,29 +78,29 @@ export const sourceModalLogic = kea([ ], }), forms(() => ({ - externalDataResource: { - defaults: { account_id: '', client_secret: '' } as ExternalDataStripeResourceCreatePayload, + externalDataSource: { + defaults: { account_id: '', client_secret: '' } as ExternalDataStripeSourceCreatePayload, errors: ({ account_id, client_secret }) => { return { account_id: !account_id && 'Please enter an account id.', client_secret: !client_secret && 'Please enter a client secret.', } }, - submit: async (payload: ExternalDataStripeResourceCreatePayload) => { - const newResource = await api.externalDataResources.create(payload) + submit: async (payload: ExternalDataStripeSourceCreatePayload) => { + const newResource = await api.externalDataSources.create(payload) return newResource }, }, })), listeners(({ actions }) => ({ - submitExternalDataResourceSuccess: () => { + submitExternalDataSourceSuccess: () => { lemonToast.success('New Data Resource Created') actions.toggleSourceModal() - actions.resetExternalDataResource() + actions.resetExternalDataSource() actions.loadSources() router.actions.push(urls.dataWarehouseSettings()) }, - submitExternalDataResourceFailure: () => { + submitExternalDataSourceFailure: () => { lemonToast.error('Error creating new Data Resource. Check that provided credentials are valid.') }, })), diff --git a/frontend/src/scenes/data-warehouse/settings/dataWarehouseSettingsLogic.ts b/frontend/src/scenes/data-warehouse/settings/dataWarehouseSettingsLogic.ts index 6432f3956dcba..5be2cb17dfbf5 100644 --- a/frontend/src/scenes/data-warehouse/settings/dataWarehouseSettingsLogic.ts +++ b/frontend/src/scenes/data-warehouse/settings/dataWarehouseSettingsLogic.ts @@ -3,7 +3,7 @@ import { afterMount, kea, path, selectors } from 'kea' import type { dataWarehouseSettingsLogicType } from './dataWarehouseSettingsLogicType' import { loaders } from 'kea-loaders' import api, { PaginatedResponse } from 'lib/api' -import { ExternalDataStripeResource, Breadcrumb } from '~/types' +import { ExternalDataStripeSource, Breadcrumb } from '~/types' import { urls } from 'scenes/urls' export interface DataWarehouseSource {} @@ -12,10 +12,10 @@ export const dataWarehouseSettingsLogic = kea([ path(['scenes', 'data-warehouse', 'settings', 'dataWarehouseSettingsLogic']), loaders({ dataWarehouseSources: [ - null as PaginatedResponse | null, + null as PaginatedResponse | null, { loadSources: async () => { - return api.externalDataResources.list() + return api.externalDataSources.list() }, }, ], diff --git a/posthog/api/__init__.py b/posthog/api/__init__.py index ee7d3449ff1d5..2756855a074f9 100644 --- a/posthog/api/__init__.py +++ b/posthog/api/__init__.py @@ -3,7 +3,7 @@ from posthog.api.routing import DefaultRouterPlusPlus from posthog.batch_exports import http as batch_exports from posthog.settings import EE_AVAILABLE -from posthog.warehouse.api import external_data_resource, saved_query, table, view_link +from posthog.warehouse.api import external_data_source, saved_query, table, view_link from ..session_recordings.session_recording_api import SessionRecordingViewSet from . import ( activity_log, @@ -212,9 +212,9 @@ def api_not_found(request): # External data resources projects_router.register( - r"external_data_resources", - external_data_resource.ExternalDataReourceViewSet, - "project_external_data_resources", + r"external_data_sources", + external_data_source.ExternalDataSourceViewSet, + "project_external_data_sources", ["team_id"], ) diff --git a/posthog/migrations/0357_externaldataresource.py b/posthog/migrations/0357_externaldatasource.py similarity index 97% rename from posthog/migrations/0357_externaldataresource.py rename to posthog/migrations/0357_externaldatasource.py index bf54c3e6f1921..41c27fbd2d451 100644 --- a/posthog/migrations/0357_externaldataresource.py +++ b/posthog/migrations/0357_externaldatasource.py @@ -14,7 +14,7 @@ class Migration(migrations.Migration): operations = [ migrations.CreateModel( - name="ExternalDataResource", + name="ExternalDataSource", fields=[ ("created_at", models.DateTimeField(auto_now_add=True)), ( diff --git a/posthog/warehouse/api/external_data_resource.py b/posthog/warehouse/api/external_data_source.py similarity index 78% rename from posthog/warehouse/api/external_data_resource.py rename to posthog/warehouse/api/external_data_source.py index 92a99b3fd3ea2..72fae355c96d5 100644 --- a/posthog/warehouse/api/external_data_resource.py +++ b/posthog/warehouse/api/external_data_source.py @@ -5,33 +5,33 @@ from rest_framework.exceptions import NotAuthenticated from rest_framework.permissions import IsAuthenticated from rest_framework import filters, serializers, viewsets -from posthog.warehouse.models import ExternalDataResource -from posthog.warehouse.external_data_resource.source import StripeSourcePayload, create_stripe_source -from posthog.warehouse.external_data_resource.connection import create_connection -from posthog.warehouse.external_data_resource.destination import create_destination +from posthog.warehouse.models import ExternalDataSource +from posthog.warehouse.external_data_source.source import StripeSourcePayload, create_stripe_source +from posthog.warehouse.external_data_source.connection import create_connection +from posthog.warehouse.external_data_source.destination import create_destination from posthog.api.routing import StructuredViewSetMixin from posthog.models import User from typing import Any -class ExternalDataReourceSerializers(serializers.ModelSerializer): +class ExternalDataSourceSerializers(serializers.ModelSerializer): account_id = serializers.CharField(write_only=True) client_secret = serializers.CharField(write_only=True) class Meta: - model = ExternalDataResource + model = ExternalDataSource fields = ["id", "source_id", "created_at", "created_by", "status", "client_secret", "account_id", "source_type"] read_only_fields = ["id", "source_id", "created_by", "created_at", "status", "source_type"] -class ExternalDataReourceViewSet(StructuredViewSetMixin, viewsets.ModelViewSet): +class ExternalDataSourceViewSet(StructuredViewSetMixin, viewsets.ModelViewSet): """ Create, Read, Update and Delete External data Sources. """ - queryset = ExternalDataResource.objects.all() - serializer_class = ExternalDataReourceSerializers + queryset = ExternalDataSource.objects.all() + serializer_class = ExternalDataSourceSerializers permission_classes = [IsAuthenticated, OrganizationMemberPermissions] filter_backends = [filters.SearchFilter] search_fields = ["source_id"] @@ -58,7 +58,7 @@ def create(self, request: Request, *args: Any, **kwargs: Any) -> Response: new_destination = create_destination(self.team_id) new_connection = create_connection(new_source.source_id, new_destination.destination_id) - ExternalDataResource.objects.create( + ExternalDataSource.objects.create( source_id=new_source.source_id, connection_id=new_connection.connection_id, team=self.request.user.current_team, diff --git a/posthog/warehouse/external_data_resource/connection.py b/posthog/warehouse/external_data_source/connection.py similarity index 100% rename from posthog/warehouse/external_data_resource/connection.py rename to posthog/warehouse/external_data_source/connection.py diff --git a/posthog/warehouse/external_data_resource/destination.py b/posthog/warehouse/external_data_source/destination.py similarity index 100% rename from posthog/warehouse/external_data_resource/destination.py rename to posthog/warehouse/external_data_source/destination.py diff --git a/posthog/warehouse/external_data_resource/source.py b/posthog/warehouse/external_data_source/source.py similarity index 100% rename from posthog/warehouse/external_data_resource/source.py rename to posthog/warehouse/external_data_source/source.py diff --git a/posthog/warehouse/models/__init__.py b/posthog/warehouse/models/__init__.py index 7de3d0769aa88..c3286f1b7f6bb 100644 --- a/posthog/warehouse/models/__init__.py +++ b/posthog/warehouse/models/__init__.py @@ -2,4 +2,4 @@ from .credential import * from .datawarehouse_saved_query import * from .view_link import * -from .external_data_resource import * +from .external_data_source import * diff --git a/posthog/warehouse/models/external_data_resource.py b/posthog/warehouse/models/external_data_source.py similarity index 92% rename from posthog/warehouse/models/external_data_resource.py rename to posthog/warehouse/models/external_data_source.py index 203e943e661c7..60171a7035cc2 100644 --- a/posthog/warehouse/models/external_data_resource.py +++ b/posthog/warehouse/models/external_data_source.py @@ -3,7 +3,7 @@ from posthog.models.team import Team -class ExternalDataResource(CreatedMetaFields, UUIDModel): +class ExternalDataSource(CreatedMetaFields, UUIDModel): class Type(models.TextChoices): STRIPE = "Stripe", "Stripe" diff --git a/posthog/warehouse/sync_resource.py b/posthog/warehouse/sync_resource.py index 34061722e0286..798ee63448b1f 100644 --- a/posthog/warehouse/sync_resource.py +++ b/posthog/warehouse/sync_resource.py @@ -1,6 +1,6 @@ -from posthog.warehouse.models.external_data_resource import ExternalDataResource +from posthog.warehouse.models.external_data_source import ExternalDataSource from posthog.warehouse.models import DataWarehouseCredential, DataWarehouseTable -from posthog.warehouse.external_data_resource.connection import retrieve_sync +from posthog.warehouse.external_data_source.connection import retrieve_sync from posthog.celery import app from django.conf import settings @@ -10,7 +10,7 @@ def sync_resources(): - resources = ExternalDataResource.objects.filter(are_tables_created=False, status="running") + resources = ExternalDataSource.objects.filter(are_tables_created=False, status="running") for resource in resources: _sync_resource.delay(resource.pk) @@ -18,12 +18,12 @@ def sync_resources(): @app.task(ignore_result=True) def _sync_resource(resource_id): - resource = ExternalDataResource.objects.get(pk=resource_id) + resource = ExternalDataSource.objects.get(pk=resource_id) job = retrieve_sync(resource.connection_id) if job["status"] == "succeeded": - resource = ExternalDataResource.objects.get(pk=resource_id) + resource = ExternalDataSource.objects.get(pk=resource_id) credential, _ = DataWarehouseCredential.objects.get_or_create( team_id=resource.team.pk, access_key=settings.AIRBYTE_BUCKET_KEY,