feat: added new issue subscriber table

This commit is contained in:
NarayanBavisetti 2023-06-21 12:04:47 +05:30
parent cf8c902473
commit b2451ac03d
7 changed files with 78 additions and 0 deletions

View File

@ -41,6 +41,7 @@ from .issue import (
IssueLinkSerializer, IssueLinkSerializer,
IssueLiteSerializer, IssueLiteSerializer,
IssueAttachmentSerializer, IssueAttachmentSerializer,
IssueSubscriberSerializer,
) )
from .module import ( from .module import (

View File

@ -19,6 +19,7 @@ from plane.db.models import (
IssueProperty, IssueProperty,
IssueBlocker, IssueBlocker,
IssueAssignee, IssueAssignee,
IssueSubscriber,
IssueLabel, IssueLabel,
Label, Label,
IssueBlocker, IssueBlocker,
@ -530,3 +531,14 @@ class IssueLiteSerializer(BaseSerializer):
"created_at", "created_at",
"updated_at", "updated_at",
] ]
class IssueSubscriberSerializer(BaseSerializer):
project = serializers.PrimaryKeyRelatedField(read_only=True)
workspace = serializers.PrimaryKeyRelatedField(read_only=True)
issue = serializers.PrimaryKeyRelatedField(read_only=True)
subscriber = serializers.PrimaryKeyRelatedField(read_only=True)
class Meta:
model = IssueSubscriber
fields = "__all__"

View File

@ -76,6 +76,7 @@ from plane.api.views import (
IssueLinkViewSet, IssueLinkViewSet,
BulkCreateIssueLabelsEndpoint, BulkCreateIssueLabelsEndpoint,
IssueAttachmentEndpoint, IssueAttachmentEndpoint,
IssueSubscriberViewSet,
## End Issues ## End Issues
# States # States
StateViewSet, StateViewSet,
@ -798,6 +799,19 @@ urlpatterns = [
name="project-issue-comment", name="project-issue-comment",
), ),
## End IssueComments ## End IssueComments
# Issue Subscribers
path(
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/subscribers/",
IssueSubscriberViewSet.as_view(
{
"get": "list",
"post": "create",
"delete": "destroy"
}
),
name="project-issue-subscriber",
),
## End Issue Subscribers
## IssueProperty ## IssueProperty
path( path(
"workspaces/<str:slug>/projects/<uuid:project_id>/issue-properties/", "workspaces/<str:slug>/projects/<uuid:project_id>/issue-properties/",

View File

@ -65,6 +65,7 @@ from .issue import (
IssueLinkViewSet, IssueLinkViewSet,
BulkCreateIssueLabelsEndpoint, BulkCreateIssueLabelsEndpoint,
IssueAttachmentEndpoint, IssueAttachmentEndpoint,
IssueSubscriberViewSet,
) )
from .auth_extended import ( from .auth_extended import (

View File

@ -42,6 +42,7 @@ from plane.api.serializers import (
IssueLinkSerializer, IssueLinkSerializer,
IssueLiteSerializer, IssueLiteSerializer,
IssueAttachmentSerializer, IssueAttachmentSerializer,
IssueSubscriberSerializer,
) )
from plane.api.permissions import ( from plane.api.permissions import (
ProjectEntityPermission, ProjectEntityPermission,
@ -58,6 +59,7 @@ from plane.db.models import (
IssueLink, IssueLink,
IssueAttachment, IssueAttachment,
State, State,
IssueSubscriber,
) )
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
@ -842,3 +844,29 @@ class IssueAttachmentEndpoint(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,
) )
class IssueSubscriberViewSet(BaseViewSet):
serializer_class = IssueSubscriberSerializer
model = IssueSubscriber
permission_classes = [
ProjectEntityPermission,
]
def perform_create(self, serializer):
serializer.save(
subscriber_id=self.request.user.id, issue_id=self.kwargs.get("issue_id")
)
def get_queryset(self):
return (
super()
.get_queryset()
.filter(workspace__slug=self.kwargs.get("slug"))
.filter(project_id=self.kwargs.get("project_id"))
.filter(issue_id=self.kwargs.get("issue_id"))
.filter(project__project_projectmember__member=self.request.user)
.order_by("-created_at")
.distinct()
)

View File

@ -33,6 +33,7 @@ from .issue import (
IssueLink, IssueLink,
IssueSequence, IssueSequence,
IssueAttachment, IssueAttachment,
IssueSubscriber,
) )
from .asset import FileAsset from .asset import FileAsset

View File

@ -399,6 +399,27 @@ class IssueSequence(ProjectBaseModel):
ordering = ("-created_at",) ordering = ("-created_at",)
class IssueSubscriber(ProjectBaseModel):
issue = models.ForeignKey(
Issue, on_delete=models.CASCADE, related_name="issue_subscribers"
)
subscriber = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name="issue_subscribers",
)
class Meta:
unique_together = ["issue", "subscriber"]
verbose_name = "Issue Subscriber"
verbose_name_plural = "Issue Subscribers"
db_table = "issue_subscribers"
ordering = ("-created_at",)
def __str__(self):
return f"{self.issue.name} {self.subscriber.email}"
# TODO: Find a better method to save the model # TODO: Find a better method to save the model
@receiver(post_save, sender=Issue) @receiver(post_save, sender=Issue)
def create_issue_sequence(sender, instance, created, **kwargs): def create_issue_sequence(sender, instance, created, **kwargs):