chore: track public board comments and reaction users for public deploy boards (#1972)

* chore: track project deploy board comment and reaction users for public deploy boards

* dev: remove tracking from project viewsets
This commit is contained in:
Nikhil 2023-08-30 12:15:08 +05:30 committed by GitHub
parent 2e5ade05fe
commit 23f5d5d172
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 2 deletions

View File

@ -20,6 +20,7 @@ from .project import (
ProjectMemberLiteSerializer, ProjectMemberLiteSerializer,
ProjectDeployBoardSerializer, ProjectDeployBoardSerializer,
ProjectMemberAdminSerializer, ProjectMemberAdminSerializer,
ProjectPublicMemberSerializer
) )
from .state import StateSerializer, StateLiteSerializer from .state import StateSerializer, StateLiteSerializer
from .view import IssueViewSerializer, IssueViewFavoriteSerializer from .view import IssueViewSerializer, IssueViewFavoriteSerializer

View File

@ -15,6 +15,7 @@ from plane.db.models import (
ProjectIdentifier, ProjectIdentifier,
ProjectFavorite, ProjectFavorite,
ProjectDeployBoard, ProjectDeployBoard,
ProjectPublicMember,
) )
@ -177,5 +178,17 @@ class ProjectDeployBoardSerializer(BaseSerializer):
fields = "__all__" fields = "__all__"
read_only_fields = [ read_only_fields = [
"workspace", "workspace",
"project" "anchor", "project", "anchor",
]
class ProjectPublicMemberSerializer(BaseSerializer):
class Meta:
model = ProjectPublicMember
fields = "__all__"
read_only_fields = [
"workspace",
"project",
"member",
] ]

View File

@ -75,6 +75,7 @@ from plane.db.models import (
CommentReaction, CommentReaction,
ProjectDeployBoard, ProjectDeployBoard,
IssueVote, IssueVote,
ProjectPublicMember,
) )
from plane.bgtasks.issue_activites_task import issue_activity from plane.bgtasks.issue_activites_task import issue_activity
from plane.utils.grouper import group_results from plane.utils.grouper import group_results
@ -1545,6 +1546,16 @@ class IssueCommentPublicViewSet(BaseViewSet):
project_id=str(project_id), project_id=str(project_id),
current_instance=None, current_instance=None,
) )
if not ProjectMember.objects.filter(
project_id=project_id,
member=request.user,
).exists():
# Add the user for workspace tracking
_ = ProjectPublicMember.objects.get_or_create(
project_id=project_id,
member=request.user,
)
return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except Exception as e: except Exception as e:
@ -1671,6 +1682,15 @@ class IssueReactionPublicViewSet(BaseViewSet):
serializer.save( serializer.save(
project_id=project_id, issue_id=issue_id, actor=request.user project_id=project_id, issue_id=issue_id, actor=request.user
) )
if not ProjectMember.objects.filter(
project_id=project_id,
member=request.user,
).exists():
# Add the user for workspace tracking
_ = ProjectPublicMember.objects.get_or_create(
project_id=project_id,
member=request.user,
)
return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except ProjectDeployBoard.DoesNotExist: except ProjectDeployBoard.DoesNotExist:
@ -1756,6 +1776,14 @@ class CommentReactionPublicViewSet(BaseViewSet):
serializer.save( serializer.save(
project_id=project_id, comment_id=comment_id, actor=request.user project_id=project_id, comment_id=comment_id, actor=request.user
) )
if not ProjectMember.objects.filter(
project_id=project_id, member=request.user
).exists():
# Add the user for workspace tracking
_ = ProjectPublicMember.objects.get_or_create(
project_id=project_id,
member=request.user,
)
return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except ProjectDeployBoard.DoesNotExist: except ProjectDeployBoard.DoesNotExist:
@ -1823,6 +1851,14 @@ class IssueVotePublicViewSet(BaseViewSet):
project_id=project_id, project_id=project_id,
issue_id=issue_id, issue_id=issue_id,
) )
# Add the user for workspace tracking
if not ProjectMember.objects.filter(
project_id=project_id, member=request.user
).exists():
_ = ProjectPublicMember.objects.get_or_create(
project_id=project_id,
member=request.user,
)
issue_vote.vote = request.data.get("vote", 1) issue_vote.vote = request.data.get("vote", 1)
issue_vote.save() issue_vote.save()
serializer = IssueVoteSerializer(issue_vote) serializer = IssueVoteSerializer(issue_vote)
@ -2022,3 +2058,4 @@ class ProjectIssuesPublicEndpoint(BaseAPIView):
{"error": "Something went wrong please try again later"}, {"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST, status=status.HTTP_400_BAD_REQUEST,
) )

View File

@ -19,6 +19,7 @@ from .project import (
ProjectIdentifier, ProjectIdentifier,
ProjectFavorite, ProjectFavorite,
ProjectDeployBoard, ProjectDeployBoard,
ProjectPublicMember,
) )
from .issue import ( from .issue import (

View File

@ -254,3 +254,18 @@ class ProjectDeployBoard(ProjectBaseModel):
def __str__(self): def __str__(self):
"""Return project and anchor""" """Return project and anchor"""
return f"{self.anchor} <{self.project.name}>" return f"{self.anchor} <{self.project.name}>"
class ProjectPublicMember(ProjectBaseModel):
member = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name="public_project_members",
)
class Meta:
unique_together = ["project", "member"]
verbose_name = "Project Public Member"
verbose_name_plural = "Project Public Members"
db_table = "project_public_members"
ordering = ("-created_at",)