mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
Merge branch 'feat/notifications' of github.com:makeplane/plane into feat/notifications
This commit is contained in:
commit
ecfc09da30
@ -534,11 +534,11 @@ class IssueLiteSerializer(BaseSerializer):
|
|||||||
|
|
||||||
|
|
||||||
class IssueSubscriberSerializer(BaseSerializer):
|
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:
|
class Meta:
|
||||||
model = IssueSubscriber
|
model = IssueSubscriber
|
||||||
fields = "__all__"
|
fields = "__all__"
|
||||||
|
read_only_fields = [
|
||||||
|
"workspace",
|
||||||
|
"project",
|
||||||
|
"issue",
|
||||||
|
]
|
||||||
|
@ -804,11 +804,29 @@ urlpatterns = [
|
|||||||
## End IssueComments
|
## End IssueComments
|
||||||
# Issue Subscribers
|
# Issue Subscribers
|
||||||
path(
|
path(
|
||||||
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/subscribers/",
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/issue-subscribers/",
|
||||||
IssueSubscriberViewSet.as_view(
|
IssueSubscriberViewSet.as_view(
|
||||||
{"get": "list", "post": "create", "delete": "destroy"}
|
{
|
||||||
|
"get": "list",
|
||||||
|
"post": "create",
|
||||||
|
}
|
||||||
),
|
),
|
||||||
name="project-issue-subscriber",
|
name="project-issue-subscribers",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/issue-subscribers/<uuid:subscriber_id>/",
|
||||||
|
IssueSubscriberViewSet.as_view({"delete": "destroy"}),
|
||||||
|
name="project-issue-subscribers",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"workspaces/<str:slug>/projects/<uuid:project_id>/issues/<uuid:issue_id>/subscribe/",
|
||||||
|
IssueSubscriberViewSet.as_view(
|
||||||
|
{
|
||||||
|
"get": "subscription_status",
|
||||||
|
"post": "subscribe",
|
||||||
|
}
|
||||||
|
),
|
||||||
|
name="project-issue-subscribers",
|
||||||
),
|
),
|
||||||
## End Issue Subscribers
|
## End Issue Subscribers
|
||||||
## IssueProperty
|
## IssueProperty
|
||||||
|
@ -856,7 +856,8 @@ class IssueSubscriberViewSet(BaseViewSet):
|
|||||||
|
|
||||||
def perform_create(self, serializer):
|
def perform_create(self, serializer):
|
||||||
serializer.save(
|
serializer.save(
|
||||||
subscriber_id=self.request.user.id, issue_id=self.kwargs.get("issue_id")
|
project_id=self.kwargs.get("project_id"),
|
||||||
|
issue_id=self.kwargs.get("issue_id"),
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
@ -870,3 +871,71 @@ class IssueSubscriberViewSet(BaseViewSet):
|
|||||||
.order_by("-created_at")
|
.order_by("-created_at")
|
||||||
.distinct()
|
.distinct()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def subscribe(self, request, slug, project_id, issue_id):
|
||||||
|
try:
|
||||||
|
if IssueSubscriber.objects.filter(
|
||||||
|
issue_id=issue_id,
|
||||||
|
subscriber=request.user,
|
||||||
|
workspace__slug=slug,
|
||||||
|
project=project_id,
|
||||||
|
).exists():
|
||||||
|
return Response(
|
||||||
|
{"message": "User already subscribed to the issue."},
|
||||||
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
|
)
|
||||||
|
|
||||||
|
subscriber = IssueSubscriber.objects.create(
|
||||||
|
issue_id=issue_id,
|
||||||
|
subscriber_id=request.user.id,
|
||||||
|
project_id=project_id,
|
||||||
|
)
|
||||||
|
serilaizer = IssueSubscriberSerializer(subscriber)
|
||||||
|
return Response(serilaizer.data, status=status.HTTP_201_CREATED)
|
||||||
|
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):
|
||||||
|
try:
|
||||||
|
issue_subscriber = IssueSubscriber.objects.filter(
|
||||||
|
issue=issue_id,
|
||||||
|
subscriber=request.user,
|
||||||
|
workspace__slug=slug,
|
||||||
|
project=project_id,
|
||||||
|
).exists()
|
||||||
|
return Response({"subscribed": issue_subscriber}, status=status.HTTP_200_OK)
|
||||||
|
except Exception as e:
|
||||||
|
capture_exception(e)
|
||||||
|
return Response(
|
||||||
|
{"error": "Something went wrong, please try again later"},
|
||||||
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
|
)
|
||||||
|
|
||||||
|
def destroy(self, request, slug, project_id, issue_id, subscriber_id):
|
||||||
|
try:
|
||||||
|
issue_subscriber = IssueSubscriber.objects.get(
|
||||||
|
project=project_id,
|
||||||
|
subscriber=subscriber_id,
|
||||||
|
workspace__slug=slug,
|
||||||
|
issue=issue_id,
|
||||||
|
)
|
||||||
|
issue_subscriber.delete()
|
||||||
|
return Response(
|
||||||
|
{"message": "Removed Subscription"},
|
||||||
|
status=status.HTTP_200_OK,
|
||||||
|
)
|
||||||
|
except IssueSubscriber.DoesNotExist:
|
||||||
|
return Response(
|
||||||
|
{"error": "User is not 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,
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user