From 7249f84e18b135a2aeb33360f0997e3ddb2ae669 Mon Sep 17 00:00:00 2001 From: Nikhil <118773738+pablohashescobar@users.noreply.github.com> Date: Wed, 1 Nov 2023 20:35:06 +0530 Subject: [PATCH] dev: code improvements and minor performance upgrades (#2201) * dev: remove len for empty comparison * dev: using in instead of multiple ors * dev: assign expression to empty variables * dev: use f-string * dev: remove list comprehension and use generators * dev: remove assert from paginator * dev: use is for identity comparison with singleton * dev: remove unnecessary else statements * dev: fix does not exists error for both project and workspace * dev: remove reimports * dev: iterate a dictionary * dev: remove unused commented code * dev: remove redefinition * dev: remove unused imports * dev: remove unused imports * dev: remove unnecessary f strings * dev: remove unused variables * dev: use literal structure to create the data structure * dev: add empty lines at the end of the file * dev: remove user middleware * dev: remove unnecessary default None --- apiserver/bin/user_script.py | 2 +- apiserver/gunicorn.config.py | 2 +- apiserver/plane/api/permissions/project.py | 2 +- apiserver/plane/api/serializers/analytic.py | 4 +-- apiserver/plane/api/serializers/cycle.py | 3 -- apiserver/plane/api/serializers/inbox.py | 1 - .../api/serializers/integration/__init__.py | 2 +- apiserver/plane/api/serializers/issue.py | 23 +------------ apiserver/plane/api/serializers/module.py | 3 +- apiserver/plane/api/serializers/view.py | 4 +-- apiserver/plane/api/serializers/workspace.py | 8 ++--- apiserver/plane/api/urls_deprecated.py | 1 - apiserver/plane/api/views/__init__.py | 2 +- apiserver/plane/api/views/auth_extended.py | 4 +-- apiserver/plane/api/views/cycle.py | 1 - apiserver/plane/api/views/inbox.py | 3 +- apiserver/plane/api/views/issue.py | 13 +++----- apiserver/plane/api/views/oauth.py | 9 ++--- apiserver/plane/api/views/page.py | 2 +- apiserver/plane/api/views/project.py | 6 ++-- apiserver/plane/api/views/user.py | 1 - apiserver/plane/api/views/workspace.py | 3 -- .../plane/bgtasks/email_verification_task.py | 2 +- apiserver/plane/bgtasks/export_task.py | 1 - .../plane/bgtasks/forgot_password_task.py | 4 +-- apiserver/plane/bgtasks/importer_task.py | 9 ++--- .../plane/bgtasks/issue_activites_task.py | 2 +- .../plane/bgtasks/magic_link_code_task.py | 2 +- .../bgtasks/workspace_invitation_task.py | 2 +- apiserver/plane/celery.py | 2 +- apiserver/plane/db/models/__init__.py | 3 +- apiserver/plane/db/models/exporter.py | 2 +- .../plane/db/models/integration/__init__.py | 2 +- .../plane/db/models/integration/github.py | 1 - apiserver/plane/db/models/project.py | 3 -- apiserver/plane/middleware/user_middleware.py | 33 ------------------- apiserver/plane/settings/staging.py | 1 - apiserver/plane/tests/__init__.py | 2 +- apiserver/plane/urls.py | 3 -- apiserver/plane/utils/analytics_plot.py | 14 +++----- apiserver/plane/utils/grouper.py | 2 +- apiserver/plane/utils/imports.py | 2 +- apiserver/plane/utils/ip_address.py | 2 +- apiserver/plane/utils/issue_filters.py | 2 +- apiserver/plane/utils/markdown.py | 2 +- apiserver/plane/utils/paginator.py | 11 +------ 46 files changed, 51 insertions(+), 157 deletions(-) delete mode 100644 apiserver/plane/middleware/user_middleware.py diff --git a/apiserver/bin/user_script.py b/apiserver/bin/user_script.py index e115b20b8..a356f2ec9 100644 --- a/apiserver/bin/user_script.py +++ b/apiserver/bin/user_script.py @@ -1,4 +1,4 @@ -import os, sys, random, string +import os, sys import uuid sys.path.append("/code") diff --git a/apiserver/gunicorn.config.py b/apiserver/gunicorn.config.py index 67205b5ec..51c2a5488 100644 --- a/apiserver/gunicorn.config.py +++ b/apiserver/gunicorn.config.py @@ -3,4 +3,4 @@ from psycogreen.gevent import patch_psycopg def post_fork(server, worker): patch_psycopg() - worker.log.info("Made Psycopg2 Green") \ No newline at end of file + worker.log.info("Made Psycopg2 Green") diff --git a/apiserver/plane/api/permissions/project.py b/apiserver/plane/api/permissions/project.py index e4e3e0f9b..4f907dbd6 100644 --- a/apiserver/plane/api/permissions/project.py +++ b/apiserver/plane/api/permissions/project.py @@ -101,4 +101,4 @@ class ProjectLitePermission(BasePermission): workspace__slug=view.workspace_slug, member=request.user, project_id=view.project_id, - ).exists() \ No newline at end of file + ).exists() diff --git a/apiserver/plane/api/serializers/analytic.py b/apiserver/plane/api/serializers/analytic.py index 5f35e1117..9f3ee6d0a 100644 --- a/apiserver/plane/api/serializers/analytic.py +++ b/apiserver/plane/api/serializers/analytic.py @@ -17,7 +17,7 @@ class AnalyticViewSerializer(BaseSerializer): if bool(query_params): validated_data["query"] = issue_filters(query_params, "POST") else: - validated_data["query"] = dict() + validated_data["query"] = {} return AnalyticView.objects.create(**validated_data) def update(self, instance, validated_data): @@ -25,6 +25,6 @@ class AnalyticViewSerializer(BaseSerializer): if bool(query_params): validated_data["query"] = issue_filters(query_params, "POST") else: - validated_data["query"] = dict() + validated_data["query"] = {} validated_data["query"] = issue_filters(query_params, "PATCH") return super().update(instance, validated_data) diff --git a/apiserver/plane/api/serializers/cycle.py b/apiserver/plane/api/serializers/cycle.py index 54aa4fd0c..104a3dd06 100644 --- a/apiserver/plane/api/serializers/cycle.py +++ b/apiserver/plane/api/serializers/cycle.py @@ -1,6 +1,3 @@ -# Django imports -from django.db.models.functions import TruncDate - # Third party imports from rest_framework import serializers diff --git a/apiserver/plane/api/serializers/inbox.py b/apiserver/plane/api/serializers/inbox.py index ae17b749b..f52a90660 100644 --- a/apiserver/plane/api/serializers/inbox.py +++ b/apiserver/plane/api/serializers/inbox.py @@ -6,7 +6,6 @@ from .base import BaseSerializer from .issue import IssueFlatSerializer, LabelLiteSerializer from .project import ProjectLiteSerializer from .state import StateLiteSerializer -from .project import ProjectLiteSerializer from .user import UserLiteSerializer from plane.db.models import Inbox, InboxIssue, Issue diff --git a/apiserver/plane/api/serializers/integration/__init__.py b/apiserver/plane/api/serializers/integration/__init__.py index 963fc295e..112ff02d1 100644 --- a/apiserver/plane/api/serializers/integration/__init__.py +++ b/apiserver/plane/api/serializers/integration/__init__.py @@ -5,4 +5,4 @@ from .github import ( GithubIssueSyncSerializer, GithubCommentSyncSerializer, ) -from .slack import SlackProjectSyncSerializer \ No newline at end of file +from .slack import SlackProjectSyncSerializer diff --git a/apiserver/plane/api/serializers/issue.py b/apiserver/plane/api/serializers/issue.py index 2b64e22ef..f061a0a19 100644 --- a/apiserver/plane/api/serializers/issue.py +++ b/apiserver/plane/api/serializers/issue.py @@ -8,8 +8,7 @@ from rest_framework import serializers from .base import BaseSerializer from .user import UserLiteSerializer from .state import StateSerializer, StateLiteSerializer -from .user import UserLiteSerializer -from .project import ProjectSerializer, ProjectLiteSerializer +from .project import ProjectLiteSerializer from .workspace import WorkspaceLiteSerializer from plane.db.models import ( User, @@ -232,25 +231,6 @@ class IssueActivitySerializer(BaseSerializer): fields = "__all__" -class IssueCommentSerializer(BaseSerializer): - actor_detail = UserLiteSerializer(read_only=True, source="actor") - issue_detail = IssueFlatSerializer(read_only=True, source="issue") - project_detail = ProjectLiteSerializer(read_only=True, source="project") - workspace_detail = WorkspaceLiteSerializer(read_only=True, source="workspace") - - class Meta: - model = IssueComment - fields = "__all__" - read_only_fields = [ - "workspace", - "project", - "issue", - "created_by", - "updated_by", - "created_at", - "updated_at", - ] - class IssuePropertySerializer(BaseSerializer): class Meta: @@ -287,7 +267,6 @@ class LabelLiteSerializer(BaseSerializer): class IssueLabelSerializer(BaseSerializer): - # label_details = LabelSerializer(read_only=True, source="label") class Meta: model = IssueLabel diff --git a/apiserver/plane/api/serializers/module.py b/apiserver/plane/api/serializers/module.py index 9d4bfbaa9..48f773b0f 100644 --- a/apiserver/plane/api/serializers/module.py +++ b/apiserver/plane/api/serializers/module.py @@ -4,9 +4,8 @@ from rest_framework import serializers # Module imports from .base import BaseSerializer from .user import UserLiteSerializer -from .project import ProjectSerializer, ProjectLiteSerializer +from .project import ProjectLiteSerializer from .workspace import WorkspaceLiteSerializer -from .issue import IssueStateSerializer from plane.db.models import ( User, diff --git a/apiserver/plane/api/serializers/view.py b/apiserver/plane/api/serializers/view.py index a3b6f48be..e7502609a 100644 --- a/apiserver/plane/api/serializers/view.py +++ b/apiserver/plane/api/serializers/view.py @@ -57,7 +57,7 @@ class IssueViewSerializer(BaseSerializer): if bool(query_params): validated_data["query"] = issue_filters(query_params, "POST") else: - validated_data["query"] = dict() + validated_data["query"] = {} return IssueView.objects.create(**validated_data) def update(self, instance, validated_data): @@ -65,7 +65,7 @@ class IssueViewSerializer(BaseSerializer): if bool(query_params): validated_data["query"] = issue_filters(query_params, "POST") else: - validated_data["query"] = dict() + validated_data["query"] = {} validated_data["query"] = issue_filters(query_params, "PATCH") return super().update(instance, validated_data) diff --git a/apiserver/plane/api/serializers/workspace.py b/apiserver/plane/api/serializers/workspace.py index 8c718a18e..0a80ce8b7 100644 --- a/apiserver/plane/api/serializers/workspace.py +++ b/apiserver/plane/api/serializers/workspace.py @@ -110,9 +110,8 @@ class TeamSerializer(BaseSerializer): ] TeamMember.objects.bulk_create(team_members, batch_size=10) return team - else: - team = Team.objects.create(**validated_data) - return team + team = Team.objects.create(**validated_data) + return team def update(self, instance, validated_data): if "members" in validated_data: @@ -124,8 +123,7 @@ class TeamSerializer(BaseSerializer): ] TeamMember.objects.bulk_create(team_members, batch_size=10) return super().update(instance, validated_data) - else: - return super().update(instance, validated_data) + return super().update(instance, validated_data) class WorkspaceThemeSerializer(BaseSerializer): diff --git a/apiserver/plane/api/urls_deprecated.py b/apiserver/plane/api/urls_deprecated.py index c108257b3..67cc62e46 100644 --- a/apiserver/plane/api/urls_deprecated.py +++ b/apiserver/plane/api/urls_deprecated.py @@ -28,7 +28,6 @@ from plane.api.views import ( ## End User # Workspaces WorkSpaceViewSet, - UserWorkspaceInvitationsEndpoint, UserWorkSpacesEndpoint, InviteWorkspaceEndpoint, JoinWorkspaceEndpoint, diff --git a/apiserver/plane/api/views/__init__.py b/apiserver/plane/api/views/__init__.py index df6de7a82..8f4b2fb9d 100644 --- a/apiserver/plane/api/views/__init__.py +++ b/apiserver/plane/api/views/__init__.py @@ -166,4 +166,4 @@ from .notification import NotificationViewSet, UnreadNotificationEndpoint, MarkA from .exporter import ExportIssuesEndpoint -from .config import ConfigurationEndpoint \ No newline at end of file +from .config import ConfigurationEndpoint diff --git a/apiserver/plane/api/views/auth_extended.py b/apiserver/plane/api/views/auth_extended.py index c7107ecfa..fbffacff8 100644 --- a/apiserver/plane/api/views/auth_extended.py +++ b/apiserver/plane/api/views/auth_extended.py @@ -55,11 +55,11 @@ class VerifyEmailEndpoint(BaseAPIView): return Response( {"email": "Successfully activated"}, status=status.HTTP_200_OK ) - except jwt.ExpiredSignatureError as indentifier: + except jwt.ExpiredSignatureError as _indentifier: return Response( {"email": "Activation expired"}, status=status.HTTP_400_BAD_REQUEST ) - except jwt.exceptions.DecodeError as indentifier: + except jwt.exceptions.DecodeError as _indentifier: return Response( {"email": "Invalid token"}, status=status.HTTP_400_BAD_REQUEST ) diff --git a/apiserver/plane/api/views/cycle.py b/apiserver/plane/api/views/cycle.py index b18c42d86..e7d247872 100644 --- a/apiserver/plane/api/views/cycle.py +++ b/apiserver/plane/api/views/cycle.py @@ -3,7 +3,6 @@ import json # Django imports from django.db.models import ( - OuterRef, Func, F, Q, diff --git a/apiserver/plane/api/views/inbox.py b/apiserver/plane/api/views/inbox.py index 632da0d95..517e9b6de 100644 --- a/apiserver/plane/api/views/inbox.py +++ b/apiserver/plane/api/views/inbox.py @@ -360,8 +360,7 @@ class InboxIssuePublicViewSet(BaseViewSet): ) .select_related("issue", "workspace", "project") ) - else: - return InboxIssue.objects.none() + return InboxIssue.objects.none() def list(self, request, slug, project_id, inbox_id): project_deploy_board = ProjectDeployBoard.objects.get(workspace__slug=slug, project_id=project_id) diff --git a/apiserver/plane/api/views/issue.py b/apiserver/plane/api/views/issue.py index a6a03c16c..2443e0752 100644 --- a/apiserver/plane/api/views/issue.py +++ b/apiserver/plane/api/views/issue.py @@ -39,7 +39,6 @@ from plane.api.serializers import ( IssueActivitySerializer, IssueCommentSerializer, IssuePropertySerializer, - LabelSerializer, IssueSerializer, LabelSerializer, IssueFlatSerializer, @@ -1392,8 +1391,7 @@ class IssueCommentPublicViewSet(BaseViewSet): ) .distinct() ).order_by("created_at") - else: - return IssueComment.objects.none() + return IssueComment.objects.none() except ProjectDeployBoard.DoesNotExist: return IssueComment.objects.none() @@ -1518,8 +1516,7 @@ class IssueReactionPublicViewSet(BaseViewSet): .order_by("-created_at") .distinct() ) - else: - return IssueReaction.objects.none() + return IssueReaction.objects.none() except ProjectDeployBoard.DoesNotExist: return IssueReaction.objects.none() @@ -1614,8 +1611,7 @@ class CommentReactionPublicViewSet(BaseViewSet): .order_by("-created_at") .distinct() ) - else: - return CommentReaction.objects.none() + return CommentReaction.objects.none() except ProjectDeployBoard.DoesNotExist: return CommentReaction.objects.none() @@ -1709,8 +1705,7 @@ class IssueVotePublicViewSet(BaseViewSet): .filter(workspace__slug=self.kwargs.get("slug")) .filter(project_id=self.kwargs.get("project_id")) ) - else: - return IssueVote.objects.none() + return IssueVote.objects.none() except ProjectDeployBoard.DoesNotExist: return IssueVote.objects.none() diff --git a/apiserver/plane/api/views/oauth.py b/apiserver/plane/api/views/oauth.py index 04c83813a..f0ea9acc9 100644 --- a/apiserver/plane/api/views/oauth.py +++ b/apiserver/plane/api/views/oauth.py @@ -11,7 +11,6 @@ from django.conf import settings from rest_framework.response import Response from rest_framework import exceptions from rest_framework.permissions import AllowAny -from rest_framework.views import APIView from rest_framework_simplejwt.tokens import RefreshToken from rest_framework import status from sentry_sdk import capture_exception @@ -113,7 +112,7 @@ def get_user_data(access_token: str) -> dict: url="https://api.github.com/user/emails", headers=headers ).json() - [ + _ = [ user_data.update({"email": item.get("email")}) for item in response if item.get("primary") is True @@ -147,7 +146,7 @@ class OauthEndpoint(BaseAPIView): data = get_user_data(access_token) email = data.get("email", None) - if email == None: + if email is None: return Response( { "error": "Something went wrong. Please try again later or contact the support team." @@ -158,7 +157,6 @@ class OauthEndpoint(BaseAPIView): if "@" in email: user = User.objects.get(email=email) email = data["email"] - channel = "email" mobile_number = uuid.uuid4().hex email_verified = True else: @@ -182,7 +180,7 @@ class OauthEndpoint(BaseAPIView): user.last_active = timezone.now() user.last_login_time = timezone.now() user.last_login_ip = request.META.get("REMOTE_ADDR") - user.last_login_medium = f"oauth" + user.last_login_medium = "oauth" user.last_login_uagent = request.META.get("HTTP_USER_AGENT") user.is_email_verified = email_verified user.save() @@ -233,7 +231,6 @@ class OauthEndpoint(BaseAPIView): if "@" in email: email = data["email"] mobile_number = uuid.uuid4().hex - channel = "email" email_verified = True else: return Response( diff --git a/apiserver/plane/api/views/page.py b/apiserver/plane/api/views/page.py index fd31cdf14..ca0927a51 100644 --- a/apiserver/plane/api/views/page.py +++ b/apiserver/plane/api/views/page.py @@ -1,5 +1,5 @@ # Python imports -from datetime import timedelta, datetime, date +from datetime import timedelta, date # Django imports from django.db.models import Exists, OuterRef, Q, Prefetch diff --git a/apiserver/plane/api/views/project.py b/apiserver/plane/api/views/project.py index 6ce847f9d..37e491e83 100644 --- a/apiserver/plane/api/views/project.py +++ b/apiserver/plane/api/views/project.py @@ -11,7 +11,6 @@ from django.db.models import ( Q, Exists, OuterRef, - Func, F, Func, Subquery, @@ -35,7 +34,6 @@ from plane.api.serializers import ( ProjectDetailSerializer, ProjectMemberInviteSerializer, ProjectFavoriteSerializer, - IssueLiteSerializer, ProjectDeployBoardSerializer, ProjectMemberAdminSerializer, ) @@ -84,7 +82,7 @@ class ProjectViewSet(BaseViewSet): ] def get_serializer_class(self, *args, **kwargs): - if self.action == "update" or self.action == "partial_update": + if self.action in ["update", "partial_update"]: return ProjectSerializer return ProjectDetailSerializer @@ -336,7 +334,7 @@ class ProjectViewSet(BaseViewSet): {"name": "The project name is already taken"}, status=status.HTTP_410_GONE, ) - except Project.DoesNotExist or Workspace.DoesNotExist as e: + except (Project.DoesNotExist, Workspace.DoesNotExist): return Response( {"error": "Project does not exist"}, status=status.HTTP_404_NOT_FOUND ) diff --git a/apiserver/plane/api/views/user.py b/apiserver/plane/api/views/user.py index f17b176ba..2e40565b4 100644 --- a/apiserver/plane/api/views/user.py +++ b/apiserver/plane/api/views/user.py @@ -19,7 +19,6 @@ from plane.db.models import ( WorkspaceMemberInvite, Issue, IssueActivity, - WorkspaceMember, ) from plane.utils.paginator import BasePaginator diff --git a/apiserver/plane/api/views/workspace.py b/apiserver/plane/api/views/workspace.py index ff555a711..c53fbf126 100644 --- a/apiserver/plane/api/views/workspace.py +++ b/apiserver/plane/api/views/workspace.py @@ -6,12 +6,10 @@ from uuid import uuid4 # Django imports from django.db import IntegrityError -from django.db.models import Prefetch from django.conf import settings from django.utils import timezone from django.core.exceptions import ValidationError from django.core.validators import validate_email -from django.contrib.sites.shortcuts import get_current_site from django.db.models import ( Prefetch, OuterRef, @@ -55,7 +53,6 @@ from . import BaseViewSet from plane.db.models import ( User, Workspace, - WorkspaceMember, WorkspaceMemberInvite, Team, ProjectMember, diff --git a/apiserver/plane/bgtasks/email_verification_task.py b/apiserver/plane/bgtasks/email_verification_task.py index 93b15c425..9f9d06437 100644 --- a/apiserver/plane/bgtasks/email_verification_task.py +++ b/apiserver/plane/bgtasks/email_verification_task.py @@ -23,7 +23,7 @@ def email_verification(first_name, email, token, current_site): from_email_string = settings.EMAIL_FROM - subject = f"Verify your Email!" + subject = "Verify your Email!" context = { "first_name": first_name, diff --git a/apiserver/plane/bgtasks/export_task.py b/apiserver/plane/bgtasks/export_task.py index a45120eb5..1329697e9 100644 --- a/apiserver/plane/bgtasks/export_task.py +++ b/apiserver/plane/bgtasks/export_task.py @@ -4,7 +4,6 @@ import io import json import boto3 import zipfile -from urllib.parse import urlparse, urlunparse # Django imports from django.conf import settings diff --git a/apiserver/plane/bgtasks/forgot_password_task.py b/apiserver/plane/bgtasks/forgot_password_task.py index 95828765c..de1390f01 100644 --- a/apiserver/plane/bgtasks/forgot_password_task.py +++ b/apiserver/plane/bgtasks/forgot_password_task.py @@ -8,8 +8,6 @@ from django.conf import settings from celery import shared_task from sentry_sdk import capture_exception -# Module imports -from plane.db.models import User @shared_task @@ -21,7 +19,7 @@ def forgot_password(first_name, email, uidb64, token, current_site): from_email_string = settings.EMAIL_FROM - subject = f"Reset Your Password - Plane" + subject = "Reset Your Password - Plane" context = { "first_name": first_name, diff --git a/apiserver/plane/bgtasks/importer_task.py b/apiserver/plane/bgtasks/importer_task.py index 20dc65e51..14bece21b 100644 --- a/apiserver/plane/bgtasks/importer_task.py +++ b/apiserver/plane/bgtasks/importer_task.py @@ -2,8 +2,6 @@ import json import requests import uuid -import jwt -from datetime import datetime # Django imports from django.conf import settings @@ -27,7 +25,6 @@ from plane.db.models import ( User, IssueProperty, ) -from .workspace_invitation_task import workspace_invitation from plane.bgtasks.user_welcome_task import send_welcome_slack @@ -58,7 +55,7 @@ def service_importer(service, importer_id): ignore_conflicts=True, ) - [ + _ = [ send_welcome_slack.delay( str(user.id), True, @@ -157,7 +154,7 @@ def service_importer(service, importer_id): ) # Create repo sync - repo_sync = GithubRepositorySync.objects.create( + _ = GithubRepositorySync.objects.create( repository=repo, workspace_integration=workspace_integration, actor=workspace_integration.actor, @@ -179,7 +176,7 @@ def service_importer(service, importer_id): ImporterSerializer(importer).data, cls=DjangoJSONEncoder, ) - res = requests.post( + _ = requests.post( f"{settings.PROXY_BASE_URL}/hooks/workspaces/{str(importer.workspace_id)}/projects/{str(importer.project_id)}/importers/{str(service)}/", json=import_data_json, headers=headers, diff --git a/apiserver/plane/bgtasks/issue_activites_task.py b/apiserver/plane/bgtasks/issue_activites_task.py index b1277cb3d..bfdb4b498 100644 --- a/apiserver/plane/bgtasks/issue_activites_task.py +++ b/apiserver/plane/bgtasks/issue_activites_task.py @@ -537,7 +537,7 @@ def update_issue_activity( ) for key in requested_data: - func = ISSUE_ACTIVITY_MAPPER.get(key, None) + func = ISSUE_ACTIVITY_MAPPER.get(key) if func is not None: func( requested_data=requested_data, diff --git a/apiserver/plane/bgtasks/magic_link_code_task.py b/apiserver/plane/bgtasks/magic_link_code_task.py index 91cc461bb..71f6db8da 100644 --- a/apiserver/plane/bgtasks/magic_link_code_task.py +++ b/apiserver/plane/bgtasks/magic_link_code_task.py @@ -17,7 +17,7 @@ def magic_link(email, key, token, current_site): from_email_string = settings.EMAIL_FROM - subject = f"Login for Plane" + subject = "Login for Plane" context = {"magic_url": abs_url, "code": token} diff --git a/apiserver/plane/bgtasks/workspace_invitation_task.py b/apiserver/plane/bgtasks/workspace_invitation_task.py index d84a0b414..94be6f879 100644 --- a/apiserver/plane/bgtasks/workspace_invitation_task.py +++ b/apiserver/plane/bgtasks/workspace_invitation_task.py @@ -11,7 +11,7 @@ from slack_sdk import WebClient from slack_sdk.errors import SlackApiError # Module imports -from plane.db.models import Workspace, User, WorkspaceMemberInvite +from plane.db.models import Workspace, WorkspaceMemberInvite @shared_task diff --git a/apiserver/plane/celery.py b/apiserver/plane/celery.py index 15fe8af52..dfb094339 100644 --- a/apiserver/plane/celery.py +++ b/apiserver/plane/celery.py @@ -29,4 +29,4 @@ app.conf.beat_schedule = { # Load task modules from all registered Django app configs. app.autodiscover_tasks() -app.conf.beat_scheduler = 'django_celery_beat.schedulers.DatabaseScheduler' \ No newline at end of file +app.conf.beat_scheduler = 'django_celery_beat.schedulers.DatabaseScheduler' diff --git a/apiserver/plane/db/models/__init__.py b/apiserver/plane/db/models/__init__.py index 42f566baf..d8286f8f8 100644 --- a/apiserver/plane/db/models/__init__.py +++ b/apiserver/plane/db/models/__init__.py @@ -27,7 +27,6 @@ from .issue import ( IssueActivity, IssueProperty, IssueComment, - IssueBlocker, IssueLabel, IssueAssignee, Label, @@ -79,4 +78,4 @@ from .analytic import AnalyticView from .notification import Notification -from .exporter import ExporterHistory \ No newline at end of file +from .exporter import ExporterHistory diff --git a/apiserver/plane/db/models/exporter.py b/apiserver/plane/db/models/exporter.py index fce31c8e7..0383807b7 100644 --- a/apiserver/plane/db/models/exporter.py +++ b/apiserver/plane/db/models/exporter.py @@ -53,4 +53,4 @@ class ExporterHistory(BaseModel): def __str__(self): """Return name of the service""" - return f"{self.provider} <{self.workspace.name}>" \ No newline at end of file + return f"{self.provider} <{self.workspace.name}>" diff --git a/apiserver/plane/db/models/integration/__init__.py b/apiserver/plane/db/models/integration/__init__.py index 3f2be93b8..3bef68708 100644 --- a/apiserver/plane/db/models/integration/__init__.py +++ b/apiserver/plane/db/models/integration/__init__.py @@ -1,3 +1,3 @@ from .base import Integration, WorkspaceIntegration from .github import GithubRepository, GithubRepositorySync, GithubIssueSync, GithubCommentSync -from .slack import SlackProjectSync \ No newline at end of file +from .slack import SlackProjectSync diff --git a/apiserver/plane/db/models/integration/github.py b/apiserver/plane/db/models/integration/github.py index 130925c21..f4d152bb1 100644 --- a/apiserver/plane/db/models/integration/github.py +++ b/apiserver/plane/db/models/integration/github.py @@ -6,7 +6,6 @@ from django.db import models # Module imports from plane.db.models import ProjectBaseModel -from plane.db.mixins import AuditModel class GithubRepository(ProjectBaseModel): diff --git a/apiserver/plane/db/models/project.py b/apiserver/plane/db/models/project.py index 4cd2134ac..f4ace65e5 100644 --- a/apiserver/plane/db/models/project.py +++ b/apiserver/plane/db/models/project.py @@ -4,9 +4,6 @@ from uuid import uuid4 # Django imports from django.db import models from django.conf import settings -from django.template.defaultfilters import slugify -from django.db.models.signals import post_save -from django.dispatch import receiver from django.core.validators import MinValueValidator, MaxValueValidator # Modeule imports diff --git a/apiserver/plane/middleware/user_middleware.py b/apiserver/plane/middleware/user_middleware.py deleted file mode 100644 index 60dee9b73..000000000 --- a/apiserver/plane/middleware/user_middleware.py +++ /dev/null @@ -1,33 +0,0 @@ -import jwt -import pytz -from django.conf import settings -from django.utils import timezone -from plane.db.models import User - - -class UserMiddleware(object): - - def __init__(self, get_response): - self.get_response = get_response - - def __call__(self, request): - - try: - if request.headers.get("Authorization"): - authorization_header = request.headers.get("Authorization") - access_token = authorization_header.split(" ")[1] - decoded = jwt.decode( - access_token, settings.SECRET_KEY, algorithms=["HS256"] - ) - id = decoded['user_id'] - user = User.objects.get(id=id) - user.last_active = timezone.now() - user.token_updated_at = None - user.save() - timezone.activate(pytz.timezone(user.user_timezone)) - except Exception as e: - print(e) - - response = self.get_response(request) - - return response diff --git a/apiserver/plane/settings/staging.py b/apiserver/plane/settings/staging.py index f776afd91..fe4732343 100644 --- a/apiserver/plane/settings/staging.py +++ b/apiserver/plane/settings/staging.py @@ -4,7 +4,6 @@ import ssl import certifi import dj_database_url -from urllib.parse import urlparse import sentry_sdk from sentry_sdk.integrations.django import DjangoIntegration diff --git a/apiserver/plane/tests/__init__.py b/apiserver/plane/tests/__init__.py index f77d5060c..0a0e47b0b 100644 --- a/apiserver/plane/tests/__init__.py +++ b/apiserver/plane/tests/__init__.py @@ -1 +1 @@ -from .api import * \ No newline at end of file +from .api import * diff --git a/apiserver/plane/urls.py b/apiserver/plane/urls.py index 2b83ef8cf..90643749c 100644 --- a/apiserver/plane/urls.py +++ b/apiserver/plane/urls.py @@ -2,16 +2,13 @@ """ -# from django.contrib import admin from django.urls import path, include, re_path from django.views.generic import TemplateView from django.conf import settings -# from django.conf.urls.static import static urlpatterns = [ - # path("admin/", admin.site.urls), path("", TemplateView.as_view(template_name="index.html")), path("api/", include("plane.api.urls")), path("", include("plane.web.urls")), diff --git a/apiserver/plane/utils/analytics_plot.py b/apiserver/plane/utils/analytics_plot.py index 074eaae30..259ab4b63 100644 --- a/apiserver/plane/utils/analytics_plot.py +++ b/apiserver/plane/utils/analytics_plot.py @@ -81,7 +81,6 @@ def burndown_plot(queryset, slug, project_id, cycle_id=None, module_id=None): # Total Issues in Cycle or Module total_issues = queryset.total_issues - if cycle_id: # Get all dates between the two dates date_range = [ @@ -103,7 +102,7 @@ def burndown_plot(queryset, slug, project_id, cycle_id=None, module_id=None): .values("date", "total_completed") .order_by("date") ) - + if module_id: # Get all dates between the two dates date_range = [ @@ -126,18 +125,15 @@ def burndown_plot(queryset, slug, project_id, cycle_id=None, module_id=None): .order_by("date") ) - for date in date_range: cumulative_pending_issues = total_issues total_completed = 0 total_completed = sum( - [ - item["total_completed"] - for item in completed_issues_distribution - if item["date"] is not None and item["date"] <= date - ] + item["total_completed"] + for item in completed_issues_distribution + if item["date"] is not None and item["date"] <= date ) cumulative_pending_issues -= total_completed chart_data[str(date)] = cumulative_pending_issues - return chart_data \ No newline at end of file + return chart_data diff --git a/apiserver/plane/utils/grouper.py b/apiserver/plane/utils/grouper.py index 9e134042a..853874b31 100644 --- a/apiserver/plane/utils/grouper.py +++ b/apiserver/plane/utils/grouper.py @@ -127,7 +127,7 @@ def group_results(results_data, group_by, sub_group_by=False): return main_responsive_dict else: - response_dict = dict() + response_dict = {} if group_by == "priority": response_dict = { diff --git a/apiserver/plane/utils/imports.py b/apiserver/plane/utils/imports.py index 1a0d2924e..5f9f1c98c 100644 --- a/apiserver/plane/utils/imports.py +++ b/apiserver/plane/utils/imports.py @@ -17,4 +17,4 @@ def import_submodules(context, root_module, path): for k, v in six.iteritems(vars(module)): if not k.startswith('_'): context[k] = v - context[module_name] = module \ No newline at end of file + context[module_name] = module diff --git a/apiserver/plane/utils/ip_address.py b/apiserver/plane/utils/ip_address.py index 29a2fa520..06ca4353d 100644 --- a/apiserver/plane/utils/ip_address.py +++ b/apiserver/plane/utils/ip_address.py @@ -4,4 +4,4 @@ def get_client_ip(request): ip = x_forwarded_for.split(',')[0] else: ip = request.META.get('REMOTE_ADDR') - return ip \ No newline at end of file + return ip diff --git a/apiserver/plane/utils/issue_filters.py b/apiserver/plane/utils/issue_filters.py index cc466c847..75437fbee 100644 --- a/apiserver/plane/utils/issue_filters.py +++ b/apiserver/plane/utils/issue_filters.py @@ -327,7 +327,7 @@ def filter_start_target_date_issues(params, filter, method): def issue_filters(query_params, method): - filter = dict() + filter = {} ISSUE_FILTER = { "state": filter_state, diff --git a/apiserver/plane/utils/markdown.py b/apiserver/plane/utils/markdown.py index 15d5b4dce..188c54fec 100644 --- a/apiserver/plane/utils/markdown.py +++ b/apiserver/plane/utils/markdown.py @@ -1,3 +1,3 @@ import mistune -markdown = mistune.Markdown() \ No newline at end of file +markdown = mistune.Markdown() diff --git a/apiserver/plane/utils/paginator.py b/apiserver/plane/utils/paginator.py index b3c50abd1..544ed8fef 100644 --- a/apiserver/plane/utils/paginator.py +++ b/apiserver/plane/utils/paginator.py @@ -21,12 +21,7 @@ class Cursor: ) def __repr__(self): - return "<{}: value={} offset={} is_prev={}>".format( - type(self).__name__, - self.value, - self.offset, - int(self.is_prev), - ) + return f"{type(self).__name__,}: value={self.value} offset={self.offset}, is_prev={int(self.is_prev)}" def __bool__(self): return bool(self.has_results) @@ -176,10 +171,6 @@ class BasePaginator: **paginator_kwargs, ): """Paginate the request""" - assert (paginator and not paginator_kwargs) or ( - paginator_cls and paginator_kwargs - ) - per_page = self.get_per_page(request, default_per_page, max_per_page) # Convert the cursor value to integer and float from string