From 3f401915d5bf0eb3a2017907de69a70cebe7bdac Mon Sep 17 00:00:00 2001 From: pablohashescobar Date: Wed, 9 Aug 2023 16:32:14 +0530 Subject: [PATCH 1/3] dev: start date and target date validation and filter for null dated issues --- apiserver/plane/api/serializers/issue.py | 5 +++++ apiserver/plane/api/views/issue.py | 1 - apiserver/plane/utils/issue_filters.py | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) 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 95e598dae35..5e442a6d32f 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/utils/issue_filters.py b/apiserver/plane/utils/issue_filters.py index a7a946e6038..1f958784878 100644 --- a/apiserver/plane/utils/issue_filters.py +++ b/apiserver/plane/utils/issue_filters.py @@ -292,8 +292,17 @@ 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 = { @@ -318,6 +327,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(): From 72cca34554557eebef77ddd358fb5074d23df790 Mon Sep 17 00:00:00 2001 From: pablohashescobar Date: Wed, 9 Aug 2023 16:42:44 +0530 Subject: [PATCH 2/3] dev: remove print logs --- apiserver/plane/utils/issue_filters.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/apiserver/plane/utils/issue_filters.py b/apiserver/plane/utils/issue_filters.py index 1f958784878..1a4c5322d79 100644 --- a/apiserver/plane/utils/issue_filters.py +++ b/apiserver/plane/utils/issue_filters.py @@ -303,8 +303,6 @@ def filter_start_target_date_issues(params, filter, method): def issue_filters(query_params, method): filter = dict() - print(query_params) - ISSUE_FILTER = { "state": filter_state, "state_group": filter_state_group, From 8c839b8bdf9a9d837ed785a1517c30bee213d485 Mon Sep 17 00:00:00 2001 From: pablohashescobar Date: Wed, 9 Aug 2023 17:01:19 +0530 Subject: [PATCH 3/3] dev: issue property dates --- .../db/migrations/0043_auto_20230809_1645.py | 38 +++++++++++++++++++ apiserver/plane/db/models/workspace.py | 1 + 2 files changed, 39 insertions(+) create mode 100644 apiserver/plane/db/migrations/0043_auto_20230809_1645.py 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, }