From 9064709d5d80864555d9d7723ee0a0db9152ac2e Mon Sep 17 00:00:00 2001 From: pablohashescobar <118773738+pablohashescobar@users.noreply.github.com> Date: Thu, 30 Mar 2023 01:25:55 +0530 Subject: [PATCH] feat: user activities endpoint (#590) --- apiserver/plane/api/urls.py | 2 ++ apiserver/plane/api/views/__init__.py | 1 + apiserver/plane/api/views/people.py | 32 ++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/apiserver/plane/api/urls.py b/apiserver/plane/api/urls.py index 96a72c017..16e292fb4 100644 --- a/apiserver/plane/api/urls.py +++ b/apiserver/plane/api/urls.py @@ -21,6 +21,7 @@ from plane.api.views import ( # User UserEndpoint, UpdateUserOnBoardedEndpoint, + UserActivityEndpoint, ## End User # Workspaces WorkSpaceViewSet, @@ -185,6 +186,7 @@ urlpatterns = [ UpdateUserOnBoardedEndpoint.as_view(), name="change-password", ), + path("users/activities/", UserActivityEndpoint.as_view(), name="user-activities"), # user workspaces path( "users/me/workspaces/", diff --git a/apiserver/plane/api/views/__init__.py b/apiserver/plane/api/views/__init__.py index 784574c4b..9338ca404 100644 --- a/apiserver/plane/api/views/__init__.py +++ b/apiserver/plane/api/views/__init__.py @@ -16,6 +16,7 @@ from .project import ( from .people import ( UserEndpoint, UpdateUserOnBoardedEndpoint, + UserActivityEndpoint, ) from .oauth import OauthEndpoint diff --git a/apiserver/plane/api/views/people.py b/apiserver/plane/api/views/people.py index de6129ac4..d08eeaa71 100644 --- a/apiserver/plane/api/views/people.py +++ b/apiserver/plane/api/views/people.py @@ -7,10 +7,18 @@ from sentry_sdk import capture_exception # Module imports from plane.api.serializers import ( UserSerializer, + IssueActivitySerializer, ) from plane.api.views.base import BaseViewSet, BaseAPIView -from plane.db.models import User, Workspace, WorkspaceMemberInvite, Issue +from plane.db.models import ( + User, + Workspace, + WorkspaceMemberInvite, + Issue, + IssueActivity, +) +from plane.utils.paginator import BasePaginator class UserEndpoint(BaseViewSet): @@ -73,3 +81,25 @@ class UpdateUserOnBoardedEndpoint(BaseAPIView): {"error": "Something went wrong please try again later"}, status=status.HTTP_400_BAD_REQUEST, ) + + +class UserActivityEndpoint(BaseAPIView, BasePaginator): + def get(self, request): + try: + queryset = IssueActivity.objects.filter(actor=request.user).select_related( + "actor" + ) + + return self.paginate( + request=request, + queryset=queryset, + on_results=lambda issue_activities: IssueActivitySerializer( + issue_activities, many=True + ).data, + ) + except Exception as e: + capture_exception(e) + return Response( + {"error": "Something went wrong please try again later"}, + status=status.HTTP_400_BAD_REQUEST, + )