feat: flag for onboarding tour completion (#1499)

* feat: flag for onboarding tour completion

* dev: boolean field

* dev: user tour completed endpoint

* dev: onboarding step json
This commit is contained in:
pablohashescobar 2023-07-12 22:10:07 +05:30 committed by GitHub
parent a1b09fcbc6
commit 275942a246
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 8 deletions

View File

@ -22,6 +22,7 @@ from plane.api.views import (
# User # User
UserEndpoint, UserEndpoint,
UpdateUserOnBoardedEndpoint, UpdateUserOnBoardedEndpoint,
UpdateUserTourCompletedEndpoint,
UserActivityEndpoint, UserActivityEndpoint,
## End User ## End User
# Workspaces # Workspaces
@ -202,7 +203,12 @@ urlpatterns = [
path( path(
"users/me/onboard/", "users/me/onboard/",
UpdateUserOnBoardedEndpoint.as_view(), UpdateUserOnBoardedEndpoint.as_view(),
name="change-password", name="user-onboard",
),
path(
"users/me/tour-completed/",
UpdateUserTourCompletedEndpoint.as_view(),
name="user-tour",
), ),
path("users/activities/", UserActivityEndpoint.as_view(), name="user-activities"), path("users/activities/", UserActivityEndpoint.as_view(), name="user-activities"),
# user workspaces # user workspaces

View File

@ -16,6 +16,7 @@ from .project import (
from .people import ( from .people import (
UserEndpoint, UserEndpoint,
UpdateUserOnBoardedEndpoint, UpdateUserOnBoardedEndpoint,
UpdateUserTourCompletedEndpoint,
UserActivityEndpoint, UserActivityEndpoint,
) )

View File

@ -37,7 +37,9 @@ class UserEndpoint(BaseViewSet):
workspace_invites = WorkspaceMemberInvite.objects.filter( workspace_invites = WorkspaceMemberInvite.objects.filter(
email=request.user.email email=request.user.email
).count() ).count()
assigned_issues = Issue.issue_objects.filter(assignees__in=[request.user]).count() assigned_issues = Issue.issue_objects.filter(
assignees__in=[request.user]
).count()
serialized_data = UserSerializer(request.user).data serialized_data = UserSerializer(request.user).data
serialized_data["workspace"] = { serialized_data["workspace"] = {
@ -47,7 +49,9 @@ class UserEndpoint(BaseViewSet):
"fallback_workspace_slug": workspace.slug, "fallback_workspace_slug": workspace.slug,
"invites": workspace_invites, "invites": workspace_invites,
} }
serialized_data.setdefault("issues", {})["assigned_issues"] = assigned_issues serialized_data.setdefault("issues", {})[
"assigned_issues"
] = assigned_issues
return Response( return Response(
serialized_data, serialized_data,
@ -59,11 +63,15 @@ class UserEndpoint(BaseViewSet):
workspace_invites = WorkspaceMemberInvite.objects.filter( workspace_invites = WorkspaceMemberInvite.objects.filter(
email=request.user.email email=request.user.email
).count() ).count()
assigned_issues = Issue.issue_objects.filter(assignees__in=[request.user]).count() assigned_issues = Issue.issue_objects.filter(
assignees__in=[request.user]
).count()
fallback_workspace = Workspace.objects.filter( fallback_workspace = (
workspace_member__member=request.user Workspace.objects.filter(workspace_member__member=request.user)
).order_by("created_at").first() .order_by("created_at")
.first()
)
serialized_data = UserSerializer(request.user).data serialized_data = UserSerializer(request.user).data
@ -78,7 +86,9 @@ class UserEndpoint(BaseViewSet):
else None, else None,
"invites": workspace_invites, "invites": workspace_invites,
} }
serialized_data.setdefault("issues", {})["assigned_issues"] = assigned_issues serialized_data.setdefault("issues", {})[
"assigned_issues"
] = assigned_issues
return Response( return Response(
serialized_data, serialized_data,
@ -109,6 +119,23 @@ class UpdateUserOnBoardedEndpoint(BaseAPIView):
) )
class UpdateUserTourCompletedEndpoint(BaseAPIView):
def patch(self, request):
try:
user = User.objects.get(pk=request.user.id)
user.is_tour_completed = request.data.get("is_tour_completed", False)
user.save()
return Response(
{"message": "Updated successfully"}, status=status.HTTP_200_OK
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class UserActivityEndpoint(BaseAPIView, BasePaginator): class UserActivityEndpoint(BaseAPIView, BasePaginator):
def get(self, request): def get(self, request):
try: try:

View File

@ -18,6 +18,13 @@ from sentry_sdk import capture_exception
from slack_sdk import WebClient from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError from slack_sdk.errors import SlackApiError
def get_default_onboarding():
return {
"profile_complete": False,
"workspace_create": False,
"workspace_invite": False,
"workspace_join": False,
}
class User(AbstractBaseUser, PermissionsMixin): class User(AbstractBaseUser, PermissionsMixin):
id = models.UUIDField( id = models.UUIDField(
@ -73,6 +80,8 @@ class User(AbstractBaseUser, PermissionsMixin):
role = models.CharField(max_length=300, null=True, blank=True) role = models.CharField(max_length=300, null=True, blank=True)
is_bot = models.BooleanField(default=False) is_bot = models.BooleanField(default=False)
theme = models.JSONField(default=dict) theme = models.JSONField(default=dict)
is_tour_completed = models.BooleanField(default=False)
onboarding_step = models.JSONField(default=get_default_onboarding)
USERNAME_FIELD = "email" USERNAME_FIELD = "email"