Skip to content

Commit

Permalink
feat(onboarding-tasks): Add endpoint to get onboarding tasks (#79531)
Browse files Browse the repository at this point in the history
  • Loading branch information
priscilawebdev authored Oct 22, 2024
1 parent 23fed35 commit f75afc7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/sentry/api/endpoints/organization_onboarding_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,)
Expand Down Expand Up @@ -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)
19 changes: 19 additions & 0 deletions tests/sentry/api/endpoints/test_organization_onboarding_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit f75afc7

Please sign in to comment.