* chore: migrations and backmigration to move attachments to file asset * chore: move attachments to file assets * chore: update migration file to include created by and updated by and size * chore: remove uninmport errors * chore: make size as float field * fix: file asset uploads * chore: asset uploads migration changes * chore: v2 assets endpoint * chore: remove unused imports * chore: issue attachments * chore: issue attachments * chore: workspace logo endpoints * chore: private bucket changes * chore: user asset endpoint * chore: add logo_url validation * chore: cover image urlk * chore: change asset max length * chore: pages endpoint * chore: store the storage_metadata only when none * chore: attachment asset apis * chore: update create private bucket * chore: make bucket private * chore: fix response of user uploads * fix: response of user uploads * fix: job to fix file asset uploads * fix: user asset endpoints * chore: avatar for user profile * chore: external apis user url endpoint * chore: upload workspace and user asset actions updated * chore: analytics endpoint * fix: analytics export * chore: avatar urls * chore: update user avatar instances * chore: avatar urls for assignees and creators * chore: bucket permission script * fix: all user avatr instances in the web app * chore: update project cover image logic * fix: issue attachment endpoint * chore: patch endpoint for issue attachment * chore: attachments * chore: change attachment storage class * chore: update issue attachment endpoints * fix: issue attachment * chore: update issue attachment implementation * chore: page asset endpoints * fix: web build errors * chore: attachments * chore: page asset urls * chore: comment and issue asset endpoints * chore: asset endpoints * chore: attachment endpoints * chore: bulk asset endpoint * chore: restore endpoint * chore: project assets endpoints * chore: asset url * chore: add delete asset endpoints * chore: fix asset upload endpoint * chore: update patch endpoints * chore: update patch endpoint * chore: update editor image handling * chore: asset restore endpoints * chore: avatar url for space assets * chore: space app assets migration * fix: space app urls * chore: space endpoints * fix: old editor images rendering logic * fix: issue archive and attachment activity * chore: asset deletes * chore: attachment delete * fix: issue attachment * fix: issue attachment get * chore: cover image url for projects * chore: remove duplicate py file * fix: url check function * chore: chore project cover asset delete * fix: migrations * chore: delete migration files * chore: update bucket * fix: build errors * chore: add asset url in intake attachment * chore: project cover fix * chore: update next.config * chore: delete old workspace logos * chore: workspace assets * chore: asset get for space * chore: update project modal * chore: remove unused imports * fix: space app editor helper * chore: update rich-text read-only editor * chore: create multiple column for entity identifiers * chore: update migrations * chore: remove entity identifier * fix: issue assets * chore: update maximum file size logic * chore: update editor max file size logic * fix: close modal after removing workspace logo * chore: update uploaded asstes' status post issue creation * chore: added file size limit to the space app * dev: add file size limit restriction on all endpoints * fix: remove old workspace logo and user avatar --------- Co-authored-by: pablohashescobar <nikhilschacko@gmail.com>
335 lines
12 KiB
Python
335 lines
12 KiB
Python
# Python imports
|
|
import json
|
|
|
|
from django.db.models import (
|
|
F,
|
|
Func,
|
|
OuterRef,
|
|
Q,
|
|
)
|
|
|
|
# Django Imports
|
|
from django.utils import timezone
|
|
from django.utils.decorators import method_decorator
|
|
from django.views.decorators.gzip import gzip_page
|
|
|
|
# Third party imports
|
|
from rest_framework import status
|
|
from rest_framework.response import Response
|
|
|
|
from plane.app.permissions import allow_permission, ROLE
|
|
from plane.app.serializers import (
|
|
ModuleIssueSerializer,
|
|
)
|
|
from plane.bgtasks.issue_activities_task import issue_activity
|
|
from plane.db.models import (
|
|
Issue,
|
|
FileAsset,
|
|
IssueLink,
|
|
ModuleIssue,
|
|
Project,
|
|
)
|
|
from plane.utils.grouper import (
|
|
issue_group_values,
|
|
issue_on_results,
|
|
issue_queryset_grouper,
|
|
)
|
|
from plane.utils.issue_filters import issue_filters
|
|
from plane.utils.order_queryset import order_issue_queryset
|
|
from plane.utils.paginator import (
|
|
GroupedOffsetPaginator,
|
|
SubGroupedOffsetPaginator,
|
|
)
|
|
|
|
# Module imports
|
|
from .. import BaseViewSet
|
|
|
|
|
|
class ModuleIssueViewSet(BaseViewSet):
|
|
serializer_class = ModuleIssueSerializer
|
|
model = ModuleIssue
|
|
webhook_event = "module_issue"
|
|
bulk = True
|
|
|
|
filterset_fields = [
|
|
"issue__labels__id",
|
|
"issue__assignees__id",
|
|
]
|
|
|
|
def get_queryset(self):
|
|
return (
|
|
Issue.issue_objects.filter(
|
|
project_id=self.kwargs.get("project_id"),
|
|
workspace__slug=self.kwargs.get("slug"),
|
|
issue_module__module_id=self.kwargs.get("module_id"),
|
|
)
|
|
.select_related("workspace", "project", "state", "parent")
|
|
.prefetch_related("assignees", "labels", "issue_module__module")
|
|
.annotate(cycle_id=F("issue_cycle__cycle_id"))
|
|
.annotate(
|
|
link_count=IssueLink.objects.filter(issue=OuterRef("id"))
|
|
.order_by()
|
|
.annotate(count=Func(F("id"), function="Count"))
|
|
.values("count")
|
|
)
|
|
.annotate(
|
|
attachment_count=FileAsset.objects.filter(
|
|
issue_id=OuterRef("id"),
|
|
entity_type=FileAsset.EntityTypeContext.ISSUE_ATTACHMENT,
|
|
)
|
|
.order_by()
|
|
.annotate(count=Func(F("id"), function="Count"))
|
|
.values("count")
|
|
)
|
|
.annotate(
|
|
sub_issues_count=Issue.issue_objects.filter(
|
|
parent=OuterRef("id")
|
|
)
|
|
.order_by()
|
|
.annotate(count=Func(F("id"), function="Count"))
|
|
.values("count")
|
|
)
|
|
).distinct()
|
|
|
|
@method_decorator(gzip_page)
|
|
@allow_permission(
|
|
[
|
|
ROLE.ADMIN,
|
|
ROLE.MEMBER,
|
|
]
|
|
)
|
|
def list(self, request, slug, project_id, module_id):
|
|
filters = issue_filters(request.query_params, "GET")
|
|
issue_queryset = self.get_queryset().filter(**filters)
|
|
order_by_param = request.GET.get("order_by", "created_at")
|
|
|
|
# Issue queryset
|
|
issue_queryset, order_by_param = order_issue_queryset(
|
|
issue_queryset=issue_queryset,
|
|
order_by_param=order_by_param,
|
|
)
|
|
|
|
# Group by
|
|
group_by = request.GET.get("group_by", False)
|
|
sub_group_by = request.GET.get("sub_group_by", False)
|
|
|
|
# issue queryset
|
|
issue_queryset = issue_queryset_grouper(
|
|
queryset=issue_queryset,
|
|
group_by=group_by,
|
|
sub_group_by=sub_group_by,
|
|
)
|
|
|
|
if group_by:
|
|
# Check group and sub group value paginate
|
|
if sub_group_by:
|
|
if group_by == sub_group_by:
|
|
return Response(
|
|
{
|
|
"error": "Group by and sub group by cannot have same parameters"
|
|
},
|
|
status=status.HTTP_400_BAD_REQUEST,
|
|
)
|
|
else:
|
|
# group and sub group pagination
|
|
return self.paginate(
|
|
request=request,
|
|
order_by=order_by_param,
|
|
queryset=issue_queryset,
|
|
on_results=lambda issues: issue_on_results(
|
|
group_by=group_by,
|
|
issues=issues,
|
|
sub_group_by=sub_group_by,
|
|
),
|
|
paginator_cls=SubGroupedOffsetPaginator,
|
|
group_by_fields=issue_group_values(
|
|
field=group_by,
|
|
slug=slug,
|
|
project_id=project_id,
|
|
filters=filters,
|
|
),
|
|
sub_group_by_fields=issue_group_values(
|
|
field=sub_group_by,
|
|
slug=slug,
|
|
project_id=project_id,
|
|
filters=filters,
|
|
),
|
|
group_by_field_name=group_by,
|
|
sub_group_by_field_name=sub_group_by,
|
|
count_filter=Q(
|
|
Q(issue_inbox__status=1)
|
|
| Q(issue_inbox__status=-1)
|
|
| Q(issue_inbox__status=2)
|
|
| Q(issue_inbox__isnull=True),
|
|
archived_at__isnull=True,
|
|
is_draft=False,
|
|
),
|
|
)
|
|
# Group Paginate
|
|
else:
|
|
# Group paginate
|
|
return self.paginate(
|
|
request=request,
|
|
order_by=order_by_param,
|
|
queryset=issue_queryset,
|
|
on_results=lambda issues: issue_on_results(
|
|
group_by=group_by,
|
|
issues=issues,
|
|
sub_group_by=sub_group_by,
|
|
),
|
|
paginator_cls=GroupedOffsetPaginator,
|
|
group_by_fields=issue_group_values(
|
|
field=group_by,
|
|
slug=slug,
|
|
project_id=project_id,
|
|
filters=filters,
|
|
),
|
|
group_by_field_name=group_by,
|
|
count_filter=Q(
|
|
Q(issue_inbox__status=1)
|
|
| Q(issue_inbox__status=-1)
|
|
| Q(issue_inbox__status=2)
|
|
| Q(issue_inbox__isnull=True),
|
|
archived_at__isnull=True,
|
|
is_draft=False,
|
|
),
|
|
)
|
|
else:
|
|
# List Paginate
|
|
return self.paginate(
|
|
order_by=order_by_param,
|
|
request=request,
|
|
queryset=issue_queryset,
|
|
on_results=lambda issues: issue_on_results(
|
|
group_by=group_by, issues=issues, sub_group_by=sub_group_by
|
|
),
|
|
)
|
|
|
|
@allow_permission([ROLE.ADMIN, ROLE.MEMBER])
|
|
# create multiple issues inside a module
|
|
def create_module_issues(self, request, slug, project_id, module_id):
|
|
issues = request.data.get("issues", [])
|
|
if not issues:
|
|
return Response(
|
|
{"error": "Issues are required"},
|
|
status=status.HTTP_400_BAD_REQUEST,
|
|
)
|
|
project = Project.objects.get(pk=project_id)
|
|
_ = ModuleIssue.objects.bulk_create(
|
|
[
|
|
ModuleIssue(
|
|
issue_id=str(issue),
|
|
module_id=module_id,
|
|
project_id=project_id,
|
|
workspace_id=project.workspace_id,
|
|
created_by=request.user,
|
|
updated_by=request.user,
|
|
)
|
|
for issue in issues
|
|
],
|
|
batch_size=10,
|
|
ignore_conflicts=True,
|
|
)
|
|
# Bulk Update the activity
|
|
_ = [
|
|
issue_activity.delay(
|
|
type="module.activity.created",
|
|
requested_data=json.dumps({"module_id": str(module_id)}),
|
|
actor_id=str(request.user.id),
|
|
issue_id=str(issue),
|
|
project_id=project_id,
|
|
current_instance=None,
|
|
epoch=int(timezone.now().timestamp()),
|
|
notification=True,
|
|
origin=request.META.get("HTTP_ORIGIN"),
|
|
)
|
|
for issue in issues
|
|
]
|
|
return Response({"message": "success"}, status=status.HTTP_201_CREATED)
|
|
|
|
@allow_permission([ROLE.ADMIN, ROLE.MEMBER])
|
|
# add multiple module inside an issue and remove multiple modules from an issue
|
|
def create_issue_modules(self, request, slug, project_id, issue_id):
|
|
modules = request.data.get("modules", [])
|
|
removed_modules = request.data.get("removed_modules", [])
|
|
project = Project.objects.get(pk=project_id)
|
|
|
|
if modules:
|
|
_ = ModuleIssue.objects.bulk_create(
|
|
[
|
|
ModuleIssue(
|
|
issue_id=issue_id,
|
|
module_id=module,
|
|
project_id=project_id,
|
|
workspace_id=project.workspace_id,
|
|
created_by=request.user,
|
|
updated_by=request.user,
|
|
)
|
|
for module in modules
|
|
],
|
|
batch_size=10,
|
|
ignore_conflicts=True,
|
|
)
|
|
# Bulk Update the activity
|
|
_ = [
|
|
issue_activity.delay(
|
|
type="module.activity.created",
|
|
requested_data=json.dumps({"module_id": module}),
|
|
actor_id=str(request.user.id),
|
|
issue_id=issue_id,
|
|
project_id=project_id,
|
|
current_instance=None,
|
|
epoch=int(timezone.now().timestamp()),
|
|
notification=True,
|
|
origin=request.META.get("HTTP_ORIGIN"),
|
|
)
|
|
for module in modules
|
|
]
|
|
|
|
for module_id in removed_modules:
|
|
module_issue = ModuleIssue.objects.filter(
|
|
workspace__slug=slug,
|
|
project_id=project_id,
|
|
module_id=module_id,
|
|
issue_id=issue_id,
|
|
)
|
|
issue_activity.delay(
|
|
type="module.activity.deleted",
|
|
requested_data=json.dumps({"module_id": str(module_id)}),
|
|
actor_id=str(request.user.id),
|
|
issue_id=str(issue_id),
|
|
project_id=str(project_id),
|
|
current_instance=json.dumps(
|
|
{"module_name": module_issue.first().module.name}
|
|
),
|
|
epoch=int(timezone.now().timestamp()),
|
|
notification=True,
|
|
origin=request.META.get("HTTP_ORIGIN"),
|
|
)
|
|
module_issue.delete()
|
|
|
|
return Response({"message": "success"}, status=status.HTTP_201_CREATED)
|
|
|
|
@allow_permission([ROLE.ADMIN, ROLE.MEMBER])
|
|
def destroy(self, request, slug, project_id, module_id, issue_id):
|
|
module_issue = ModuleIssue.objects.filter(
|
|
workspace__slug=slug,
|
|
project_id=project_id,
|
|
module_id=module_id,
|
|
issue_id=issue_id,
|
|
)
|
|
issue_activity.delay(
|
|
type="module.activity.deleted",
|
|
requested_data=json.dumps({"module_id": str(module_id)}),
|
|
actor_id=str(request.user.id),
|
|
issue_id=str(issue_id),
|
|
project_id=str(project_id),
|
|
current_instance=json.dumps(
|
|
{"module_name": module_issue.first().module.name}
|
|
),
|
|
epoch=int(timezone.now().timestamp()),
|
|
notification=True,
|
|
origin=request.META.get("HTTP_ORIGIN"),
|
|
)
|
|
module_issue.delete()
|
|
return Response(status=status.HTTP_204_NO_CONTENT)
|