Skip to content

Commit

Permalink
[WEB-2615] fix: module date validation during chart distribution gene…
Browse files Browse the repository at this point in the history
…ration (#5791)

* fix: module date validation while generating the chart distribution

* chore: indentation fix

---------

Co-authored-by: NarayanBavisetti <narayan3119@gmail.com>
  • Loading branch information
gurusainath and NarayanBavisetti authored Oct 10, 2024
1 parent 1e1733f commit e9158f8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
26 changes: 14 additions & 12 deletions apiserver/plane/app/views/module/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
# Module imports
from plane.app.permissions import (
ProjectEntityPermission,
ProjectLitePermission,
allow_permission,
ROLE,
)
Expand Down Expand Up @@ -317,13 +318,12 @@ def get_queryset(self):
.order_by("-is_favorite", "-created_at")
)

allow_permission(
@allow_permission(
[
ROLE.ADMIN,
ROLE.MEMBER,
]
)

def create(self, request, slug, project_id):
project = Project.objects.get(workspace__slug=slug, pk=project_id)
serializer = ModuleWriteSerializer(
Expand Down Expand Up @@ -386,8 +386,7 @@ def create(self, request, slug, project_id):
return Response(module, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

allow_permission([ROLE.ADMIN, ROLE.MEMBER, ROLE.GUEST])

@allow_permission([ROLE.ADMIN, ROLE.MEMBER, ROLE.GUEST])
def list(self, request, slug, project_id):
queryset = self.get_queryset().filter(archived_at__isnull=True)
if self.fields:
Expand Down Expand Up @@ -435,13 +434,7 @@ def list(self, request, slug, project_id):
)
return Response(modules, status=status.HTTP_200_OK)

allow_permission(
[
ROLE.ADMIN,
ROLE.MEMBER,
]
)

@allow_permission([ROLE.ADMIN, ROLE.MEMBER])
def retrieve(self, request, slug, project_id, pk):
queryset = (
self.get_queryset()
Expand Down Expand Up @@ -672,7 +665,13 @@ def retrieve(self, request, slug, project_id, pk):
"labels": label_distribution,
"completion_chart": {},
}
if modules and modules.start_date and modules.target_date:

if (
modules
and modules.start_date
and modules.target_date
and modules.total_issues > 0
):
data["distribution"]["completion_chart"] = burndown_plot(
queryset=modules,
slug=slug,
Expand Down Expand Up @@ -838,6 +837,9 @@ def get_queryset(self):

class ModuleFavoriteViewSet(BaseViewSet):
model = UserFavorite
permission_classes = [
ProjectLitePermission,
]

def get_queryset(self):
return self.filter_queryset(
Expand Down
18 changes: 6 additions & 12 deletions apiserver/plane/app/views/view/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,7 @@ def get_queryset(self):
.distinct()
)

allow_permission(allowed_roles=[ROLE.ADMIN, ROLE.MEMBER, ROLE.GUEST])

@allow_permission(allowed_roles=[ROLE.ADMIN, ROLE.MEMBER, ROLE.GUEST])
def list(self, request, slug, project_id):
queryset = self.get_queryset()
project = Project.objects.get(id=project_id)
Expand All @@ -457,8 +456,7 @@ def list(self, request, slug, project_id):
).data
return Response(views, status=status.HTTP_200_OK)

allow_permission(allowed_roles=[ROLE.ADMIN, ROLE.MEMBER, ROLE.GUEST])

@allow_permission(allowed_roles=[ROLE.ADMIN, ROLE.MEMBER, ROLE.GUEST])
def retrieve(self, request, slug, project_id, pk):
issue_view = (
self.get_queryset().filter(pk=pk, project_id=project_id).first()
Expand Down Expand Up @@ -498,8 +496,7 @@ def retrieve(self, request, slug, project_id, pk):
status=status.HTTP_200_OK,
)

allow_permission(allowed_roles=[], creator=True, model=IssueView)

@allow_permission(allowed_roles=[], creator=True, model=IssueView)
def partial_update(self, request, slug, project_id, pk):
with transaction.atomic():
issue_view = IssueView.objects.select_for_update().get(
Expand Down Expand Up @@ -532,8 +529,7 @@ def partial_update(self, request, slug, project_id, pk):
serializer.errors, status=status.HTTP_400_BAD_REQUEST
)

allow_permission(allowed_roles=[ROLE.ADMIN], creator=True, model=IssueView)

@allow_permission(allowed_roles=[ROLE.ADMIN], creator=True, model=IssueView)
def destroy(self, request, slug, project_id, pk):
project_view = IssueView.objects.get(
pk=pk,
Expand Down Expand Up @@ -578,8 +574,7 @@ def get_queryset(self):
.select_related("view")
)

allow_permission([ROLE.ADMIN, ROLE.MEMBER])

@allow_permission([ROLE.ADMIN, ROLE.MEMBER])
def create(self, request, slug, project_id):
_ = UserFavorite.objects.create(
user=request.user,
Expand All @@ -589,8 +584,7 @@ def create(self, request, slug, project_id):
)
return Response(status=status.HTTP_204_NO_CONTENT)

allow_permission([ROLE.ADMIN, ROLE.MEMBER])

@allow_permission([ROLE.ADMIN, ROLE.MEMBER])
def destroy(self, request, slug, project_id, view_id):
view_favorite = UserFavorite.objects.get(
project=project_id,
Expand Down
2 changes: 1 addition & 1 deletion apiserver/plane/utils/analytics_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def burndown_plot(
if module_id:
# Get all dates between the two dates
date_range = [
(queryset.start_date + timedelta(days=x)).date()
(queryset.start_date + timedelta(days=x))
for x in range(
(queryset.target_date - queryset.start_date).days + 1
)
Expand Down

0 comments on commit e9158f8

Please sign in to comment.