Skip to content

Commit

Permalink
fix(created-by-sources): Adding created_by to sources (#27751)
Browse files Browse the repository at this point in the history
  • Loading branch information
phixMe authored Jan 22, 2025
1 parent c0f6a80 commit 7f49417
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion posthog/warehouse/api/external_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from posthog.api.routing import TeamAndOrgViewSetMixin
from posthog.api.utils import action
from posthog.cloud_utils import is_cloud
from posthog.models.user import User
from posthog.hogql.database.database import create_hogql_database
from posthog.temporal.data_imports.pipelines.bigquery import (
filter_incremental_fields as filter_bigquery_incremental_fields,
Expand Down Expand Up @@ -154,6 +155,7 @@ class ExternalDataSourceSerializers(serializers.ModelSerializer):
account_id = serializers.CharField(write_only=True)
client_secret = serializers.CharField(write_only=True)
last_run_at = serializers.SerializerMethodField(read_only=True)
created_by = serializers.SerializerMethodField(read_only=True)
status = serializers.SerializerMethodField(read_only=True)
schemas = serializers.SerializerMethodField(read_only=True)

Expand Down Expand Up @@ -191,6 +193,9 @@ def get_last_run_at(self, instance: ExternalDataSource) -> str:

return latest_completed_run.created_at if latest_completed_run else None

def get_created_by(self, instance: ExternalDataSource) -> str | None:
return instance.created_by.email if instance.created_by else None

def get_status(self, instance: ExternalDataSource) -> str:
active_schemas: list[ExternalDataSchema] = list(instance.active_schemas) # type: ignore
any_failures = any(schema.status == ExternalDataSchema.Status.ERROR for schema in active_schemas)
Expand Down Expand Up @@ -423,12 +428,12 @@ def _handle_stripe_source(self, request: Request, *args: Any, **kwargs: Any) ->
account_id = payload.get("account_id", None)
prefix = request.data.get("prefix", None)
source_type = request.data["source_type"]

# TODO: remove dummy vars
new_source_model = ExternalDataSource.objects.create(
source_id=str(uuid.uuid4()),
connection_id=str(uuid.uuid4()),
destination_id=str(uuid.uuid4()),
created_by=request.user if isinstance(request.user, User) else None,
team=self.team,
status="Running",
source_type=source_type,
Expand All @@ -451,6 +456,7 @@ def _handle_vitally_source(self, request: Request, *args: Any, **kwargs: Any) ->
source_id=str(uuid.uuid4()),
connection_id=str(uuid.uuid4()),
destination_id=str(uuid.uuid4()),
created_by=request.user if isinstance(request.user, User) else None,
team=self.team,
status="Running",
source_type=source_type,
Expand All @@ -472,6 +478,7 @@ def _handle_chargebee_source(self, request: Request, *args: Any, **kwargs: Any)
connection_id=str(uuid.uuid4()),
destination_id=str(uuid.uuid4()),
team=self.team,
created_by=request.user if isinstance(request.user, User) else None,
status="Running",
source_type=source_type,
job_inputs={"api_key": api_key, "site_name": site_name},
Expand All @@ -494,6 +501,7 @@ def _handle_zendesk_source(self, request: Request, *args: Any, **kwargs: Any) ->
connection_id=str(uuid.uuid4()),
destination_id=str(uuid.uuid4()),
team=self.team,
created_by=request.user if isinstance(request.user, User) else None,
status="Running",
source_type=source_type,
job_inputs={
Expand All @@ -518,6 +526,7 @@ def _handle_salesforce_source(self, request: Request, *args: Any, **kwargs: Any)
connection_id=str(uuid.uuid4()),
destination_id=str(uuid.uuid4()),
team=self.team,
created_by=request.user if isinstance(request.user, User) else None,
status="Running",
source_type=source_type,
job_inputs={
Expand All @@ -543,6 +552,7 @@ def _handle_hubspot_source(self, request: Request, *args: Any, **kwargs: Any) ->
connection_id=str(uuid.uuid4()),
destination_id=str(uuid.uuid4()),
team=self.team,
created_by=request.user if isinstance(request.user, User) else None,
status="Running",
source_type=source_type,
job_inputs={
Expand Down Expand Up @@ -589,6 +599,7 @@ def _handle_sql_source(self, request: Request, *args: Any, **kwargs: Any) -> tup
connection_id=str(uuid.uuid4()),
destination_id=str(uuid.uuid4()),
team=self.team,
created_by=request.user if isinstance(request.user, User) else None,
status="Running",
source_type=source_type,
job_inputs={
Expand Down Expand Up @@ -661,6 +672,7 @@ def _handle_snowflake_source(
connection_id=str(uuid.uuid4()),
destination_id=str(uuid.uuid4()),
team=self.team,
created_by=request.user if isinstance(request.user, User) else None,
status="Running",
source_type=source_type,
job_inputs={
Expand Down Expand Up @@ -717,6 +729,7 @@ def _handle_bigquery_source(
connection_id=str(uuid.uuid4()),
destination_id=str(uuid.uuid4()),
team=self.team,
created_by=request.user if isinstance(request.user, User) else None,
status="Running",
source_type=source_type,
job_inputs={
Expand Down

0 comments on commit 7f49417

Please sign in to comment.