Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(data-warehouse): accept a pasted site url for clickup and confluence (#114830)

Tom Owers1fa42fffedd6
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clickup/clickup.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clickup/clickup.py
index 280fab2ccaa5..bab2d2c500e7 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clickup/clickup.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clickup/clickup.py
@@ -1,3 +1,4 @@
+import re
import dataclasses
from collections.abc import Iterator
from datetime import UTC, date, datetime, timedelta
@@ -59,6 +60,9 @@ TIME_IN_STATUS_BATCH_SIZE = 100
# costs a few bounded attempts instead.
REQUEST_TIMEOUT_SECONDS: tuple[float, float] = (10.0, 60.0)
+# Every app.clickup.com URL starts with the workspace ID, so people paste the whole URL into the field.
+_WORKSPACE_URL_RE = re.compile(r"^(?:https?://)?app\.clickup\.com/(\d+)(?:[/?#]|$)", re.IGNORECASE)
+
@dataclasses.dataclass(frozen=True)
class ClickUpResumeConfig:
@@ -527,6 +531,12 @@ def _list_children_rows(
yield [{**row, "_list_id": str(list_id)} for row in rows]
+def normalize_workspace_id(workspace_id: str) -> str:
+ workspace_id = workspace_id.strip()
+ match = _WORKSPACE_URL_RE.match(workspace_id)
+ return match.group(1) if match else workspace_id
+
+
def clickup_source(
api_key: str,
workspace_id: str,
@@ -538,6 +548,7 @@ def clickup_source(
db_incremental_field_last_value: Optional[Any] = None,
) -> SourceResponse:
config = CLICKUP_ENDPOINTS[endpoint]
+ workspace_id = normalize_workspace_id(workspace_id)
items: Any
if config.kind == "tasks":
@@ -618,10 +629,12 @@ def clickup_source(
def validate_credentials(api_key: str, workspace_id: str | None) -> tuple[bool, str | None]:
"""Confirm the token is genuine and (when provided) can see the configured workspace."""
+ if workspace_id:
+ workspace_id = normalize_workspace_id(workspace_id)
if workspace_id and not workspace_id.isdigit():
return False, (
"Your workspace ID is the number right after app.clickup.com/ in your ClickUp URL. "
- "Enter only that number, not the full URL."
+ "Paste that URL or enter just the number."
)
try:
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clickup/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clickup/source.py
index 02f140ecc2cc..7b3ea36d476b 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clickup/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clickup/source.py
@@ -64,7 +64,7 @@ class ClickUpSource(ResumableSource[ClickUpSourceConfig, ClickUpResumeConfig]):
You can generate a personal token (starts with `pk_`) under **Settings → Apps** in ClickUp.
-The **Workspace ID** is the numeric ID in your ClickUp URL: `https://app.clickup.com/{workspace_id}/...`.
+The **Workspace ID** is the numeric ID in your ClickUp URL: `https://app.clickup.com/{workspace_id}/...`. You can paste the full URL.
""",
iconPath="/static/services/clickup.svg",
docsUrl="https://posthog.com/docs/cdp/sources/clickup",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/clickup/tests/test_clickup.py b/products/warehouse_sources/backend/temporal/data_imports/sources/clickup/tests/test_clickup.py
index 44af3f614c2c..df1fe4179dcb 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/clickup/tests/test_clickup.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/clickup/tests/test_clickup.py
@@ -145,16 +145,28 @@ class TestValidateCredentials:
@pytest.mark.parametrize(
"workspace_id",
- ["https://app.clickup.com/9/settings/team/9/general", "app.clickup.com/9/home"],
+ ["https://app.clickup.com/9/settings/team/9/general", "app.clickup.com/9/home", " 9 "],
)
@mock.patch(CLICKUP_SESSION_PATCH)
- def test_workspace_url_is_rejected_before_calling_clickup(
+ def test_pasted_workspace_url_resolves_to_its_id(self, mock_session: mock.MagicMock, workspace_id: str) -> None:
+ mock_session.return_value.get.return_value = _response({"teams": [{"id": "9"}]})
+
+ valid, message = validate_credentials("pk_token", workspace_id=workspace_id)
+
+ assert (valid, message) == (True, None)
+
+ @pytest.mark.parametrize(
+ "workspace_id",
+ ["https://app.clickup.com/t/86abc123", "my-workspace", "https://evil.com/app.clickup.com/9"],
+ )
+ @mock.patch(CLICKUP_SESSION_PATCH)
+ def test_non_numeric_workspace_is_rejected_before_calling_clickup(
self, mock_session: mock.MagicMock, workspace_id: str
) -> None:
valid, message = validate_credentials("pk_token", workspace_id=workspace_id)
assert valid is False
- assert message is not None and "Enter only that number" in message
+ assert message is not None and "Paste that URL or enter just the number" in message
assert workspace_id not in message
mock_session.return_value.get.assert_not_called()
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/confluence/confluence.py b/products/warehouse_sources/backend/temporal/data_imports/sources/confluence/confluence.py
index 6996777499b5..fb74ddc3c055 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/confluence/confluence.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/confluence/confluence.py
@@ -22,6 +22,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.confluence
# the host ourselves from a validated subdomain (rather than accepting an
# arbitrary host) keeps the API token from being sent anywhere off-Atlassian.
_SUBDOMAIN_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9-]{0,62}$")
+_ATLASSIAN_HOST_SUFFIX = ".atlassian.net"
@dataclasses.dataclass
@@ -37,6 +38,17 @@ def _base_url(subdomain: str) -> str:
return f"{_site_origin(subdomain)}/wiki/api/v2"
+def normalize_subdomain(subdomain: str) -> str:
+ """Reduce a pasted host or URL ("https://acme.atlassian.net/wiki/home") to the bare site name."""
+ subdomain = subdomain.strip()
+ if "://" in subdomain:
+ subdomain = subdomain.split("://", 1)[1]
+ subdomain = re.split(r"[/?#]", subdomain, maxsplit=1)[0]
+ if subdomain.lower().endswith(_ATLASSIAN_HOST_SUFFIX):
+ subdomain = subdomain[: -len(_ATLASSIAN_HOST_SUFFIX)]
+ return subdomain
+
+
def is_valid_subdomain(subdomain: str) -> bool:
return bool(subdomain) and _SUBDOMAIN_RE.match(subdomain) is not None
@@ -75,6 +87,7 @@ def confluence_source(
db_incremental_field_last_value: Optional[Any] = None,
) -> SourceResponse:
config = CONFLUENCE_ENDPOINTS[endpoint]
+ subdomain = normalize_subdomain(subdomain)
rest_config: RESTAPIConfig = {
"client": {
@@ -141,6 +154,7 @@ def validate_credentials(
be valid but lack access to the probed resource. Once a specific schema is
being validated we surface the 403.
"""
+ subdomain = normalize_subdomain(subdomain)
if not is_valid_subdomain(subdomain):
return (
False,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/confluence/tests/test_confluence.py b/products/warehouse_sources/backend/temporal/data_imports/sources/confluence/tests/test_confluence.py
index 900249f7d5ea..eb8d6c53cc12 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/confluence/tests/test_confluence.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/confluence/tests/test_confluence.py
@@ -131,10 +131,40 @@ class TestValidateCredentials:
assert is_valid is False
assert message is None
- def test_invalid_subdomain_short_circuits(self) -> None:
- is_valid, message = validate_credentials("evil.com", "[email protected]", "token")
+ @parameterized.expand(
+ [
+ ("bare", "acme"),
+ ("host", "acme.atlassian.net"),
+ ("url_with_path", "https://acme.atlassian.net/wiki/spaces/HOME"),
+ ("padded_mixed_case_host", " Acme.Atlassian.net/ "),
+ ]
+ )
+ @mock.patch(CONFLUENCE_SESSION_PATCH)
+ def test_pasted_site_address_probes_the_atlassian_site(
+ self, _name: str, subdomain: str, mock_session: mock.MagicMock
+ ) -> None:
+ mock_session.return_value.get.return_value = mock.MagicMock(status_code=200)
+
+ is_valid, _ = validate_credentials(subdomain, "[email protected]", "token")
+
+ assert is_valid is True
+ probed_url = mock_session.return_value.get.call_args.args[0]
+ assert probed_url.lower().startswith("https://acme.atlassian.net/wiki/api/v2/")
+
+ @parameterized.expand(
+ [
+ ("other_host", "evil.com"),
+ ("atlassian_lookalike", "acme.atlassian.net.evil.com"),
+ ("other_host_url", "https://evil.com/acme.atlassian.net"),
+ ]
+ )
+ @mock.patch(CONFLUENCE_SESSION_PATCH)
+ def test_invalid_subdomain_short_circuits(self, _name: str, subdomain: str, mock_session: mock.MagicMock) -> None:
+ is_valid, message = validate_credentials(subdomain, "[email protected]", "token")
+
assert is_valid is False
assert message is not None and "subdomain" in message
+ mock_session.return_value.get.assert_not_called()
class TestConfluenceSource: