From 0a1483c4820786809f19f695fad21b47a421cf3d Mon Sep 17 00:00:00 2001 From: Nikhil <118773738+pablohashescobar@users.noreply.github.com> Date: Fri, 11 Aug 2023 12:45:51 +0530 Subject: [PATCH] chore: issue list date filters and properties (#1820) * dev: start date and target date validation and filter for null dated issues * dev: remove print logs * dev: issue property dates --- apiserver/plane/api/serializers/issue.py | 5 +++ apiserver/plane/api/views/issue.py | 1 - .../db/migrations/0043_auto_20230809_1645.py | 38 +++++++++++++++++++ apiserver/plane/db/models/workspace.py | 1 + apiserver/plane/utils/issue_filters.py | 10 ++++- 5 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 apiserver/plane/db/migrations/0043_auto_20230809_1645.py diff --git a/apiserver/plane/api/serializers/issue.py b/apiserver/plane/api/serializers/issue.py index 770880ef035..b2fcb0a8565 100644 --- a/apiserver/plane/api/serializers/issue.py +++ b/apiserver/plane/api/serializers/issue.py @@ -111,6 +111,11 @@ class Meta: "updated_at", ] + def validate(self, data): + if data.get("start_date", None) is not None and data.get("target_date", None) is not None and data.get("start_date", None) > data.get("target_date", None): + raise serializers.ValidationError("Start date cannot exceed target date") + return data + def create(self, validated_data): blockers = validated_data.pop("blockers_list", None) assignees = validated_data.pop("assignees_list", None) diff --git a/apiserver/plane/api/views/issue.py b/apiserver/plane/api/views/issue.py index 32d80ecf741..077ff402399 100644 --- a/apiserver/plane/api/views/issue.py +++ b/apiserver/plane/api/views/issue.py @@ -169,7 +169,6 @@ def get_queryset(self): def list(self, request, slug, project_id): try: filters = issue_filters(request.query_params, "GET") - print(filters) # Custom ordering for priority and state priority_order = ["urgent", "high", "medium", "low", None] diff --git a/apiserver/plane/db/migrations/0043_auto_20230809_1645.py b/apiserver/plane/db/migrations/0043_auto_20230809_1645.py new file mode 100644 index 00000000000..3dbbc44a2ca --- /dev/null +++ b/apiserver/plane/db/migrations/0043_auto_20230809_1645.py @@ -0,0 +1,38 @@ +# Generated by Django 4.2.3 on 2023-08-09 11:15 + +from django.db import migrations + + +def update_user_issue_properties(apps, schema_editor): + IssuePropertyModel = apps.get_model("db", "IssueProperty") + updated_issue_properties = [] + for obj in IssuePropertyModel.objects.all(): + obj.properties["start_date"] = True + updated_issue_properties.append(obj) + IssuePropertyModel.objects.bulk_update( + updated_issue_properties, ["properties"], batch_size=100 + ) + + +def workspace_member_properties(apps, schema_editor): + WorkspaceMemberModel = apps.get_model("db", "WorkspaceMember") + updated_workspace_members = [] + for obj in WorkspaceMemberModel.objects.all(): + obj.view_props["properties"]["start_date"] = True + obj.default_props["properties"]["start_date"] = True + updated_workspace_members.append(obj) + + WorkspaceMemberModel.objects.bulk_update( + updated_workspace_members, ["view_props", "default_props"], batch_size=100 + ) + + +class Migration(migrations.Migration): + dependencies = [ + ("db", "0042_alter_analyticview_created_by_and_more"), + ] + + operations = [ + migrations.RunPython(update_user_issue_properties), + migrations.RunPython(workspace_member_properties), + ] diff --git a/apiserver/plane/db/models/workspace.py b/apiserver/plane/db/models/workspace.py index 09db4200249..48d8c9f2d03 100644 --- a/apiserver/plane/db/models/workspace.py +++ b/apiserver/plane/db/models/workspace.py @@ -33,6 +33,7 @@ def get_default_props(): "estimate": True, "created_on": True, "updated_on": True, + "start_date": True, }, "showEmptyGroups": True, } diff --git a/apiserver/plane/utils/issue_filters.py b/apiserver/plane/utils/issue_filters.py index a7a946e6038..1a4c5322d79 100644 --- a/apiserver/plane/utils/issue_filters.py +++ b/apiserver/plane/utils/issue_filters.py @@ -292,9 +292,16 @@ def filter_subscribed_issues(params, filter, method): return filter +def filter_start_target_date_issues(params, filter, method): + start_target_date = params.get("start_target_date", "false") + if start_target_date == "true": + filter["target_date__isnull"] = False + filter["start_date__isnull"] = False + return filter + + def issue_filters(query_params, method): filter = dict() - print(query_params) ISSUE_FILTER = { "state": filter_state, @@ -318,6 +325,7 @@ def issue_filters(query_params, method): "inbox_status": filter_inbox_status, "sub_issue": filter_sub_issue_toggle, "subscriber": filter_subscribed_issues, + "start_target_date": filter_start_target_date_issues, } for key, value in ISSUE_FILTER.items():