Skip to content

Commit

Permalink
chore: improve access field for comments for public boards (#1956)
Browse files Browse the repository at this point in the history
Co-authored-by: Bavisetti Narayan <72156168+NarayanBavisetti@users.noreply.github.com>
  • Loading branch information
pablohashescobar and NarayanBavisetti committed Aug 29, 2023
1 parent c65bbf8 commit 8581226
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion apiserver/plane/api/serializers/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ class IssueCommentSerializer(BaseSerializer):
project_detail = ProjectLiteSerializer(read_only=True, source="project")
workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace")
comment_reactions = CommentReactionLiteSerializer(read_only=True, many=True)

is_member = serializers.BooleanField(read_only=True)

class Meta:
model = IssueComment
Expand Down
37 changes: 25 additions & 12 deletions apiserver/plane/api/views/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
from plane.bgtasks.issue_activites_task import issue_activity
from plane.utils.grouper import group_results
from plane.utils.issue_filters import issue_filters
from plane.bgtasks.export_task import issue_export_task


class IssueViewSet(BaseViewSet):
Expand Down Expand Up @@ -588,6 +589,15 @@ def get_queryset(self):
.select_related("project")
.select_related("workspace")
.select_related("issue")
.annotate(
is_member=Exists(
ProjectMember.objects.filter(
workspace__slug=self.kwargs.get("slug"),
project_id=self.kwargs.get("project_id"),
member_id=self.request.user.id,
)
)
)
.distinct()
)

Expand Down Expand Up @@ -769,7 +779,9 @@ def get(self, request, slug, project_id, issue_id):
.order_by("state_group")
)

result = {item["state_group"]: item["state_count"] for item in state_distribution}
result = {
item["state_group"]: item["state_count"] for item in state_distribution
}

serializer = IssueLiteSerializer(
sub_issues,
Expand Down Expand Up @@ -1482,6 +1494,15 @@ def get_queryset(self):
.select_related("project")
.select_related("workspace")
.select_related("issue")
.annotate(
is_member=Exists(
ProjectMember.objects.filter(
workspace__slug=self.kwargs.get("slug"),
project_id=self.kwargs.get("project_id"),
member_id=self.request.user.id,
)
)
)
.distinct()
)
else:
Expand All @@ -1499,21 +1520,13 @@ def create(self, request, slug, project_id, issue_id):
status=status.HTTP_400_BAD_REQUEST,
)

access = (
"INTERNAL"
if ProjectMember.objects.filter(
project_id=project_id, member=request.user
).exists()
else "EXTERNAL"
)

serializer = IssueCommentSerializer(data=request.data)
if serializer.is_valid():
serializer.save(
project_id=project_id,
issue_id=issue_id,
actor=request.user,
access=access,
access="EXTERNAL",
)
issue_activity.delay(
type="comment.activity.created",
Expand Down Expand Up @@ -1567,7 +1580,8 @@ def partial_update(self, request, slug, project_id, issue_id, pk):
except (IssueComment.DoesNotExist, ProjectDeployBoard.DoesNotExist):
return Response(
{"error": "IssueComent Does not exists"},
status=status.HTTP_400_BAD_REQUEST,)
status=status.HTTP_400_BAD_REQUEST,
)

def destroy(self, request, slug, project_id, issue_id, pk):
try:
Expand Down Expand Up @@ -1826,4 +1840,3 @@ def destroy(self, request, slug, project_id, issue_id):
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)

1 comment on commit 8581226

@vercel
Copy link

@vercel vercel bot commented on 8581226 Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

plane-dev – ./apps/app

plane-dev.vercel.app
plane-dev-plane.vercel.app
plane-dev-git-develop-plane.vercel.app

Please sign in to comment.