From f75afc7d54e7a61daf75ca01857fa7e8411512bd Mon Sep 17 00:00:00 2001 From: Priscila Oliveira Date: Tue, 22 Oct 2024 21:24:27 +0200 Subject: [PATCH] feat(onboarding-tasks): Add endpoint to get onboarding tasks (#79531) --- .../organization_onboarding_tasks.py | 12 +++++++++++- .../test_organization_onboarding_tasks.py | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/sentry/api/endpoints/organization_onboarding_tasks.py b/src/sentry/api/endpoints/organization_onboarding_tasks.py index e33c3a78805dd2..4f8be85c047b9a 100644 --- a/src/sentry/api/endpoints/organization_onboarding_tasks.py +++ b/src/sentry/api/endpoints/organization_onboarding_tasks.py @@ -7,17 +7,19 @@ from sentry.api.api_publish_status import ApiPublishStatus from sentry.api.base import region_silo_endpoint from sentry.api.bases.organization import OrganizationEndpoint, OrganizationPermission +from sentry.api.serializers import serialize from sentry.models.organizationonboardingtask import OnboardingTaskStatus class OnboardingTaskPermission(OrganizationPermission): - scope_map = {"POST": ["org:read"]} + scope_map = {"POST": ["org:read"], "GET": ["org:read"]} @region_silo_endpoint class OrganizationOnboardingTaskEndpoint(OrganizationEndpoint): publish_status = { "POST": ApiPublishStatus.PRIVATE, + "GET": ApiPublishStatus.PRIVATE, } owner = ApiOwner.TELEMETRY_EXPERIENCE permission_classes = (OnboardingTaskPermission,) @@ -64,3 +66,11 @@ def post(self, request: Request, organization) -> Response: onboarding_tasks.try_mark_onboarding_complete(organization.id) return Response(status=204) + + def get(self, request: Request, organization) -> Response: + tasks_to_serialize = list( + onboarding_tasks.fetch_onboarding_tasks(organization, request.user) + ) + serialized_tasks = serialize(tasks_to_serialize, request.user) + + return Response({"onboardingTasks": serialized_tasks}, status=200) diff --git a/tests/sentry/api/endpoints/test_organization_onboarding_tasks.py b/tests/sentry/api/endpoints/test_organization_onboarding_tasks.py index a9d70e13b1818f..538fc1ab60de1a 100644 --- a/tests/sentry/api/endpoints/test_organization_onboarding_tasks.py +++ b/tests/sentry/api/endpoints/test_organization_onboarding_tasks.py @@ -95,3 +95,22 @@ def test_missing_status_or_completion_seen(self): assert not OrganizationOnboardingTask.objects.filter( organization=self.org, task=OnboardingTask.FIRST_PROJECT ).exists() + + def test_get_tasks(self): + # create a task + self.client.post(self.path, {"task": "create_project", "status": "complete"}) + + # get tasks + response = self.client.get(self.path) + assert response.status_code == 200, response.content + + # Verify that the response contains the 'onboardingTasks' key + assert "onboardingTasks" in response.data + tasks = response.data["onboardingTasks"] + + # Verify that the 'create_project' task is in the list of onboarding tasks + create_project_task = next( + (task for task in tasks if task["task"] == "create_project"), None + ) + assert create_project_task is not None + assert create_project_task["status"] == "complete"