mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
feat: added list and unsubscribe function in issue subscriber
This commit is contained in:
parent
dcde6b2567
commit
be96ec47ba
@ -96,6 +96,7 @@ class ProjectMemberSerializer(BaseSerializer):
|
|||||||
workspace = WorkSpaceSerializer(read_only=True)
|
workspace = WorkSpaceSerializer(read_only=True)
|
||||||
project = ProjectSerializer(read_only=True)
|
project = ProjectSerializer(read_only=True)
|
||||||
member = UserLiteSerializer(read_only=True)
|
member = UserLiteSerializer(read_only=True)
|
||||||
|
is_subscribed = serializers.BooleanField(read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ProjectMember
|
model = ProjectMember
|
||||||
|
@ -824,6 +824,7 @@ urlpatterns = [
|
|||||||
{
|
{
|
||||||
"get": "subscription_status",
|
"get": "subscription_status",
|
||||||
"post": "subscribe",
|
"post": "subscribe",
|
||||||
|
"delete": "unsubscribe",
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
name="project-issue-subscribers",
|
name="project-issue-subscribers",
|
||||||
|
@ -15,6 +15,7 @@ from django.db.models import (
|
|||||||
Value,
|
Value,
|
||||||
CharField,
|
CharField,
|
||||||
When,
|
When,
|
||||||
|
Exists,
|
||||||
)
|
)
|
||||||
from django.core.serializers.json import DjangoJSONEncoder
|
from django.core.serializers.json import DjangoJSONEncoder
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
@ -43,6 +44,7 @@ from plane.api.serializers import (
|
|||||||
IssueLiteSerializer,
|
IssueLiteSerializer,
|
||||||
IssueAttachmentSerializer,
|
IssueAttachmentSerializer,
|
||||||
IssueSubscriberSerializer,
|
IssueSubscriberSerializer,
|
||||||
|
ProjectMemberSerializer,
|
||||||
)
|
)
|
||||||
from plane.api.permissions import (
|
from plane.api.permissions import (
|
||||||
ProjectEntityPermission,
|
ProjectEntityPermission,
|
||||||
@ -60,6 +62,7 @@ from plane.db.models import (
|
|||||||
IssueAttachment,
|
IssueAttachment,
|
||||||
State,
|
State,
|
||||||
IssueSubscriber,
|
IssueSubscriber,
|
||||||
|
ProjectMember,
|
||||||
)
|
)
|
||||||
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
|
||||||
@ -868,6 +871,30 @@ class IssueSubscriberViewSet(BaseViewSet):
|
|||||||
ProjectEntityPermission,
|
ProjectEntityPermission,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def list(self, request, slug, project_id, issue_id):
|
||||||
|
try:
|
||||||
|
members = ProjectMember.objects.filter(
|
||||||
|
workspace__slug=slug, project_id=project_id
|
||||||
|
)
|
||||||
|
members = members.annotate(
|
||||||
|
is_subscribed=Exists(
|
||||||
|
IssueSubscriber.objects.filter(
|
||||||
|
workspace__slug=slug,
|
||||||
|
project_id=project_id,
|
||||||
|
issue_id=issue_id,
|
||||||
|
subscriber=OuterRef("member"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
serializer = ProjectMemberSerializer(members, many=True)
|
||||||
|
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||||
|
except Exception as e:
|
||||||
|
capture_exception(e)
|
||||||
|
return Response(
|
||||||
|
{"error": e},
|
||||||
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
|
)
|
||||||
|
|
||||||
def perform_create(self, serializer):
|
def perform_create(self, serializer):
|
||||||
serializer.save(
|
serializer.save(
|
||||||
project_id=self.kwargs.get("project_id"),
|
project_id=self.kwargs.get("project_id"),
|
||||||
@ -913,6 +940,30 @@ class IssueSubscriberViewSet(BaseViewSet):
|
|||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def unsubscribe(self, request, slug, project_id, issue_id):
|
||||||
|
try:
|
||||||
|
issue_subscriber = IssueSubscriber.objects.get(
|
||||||
|
project=project_id,
|
||||||
|
subscriber=request.user,
|
||||||
|
workspace__slug=slug,
|
||||||
|
issue=issue_id,
|
||||||
|
)
|
||||||
|
issue_subscriber.delete()
|
||||||
|
return Response(
|
||||||
|
status=status.HTTP_204_NO_CONTENT,
|
||||||
|
)
|
||||||
|
except IssueSubscriber.DoesNotExist:
|
||||||
|
return Response(
|
||||||
|
{"error": "User subscribed to this issue"},
|
||||||
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
capture_exception(e)
|
||||||
|
return Response(
|
||||||
|
{"error": "Something went wrong please try again later"},
|
||||||
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
|
)
|
||||||
|
|
||||||
def subscription_status(self, request, slug, project_id, issue_id):
|
def subscription_status(self, request, slug, project_id, issue_id):
|
||||||
try:
|
try:
|
||||||
issue_subscriber = IssueSubscriber.objects.filter(
|
issue_subscriber = IssueSubscriber.objects.filter(
|
||||||
|
Loading…
Reference in New Issue
Block a user