From 8ef9df28c4ecc0183d27ad627f2588a63efbb2ab Mon Sep 17 00:00:00 2001 From: NarayanBavisetti Date: Tue, 19 Sep 2023 18:51:08 +0530 Subject: [PATCH] fix: changed name workspace view to global view --- apiserver/plane/api/serializers/__init__.py | 2 +- apiserver/plane/api/serializers/view.py | 8 ++-- apiserver/plane/api/urls.py | 36 +++++++++--------- apiserver/plane/api/views/__init__.py | 2 +- apiserver/plane/api/views/view.py | 15 ++++---- ..._alter_analyticview_created_by_and_more.py | 38 ------------------- .../db/migrations/0045_auto_20230915_0655.py | 28 +++++++++++++- apiserver/plane/db/models/__init__.py | 2 +- apiserver/plane/db/models/view.py | 10 ++--- 9 files changed, 64 insertions(+), 77 deletions(-) delete mode 100644 apiserver/plane/db/migrations/0045_alter_analyticview_created_by_and_more.py diff --git a/apiserver/plane/api/serializers/__init__.py b/apiserver/plane/api/serializers/__init__.py index b8b7c6539..dbf7ca049 100644 --- a/apiserver/plane/api/serializers/__init__.py +++ b/apiserver/plane/api/serializers/__init__.py @@ -23,7 +23,7 @@ from .project import ( ProjectPublicMemberSerializer ) from .state import StateSerializer, StateLiteSerializer -from .view import WorkspaceViewSerializer, IssueViewSerializer, IssueViewFavoriteSerializer +from .view import GlobalViewSerializer, IssueViewSerializer, IssueViewFavoriteSerializer from .cycle import CycleSerializer, CycleIssueSerializer, CycleFavoriteSerializer, CycleWriteSerializer from .asset import FileAssetSerializer from .issue import ( diff --git a/apiserver/plane/api/serializers/view.py b/apiserver/plane/api/serializers/view.py index a2502c59a..a3b6f48be 100644 --- a/apiserver/plane/api/serializers/view.py +++ b/apiserver/plane/api/serializers/view.py @@ -5,15 +5,15 @@ from rest_framework import serializers from .base import BaseSerializer from .workspace import WorkspaceLiteSerializer from .project import ProjectLiteSerializer -from plane.db.models import WorkspaceView, IssueView, IssueViewFavorite +from plane.db.models import GlobalView, IssueView, IssueViewFavorite from plane.utils.issue_filters import issue_filters -class WorkspaceViewSerializer(BaseSerializer): +class GlobalViewSerializer(BaseSerializer): workspace_detail = WorkspaceLiteSerializer(source="workspace", read_only=True) class Meta: - model = WorkspaceView + model = GlobalView fields = "__all__" read_only_fields = [ "workspace", @@ -26,7 +26,7 @@ class WorkspaceViewSerializer(BaseSerializer): validated_data["query"] = issue_filters(query_params, "POST") else: validated_data["query"] = dict() - return WorkspaceView.objects.create(**validated_data) + return GlobalView.objects.create(**validated_data) def update(self, instance, validated_data): query_params = validated_data.get("query_data", {}) diff --git a/apiserver/plane/api/urls.py b/apiserver/plane/api/urls.py index b9c5cc6b3..c206c57c0 100644 --- a/apiserver/plane/api/urls.py +++ b/apiserver/plane/api/urls.py @@ -102,8 +102,8 @@ from plane.api.views import ( BulkEstimatePointEndpoint, ## End Estimates # Views - WorkspaceViewViewSet, - WorkspaceViewIssuesViewSet, + GlobalViewViewSet, + GlobalViewIssuesViewSet, IssueViewViewSet, ViewIssuesEndpoint, IssueViewFavoriteViewSet, @@ -186,7 +186,6 @@ from plane.api.views import ( ## Exporter ExportIssuesEndpoint, ## End Exporter - ) @@ -243,7 +242,11 @@ urlpatterns = [ UpdateUserTourCompletedEndpoint.as_view(), name="user-tour", ), - path("users/workspaces//activities/", UserActivityEndpoint.as_view(), name="user-activities"), + path( + "users/workspaces//activities/", + UserActivityEndpoint.as_view(), + name="user-activities", + ), # user workspaces path( "users/me/workspaces/", @@ -653,17 +656,17 @@ urlpatterns = [ ), path( "workspaces//views/", - WorkspaceViewViewSet.as_view( + GlobalViewViewSet.as_view( { "get": "list", "post": "create", } ), - name="workspace-view", + name="global-view", ), path( "workspaces//views//", - WorkspaceViewViewSet.as_view( + GlobalViewViewSet.as_view( { "get": "retrieve", "put": "update", @@ -671,16 +674,7 @@ urlpatterns = [ "delete": "destroy", } ), - name="workspace-view", - ), - path( - "workspaces//views//issues/", - WorkspaceViewIssuesViewSet.as_view( - { - "get": "list", - } - ), - name="workspace-view-issues", + name="global-view", ), path( "workspaces//projects//user-favorite-views/", @@ -802,8 +796,12 @@ urlpatterns = [ ), path( "workspaces//issues/", - WorkSpaceIssuesEndpoint.as_view(), - name="workspace-issue", + GlobalViewIssuesViewSet.as_view( + { + "get": "list", + } + ), + name="global-view-issues", ), path( "workspaces//projects//issue-labels/", diff --git a/apiserver/plane/api/views/__init__.py b/apiserver/plane/api/views/__init__.py index f35ae4e76..c03d6d5b7 100644 --- a/apiserver/plane/api/views/__init__.py +++ b/apiserver/plane/api/views/__init__.py @@ -56,7 +56,7 @@ from .workspace import ( LeaveWorkspaceEndpoint, ) from .state import StateViewSet -from .view import WorkspaceViewViewSet, WorkspaceViewIssuesViewSet, IssueViewViewSet, ViewIssuesEndpoint, IssueViewFavoriteViewSet +from .view import GlobalViewViewSet, GlobalViewIssuesViewSet, IssueViewViewSet, ViewIssuesEndpoint, IssueViewFavoriteViewSet from .cycle import ( CycleViewSet, CycleIssueViewSet, diff --git a/apiserver/plane/api/views/view.py b/apiserver/plane/api/views/view.py index 726d0fcf1..b6f1d7c4b 100644 --- a/apiserver/plane/api/views/view.py +++ b/apiserver/plane/api/views/view.py @@ -24,7 +24,7 @@ from sentry_sdk import capture_exception # Module imports from . import BaseViewSet, BaseAPIView from plane.api.serializers import ( - WorkspaceViewSerializer, + GlobalViewSerializer, IssueViewSerializer, IssueLiteSerializer, IssueViewFavoriteSerializer, @@ -32,7 +32,7 @@ from plane.api.serializers import ( from plane.api.permissions import WorkspaceEntityPermission, ProjectEntityPermission from plane.db.models import ( Workspace, - WorkspaceView, + GlobalView, IssueView, Issue, IssueViewFavorite, @@ -44,9 +44,9 @@ from plane.utils.issue_filters import issue_filters from plane.utils.grouper import group_results -class WorkspaceViewViewSet(BaseViewSet): - serializer_class = WorkspaceViewSerializer - model = WorkspaceView +class GlobalViewViewSet(BaseViewSet): + serializer_class = GlobalViewSerializer + model = GlobalView permission_classes = [ WorkspaceEntityPermission, ] @@ -66,7 +66,7 @@ class WorkspaceViewViewSet(BaseViewSet): ) -class WorkspaceViewIssuesViewSet(BaseViewSet): +class GlobalViewIssuesViewSet(BaseViewSet): permission_classes = [ WorkspaceEntityPermission, ] @@ -80,6 +80,7 @@ class WorkspaceViewIssuesViewSet(BaseViewSet): .values("count") ) .filter(workspace__slug=self.kwargs.get("slug")) + .select_related("project") .select_related("workspace") .select_related("state") .select_related("parent") @@ -95,7 +96,7 @@ class WorkspaceViewIssuesViewSet(BaseViewSet): @method_decorator(gzip_page) - def list(self, request, slug, view_id): + def list(self, request, slug): try: filters = issue_filters(request.query_params, "GET") diff --git a/apiserver/plane/db/migrations/0045_alter_analyticview_created_by_and_more.py b/apiserver/plane/db/migrations/0045_alter_analyticview_created_by_and_more.py deleted file mode 100644 index b3f56a3de..000000000 --- a/apiserver/plane/db/migrations/0045_alter_analyticview_created_by_and_more.py +++ /dev/null @@ -1,38 +0,0 @@ -# Generated by Django 4.2.3 on 2023-09-14 13:17 - -from django.conf import settings -from django.db import migrations, models -import django.db.models.deletion -import uuid - - -class Migration(migrations.Migration): - - dependencies = [ - ('db', '0044_auto_20230913_0709'), - ] - - operations = [ - migrations.CreateModel( - name='WorkspaceView', - fields=[ - ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), - ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), - ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), - ('name', models.CharField(max_length=255, verbose_name='View Name')), - ('description', models.TextField(blank=True, verbose_name='View Description')), - ('query', models.JSONField(verbose_name='View Query')), - ('access', models.PositiveSmallIntegerField(choices=[(0, 'Private'), (1, 'Public')], default=1)), - ('query_data', models.JSONField(default=dict)), - ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_created_by', to=settings.AUTH_USER_MODEL, verbose_name='Created By')), - ('updated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated_by', to=settings.AUTH_USER_MODEL, verbose_name='Last Modified By')), - ('workspace', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='workspace_views', to='db.workspace')), - ], - options={ - 'verbose_name': 'Workspace View', - 'verbose_name_plural': 'Workspace Views', - 'db_table': 'workspace_views', - 'ordering': ('-created_at',), - }, - ), - ] diff --git a/apiserver/plane/db/migrations/0045_auto_20230915_0655.py b/apiserver/plane/db/migrations/0045_auto_20230915_0655.py index 7bd907e29..a757def07 100644 --- a/apiserver/plane/db/migrations/0045_auto_20230915_0655.py +++ b/apiserver/plane/db/migrations/0045_auto_20230915_0655.py @@ -1,6 +1,10 @@ # Generated by Django 4.2.3 on 2023-09-15 06:55 -from django.db import migrations +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import uuid + def update_issue_activity(apps, schema_editor): IssueActivityModel = apps.get_model("db", "IssueActivity") @@ -19,5 +23,27 @@ class Migration(migrations.Migration): ] operations = [ + migrations.CreateModel( + name='GlobalView', + fields=[ + ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created At')), + ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Last Modified At')), + ('id', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)), + ('name', models.CharField(max_length=255, verbose_name='View Name')), + ('description', models.TextField(blank=True, verbose_name='View Description')), + ('query', models.JSONField(verbose_name='View Query')), + ('access', models.PositiveSmallIntegerField(choices=[(0, 'Private'), (1, 'Public')], default=1)), + ('query_data', models.JSONField(default=dict)), + ('created_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_created_by', to=settings.AUTH_USER_MODEL, verbose_name='Created By')), + ('updated_by', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='%(class)s_updated_by', to=settings.AUTH_USER_MODEL, verbose_name='Last Modified By')), + ('workspace', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='global_views', to='db.workspace')), + ], + options={ + 'verbose_name': 'Global View', + 'verbose_name_plural': 'Global Views', + 'db_table': 'global_views', + 'ordering': ('-created_at',), + }, + ), migrations.RunPython(update_issue_activity), ] diff --git a/apiserver/plane/db/models/__init__.py b/apiserver/plane/db/models/__init__.py index 3742f36f9..9496b5906 100644 --- a/apiserver/plane/db/models/__init__.py +++ b/apiserver/plane/db/models/__init__.py @@ -50,7 +50,7 @@ from .state import State from .cycle import Cycle, CycleIssue, CycleFavorite -from .view import WorkspaceView, IssueView, IssueViewFavorite +from .view import GlobalView, IssueView, IssueViewFavorite from .module import Module, ModuleMember, ModuleIssue, ModuleLink, ModuleFavorite diff --git a/apiserver/plane/db/models/view.py b/apiserver/plane/db/models/view.py index 9d9f8f5cc..6e0a47105 100644 --- a/apiserver/plane/db/models/view.py +++ b/apiserver/plane/db/models/view.py @@ -6,9 +6,9 @@ from django.conf import settings from . import ProjectBaseModel, BaseModel -class WorkspaceView(BaseModel): +class GlobalView(BaseModel): workspace = models.ForeignKey( - "db.Workspace", on_delete=models.CASCADE, related_name="workspace_views" + "db.Workspace", on_delete=models.CASCADE, related_name="global_views" ) name = models.CharField(max_length=255, verbose_name="View Name") description = models.TextField(verbose_name="View Description", blank=True) @@ -19,9 +19,9 @@ class WorkspaceView(BaseModel): query_data = models.JSONField(default=dict) class Meta: - verbose_name = "Workspace View" - verbose_name_plural = "Workspace Views" - db_table = "workspace_views" + verbose_name = "Global View" + verbose_name_plural = "Global Views" + db_table = "global_views" ordering = ("-created_at",) def __str__(self):