mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
fix: user caching when the user leaves/deletes the workspace (#3989)
This commit is contained in:
parent
53ddef1cd5
commit
293854fb3a
@ -1,49 +1,51 @@
|
|||||||
# Python imports
|
# Python imports
|
||||||
from datetime import date
|
|
||||||
from dateutil.relativedelta import relativedelta
|
|
||||||
import csv
|
import csv
|
||||||
import io
|
import io
|
||||||
|
from datetime import date
|
||||||
|
|
||||||
|
from dateutil.relativedelta import relativedelta
|
||||||
|
from django.db import IntegrityError
|
||||||
|
from django.db.models import (
|
||||||
|
Count,
|
||||||
|
F,
|
||||||
|
Func,
|
||||||
|
OuterRef,
|
||||||
|
Prefetch,
|
||||||
|
Q,
|
||||||
|
)
|
||||||
|
from django.db.models.fields import DateField
|
||||||
|
from django.db.models.functions import Cast, ExtractDay, ExtractWeek
|
||||||
|
|
||||||
# Django imports
|
# Django imports
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.db import IntegrityError
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.db.models import (
|
|
||||||
Prefetch,
|
|
||||||
OuterRef,
|
|
||||||
Func,
|
|
||||||
F,
|
|
||||||
Q,
|
|
||||||
Count,
|
|
||||||
)
|
|
||||||
from django.db.models.functions import ExtractWeek, Cast, ExtractDay
|
|
||||||
from django.db.models.fields import DateField
|
|
||||||
|
|
||||||
# Third party modules
|
# Third party modules
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
|
from plane.app.permissions import (
|
||||||
|
WorkSpaceAdminPermission,
|
||||||
|
WorkSpaceBasePermission,
|
||||||
|
WorkspaceEntityPermission,
|
||||||
|
)
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from plane.app.serializers import (
|
from plane.app.serializers import (
|
||||||
WorkSpaceSerializer,
|
WorkSpaceSerializer,
|
||||||
WorkspaceThemeSerializer,
|
WorkspaceThemeSerializer,
|
||||||
)
|
)
|
||||||
from plane.app.views.base import BaseViewSet, BaseAPIView
|
from plane.app.views.base import BaseAPIView, BaseViewSet
|
||||||
from plane.db.models import (
|
from plane.db.models import (
|
||||||
Workspace,
|
|
||||||
IssueActivity,
|
|
||||||
Issue,
|
Issue,
|
||||||
WorkspaceTheme,
|
IssueActivity,
|
||||||
|
Workspace,
|
||||||
WorkspaceMember,
|
WorkspaceMember,
|
||||||
)
|
WorkspaceTheme,
|
||||||
from plane.app.permissions import (
|
|
||||||
WorkSpaceBasePermission,
|
|
||||||
WorkSpaceAdminPermission,
|
|
||||||
WorkspaceEntityPermission,
|
|
||||||
)
|
)
|
||||||
from plane.utils.cache import cache_response, invalidate_cache
|
from plane.utils.cache import cache_response, invalidate_cache
|
||||||
|
|
||||||
|
|
||||||
class WorkSpaceViewSet(BaseViewSet):
|
class WorkSpaceViewSet(BaseViewSet):
|
||||||
model = Workspace
|
model = Workspace
|
||||||
serializer_class = WorkSpaceSerializer
|
serializer_class = WorkSpaceSerializer
|
||||||
@ -138,6 +140,7 @@ class WorkSpaceViewSet(BaseViewSet):
|
|||||||
{"slug": "The workspace with the slug already exists"},
|
{"slug": "The workspace with the slug already exists"},
|
||||||
status=status.HTTP_410_GONE,
|
status=status.HTTP_410_GONE,
|
||||||
)
|
)
|
||||||
|
|
||||||
@cache_response(60 * 60 * 2)
|
@cache_response(60 * 60 * 2)
|
||||||
def list(self, request, *args, **kwargs):
|
def list(self, request, *args, **kwargs):
|
||||||
return super().list(request, *args, **kwargs)
|
return super().list(request, *args, **kwargs)
|
||||||
@ -149,6 +152,7 @@ class WorkSpaceViewSet(BaseViewSet):
|
|||||||
|
|
||||||
@invalidate_cache(path="/api/workspaces/", user=False)
|
@invalidate_cache(path="/api/workspaces/", user=False)
|
||||||
@invalidate_cache(path="/api/users/me/workspaces/")
|
@invalidate_cache(path="/api/users/me/workspaces/")
|
||||||
|
@invalidate_cache(path="/api/users/me/settings/")
|
||||||
def destroy(self, request, *args, **kwargs):
|
def destroy(self, request, *args, **kwargs):
|
||||||
return super().destroy(request, *args, **kwargs)
|
return super().destroy(request, *args, **kwargs)
|
||||||
|
|
||||||
|
@ -1,41 +1,43 @@
|
|||||||
# Django imports
|
# Django imports
|
||||||
from django.db.models import (
|
from django.db.models import (
|
||||||
Q,
|
CharField,
|
||||||
Count,
|
Count,
|
||||||
|
Q,
|
||||||
)
|
)
|
||||||
from django.db.models.functions import Cast
|
from django.db.models.functions import Cast
|
||||||
from django.db.models import CharField
|
|
||||||
|
|
||||||
# Third party modules
|
# Third party modules
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
# Module imports
|
|
||||||
from plane.app.serializers import (
|
|
||||||
WorkSpaceMemberSerializer,
|
|
||||||
TeamSerializer,
|
|
||||||
UserLiteSerializer,
|
|
||||||
WorkspaceMemberAdminSerializer,
|
|
||||||
WorkspaceMemberMeSerializer,
|
|
||||||
ProjectMemberRoleSerializer,
|
|
||||||
)
|
|
||||||
from plane.app.views.base import BaseAPIView
|
|
||||||
from .. import BaseViewSet
|
|
||||||
from plane.db.models import (
|
|
||||||
User,
|
|
||||||
Workspace,
|
|
||||||
Team,
|
|
||||||
ProjectMember,
|
|
||||||
Project,
|
|
||||||
WorkspaceMember,
|
|
||||||
)
|
|
||||||
from plane.app.permissions import (
|
from plane.app.permissions import (
|
||||||
WorkSpaceAdminPermission,
|
WorkSpaceAdminPermission,
|
||||||
WorkspaceEntityPermission,
|
WorkspaceEntityPermission,
|
||||||
WorkspaceUserPermission,
|
WorkspaceUserPermission,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Module imports
|
||||||
|
from plane.app.serializers import (
|
||||||
|
ProjectMemberRoleSerializer,
|
||||||
|
TeamSerializer,
|
||||||
|
UserLiteSerializer,
|
||||||
|
WorkspaceMemberAdminSerializer,
|
||||||
|
WorkspaceMemberMeSerializer,
|
||||||
|
WorkSpaceMemberSerializer,
|
||||||
|
)
|
||||||
|
from plane.app.views.base import BaseAPIView
|
||||||
|
from plane.db.models import (
|
||||||
|
Project,
|
||||||
|
ProjectMember,
|
||||||
|
Team,
|
||||||
|
User,
|
||||||
|
Workspace,
|
||||||
|
WorkspaceMember,
|
||||||
|
)
|
||||||
from plane.utils.cache import cache_response, invalidate_cache
|
from plane.utils.cache import cache_response, invalidate_cache
|
||||||
|
|
||||||
|
from .. import BaseViewSet
|
||||||
|
|
||||||
|
|
||||||
class WorkSpaceMemberViewSet(BaseViewSet):
|
class WorkSpaceMemberViewSet(BaseViewSet):
|
||||||
serializer_class = WorkspaceMemberAdminSerializer
|
serializer_class = WorkspaceMemberAdminSerializer
|
||||||
@ -147,6 +149,7 @@ class WorkSpaceMemberViewSet(BaseViewSet):
|
|||||||
@invalidate_cache(
|
@invalidate_cache(
|
||||||
path="/api/workspaces/:slug/members/", url_params=True, user=False
|
path="/api/workspaces/:slug/members/", url_params=True, user=False
|
||||||
)
|
)
|
||||||
|
@invalidate_cache(path="/api/users/me/settings/")
|
||||||
def destroy(self, request, slug, pk):
|
def destroy(self, request, slug, pk):
|
||||||
# Check the user role who is deleting the user
|
# Check the user role who is deleting the user
|
||||||
workspace_member = WorkspaceMember.objects.get(
|
workspace_member = WorkspaceMember.objects.get(
|
||||||
@ -214,6 +217,7 @@ class WorkSpaceMemberViewSet(BaseViewSet):
|
|||||||
@invalidate_cache(
|
@invalidate_cache(
|
||||||
path="/api/workspaces/:slug/members/", url_params=True, user=False
|
path="/api/workspaces/:slug/members/", url_params=True, user=False
|
||||||
)
|
)
|
||||||
|
@invalidate_cache(path="/api/users/me/settings/")
|
||||||
def leave(self, request, slug):
|
def leave(self, request, slug):
|
||||||
workspace_member = WorkspaceMember.objects.get(
|
workspace_member = WorkspaceMember.objects.get(
|
||||||
workspace__slug=slug,
|
workspace__slug=slug,
|
||||||
|
Loading…
Reference in New Issue
Block a user