refactor: exception handling (#2454)

* chore: implemented global exception handler

* dev: remove something went wrong

* chore: exception handling cleanup

* chore: changed the status code

* chore: added status 500 internal server error

---------

Co-authored-by: pablohashescobar <nikhilschacko@gmail.com>
This commit is contained in:
Bavisetti Narayan 2023-10-17 14:38:06 +05:30 committed by GitHub
parent 46d34263f0
commit 0b79f8687e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 5866 additions and 7889 deletions

View File

@ -1,6 +1,3 @@
# Django imports
from django.db import IntegrityError
# Third party imports # Third party imports
from rest_framework import serializers from rest_framework import serializers

View File

@ -23,7 +23,6 @@ class AnalyticsEndpoint(BaseAPIView):
] ]
def get(self, request, slug): def get(self, request, slug):
try:
x_axis = request.GET.get("x_axis", False) x_axis = request.GET.get("x_axis", False)
y_axis = request.GET.get("y_axis", False) y_axis = request.GET.get("y_axis", False)
segment = request.GET.get("segment", False) segment = request.GET.get("segment", False)
@ -126,9 +125,7 @@ class AnalyticsEndpoint(BaseAPIView):
) )
cycle_details = {} cycle_details = {}
if x_axis in ["issue_cycle__cycle_id"] or segment in [ if x_axis in ["issue_cycle__cycle_id"] or segment in ["issue_cycle__cycle_id"]:
"issue_cycle__cycle_id"
]:
cycle_details = ( cycle_details = (
Issue.issue_objects.filter( Issue.issue_objects.filter(
workspace__slug=slug, workspace__slug=slug,
@ -176,13 +173,6 @@ class AnalyticsEndpoint(BaseAPIView):
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class AnalyticViewViewset(BaseViewSet): class AnalyticViewViewset(BaseViewSet):
permission_classes = [ permission_classes = [
@ -207,10 +197,7 @@ class SavedAnalyticEndpoint(BaseAPIView):
] ]
def get(self, request, slug, analytic_id): def get(self, request, slug, analytic_id):
try: analytic_view = AnalyticView.objects.get(pk=analytic_id, workspace__slug=slug)
analytic_view = AnalyticView.objects.get(
pk=analytic_id, workspace__slug=slug
)
filter = analytic_view.query filter = analytic_view.query
queryset = Issue.issue_objects.filter(**filter) queryset = Issue.issue_objects.filter(**filter)
@ -234,18 +221,6 @@ class SavedAnalyticEndpoint(BaseAPIView):
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except AnalyticView.DoesNotExist:
return Response(
{"error": "Analytic View Does not exist"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class ExportAnalyticsEndpoint(BaseAPIView): class ExportAnalyticsEndpoint(BaseAPIView):
permission_classes = [ permission_classes = [
@ -253,12 +228,10 @@ class ExportAnalyticsEndpoint(BaseAPIView):
] ]
def post(self, request, slug): def post(self, request, slug):
try:
x_axis = request.data.get("x_axis", False) x_axis = request.data.get("x_axis", False)
y_axis = request.data.get("y_axis", False) y_axis = request.data.get("y_axis", False)
segment = request.data.get("segment", False) segment = request.data.get("segment", False)
valid_xaxis_segment = [ valid_xaxis_segment = [
"state_id", "state_id",
"state__group", "state__group",
@ -302,7 +275,6 @@ class ExportAnalyticsEndpoint(BaseAPIView):
status=status.HTTP_400_BAD_REQUEST, status=status.HTTP_400_BAD_REQUEST,
) )
analytic_export_task.delay( analytic_export_task.delay(
email=request.user.email, data=request.data, slug=slug email=request.user.email, data=request.data, slug=slug
) )
@ -313,12 +285,6 @@ class ExportAnalyticsEndpoint(BaseAPIView):
}, },
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class DefaultAnalyticsEndpoint(BaseAPIView): class DefaultAnalyticsEndpoint(BaseAPIView):
@ -327,7 +293,6 @@ class DefaultAnalyticsEndpoint(BaseAPIView):
] ]
def get(self, request, slug): def get(self, request, slug):
try:
filters = issue_filters(request.GET, "GET") filters = issue_filters(request.GET, "GET")
base_issues = Issue.issue_objects.filter(workspace__slug=slug, **filters) base_issues = Issue.issue_objects.filter(workspace__slug=slug, **filters)
@ -342,9 +307,7 @@ class DefaultAnalyticsEndpoint(BaseAPIView):
) )
open_issues_groups = ["backlog", "unstarted", "started"] open_issues_groups = ["backlog", "unstarted", "started"]
open_issues_queryset = state_groups.filter( open_issues_queryset = state_groups.filter(state__group__in=open_issues_groups)
state__group__in=open_issues_groups
)
open_issues = open_issues_queryset.count() open_issues = open_issues_queryset.count()
open_issues_classified = ( open_issues_classified = (
@ -399,9 +362,9 @@ class DefaultAnalyticsEndpoint(BaseAPIView):
.order_by("-count") .order_by("-count")
) )
open_estimate_sum = open_issues_queryset.aggregate( open_estimate_sum = open_issues_queryset.aggregate(sum=Sum("estimate_point"))[
sum=Sum("estimate_point") "sum"
)["sum"] ]
total_estimate_sum = base_issues.aggregate(sum=Sum("estimate_point"))["sum"] total_estimate_sum = base_issues.aggregate(sum=Sum("estimate_point"))["sum"]
return Response( return Response(
@ -419,10 +382,3 @@ class DefaultAnalyticsEndpoint(BaseAPIView):
}, },
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong. Please try again later."},
status=status.HTTP_400_BAD_REQUEST,
)

View File

@ -14,7 +14,6 @@ from plane.api.serializers import APITokenSerializer
class ApiTokenEndpoint(BaseAPIView): class ApiTokenEndpoint(BaseAPIView):
def post(self, request): def post(self, request):
try:
label = request.data.get("label", str(uuid4().hex)) label = request.data.get("label", str(uuid4().hex))
workspace = request.data.get("workspace", False) workspace = request.data.get("workspace", False)
@ -34,37 +33,15 @@ class ApiTokenEndpoint(BaseAPIView):
status=status.HTTP_201_CREATED, status=status.HTTP_201_CREATED,
) )
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def get(self, request): def get(self, request):
try:
api_tokens = APIToken.objects.filter(user=request.user) api_tokens = APIToken.objects.filter(user=request.user)
serializer = APITokenSerializer(api_tokens, many=True) serializer = APITokenSerializer(api_tokens, many=True)
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def delete(self, request, pk): def delete(self, request, pk):
try:
api_token = APIToken.objects.get(pk=pk) api_token = APIToken.objects.get(pk=pk)
api_token.delete() api_token.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except APIToken.DoesNotExist:
return Response(
{"error": "Token does not exists"}, status=status.HTTP_400_BAD_REQUEST
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)

View File

@ -18,7 +18,6 @@ class FileAssetEndpoint(BaseAPIView):
""" """
def get(self, request, workspace_id, asset_key): def get(self, request, workspace_id, asset_key):
try:
asset_key = str(workspace_id) + "/" + asset_key asset_key = str(workspace_id) + "/" + asset_key
files = FileAsset.objects.filter(asset=asset_key) files = FileAsset.objects.filter(asset=asset_key)
if files.exists(): if files.exists():
@ -26,16 +25,9 @@ class FileAssetEndpoint(BaseAPIView):
return Response({"data": serializer.data, "status": True}, status=status.HTTP_200_OK) return Response({"data": serializer.data, "status": True}, status=status.HTTP_200_OK)
else: else:
return Response({"error": "Asset key does not exist", "status": False}, status=status.HTTP_200_OK) return Response({"error": "Asset key does not exist", "status": False}, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def post(self, request, slug): def post(self, request, slug):
try:
serializer = FileAssetSerializer(data=request.data) serializer = FileAssetSerializer(data=request.data)
if serializer.is_valid(): if serializer.is_valid():
# Get the workspace # Get the workspace
@ -43,17 +35,9 @@ class FileAssetEndpoint(BaseAPIView):
serializer.save(workspace_id=workspace.id) serializer.save(workspace_id=workspace.id)
return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except Workspace.DoesNotExist:
return Response({"error": "Workspace does not exist"}, status=status.HTTP_400_BAD_REQUEST)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def delete(self, request, workspace_id, asset_key): def delete(self, request, workspace_id, asset_key):
try:
asset_key = str(workspace_id) + "/" + asset_key asset_key = str(workspace_id) + "/" + asset_key
file_asset = FileAsset.objects.get(asset=asset_key) file_asset = FileAsset.objects.get(asset=asset_key)
# Delete the file from storage # Delete the file from storage
@ -61,65 +45,31 @@ class FileAssetEndpoint(BaseAPIView):
# Delete the file object # Delete the file object
file_asset.delete() file_asset.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except FileAsset.DoesNotExist:
return Response(
{"error": "File Asset doesn't exist"}, status=status.HTTP_404_NOT_FOUND
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class UserAssetsEndpoint(BaseAPIView): class UserAssetsEndpoint(BaseAPIView):
parser_classes = (MultiPartParser, FormParser) parser_classes = (MultiPartParser, FormParser)
def get(self, request, asset_key): def get(self, request, asset_key):
try:
files = FileAsset.objects.filter(asset=asset_key, created_by=request.user) files = FileAsset.objects.filter(asset=asset_key, created_by=request.user)
if files.exists(): if files.exists():
serializer = FileAssetSerializer(files, context={"request": request}) serializer = FileAssetSerializer(files, context={"request": request})
return Response({"data": serializer.data, "status": True}, status=status.HTTP_200_OK) return Response({"data": serializer.data, "status": True}, status=status.HTTP_200_OK)
else: else:
return Response({"error": "Asset key does not exist", "status": False}, status=status.HTTP_200_OK) return Response({"error": "Asset key does not exist", "status": False}, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def post(self, request): def post(self, request):
try:
serializer = FileAssetSerializer(data=request.data) serializer = FileAssetSerializer(data=request.data)
if serializer.is_valid(): if serializer.is_valid():
serializer.save() serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def delete(self, request, asset_key): def delete(self, request, asset_key):
try:
file_asset = FileAsset.objects.get(asset=asset_key, created_by=request.user) file_asset = FileAsset.objects.get(asset=asset_key, created_by=request.user)
# Delete the file from storage # Delete the file from storage
file_asset.asset.delete(save=False) file_asset.asset.delete(save=False)
# Delete the file object # Delete the file object
file_asset.delete() file_asset.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except FileAsset.DoesNotExist:
return Response(
{"error": "File Asset doesn't exist"}, status=status.HTTP_404_NOT_FOUND
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)

View File

@ -127,7 +127,6 @@ class ResetPasswordEndpoint(BaseAPIView):
class ChangePasswordEndpoint(BaseAPIView): class ChangePasswordEndpoint(BaseAPIView):
def post(self, request): def post(self, request):
try:
serializer = ChangePasswordSerializer(data=request.data) serializer = ChangePasswordSerializer(data=request.data)
user = User.objects.get(pk=request.user.id) user = User.objects.get(pk=request.user.id)
@ -150,9 +149,3 @@ class ChangePasswordEndpoint(BaseAPIView):
return Response(response) return Response(response)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)

View File

@ -40,7 +40,6 @@ class SignUpEndpoint(BaseAPIView):
permission_classes = (AllowAny,) permission_classes = (AllowAny,)
def post(self, request): def post(self, request):
try:
if not settings.ENABLE_SIGNUP: if not settings.ENABLE_SIGNUP:
return Response( return Response(
{ {
@ -118,19 +117,11 @@ class SignUpEndpoint(BaseAPIView):
return Response(data, status=status.HTTP_200_OK) return Response(data, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class SignInEndpoint(BaseAPIView): class SignInEndpoint(BaseAPIView):
permission_classes = (AllowAny,) permission_classes = (AllowAny,)
def post(self, request): def post(self, request):
try:
email = request.data.get("email", False) email = request.data.get("email", False)
password = request.data.get("password", False) password = request.data.get("password", False)
@ -214,27 +205,15 @@ class SignInEndpoint(BaseAPIView):
return Response(data, status=status.HTTP_200_OK) return Response(data, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{
"error": "Something went wrong. Please try again later or contact the support team."
},
status=status.HTTP_400_BAD_REQUEST,
)
class SignOutEndpoint(BaseAPIView): class SignOutEndpoint(BaseAPIView):
def post(self, request): def post(self, request):
try:
refresh_token = request.data.get("refresh_token", False) refresh_token = request.data.get("refresh_token", False)
if not refresh_token: if not refresh_token:
capture_message("No refresh token provided") capture_message("No refresh token provided")
return Response( return Response(
{ {"error": "No refresh token provided"},
"error": "Something went wrong. Please try again later or contact the support team."
},
status=status.HTTP_400_BAD_REQUEST, status=status.HTTP_400_BAD_REQUEST,
) )
@ -248,14 +227,6 @@ class SignOutEndpoint(BaseAPIView):
token = RefreshToken(refresh_token) token = RefreshToken(refresh_token)
token.blacklist() token.blacklist()
return Response({"message": "success"}, status=status.HTTP_200_OK) return Response({"message": "success"}, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{
"error": "Something went wrong. Please try again later or contact the support team."
},
status=status.HTTP_400_BAD_REQUEST,
)
class MagicSignInGenerateEndpoint(BaseAPIView): class MagicSignInGenerateEndpoint(BaseAPIView):
@ -264,7 +235,6 @@ class MagicSignInGenerateEndpoint(BaseAPIView):
] ]
def post(self, request): def post(self, request):
try:
email = request.data.get("email", False) email = request.data.get("email", False)
if not email: if not email:
@ -321,17 +291,6 @@ class MagicSignInGenerateEndpoint(BaseAPIView):
magic_link.delay(email, key, token, current_site) magic_link.delay(email, key, token, current_site)
return Response({"key": key}, status=status.HTTP_200_OK) return Response({"key": key}, status=status.HTTP_200_OK)
except ValidationError:
return Response(
{"error": "Please provide a valid email address."},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class MagicSignInEndpoint(BaseAPIView): class MagicSignInEndpoint(BaseAPIView):
@ -340,7 +299,6 @@ class MagicSignInEndpoint(BaseAPIView):
] ]
def post(self, request): def post(self, request):
try:
user_token = request.data.get("token", "").strip() user_token = request.data.get("token", "").strip()
key = request.data.get("key", False).strip().lower() key = request.data.get("key", False).strip().lower()
@ -377,9 +335,7 @@ class MagicSignInEndpoint(BaseAPIView):
"user": {"email": email, "id": str(user.id)}, "user": {"email": email, "id": str(user.id)},
"device_ctx": { "device_ctx": {
"ip": request.META.get("REMOTE_ADDR"), "ip": request.META.get("REMOTE_ADDR"),
"user_agent": request.META.get( "user_agent": request.META.get("HTTP_USER_AGENT"),
"HTTP_USER_AGENT"
),
}, },
"event_type": "SIGN_IN", "event_type": "SIGN_IN",
}, },
@ -407,9 +363,7 @@ class MagicSignInEndpoint(BaseAPIView):
"user": {"email": email, "id": str(user.id)}, "user": {"email": email, "id": str(user.id)},
"device_ctx": { "device_ctx": {
"ip": request.META.get("REMOTE_ADDR"), "ip": request.META.get("REMOTE_ADDR"),
"user_agent": request.META.get( "user_agent": request.META.get("HTTP_USER_AGENT"),
"HTTP_USER_AGENT"
),
}, },
"event_type": "SIGN_UP", "event_type": "SIGN_UP",
}, },
@ -441,10 +395,3 @@ class MagicSignInEndpoint(BaseAPIView):
{"error": "The magic code/link has expired please try again"}, {"error": "The magic code/link has expired please try again"},
status=status.HTTP_400_BAD_REQUEST, status=status.HTTP_400_BAD_REQUEST,
) )
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)

View File

@ -5,10 +5,14 @@ import zoneinfo
from django.urls import resolve from django.urls import resolve
from django.conf import settings from django.conf import settings
from django.utils import timezone from django.utils import timezone
# Third part imports from django.db import IntegrityError
from django.core.exceptions import ObjectDoesNotExist, ValidationError
# Third part imports
from rest_framework import status
from rest_framework import status from rest_framework import status
from rest_framework.viewsets import ModelViewSet from rest_framework.viewsets import ModelViewSet
from rest_framework.response import Response
from rest_framework.exceptions import APIException from rest_framework.exceptions import APIException
from rest_framework.views import APIView from rest_framework.views import APIView
from rest_framework.filters import SearchFilter from rest_framework.filters import SearchFilter
@ -33,8 +37,6 @@ class TimezoneMixin:
timezone.deactivate() timezone.deactivate()
class BaseViewSet(TimezoneMixin, ModelViewSet, BasePaginator): class BaseViewSet(TimezoneMixin, ModelViewSet, BasePaginator):
model = None model = None
@ -59,7 +61,35 @@ class BaseViewSet(TimezoneMixin, ModelViewSet, BasePaginator):
capture_exception(e) capture_exception(e)
raise APIException("Please check the view", status.HTTP_400_BAD_REQUEST) raise APIException("Please check the view", status.HTTP_400_BAD_REQUEST)
def handle_exception(self, exc):
"""
Handle any exception that occurs, by returning an appropriate response,
or re-raising the error.
"""
try:
response = super().handle_exception(exc)
return response
except Exception as e:
if isinstance(e, IntegrityError):
return Response({"error": "The payload is not valid"}, status=status.HTTP_400_BAD_REQUEST)
if isinstance(e, ValidationError):
return Response({"error": "Please provide valid detail"}, status=status.HTTP_400_BAD_REQUEST)
if isinstance(e, ObjectDoesNotExist):
model_name = str(exc).split(" matching query does not exist.")[0]
return Response({"error": f"{model_name} does not exist."}, status=status.HTTP_404_NOT_FOUND)
if isinstance(e, KeyError):
capture_exception(e)
return Response({"error": f"key {e} does not exist"}, status=status.HTTP_400_BAD_REQUEST)
capture_exception(e)
return Response({"error": "Something went wrong please try again later"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
try:
response = super().dispatch(request, *args, **kwargs) response = super().dispatch(request, *args, **kwargs)
if settings.DEBUG: if settings.DEBUG:
@ -70,6 +100,10 @@ class BaseViewSet(TimezoneMixin, ModelViewSet, BasePaginator):
) )
return response return response
except Exception as exc:
response = self.handle_exception(exc)
return exc
@property @property
def workspace_slug(self): def workspace_slug(self):
return self.kwargs.get("slug", None) return self.kwargs.get("slug", None)
@ -104,7 +138,35 @@ class BaseAPIView(TimezoneMixin, APIView, BasePaginator):
queryset = backend().filter_queryset(self.request, queryset, self) queryset = backend().filter_queryset(self.request, queryset, self)
return queryset return queryset
def handle_exception(self, exc):
"""
Handle any exception that occurs, by returning an appropriate response,
or re-raising the error.
"""
try:
response = super().handle_exception(exc)
return response
except Exception as e:
if isinstance(e, IntegrityError):
return Response({"error": "The payload is not valid"}, status=status.HTTP_400_BAD_REQUEST)
if isinstance(e, ValidationError):
return Response({"error": "Please provide valid detail"}, status=status.HTTP_400_BAD_REQUEST)
if isinstance(e, ObjectDoesNotExist):
model_name = str(exc).split(" matching query does not exist.")[0]
return Response({"error": f"{model_name} does not exist."}, status=status.HTTP_404_NOT_FOUND)
if isinstance(e, KeyError):
return Response({"error": f"key {e} does not exist"}, status=status.HTTP_400_BAD_REQUEST)
capture_exception(e)
return Response({"error": "Something went wrong please try again later"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
try:
response = super().dispatch(request, *args, **kwargs) response = super().dispatch(request, *args, **kwargs)
if settings.DEBUG: if settings.DEBUG:
@ -115,6 +177,10 @@ class BaseAPIView(TimezoneMixin, APIView, BasePaginator):
) )
return response return response
except Exception as exc:
response = self.handle_exception(exc)
return exc
@property @property
def workspace_slug(self): def workspace_slug(self):
return self.kwargs.get("slug", None) return self.kwargs.get("slug", None)

View File

@ -20,7 +20,6 @@ class ConfigurationEndpoint(BaseAPIView):
] ]
def get(self, request): def get(self, request):
try:
data = {} data = {}
data["google"] = os.environ.get("GOOGLE_CLIENT_ID", None) data["google"] = os.environ.get("GOOGLE_CLIENT_ID", None)
data["github"] = os.environ.get("GITHUB_CLIENT_ID", None) data["github"] = os.environ.get("GITHUB_CLIENT_ID", None)
@ -32,9 +31,3 @@ class ConfigurationEndpoint(BaseAPIView):
os.environ.get("ENABLE_EMAIL_PASSWORD", "0") == "1" os.environ.get("ENABLE_EMAIL_PASSWORD", "0") == "1"
) )
return Response(data, status=status.HTTP_200_OK) return Response(data, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)

View File

@ -2,7 +2,6 @@
import json import json
# Django imports # Django imports
from django.db import IntegrityError
from django.db.models import ( from django.db.models import (
OuterRef, OuterRef,
Func, Func,
@ -62,7 +61,6 @@ class CycleViewSet(BaseViewSet):
project_id=self.kwargs.get("project_id"), owned_by=self.request.user project_id=self.kwargs.get("project_id"), owned_by=self.request.user
) )
def get_queryset(self): def get_queryset(self):
subquery = CycleFavorite.objects.filter( subquery = CycleFavorite.objects.filter(
user=self.request.user, user=self.request.user,
@ -177,7 +175,6 @@ class CycleViewSet(BaseViewSet):
) )
def list(self, request, slug, project_id): def list(self, request, slug, project_id):
try:
queryset = self.get_queryset() queryset = self.get_queryset()
cycle_view = request.GET.get("cycle_view", "all") cycle_view = request.GET.get("cycle_view", "all")
order_by = request.GET.get("order_by", "sort_order") order_by = request.GET.get("order_by", "sort_order")
@ -325,15 +322,7 @@ class CycleViewSet(BaseViewSet):
CycleSerializer(queryset, many=True).data, status=status.HTTP_200_OK CycleSerializer(queryset, many=True).data, status=status.HTTP_200_OK
) )
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def create(self, request, slug, project_id): def create(self, request, slug, project_id):
try:
if ( if (
request.data.get("start_date", None) is None request.data.get("start_date", None) is None
and request.data.get("end_date", None) is None and request.data.get("end_date", None) is None
@ -356,18 +345,9 @@ class CycleViewSet(BaseViewSet):
}, },
status=status.HTTP_400_BAD_REQUEST, status=status.HTTP_400_BAD_REQUEST,
) )
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def partial_update(self, request, slug, project_id, pk): def partial_update(self, request, slug, project_id, pk):
try: cycle = Cycle.objects.get(workspace__slug=slug, project_id=project_id, pk=pk)
cycle = Cycle.objects.get(
workspace__slug=slug, project_id=project_id, pk=pk
)
request_data = request.data request_data = request.data
@ -390,19 +370,8 @@ class CycleViewSet(BaseViewSet):
serializer.save() serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except Cycle.DoesNotExist:
return Response(
{"error": "Cycle does not exist"}, status=status.HTTP_400_BAD_REQUEST
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def retrieve(self, request, slug, project_id, pk): def retrieve(self, request, slug, project_id, pk):
try:
queryset = self.get_queryset().get(pk=pk) queryset = self.get_queryset().get(pk=pk)
# Assignee Distribution # Assignee Distribution
@ -417,9 +386,7 @@ class CycleViewSet(BaseViewSet):
.annotate(assignee_id=F("assignees__id")) .annotate(assignee_id=F("assignees__id"))
.annotate(avatar=F("assignees__avatar")) .annotate(avatar=F("assignees__avatar"))
.annotate(display_name=F("assignees__display_name")) .annotate(display_name=F("assignees__display_name"))
.values( .values("first_name", "last_name", "assignee_id", "avatar", "display_name")
"first_name", "last_name", "assignee_id", "avatar", "display_name"
)
.annotate( .annotate(
total_issues=Count( total_issues=Count(
"assignee_id", "assignee_id",
@ -505,27 +472,14 @@ class CycleViewSet(BaseViewSet):
data, data,
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except Cycle.DoesNotExist:
return Response(
{"error": "Cycle Does not exists"}, status=status.HTTP_400_BAD_REQUEST
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def destroy(self, request, slug, project_id, pk): def destroy(self, request, slug, project_id, pk):
try:
cycle_issues = list( cycle_issues = list(
CycleIssue.objects.filter(cycle_id=self.kwargs.get("pk")).values_list( CycleIssue.objects.filter(cycle_id=self.kwargs.get("pk")).values_list(
"issue", flat=True "issue", flat=True
) )
) )
cycle = Cycle.objects.get( cycle = Cycle.objects.get(workspace__slug=slug, project_id=project_id, pk=pk)
workspace__slug=slug, project_id=project_id, pk=pk
)
# Delete the cycle # Delete the cycle
cycle.delete() cycle.delete()
issue_activity.delay( issue_activity.delay(
@ -543,12 +497,6 @@ class CycleViewSet(BaseViewSet):
epoch=int(timezone.now().timestamp()), epoch=int(timezone.now().timestamp()),
) )
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class CycleIssueViewSet(BaseViewSet): class CycleIssueViewSet(BaseViewSet):
@ -594,7 +542,6 @@ class CycleIssueViewSet(BaseViewSet):
@method_decorator(gzip_page) @method_decorator(gzip_page)
def list(self, request, slug, project_id, cycle_id): def list(self, request, slug, project_id, cycle_id):
try:
order_by = request.GET.get("order_by", "created_at") order_by = request.GET.get("order_by", "created_at")
group_by = request.GET.get("group_by", False) group_by = request.GET.get("group_by", False)
sub_group_by = request.GET.get("sub_group_by", False) sub_group_by = request.GET.get("sub_group_by", False)
@ -625,9 +572,7 @@ class CycleIssueViewSet(BaseViewSet):
.values("count") .values("count")
) )
.annotate( .annotate(
attachment_count=IssueAttachment.objects.filter( attachment_count=IssueAttachment.objects.filter(issue=OuterRef("id"))
issue=OuterRef("id")
)
.order_by() .order_by()
.annotate(count=Func(F("id"), function="Count")) .annotate(count=Func(F("id"), function="Count"))
.values("count") .values("count")
@ -652,15 +597,8 @@ class CycleIssueViewSet(BaseViewSet):
issues_data, issues_data,
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def create(self, request, slug, project_id, cycle_id): def create(self, request, slug, project_id, cycle_id):
try:
issues = request.data.get("issues", []) issues = request.data.get("issues", [])
if not len(issues): if not len(issues):
@ -751,20 +689,10 @@ class CycleIssueViewSet(BaseViewSet):
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except Cycle.DoesNotExist:
return Response(
{"error": "Cycle not found"}, status=status.HTTP_404_NOT_FOUND
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def destroy(self, request, slug, project_id, cycle_id, pk): def destroy(self, request, slug, project_id, cycle_id, pk):
try: cycle_issue = CycleIssue.objects.get(
cycle_issue = CycleIssue.objects.get(pk=pk, workspace__slug=slug, project_id=project_id, cycle_id=cycle_id) pk=pk, workspace__slug=slug, project_id=project_id, cycle_id=cycle_id
)
issue_id = cycle_issue.issue_id issue_id = cycle_issue.issue_id
cycle_issue.delete() cycle_issue.delete()
issue_activity.delay( issue_activity.delay(
@ -782,9 +710,6 @@ class CycleIssueViewSet(BaseViewSet):
epoch=int(timezone.now().timestamp()), epoch=int(timezone.now().timestamp()),
) )
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except Exception as e:
capture_exception(e)
return Response({"error": "Something went wrong please try again later"}, status=status.HTTP_400_BAD_REQUEST)
class CycleDateCheckEndpoint(BaseAPIView): class CycleDateCheckEndpoint(BaseAPIView):
@ -793,7 +718,6 @@ class CycleDateCheckEndpoint(BaseAPIView):
] ]
def post(self, request, slug, project_id): def post(self, request, slug, project_id):
try:
start_date = request.data.get("start_date", False) start_date = request.data.get("start_date", False)
end_date = request.data.get("end_date", False) end_date = request.data.get("end_date", False)
cycle_id = request.data.get("cycle_id") cycle_id = request.data.get("cycle_id")
@ -822,12 +746,6 @@ class CycleDateCheckEndpoint(BaseAPIView):
) )
else: else:
return Response({"status": True}, status=status.HTTP_200_OK) return Response({"status": True}, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class CycleFavoriteViewSet(BaseViewSet): class CycleFavoriteViewSet(BaseViewSet):
@ -844,33 +762,13 @@ class CycleFavoriteViewSet(BaseViewSet):
) )
def create(self, request, slug, project_id): def create(self, request, slug, project_id):
try:
serializer = CycleFavoriteSerializer(data=request.data) serializer = CycleFavoriteSerializer(data=request.data)
if serializer.is_valid(): if serializer.is_valid():
serializer.save(user=request.user, project_id=project_id) serializer.save(user=request.user, project_id=project_id)
return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except IntegrityError as e:
if "already exists" in str(e):
return Response(
{"error": "The cycle is already added to favorites"},
status=status.HTTP_410_GONE,
)
else:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def destroy(self, request, slug, project_id, cycle_id): def destroy(self, request, slug, project_id, cycle_id):
try:
cycle_favorite = CycleFavorite.objects.get( cycle_favorite = CycleFavorite.objects.get(
project=project_id, project=project_id,
user=request.user, user=request.user,
@ -879,17 +777,6 @@ class CycleFavoriteViewSet(BaseViewSet):
) )
cycle_favorite.delete() cycle_favorite.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except CycleFavorite.DoesNotExist:
return Response(
{"error": "Cycle is not in favorites"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class TransferCycleIssueEndpoint(BaseAPIView): class TransferCycleIssueEndpoint(BaseAPIView):
@ -898,7 +785,6 @@ class TransferCycleIssueEndpoint(BaseAPIView):
] ]
def post(self, request, slug, project_id, cycle_id): def post(self, request, slug, project_id, cycle_id):
try:
new_cycle_id = request.data.get("new_cycle_id", False) new_cycle_id = request.data.get("new_cycle_id", False)
if not new_cycle_id: if not new_cycle_id:
@ -939,14 +825,3 @@ class TransferCycleIssueEndpoint(BaseAPIView):
) )
return Response({"message": "Success"}, status=status.HTTP_200_OK) return Response({"message": "Success"}, status=status.HTTP_200_OK)
except Cycle.DoesNotExist:
return Response(
{"error": "New Cycle Does not exist"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)

View File

@ -1,6 +1,3 @@
# Django imports
from django.db import IntegrityError
# Third party imports # Third party imports
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework import status from rest_framework import status
@ -23,7 +20,6 @@ class ProjectEstimatePointEndpoint(BaseAPIView):
] ]
def get(self, request, slug, project_id): def get(self, request, slug, project_id):
try:
project = Project.objects.get(workspace__slug=slug, pk=project_id) project = Project.objects.get(workspace__slug=slug, pk=project_id)
if project.estimate_id is not None: if project.estimate_id is not None:
estimate_points = EstimatePoint.objects.filter( estimate_points = EstimatePoint.objects.filter(
@ -34,12 +30,6 @@ class ProjectEstimatePointEndpoint(BaseAPIView):
serializer = EstimatePointSerializer(estimate_points, many=True) serializer = EstimatePointSerializer(estimate_points, many=True)
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
return Response([], status=status.HTTP_200_OK) return Response([], status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class BulkEstimatePointEndpoint(BaseViewSet): class BulkEstimatePointEndpoint(BaseViewSet):
@ -50,21 +40,13 @@ class BulkEstimatePointEndpoint(BaseViewSet):
serializer_class = EstimateSerializer serializer_class = EstimateSerializer
def list(self, request, slug, project_id): def list(self, request, slug, project_id):
try:
estimates = Estimate.objects.filter( estimates = Estimate.objects.filter(
workspace__slug=slug, project_id=project_id workspace__slug=slug, project_id=project_id
).prefetch_related("points").select_related("workspace", "project") ).prefetch_related("points").select_related("workspace", "project")
serializer = EstimateReadSerializer(estimates, many=True) serializer = EstimateReadSerializer(estimates, many=True)
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def create(self, request, slug, project_id): def create(self, request, slug, project_id):
try:
if not request.data.get("estimate", False): if not request.data.get("estimate", False):
return Response( return Response(
{"error": "Estimate is required"}, {"error": "Estimate is required"},
@ -84,13 +66,7 @@ class BulkEstimatePointEndpoint(BaseViewSet):
return Response( return Response(
estimate_serializer.errors, status=status.HTTP_400_BAD_REQUEST estimate_serializer.errors, status=status.HTTP_400_BAD_REQUEST
) )
try:
estimate = estimate_serializer.save(project_id=project_id) estimate = estimate_serializer.save(project_id=project_id)
except IntegrityError:
return Response(
{"errror": "Estimate with the name already exists"},
status=status.HTTP_400_BAD_REQUEST,
)
estimate_points = EstimatePoint.objects.bulk_create( estimate_points = EstimatePoint.objects.bulk_create(
[ [
EstimatePoint( EstimatePoint(
@ -120,20 +96,8 @@ class BulkEstimatePointEndpoint(BaseViewSet):
}, },
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except Estimate.DoesNotExist:
return Response(
{"error": "Estimate does not exist"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def retrieve(self, request, slug, project_id, estimate_id): def retrieve(self, request, slug, project_id, estimate_id):
try:
estimate = Estimate.objects.get( estimate = Estimate.objects.get(
pk=estimate_id, workspace__slug=slug, project_id=project_id pk=estimate_id, workspace__slug=slug, project_id=project_id
) )
@ -142,19 +106,8 @@ class BulkEstimatePointEndpoint(BaseViewSet):
serializer.data, serializer.data,
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except Estimate.DoesNotExist:
return Response(
{"error": "Estimate does not exist"}, status=status.HTTP_400_BAD_REQUEST
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def partial_update(self, request, slug, project_id, estimate_id): def partial_update(self, request, slug, project_id, estimate_id):
try:
if not request.data.get("estimate", False): if not request.data.get("estimate", False):
return Response( return Response(
{"error": "Estimate is required"}, {"error": "Estimate is required"},
@ -176,13 +129,8 @@ class BulkEstimatePointEndpoint(BaseViewSet):
return Response( return Response(
estimate_serializer.errors, status=status.HTTP_400_BAD_REQUEST estimate_serializer.errors, status=status.HTTP_400_BAD_REQUEST
) )
try:
estimate = estimate_serializer.save() estimate = estimate_serializer.save()
except IntegrityError:
return Response(
{"errror": "Estimate with the name already exists"},
status=status.HTTP_400_BAD_REQUEST,
)
estimate_points_data = request.data.get("estimate_points", []) estimate_points_data = request.data.get("estimate_points", [])
@ -209,15 +157,9 @@ class BulkEstimatePointEndpoint(BaseViewSet):
) )
updated_estimate_points.append(estimate_point) updated_estimate_points.append(estimate_point)
try:
EstimatePoint.objects.bulk_update( EstimatePoint.objects.bulk_update(
updated_estimate_points, ["value"], batch_size=10, updated_estimate_points, ["value"], batch_size=10,
) )
except IntegrityError as e:
return Response(
{"error": "Values need to be unique for each key"},
status=status.HTTP_400_BAD_REQUEST,
)
estimate_point_serializer = EstimatePointSerializer(estimate_points, many=True) estimate_point_serializer = EstimatePointSerializer(estimate_points, many=True)
return Response( return Response(
@ -227,27 +169,10 @@ class BulkEstimatePointEndpoint(BaseViewSet):
}, },
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except Estimate.DoesNotExist:
return Response(
{"error": "Estimate does not exist"}, status=status.HTTP_400_BAD_REQUEST
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def destroy(self, request, slug, project_id, estimate_id): def destroy(self, request, slug, project_id, estimate_id):
try:
estimate = Estimate.objects.get( estimate = Estimate.objects.get(
pk=estimate_id, workspace__slug=slug, project_id=project_id pk=estimate_id, workspace__slug=slug, project_id=project_id
) )
estimate.delete() estimate.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)

View File

@ -20,7 +20,6 @@ class ExportIssuesEndpoint(BaseAPIView):
serializer_class = ExporterHistorySerializer serializer_class = ExporterHistorySerializer
def post(self, request, slug): def post(self, request, slug):
try:
# Get the workspace # Get the workspace
workspace = Workspace.objects.get(slug=slug) workspace = Workspace.objects.get(slug=slug)
@ -61,20 +60,8 @@ class ExportIssuesEndpoint(BaseAPIView):
{"error": f"Provider '{provider}' not found."}, {"error": f"Provider '{provider}' not found."},
status=status.HTTP_400_BAD_REQUEST, status=status.HTTP_400_BAD_REQUEST,
) )
except Workspace.DoesNotExist:
return Response(
{"error": "Workspace does not exists"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def get(self, request, slug): def get(self, request, slug):
try:
exporter_history = ExporterHistory.objects.filter( exporter_history = ExporterHistory.objects.filter(
workspace__slug=slug workspace__slug=slug
).select_related("workspace","initiated_by") ).select_related("workspace","initiated_by")
@ -92,9 +79,3 @@ class ExportIssuesEndpoint(BaseAPIView):
{"error": "per_page and cursor are required"}, {"error": "per_page and cursor are required"},
status=status.HTTP_400_BAD_REQUEST, status=status.HTTP_400_BAD_REQUEST,
) )
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)

View File

@ -25,7 +25,6 @@ class GPTIntegrationEndpoint(BaseAPIView):
] ]
def post(self, request, slug, project_id): def post(self, request, slug, project_id):
try:
if not settings.OPENAI_API_KEY or not settings.GPT_ENGINE: if not settings.OPENAI_API_KEY or not settings.GPT_ENGINE:
return Response( return Response(
{"error": "OpenAI API key and engine is required"}, {"error": "OpenAI API key and engine is required"},
@ -64,36 +63,17 @@ class GPTIntegrationEndpoint(BaseAPIView):
}, },
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except (Workspace.DoesNotExist, Project.DoesNotExist) as e:
return Response(
{"error": "Workspace or Project Does not exist"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class ReleaseNotesEndpoint(BaseAPIView): class ReleaseNotesEndpoint(BaseAPIView):
def get(self, request): def get(self, request):
try:
release_notes = get_release_notes() release_notes = get_release_notes()
return Response(release_notes, status=status.HTTP_200_OK) return Response(release_notes, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class UnsplashEndpoint(BaseAPIView): class UnsplashEndpoint(BaseAPIView):
def get(self, request): def get(self, request):
try:
query = request.GET.get("query", False) query = request.GET.get("query", False)
page = request.GET.get("page", 1) page = request.GET.get("page", 1)
per_page = request.GET.get("per_page", 20) per_page = request.GET.get("per_page", 20)
@ -110,9 +90,3 @@ class UnsplashEndpoint(BaseAPIView):
resp = requests.get(url=url, headers=headers) resp = requests.get(url=url, headers=headers)
return Response(resp.json(), status=status.HTTP_200_OK) return Response(resp.json(), status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)

View File

@ -44,7 +44,6 @@ from plane.utils.html_processor import strip_tags
class ServiceIssueImportSummaryEndpoint(BaseAPIView): class ServiceIssueImportSummaryEndpoint(BaseAPIView):
def get(self, request, slug, service): def get(self, request, slug, service):
try:
if service == "github": if service == "github":
owner = request.GET.get("owner", False) owner = request.GET.get("owner", False)
repo = request.GET.get("repo", False) repo = request.GET.get("repo", False)
@ -117,22 +116,10 @@ class ServiceIssueImportSummaryEndpoint(BaseAPIView):
{"error": "Service not supported yet"}, {"error": "Service not supported yet"},
status=status.HTTP_400_BAD_REQUEST, status=status.HTTP_400_BAD_REQUEST,
) )
except WorkspaceIntegration.DoesNotExist:
return Response(
{"error": "Requested integration was not installed in the workspace"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class ImportServiceEndpoint(BaseAPIView): class ImportServiceEndpoint(BaseAPIView):
def post(self, request, slug, service): def post(self, request, slug, service):
try:
project_id = request.data.get("project_id", False) project_id = request.data.get("project_id", False)
if not project_id: if not project_id:
@ -220,24 +207,8 @@ class ImportServiceEndpoint(BaseAPIView):
{"error": "Servivce not supported yet"}, {"error": "Servivce not supported yet"},
status=status.HTTP_400_BAD_REQUEST, status=status.HTTP_400_BAD_REQUEST,
) )
except (
Workspace.DoesNotExist,
WorkspaceIntegration.DoesNotExist,
Project.DoesNotExist,
) as e:
return Response(
{"error": "Workspace Integration or Project does not exist"},
status=status.HTTP_404_NOT_FOUND,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def get(self, request, slug): def get(self, request, slug):
try:
imports = ( imports = (
Importer.objects.filter(workspace__slug=slug) Importer.objects.filter(workspace__slug=slug)
.order_by("-created_at") .order_by("-created_at")
@ -245,15 +216,8 @@ class ImportServiceEndpoint(BaseAPIView):
) )
serializer = ImporterSerializer(imports, many=True) serializer = ImporterSerializer(imports, many=True)
return Response(serializer.data) return Response(serializer.data)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def delete(self, request, slug, service, pk): def delete(self, request, slug, service, pk):
try:
importer = Importer.objects.get( importer = Importer.objects.get(
pk=pk, service=service, workspace__slug=slug pk=pk, service=service, workspace__slug=slug
) )
@ -272,15 +236,8 @@ class ImportServiceEndpoint(BaseAPIView):
Module.objects.filter(id__in=imported_modules).delete() Module.objects.filter(id__in=imported_modules).delete()
importer.delete() importer.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def patch(self, request, slug, service, pk): def patch(self, request, slug, service, pk):
try:
importer = Importer.objects.get( importer = Importer.objects.get(
pk=pk, service=service, workspace__slug=slug pk=pk, service=service, workspace__slug=slug
) )
@ -289,21 +246,10 @@ class ImportServiceEndpoint(BaseAPIView):
serializer.save() serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except Importer.DoesNotExist:
return Response(
{"error": "Importer Does not exists"}, status=status.HTTP_404_NOT_FOUND
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class UpdateServiceImportStatusEndpoint(BaseAPIView): class UpdateServiceImportStatusEndpoint(BaseAPIView):
def post(self, request, slug, project_id, service, importer_id): def post(self, request, slug, project_id, service, importer_id):
try:
importer = Importer.objects.get( importer = Importer.objects.get(
pk=importer_id, pk=importer_id,
workspace__slug=slug, workspace__slug=slug,
@ -313,15 +259,10 @@ class UpdateServiceImportStatusEndpoint(BaseAPIView):
importer.status = request.data.get("status", "processing") importer.status = request.data.get("status", "processing")
importer.save() importer.save()
return Response(status.HTTP_200_OK) return Response(status.HTTP_200_OK)
except Importer.DoesNotExist:
return Response(
{"error": "Importer does not exist"}, status=status.HTTP_404_NOT_FOUND
)
class BulkImportIssuesEndpoint(BaseAPIView): class BulkImportIssuesEndpoint(BaseAPIView):
def post(self, request, slug, project_id, service): def post(self, request, slug, project_id, service):
try:
# Get the project # Get the project
project = Project.objects.get(pk=project_id, workspace__slug=slug) project = Project.objects.get(pk=project_id, workspace__slug=slug)
@ -504,21 +445,10 @@ class BulkImportIssuesEndpoint(BaseAPIView):
{"issues": IssueFlatSerializer(issues, many=True).data}, {"issues": IssueFlatSerializer(issues, many=True).data},
status=status.HTTP_201_CREATED, status=status.HTTP_201_CREATED,
) )
except Project.DoesNotExist:
return Response(
{"error": "Project Does not exist"}, status=status.HTTP_404_NOT_FOUND
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class BulkImportModulesEndpoint(BaseAPIView): class BulkImportModulesEndpoint(BaseAPIView):
def post(self, request, slug, project_id, service): def post(self, request, slug, project_id, service):
try:
modules_data = request.data.get("modules_data", []) modules_data = request.data.get("modules_data", [])
project = Project.objects.get(pk=project_id, workspace__slug=slug) project = Project.objects.get(pk=project_id, workspace__slug=slug)
@ -590,13 +520,3 @@ class BulkImportModulesEndpoint(BaseAPIView):
{"message": "Modules created but issues could not be imported"}, {"message": "Modules created but issues could not be imported"},
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except Project.DoesNotExist:
return Response(
{"error": "Project does not exist"}, status=status.HTTP_404_NOT_FOUND
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)

View File

@ -64,7 +64,6 @@ class InboxViewSet(BaseViewSet):
serializer.save(project_id=self.kwargs.get("project_id")) serializer.save(project_id=self.kwargs.get("project_id"))
def destroy(self, request, slug, project_id, pk): def destroy(self, request, slug, project_id, pk):
try:
inbox = Inbox.objects.get( inbox = Inbox.objects.get(
workspace__slug=slug, project_id=project_id, pk=pk workspace__slug=slug, project_id=project_id, pk=pk
) )
@ -76,12 +75,6 @@ class InboxViewSet(BaseViewSet):
) )
inbox.delete() inbox.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wronf please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class InboxIssueViewSet(BaseViewSet): class InboxIssueViewSet(BaseViewSet):
@ -110,7 +103,6 @@ class InboxIssueViewSet(BaseViewSet):
) )
def list(self, request, slug, project_id, inbox_id): def list(self, request, slug, project_id, inbox_id):
try:
filters = issue_filters(request.query_params, "GET") filters = issue_filters(request.query_params, "GET")
issues = ( issues = (
Issue.objects.filter( Issue.objects.filter(
@ -158,15 +150,8 @@ class InboxIssueViewSet(BaseViewSet):
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def create(self, request, slug, project_id, inbox_id): def create(self, request, slug, project_id, inbox_id):
try:
if not request.data.get("issue", {}).get("name", False): if not request.data.get("issue", {}).get("name", False):
return Response( return Response(
{"error": "Name is required"}, status=status.HTTP_400_BAD_REQUEST {"error": "Name is required"}, status=status.HTTP_400_BAD_REQUEST
@ -225,15 +210,8 @@ class InboxIssueViewSet(BaseViewSet):
serializer = IssueStateInboxSerializer(issue) serializer = IssueStateInboxSerializer(issue)
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def partial_update(self, request, slug, project_id, inbox_id, pk): def partial_update(self, request, slug, project_id, inbox_id, pk):
try:
inbox_issue = InboxIssue.objects.get( inbox_issue = InboxIssue.objects.get(
pk=pk, workspace__slug=slug, project_id=project_id, inbox_id=inbox_id pk=pk, workspace__slug=slug, project_id=project_id, inbox_id=inbox_id
) )
@ -330,20 +308,8 @@ class InboxIssueViewSet(BaseViewSet):
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
else: else:
return Response(InboxIssueSerializer(inbox_issue).data, status=status.HTTP_200_OK) return Response(InboxIssueSerializer(inbox_issue).data, status=status.HTTP_200_OK)
except InboxIssue.DoesNotExist:
return Response(
{"error": "Inbox Issue does not exist"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def retrieve(self, request, slug, project_id, inbox_id, pk): def retrieve(self, request, slug, project_id, inbox_id, pk):
try:
inbox_issue = InboxIssue.objects.get( inbox_issue = InboxIssue.objects.get(
pk=pk, workspace__slug=slug, project_id=project_id, inbox_id=inbox_id pk=pk, workspace__slug=slug, project_id=project_id, inbox_id=inbox_id
) )
@ -352,15 +318,8 @@ class InboxIssueViewSet(BaseViewSet):
) )
serializer = IssueStateInboxSerializer(issue) serializer = IssueStateInboxSerializer(issue)
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def destroy(self, request, slug, project_id, inbox_id, pk): def destroy(self, request, slug, project_id, inbox_id, pk):
try:
inbox_issue = InboxIssue.objects.get( inbox_issue = InboxIssue.objects.get(
pk=pk, workspace__slug=slug, project_id=project_id, inbox_id=inbox_id pk=pk, workspace__slug=slug, project_id=project_id, inbox_id=inbox_id
) )
@ -377,14 +336,6 @@ class InboxIssueViewSet(BaseViewSet):
inbox_issue.delete() inbox_issue.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except InboxIssue.DoesNotExist:
return Response({"error": "Inbox Issue does not exists"}, status=status.HTTP_400_BAD_REQUEST)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class InboxIssuePublicViewSet(BaseViewSet): class InboxIssuePublicViewSet(BaseViewSet):
@ -413,7 +364,6 @@ class InboxIssuePublicViewSet(BaseViewSet):
return InboxIssue.objects.none() return InboxIssue.objects.none()
def list(self, request, slug, project_id, inbox_id): def list(self, request, slug, project_id, inbox_id):
try:
project_deploy_board = ProjectDeployBoard.objects.get(workspace__slug=slug, project_id=project_id) project_deploy_board = ProjectDeployBoard.objects.get(workspace__slug=slug, project_id=project_id)
if project_deploy_board.inbox is None: if project_deploy_board.inbox is None:
return Response({"error": "Inbox is not enabled for this Project Board"}, status=status.HTTP_400_BAD_REQUEST) return Response({"error": "Inbox is not enabled for this Project Board"}, status=status.HTTP_400_BAD_REQUEST)
@ -464,17 +414,8 @@ class InboxIssuePublicViewSet(BaseViewSet):
issues_data, issues_data,
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except ProjectDeployBoard.DoesNotExist:
return Response({"error": "Project Deploy Board does not exist"}, status=status.HTTP_400_BAD_REQUEST)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def create(self, request, slug, project_id, inbox_id): def create(self, request, slug, project_id, inbox_id):
try:
project_deploy_board = ProjectDeployBoard.objects.get(workspace__slug=slug, project_id=project_id) project_deploy_board = ProjectDeployBoard.objects.get(workspace__slug=slug, project_id=project_id)
if project_deploy_board.inbox is None: if project_deploy_board.inbox is None:
return Response({"error": "Inbox is not enabled for this Project Board"}, status=status.HTTP_400_BAD_REQUEST) return Response({"error": "Inbox is not enabled for this Project Board"}, status=status.HTTP_400_BAD_REQUEST)
@ -537,15 +478,8 @@ class InboxIssuePublicViewSet(BaseViewSet):
serializer = IssueStateInboxSerializer(issue) serializer = IssueStateInboxSerializer(issue)
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def partial_update(self, request, slug, project_id, inbox_id, pk): def partial_update(self, request, slug, project_id, inbox_id, pk):
try:
project_deploy_board = ProjectDeployBoard.objects.get(workspace__slug=slug, project_id=project_id) project_deploy_board = ProjectDeployBoard.objects.get(workspace__slug=slug, project_id=project_id)
if project_deploy_board.inbox is None: if project_deploy_board.inbox is None:
return Response({"error": "Inbox is not enabled for this Project Board"}, status=status.HTTP_400_BAD_REQUEST) return Response({"error": "Inbox is not enabled for this Project Board"}, status=status.HTTP_400_BAD_REQUEST)
@ -595,20 +529,8 @@ class InboxIssuePublicViewSet(BaseViewSet):
issue_serializer.save() issue_serializer.save()
return Response(issue_serializer.data, status=status.HTTP_200_OK) return Response(issue_serializer.data, status=status.HTTP_200_OK)
return Response(issue_serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(issue_serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except InboxIssue.DoesNotExist:
return Response(
{"error": "Inbox Issue does not exist"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def retrieve(self, request, slug, project_id, inbox_id, pk): def retrieve(self, request, slug, project_id, inbox_id, pk):
try:
project_deploy_board = ProjectDeployBoard.objects.get(workspace__slug=slug, project_id=project_id) project_deploy_board = ProjectDeployBoard.objects.get(workspace__slug=slug, project_id=project_id)
if project_deploy_board.inbox is None: if project_deploy_board.inbox is None:
return Response({"error": "Inbox is not enabled for this Project Board"}, status=status.HTTP_400_BAD_REQUEST) return Response({"error": "Inbox is not enabled for this Project Board"}, status=status.HTTP_400_BAD_REQUEST)
@ -621,15 +543,8 @@ class InboxIssuePublicViewSet(BaseViewSet):
) )
serializer = IssueStateInboxSerializer(issue) serializer = IssueStateInboxSerializer(issue)
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def destroy(self, request, slug, project_id, inbox_id, pk): def destroy(self, request, slug, project_id, inbox_id, pk):
try:
project_deploy_board = ProjectDeployBoard.objects.get(workspace__slug=slug, project_id=project_id) project_deploy_board = ProjectDeployBoard.objects.get(workspace__slug=slug, project_id=project_id)
if project_deploy_board.inbox is None: if project_deploy_board.inbox is None:
return Response({"error": "Inbox is not enabled for this Project Board"}, status=status.HTTP_400_BAD_REQUEST) return Response({"error": "Inbox is not enabled for this Project Board"}, status=status.HTTP_400_BAD_REQUEST)
@ -643,12 +558,3 @@ class InboxIssuePublicViewSet(BaseViewSet):
inbox_issue.delete() inbox_issue.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except InboxIssue.DoesNotExist:
return Response({"error": "Inbox Issue does not exists"}, status=status.HTTP_400_BAD_REQUEST)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)

View File

@ -2,7 +2,6 @@
import uuid import uuid
# Django imports # Django imports
from django.db import IntegrityError
from django.contrib.auth.hashers import make_password from django.contrib.auth.hashers import make_password
# Third party imports # Third party imports
@ -33,21 +32,13 @@ class IntegrationViewSet(BaseViewSet):
model = Integration model = Integration
def create(self, request): def create(self, request):
try:
serializer = IntegrationSerializer(data=request.data) serializer = IntegrationSerializer(data=request.data)
if serializer.is_valid(): if serializer.is_valid():
serializer.save() serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def partial_update(self, request, pk): def partial_update(self, request, pk):
try:
integration = Integration.objects.get(pk=pk) integration = Integration.objects.get(pk=pk)
if integration.verified: if integration.verified:
return Response( return Response(
@ -64,20 +55,7 @@ class IntegrationViewSet(BaseViewSet):
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except Integration.DoesNotExist:
return Response(
{"error": "Integration Does not exist"},
status=status.HTTP_404_NOT_FOUND,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def destroy(self, request, pk): def destroy(self, request, pk):
try:
integration = Integration.objects.get(pk=pk) integration = Integration.objects.get(pk=pk)
if integration.verified: if integration.verified:
return Response( return Response(
@ -87,11 +65,6 @@ class IntegrationViewSet(BaseViewSet):
integration.delete() integration.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except Integration.DoesNotExist:
return Response(
{"error": "Integration Does not exist"},
status=status.HTTP_404_NOT_FOUND,
)
class WorkspaceIntegrationViewSet(BaseViewSet): class WorkspaceIntegrationViewSet(BaseViewSet):
@ -111,7 +84,6 @@ class WorkspaceIntegrationViewSet(BaseViewSet):
) )
def create(self, request, slug, provider): def create(self, request, slug, provider):
try:
workspace = Workspace.objects.get(slug=slug) workspace = Workspace.objects.get(slug=slug)
integration = Integration.objects.get(provider=provider) integration = Integration.objects.get(provider=provider)
config = {} config = {}
@ -175,33 +147,8 @@ class WorkspaceIntegrationViewSet(BaseViewSet):
WorkspaceIntegrationSerializer(workspace_integration).data, WorkspaceIntegrationSerializer(workspace_integration).data,
status=status.HTTP_201_CREATED, status=status.HTTP_201_CREATED,
) )
except IntegrityError as e:
if "already exists" in str(e):
return Response(
{"error": "Integration is already active in the workspace"},
status=status.HTTP_410_GONE,
)
else:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
except (Workspace.DoesNotExist, Integration.DoesNotExist) as e:
capture_exception(e)
return Response(
{"error": "Workspace or Integration not found"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def destroy(self, request, slug, pk): def destroy(self, request, slug, pk):
try:
workspace_integration = WorkspaceIntegration.objects.get( workspace_integration = WorkspaceIntegration.objects.get(
pk=pk, workspace__slug=slug pk=pk, workspace__slug=slug
) )
@ -215,15 +162,3 @@ class WorkspaceIntegrationViewSet(BaseViewSet):
workspace_integration.delete() workspace_integration.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except WorkspaceIntegration.DoesNotExist:
return Response(
{"error": "Workspace Integration Does not exists"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)

View File

@ -30,7 +30,6 @@ class GithubRepositoriesEndpoint(BaseAPIView):
] ]
def get(self, request, slug, workspace_integration_id): def get(self, request, slug, workspace_integration_id):
try:
page = request.GET.get("page", 1) page = request.GET.get("page", 1)
workspace_integration = WorkspaceIntegration.objects.get( workspace_integration = WorkspaceIntegration.objects.get(
workspace__slug=slug, pk=workspace_integration_id workspace__slug=slug, pk=workspace_integration_id
@ -49,11 +48,6 @@ class GithubRepositoriesEndpoint(BaseAPIView):
) )
repositories = get_github_repos(access_tokens_url, repositories_url) repositories = get_github_repos(access_tokens_url, repositories_url)
return Response(repositories, status=status.HTTP_200_OK) return Response(repositories, status=status.HTTP_200_OK)
except WorkspaceIntegration.DoesNotExist:
return Response(
{"error": "Workspace Integration Does not exists"},
status=status.HTTP_400_BAD_REQUEST,
)
class GithubRepositorySyncViewSet(BaseViewSet): class GithubRepositorySyncViewSet(BaseViewSet):
@ -76,7 +70,6 @@ class GithubRepositorySyncViewSet(BaseViewSet):
) )
def create(self, request, slug, project_id, workspace_integration_id): def create(self, request, slug, project_id, workspace_integration_id):
try:
name = request.data.get("name", False) name = request.data.get("name", False)
url = request.data.get("url", False) url = request.data.get("url", False)
config = request.data.get("config", {}) config = request.data.get("config", {})
@ -147,18 +140,6 @@ class GithubRepositorySyncViewSet(BaseViewSet):
status=status.HTTP_201_CREATED, status=status.HTTP_201_CREATED,
) )
except WorkspaceIntegration.DoesNotExist:
return Response(
{"error": "Workspace Integration does not exist"},
status=status.HTTP_404_NOT_FOUND,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class GithubIssueSyncViewSet(BaseViewSet): class GithubIssueSyncViewSet(BaseViewSet):
permission_classes = [ permission_classes = [
@ -177,7 +158,6 @@ class GithubIssueSyncViewSet(BaseViewSet):
class BulkCreateGithubIssueSyncEndpoint(BaseAPIView): class BulkCreateGithubIssueSyncEndpoint(BaseAPIView):
def post(self, request, slug, project_id, repo_sync_id): def post(self, request, slug, project_id, repo_sync_id):
try:
project = Project.objects.get(pk=project_id, workspace__slug=slug) project = Project.objects.get(pk=project_id, workspace__slug=slug)
github_issue_syncs = request.data.get("github_issue_syncs", []) github_issue_syncs = request.data.get("github_issue_syncs", [])
@ -202,17 +182,6 @@ class BulkCreateGithubIssueSyncEndpoint(BaseAPIView):
serializer = GithubIssueSyncSerializer(github_issue_syncs, many=True) serializer = GithubIssueSyncSerializer(github_issue_syncs, many=True)
return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.data, status=status.HTTP_201_CREATED)
except Project.DoesNotExist:
return Response(
{"error": "Project does not exist"},
status=status.HTTP_404_NOT_FOUND,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class GithubCommentSyncViewSet(BaseViewSet): class GithubCommentSyncViewSet(BaseViewSet):

View File

@ -32,7 +32,6 @@ class SlackProjectSyncViewSet(BaseViewSet):
) )
def create(self, request, slug, project_id, workspace_integration_id): def create(self, request, slug, project_id, workspace_integration_id):
try:
serializer = SlackProjectSyncSerializer(data=request.data) serializer = SlackProjectSyncSerializer(data=request.data)
workspace_integration = WorkspaceIntegration.objects.get( workspace_integration = WorkspaceIntegration.objects.get(
@ -55,19 +54,3 @@ class SlackProjectSyncViewSet(BaseViewSet):
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except IntegrityError:
return Response(
{"error": "Slack is already enabled for the project"},
status=status.HTTP_400_BAD_REQUEST,
)
except WorkspaceIntegration.DoesNotExist:
return Response(
{"error": "Workspace Integration does not exist"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
print(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)

File diff suppressed because it is too large Load Diff

View File

@ -142,7 +142,6 @@ class ModuleViewSet(BaseViewSet):
) )
def create(self, request, slug, project_id): def create(self, request, slug, project_id):
try:
project = Project.objects.get(workspace__slug=slug, pk=project_id) project = Project.objects.get(workspace__slug=slug, pk=project_id)
serializer = ModuleWriteSerializer( serializer = ModuleWriteSerializer(
data=request.data, context={"project": project} data=request.data, context={"project": project}
@ -153,25 +152,7 @@ class ModuleViewSet(BaseViewSet):
return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except Project.DoesNotExist:
return Response(
{"error": "Project was not found"}, status=status.HTTP_404_NOT_FOUND
)
except IntegrityError as e:
if "already exists" in str(e):
return Response(
{"name": "The module name is already taken"},
status=status.HTTP_410_GONE,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def retrieve(self, request, slug, project_id, pk): def retrieve(self, request, slug, project_id, pk):
try:
queryset = self.get_queryset().get(pk=pk) queryset = self.get_queryset().get(pk=pk)
assignee_distribution = ( assignee_distribution = (
@ -185,9 +166,7 @@ class ModuleViewSet(BaseViewSet):
.annotate(assignee_id=F("assignees__id")) .annotate(assignee_id=F("assignees__id"))
.annotate(display_name=F("assignees__display_name")) .annotate(display_name=F("assignees__display_name"))
.annotate(avatar=F("assignees__avatar")) .annotate(avatar=F("assignees__avatar"))
.values( .values("first_name", "last_name", "assignee_id", "avatar", "display_name")
"first_name", "last_name", "assignee_id", "avatar", "display_name"
)
.annotate( .annotate(
total_issues=Count( total_issues=Count(
"assignee_id", "assignee_id",
@ -279,18 +258,8 @@ class ModuleViewSet(BaseViewSet):
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def destroy(self, request, slug, project_id, pk): def destroy(self, request, slug, project_id, pk):
try: module = Module.objects.get(workspace__slug=slug, project_id=project_id, pk=pk)
module = Module.objects.get(
workspace__slug=slug, project_id=project_id, pk=pk
)
module_issues = list( module_issues = list(
ModuleIssue.objects.filter(module_id=pk).values_list("issue", flat=True) ModuleIssue.objects.filter(module_id=pk).values_list("issue", flat=True)
) )
@ -310,12 +279,6 @@ class ModuleViewSet(BaseViewSet):
epoch=int(timezone.now().timestamp()), epoch=int(timezone.now().timestamp()),
) )
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class ModuleIssueViewSet(BaseViewSet): class ModuleIssueViewSet(BaseViewSet):
@ -337,7 +300,6 @@ class ModuleIssueViewSet(BaseViewSet):
module_id=self.kwargs.get("module_id"), module_id=self.kwargs.get("module_id"),
) )
def get_queryset(self): def get_queryset(self):
return self.filter_queryset( return self.filter_queryset(
super() super()
@ -363,7 +325,6 @@ class ModuleIssueViewSet(BaseViewSet):
@method_decorator(gzip_page) @method_decorator(gzip_page)
def list(self, request, slug, project_id, module_id): def list(self, request, slug, project_id, module_id):
try:
order_by = request.GET.get("order_by", "created_at") order_by = request.GET.get("order_by", "created_at")
group_by = request.GET.get("group_by", False) group_by = request.GET.get("group_by", False)
sub_group_by = request.GET.get("sub_group_by", False) sub_group_by = request.GET.get("sub_group_by", False)
@ -394,9 +355,7 @@ class ModuleIssueViewSet(BaseViewSet):
.values("count") .values("count")
) )
.annotate( .annotate(
attachment_count=IssueAttachment.objects.filter( attachment_count=IssueAttachment.objects.filter(issue=OuterRef("id"))
issue=OuterRef("id")
)
.order_by() .order_by()
.annotate(count=Func(F("id"), function="Count")) .annotate(count=Func(F("id"), function="Count"))
.values("count") .values("count")
@ -421,15 +380,8 @@ class ModuleIssueViewSet(BaseViewSet):
issues_data, issues_data,
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def create(self, request, slug, project_id, module_id): def create(self, request, slug, project_id, module_id):
try:
issues = request.data.get("issues", []) issues = request.data.get("issues", [])
if not len(issues): if not len(issues):
return Response( return Response(
@ -509,19 +461,8 @@ class ModuleIssueViewSet(BaseViewSet):
ModuleIssueSerializer(self.get_queryset(), many=True).data, ModuleIssueSerializer(self.get_queryset(), many=True).data,
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except Module.DoesNotExist:
return Response(
{"error": "Module Does not exists"}, status=status.HTTP_400_BAD_REQUEST
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def destroy(self, request, slug, project_id, module_id, pk): def destroy(self, request, slug, project_id, module_id, pk):
try:
module_issue = ModuleIssue.objects.get( module_issue = ModuleIssue.objects.get(
workspace__slug=slug, project_id=project_id, module_id=module_id, pk=pk workspace__slug=slug, project_id=project_id, module_id=module_id, pk=pk
) )
@ -541,12 +482,6 @@ class ModuleIssueViewSet(BaseViewSet):
epoch=int(timezone.now().timestamp()), epoch=int(timezone.now().timestamp()),
) )
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class ModuleLinkViewSet(BaseViewSet): class ModuleLinkViewSet(BaseViewSet):
@ -590,33 +525,13 @@ class ModuleFavoriteViewSet(BaseViewSet):
) )
def create(self, request, slug, project_id): def create(self, request, slug, project_id):
try:
serializer = ModuleFavoriteSerializer(data=request.data) serializer = ModuleFavoriteSerializer(data=request.data)
if serializer.is_valid(): if serializer.is_valid():
serializer.save(user=request.user, project_id=project_id) serializer.save(user=request.user, project_id=project_id)
return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except IntegrityError as e:
if "already exists" in str(e):
return Response(
{"error": "The module is already added to favorites"},
status=status.HTTP_410_GONE,
)
else:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def destroy(self, request, slug, project_id, module_id): def destroy(self, request, slug, project_id, module_id):
try:
module_favorite = ModuleFavorite.objects.get( module_favorite = ModuleFavorite.objects.get(
project=project_id, project=project_id,
user=request.user, user=request.user,
@ -625,14 +540,3 @@ class ModuleFavoriteViewSet(BaseViewSet):
) )
module_favorite.delete() module_favorite.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except ModuleFavorite.DoesNotExist:
return Response(
{"error": "Module is not in favorites"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)

View File

@ -36,16 +36,19 @@ class NotificationViewSet(BaseViewSet, BasePaginator):
) )
def list(self, request, slug): def list(self, request, slug):
try:
# Get query parameters # Get query parameters
snoozed = request.GET.get("snoozed", "false") snoozed = request.GET.get("snoozed", "false")
archived = request.GET.get("archived", "false") archived = request.GET.get("archived", "false")
read = request.GET.get("read", "true") read = request.GET.get("read", "true")
type = request.GET.get("type", "all") type = request.GET.get("type", "all")
notifications = Notification.objects.filter(workspace__slug=slug, receiver_id=request.user.id) \ notifications = (
.select_related("workspace", "project", "triggered_by", "receiver") \ Notification.objects.filter(
workspace__slug=slug, receiver_id=request.user.id
)
.select_related("workspace", "project", "triggered_by", "receiver")
.order_by("snoozed_till", "-created_at") .order_by("snoozed_till", "-created_at")
)
# Filters based on query parameters # Filters based on query parameters
snoozed_filters = { snoozed_filters = {
@ -89,9 +92,7 @@ class NotificationViewSet(BaseViewSet, BasePaginator):
issue_ids = Issue.objects.filter( issue_ids = Issue.objects.filter(
workspace__slug=slug, created_by=request.user workspace__slug=slug, created_by=request.user
).values_list("pk", flat=True) ).values_list("pk", flat=True)
notifications = notifications.filter( notifications = notifications.filter(entity_identifier__in=issue_ids)
entity_identifier__in=issue_ids
)
# Pagination # Pagination
if request.GET.get("per_page", False) and request.GET.get("cursor", False): if request.GET.get("per_page", False) and request.GET.get("cursor", False):
@ -105,15 +106,8 @@ class NotificationViewSet(BaseViewSet, BasePaginator):
serializer = NotificationSerializer(notifications, many=True) serializer = NotificationSerializer(notifications, many=True)
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def partial_update(self, request, slug, pk): def partial_update(self, request, slug, pk):
try:
notification = Notification.objects.get( notification = Notification.objects.get(
workspace__slug=slug, pk=pk, receiver=request.user workspace__slug=slug, pk=pk, receiver=request.user
) )
@ -129,20 +123,8 @@ class NotificationViewSet(BaseViewSet, BasePaginator):
serializer.save() serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except Notification.DoesNotExist:
return Response(
{"error": "Notification does not exists"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def mark_read(self, request, slug, pk): def mark_read(self, request, slug, pk):
try:
notification = Notification.objects.get( notification = Notification.objects.get(
receiver=request.user, workspace__slug=slug, pk=pk receiver=request.user, workspace__slug=slug, pk=pk
) )
@ -150,20 +132,8 @@ class NotificationViewSet(BaseViewSet, BasePaginator):
notification.save() notification.save()
serializer = NotificationSerializer(notification) serializer = NotificationSerializer(notification)
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
except Notification.DoesNotExist:
return Response(
{"error": "Notification does not exists"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def mark_unread(self, request, slug, pk): def mark_unread(self, request, slug, pk):
try:
notification = Notification.objects.get( notification = Notification.objects.get(
receiver=request.user, workspace__slug=slug, pk=pk receiver=request.user, workspace__slug=slug, pk=pk
) )
@ -171,20 +141,8 @@ class NotificationViewSet(BaseViewSet, BasePaginator):
notification.save() notification.save()
serializer = NotificationSerializer(notification) serializer = NotificationSerializer(notification)
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
except Notification.DoesNotExist:
return Response(
{"error": "Notification does not exists"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def archive(self, request, slug, pk): def archive(self, request, slug, pk):
try:
notification = Notification.objects.get( notification = Notification.objects.get(
receiver=request.user, workspace__slug=slug, pk=pk receiver=request.user, workspace__slug=slug, pk=pk
) )
@ -192,20 +150,8 @@ class NotificationViewSet(BaseViewSet, BasePaginator):
notification.save() notification.save()
serializer = NotificationSerializer(notification) serializer = NotificationSerializer(notification)
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
except Notification.DoesNotExist:
return Response(
{"error": "Notification does not exists"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def unarchive(self, request, slug, pk): def unarchive(self, request, slug, pk):
try:
notification = Notification.objects.get( notification = Notification.objects.get(
receiver=request.user, workspace__slug=slug, pk=pk receiver=request.user, workspace__slug=slug, pk=pk
) )
@ -213,22 +159,10 @@ class NotificationViewSet(BaseViewSet, BasePaginator):
notification.save() notification.save()
serializer = NotificationSerializer(notification) serializer = NotificationSerializer(notification)
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
except Notification.DoesNotExist:
return Response(
{"error": "Notification does not exists"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class UnreadNotificationEndpoint(BaseAPIView): class UnreadNotificationEndpoint(BaseAPIView):
def get(self, request, slug): def get(self, request, slug):
try:
# Watching Issues Count # Watching Issues Count
watching_issues_count = Notification.objects.filter( watching_issues_count = Notification.objects.filter(
workspace__slug=slug, workspace__slug=slug,
@ -270,17 +204,10 @@ class UnreadNotificationEndpoint(BaseAPIView):
}, },
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class MarkAllReadNotificationViewSet(BaseViewSet): class MarkAllReadNotificationViewSet(BaseViewSet):
def create(self, request, slug): def create(self, request, slug):
try:
snoozed = request.data.get("snoozed", False) snoozed = request.data.get("snoozed", False)
archived = request.data.get("archived", False) archived = request.data.get("archived", False)
type = request.data.get("type", "all") type = request.data.get("type", "all")
@ -335,9 +262,7 @@ class MarkAllReadNotificationViewSet(BaseViewSet):
issue_ids = Issue.objects.filter( issue_ids = Issue.objects.filter(
workspace__slug=slug, created_by=request.user workspace__slug=slug, created_by=request.user
).values_list("pk", flat=True) ).values_list("pk", flat=True)
notifications = notifications.filter( notifications = notifications.filter(entity_identifier__in=issue_ids)
entity_identifier__in=issue_ids
)
updated_notifications = [] updated_notifications = []
for notification in notifications: for notification in notifications:
@ -347,9 +272,3 @@ class MarkAllReadNotificationViewSet(BaseViewSet):
updated_notifications, ["read_at"], batch_size=100 updated_notifications, ["read_at"], batch_size=100
) )
return Response({"message": "Successful"}, status=status.HTTP_200_OK) return Response({"message": "Successful"}, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)

View File

@ -15,6 +15,7 @@ from rest_framework.views import APIView
from rest_framework_simplejwt.tokens import RefreshToken from rest_framework_simplejwt.tokens import RefreshToken
from rest_framework import status from rest_framework import status
from sentry_sdk import capture_exception from sentry_sdk import capture_exception
# sso authentication # sso authentication
from google.oauth2 import id_token from google.oauth2 import id_token
from google.auth.transport import requests as google_auth_request from google.auth.transport import requests as google_auth_request
@ -298,11 +299,3 @@ class OauthEndpoint(BaseAPIView):
}, },
) )
return Response(data, status=status.HTTP_201_CREATED) return Response(data, status=status.HTTP_201_CREATED)
except Exception as e:
capture_exception(e)
return Response(
{
"error": "Something went wrong. Please try again later or contact the support team."
},
status=status.HTTP_400_BAD_REQUEST,
)

View File

@ -2,7 +2,6 @@
from datetime import timedelta, datetime, date from datetime import timedelta, datetime, date
# Django imports # Django imports
from django.db import IntegrityError
from django.db.models import Exists, OuterRef, Q, Prefetch from django.db.models import Exists, OuterRef, Q, Prefetch
from django.utils import timezone from django.utils import timezone
@ -78,7 +77,6 @@ class PageViewSet(BaseViewSet):
) )
def create(self, request, slug, project_id): def create(self, request, slug, project_id):
try:
serializer = PageSerializer( serializer = PageSerializer(
data=request.data, data=request.data,
context={"project_id": project_id, "owned_by_id": request.user.id}, context={"project_id": project_id, "owned_by_id": request.user.id},
@ -89,15 +87,7 @@ class PageViewSet(BaseViewSet):
return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def partial_update(self, request, slug, project_id, pk): def partial_update(self, request, slug, project_id, pk):
try:
page = Page.objects.get(pk=pk, workspace__slug=slug, project_id=project_id) page = Page.objects.get(pk=pk, workspace__slug=slug, project_id=project_id)
# Only update access if the page owner is the requesting user # Only update access if the page owner is the requesting user
if ( if (
@ -115,19 +105,8 @@ class PageViewSet(BaseViewSet):
serializer.save() serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except Page.DoesNotExist:
return Response(
{"error": "Page Does not exist"}, status=status.HTTP_400_BAD_REQUEST
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def list(self, request, slug, project_id): def list(self, request, slug, project_id):
try:
queryset = self.get_queryset() queryset = self.get_queryset()
page_view = request.GET.get("page_view", False) page_view = request.GET.get("page_view", False)
@ -173,9 +152,7 @@ class PageViewSet(BaseViewSet):
return Response(PageSerializer(queryset, many=True).data, status=status.HTTP_200_OK) return Response(PageSerializer(queryset, many=True).data, status=status.HTTP_200_OK)
return Response({"error": "No matching view found"}, status=status.HTTP_400_BAD_REQUEST) return Response({"error": "No matching view found"}, status=status.HTTP_400_BAD_REQUEST)
except Exception as e:
capture_exception(e)
return Response({"error": "Something went wrong please try again later"}, status=status.HTTP_400_BAD_REQUEST)
class PageBlockViewSet(BaseViewSet): class PageBlockViewSet(BaseViewSet):
serializer_class = PageBlockSerializer serializer_class = PageBlockSerializer
@ -225,33 +202,13 @@ class PageFavoriteViewSet(BaseViewSet):
) )
def create(self, request, slug, project_id): def create(self, request, slug, project_id):
try:
serializer = PageFavoriteSerializer(data=request.data) serializer = PageFavoriteSerializer(data=request.data)
if serializer.is_valid(): if serializer.is_valid():
serializer.save(user=request.user, project_id=project_id) serializer.save(user=request.user, project_id=project_id)
return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except IntegrityError as e:
if "already exists" in str(e):
return Response(
{"error": "The page is already added to favorites"},
status=status.HTTP_410_GONE,
)
else:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def destroy(self, request, slug, project_id, page_id): def destroy(self, request, slug, project_id, page_id):
try:
page_favorite = PageFavorite.objects.get( page_favorite = PageFavorite.objects.get(
project=project_id, project=project_id,
user=request.user, user=request.user,
@ -260,18 +217,6 @@ class PageFavoriteViewSet(BaseViewSet):
) )
page_favorite.delete() page_favorite.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except PageFavorite.DoesNotExist:
return Response(
{"error": "Page is not in favorites"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class CreateIssueFromPageBlockEndpoint(BaseAPIView): class CreateIssueFromPageBlockEndpoint(BaseAPIView):
permission_classes = [ permission_classes = [
@ -279,7 +224,6 @@ class CreateIssueFromPageBlockEndpoint(BaseAPIView):
] ]
def post(self, request, slug, project_id, page_id, page_block_id): def post(self, request, slug, project_id, page_id, page_block_id):
try:
page_block = PageBlock.objects.get( page_block = PageBlock.objects.get(
pk=page_block_id, pk=page_block_id,
workspace__slug=slug, workspace__slug=slug,
@ -309,13 +253,3 @@ class CreateIssueFromPageBlockEndpoint(BaseAPIView):
page_block.save() page_block.save()
return Response(IssueLiteSerializer(issue).data, status=status.HTTP_200_OK) return Response(IssueLiteSerializer(issue).data, status=status.HTTP_200_OK)
except PageBlock.DoesNotExist:
return Response(
{"error": "Page Block does not exist"}, status=status.HTTP_404_NOT_FOUND
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)

View File

@ -152,7 +152,6 @@ class ProjectViewSet(BaseViewSet):
) )
def list(self, request, slug): def list(self, request, slug):
try:
fields = [field for field in request.GET.get("fields", "").split(",") if field] fields = [field for field in request.GET.get("fields", "").split(",") if field]
sort_order_query = ProjectMember.objects.filter( sort_order_query = ProjectMember.objects.filter(
@ -187,12 +186,6 @@ class ProjectViewSet(BaseViewSet):
projects, many=True, fields=fields if fields else None projects, many=True, fields=fields if fields else None
).data ).data
) )
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def create(self, request, slug): def create(self, request, slug):
try: try:
@ -285,12 +278,6 @@ class ProjectViewSet(BaseViewSet):
{"name": "The project name is already taken"}, {"name": "The project name is already taken"},
status=status.HTTP_410_GONE, status=status.HTTP_410_GONE,
) )
else:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_410_GONE,
)
except Workspace.DoesNotExist as e: except Workspace.DoesNotExist as e:
return Response( return Response(
{"error": "Workspace does not exist"}, status=status.HTTP_404_NOT_FOUND {"error": "Workspace does not exist"}, status=status.HTTP_404_NOT_FOUND
@ -300,12 +287,6 @@ class ProjectViewSet(BaseViewSet):
{"identifier": "The project identifier is already taken"}, {"identifier": "The project identifier is already taken"},
status=status.HTTP_410_GONE, status=status.HTTP_410_GONE,
) )
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def partial_update(self, request, slug, pk=None): def partial_update(self, request, slug, pk=None):
try: try:
@ -354,12 +335,6 @@ class ProjectViewSet(BaseViewSet):
{"identifier": "The project identifier is already taken"}, {"identifier": "The project identifier is already taken"},
status=status.HTTP_410_GONE, status=status.HTTP_410_GONE,
) )
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class InviteProjectEndpoint(BaseAPIView): class InviteProjectEndpoint(BaseAPIView):
@ -368,7 +343,6 @@ class InviteProjectEndpoint(BaseAPIView):
] ]
def post(self, request, slug, project_id): def post(self, request, slug, project_id):
try:
email = request.data.get("email", False) email = request.data.get("email", False)
role = request.data.get("role", False) role = request.data.get("role", False)
@ -423,25 +397,6 @@ class InviteProjectEndpoint(BaseAPIView):
ProjectMemberSerializer(project_member).data, status=status.HTTP_200_OK ProjectMemberSerializer(project_member).data, status=status.HTTP_200_OK
) )
except ValidationError:
return Response(
{
"error": "Invalid email address provided a valid email address is required to send the invite"
},
status=status.HTTP_400_BAD_REQUEST,
)
except (Workspace.DoesNotExist, Project.DoesNotExist) as e:
return Response(
{"error": "Workspace or Project does not exists"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class UserProjectInvitationsViewset(BaseViewSet): class UserProjectInvitationsViewset(BaseViewSet):
serializer_class = ProjectMemberInviteSerializer serializer_class = ProjectMemberInviteSerializer
@ -456,7 +411,6 @@ class UserProjectInvitationsViewset(BaseViewSet):
) )
def create(self, request): def create(self, request):
try:
invitations = request.data.get("invitations") invitations = request.data.get("invitations")
project_invitations = ProjectMemberInvite.objects.filter( project_invitations = ProjectMemberInvite.objects.filter(
pk__in=invitations, accepted=True pk__in=invitations, accepted=True
@ -478,12 +432,6 @@ class UserProjectInvitationsViewset(BaseViewSet):
project_invitations.delete() project_invitations.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class ProjectMemberViewSet(BaseViewSet): class ProjectMemberViewSet(BaseViewSet):
@ -511,7 +459,6 @@ class ProjectMemberViewSet(BaseViewSet):
) )
def partial_update(self, request, slug, project_id, pk): def partial_update(self, request, slug, project_id, pk):
try:
project_member = ProjectMember.objects.get( project_member = ProjectMember.objects.get(
pk=pk, workspace__slug=slug, project_id=project_id pk=pk, workspace__slug=slug, project_id=project_id
) )
@ -530,9 +477,7 @@ class ProjectMemberViewSet(BaseViewSet):
> requested_project_member.role > requested_project_member.role
): ):
return Response( return Response(
{ {"error": "You cannot update a role that is higher than your own role"},
"error": "You cannot update a role that is higher than your own role"
},
status=status.HTTP_400_BAD_REQUEST, status=status.HTTP_400_BAD_REQUEST,
) )
@ -544,20 +489,8 @@ class ProjectMemberViewSet(BaseViewSet):
serializer.save() serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except ProjectMember.DoesNotExist:
return Response(
{"error": "Project Member does not exist"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def destroy(self, request, slug, project_id, pk): def destroy(self, request, slug, project_id, pk):
try:
project_member = ProjectMember.objects.get( project_member = ProjectMember.objects.get(
workspace__slug=slug, project_id=project_id, pk=pk workspace__slug=slug, project_id=project_id, pk=pk
) )
@ -567,9 +500,7 @@ class ProjectMemberViewSet(BaseViewSet):
) )
if requesting_project_member.role < project_member.role: if requesting_project_member.role < project_member.role:
return Response( return Response(
{ {"error": "You cannot remove a user having role higher than yourself"},
"error": "You cannot remove a user having role higher than yourself"
},
status=status.HTTP_400_BAD_REQUEST, status=status.HTTP_400_BAD_REQUEST,
) )
@ -610,14 +541,6 @@ class ProjectMemberViewSet(BaseViewSet):
).delete() ).delete()
project_member.delete() project_member.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except ProjectMember.DoesNotExist:
return Response(
{"error": "Project Member does not exist"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response({"error": "Something went wrong please try again later"})
class AddMemberToProjectEndpoint(BaseAPIView): class AddMemberToProjectEndpoint(BaseAPIView):
@ -626,7 +549,6 @@ class AddMemberToProjectEndpoint(BaseAPIView):
] ]
def post(self, request, slug, project_id): def post(self, request, slug, project_id):
try:
members = request.data.get("members", []) members = request.data.get("members", [])
# get the project # get the project
@ -652,8 +574,7 @@ class AddMemberToProjectEndpoint(BaseAPIView):
sort_order = [ sort_order = [
project_member.get("sort_order") project_member.get("sort_order")
for project_member in project_members for project_member in project_members
if str(project_member.get("member_id")) if str(project_member.get("member_id")) == str(member.get("member_id"))
== str(member.get("member_id"))
] ]
bulk_project_members.append( bulk_project_members.append(
ProjectMember( ProjectMember(
@ -672,27 +593,7 @@ class AddMemberToProjectEndpoint(BaseAPIView):
) )
serializer = ProjectMemberSerializer(project_members, many=True) serializer = ProjectMemberSerializer(project_members, many=True)
return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.data, status=status.HTTP_201_CREATED)
except KeyError:
return Response(
{"error": "Incorrect data sent"}, status=status.HTTP_400_BAD_REQUEST
)
except Project.DoesNotExist:
return Response(
{"error": "Project does not exist"}, status=status.HTTP_400_BAD_REQUEST
)
except IntegrityError:
return Response(
{"error": "User not member of the workspace"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class AddTeamToProjectEndpoint(BaseAPIView): class AddTeamToProjectEndpoint(BaseAPIView):
@ -701,7 +602,6 @@ class AddTeamToProjectEndpoint(BaseAPIView):
] ]
def post(self, request, slug, project_id): def post(self, request, slug, project_id):
try:
team_members = TeamMember.objects.filter( team_members = TeamMember.objects.filter(
workspace__slug=slug, team__in=request.data.get("teams", []) workspace__slug=slug, team__in=request.data.get("teams", [])
).values_list("member", flat=True) ).values_list("member", flat=True)
@ -730,23 +630,6 @@ class AddTeamToProjectEndpoint(BaseAPIView):
serializer = ProjectMemberSerializer(project_members, many=True) serializer = ProjectMemberSerializer(project_members, many=True)
return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.data, status=status.HTTP_201_CREATED)
except IntegrityError as e:
if "already exists" in str(e):
return Response(
{"error": "The team with the name already exists"},
status=status.HTTP_410_GONE,
)
except Workspace.DoesNotExist:
return Response(
{"error": "The requested workspace could not be found"},
status=status.HTTP_404_NOT_FOUND,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class ProjectMemberInvitationsViewset(BaseViewSet): class ProjectMemberInvitationsViewset(BaseViewSet):
@ -795,7 +678,6 @@ class ProjectIdentifierEndpoint(BaseAPIView):
] ]
def get(self, request, slug): def get(self, request, slug):
try:
name = request.GET.get("name", "").strip().upper() name = request.GET.get("name", "").strip().upper()
if name == "": if name == "":
@ -811,15 +693,8 @@ class ProjectIdentifierEndpoint(BaseAPIView):
{"exists": len(exists), "identifiers": exists}, {"exists": len(exists), "identifiers": exists},
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def delete(self, request, slug): def delete(self, request, slug):
try:
name = request.data.get("name", "").strip().upper() name = request.data.get("name", "").strip().upper()
if name == "": if name == "":
@ -838,17 +713,10 @@ class ProjectIdentifierEndpoint(BaseAPIView):
return Response( return Response(
status=status.HTTP_204_NO_CONTENT, status=status.HTTP_204_NO_CONTENT,
) )
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class ProjectJoinEndpoint(BaseAPIView): class ProjectJoinEndpoint(BaseAPIView):
def post(self, request, slug): def post(self, request, slug):
try:
project_ids = request.data.get("project_ids", []) project_ids = request.data.get("project_ids", [])
# Get the workspace user role # Get the workspace user role
@ -879,22 +747,10 @@ class ProjectJoinEndpoint(BaseAPIView):
{"message": "Projects joined successfully"}, {"message": "Projects joined successfully"},
status=status.HTTP_201_CREATED, status=status.HTTP_201_CREATED,
) )
except WorkspaceMember.DoesNotExist:
return Response(
{"error": "User is not a member of workspace"},
status=status.HTTP_403_FORBIDDEN,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class ProjectUserViewsEndpoint(BaseAPIView): class ProjectUserViewsEndpoint(BaseAPIView):
def post(self, request, slug, project_id): def post(self, request, slug, project_id):
try:
project = Project.objects.get(pk=project_id, workspace__slug=slug) project = Project.objects.get(pk=project_id, workspace__slug=slug)
project_member = ProjectMember.objects.filter( project_member = ProjectMember.objects.filter(
@ -902,9 +758,7 @@ class ProjectUserViewsEndpoint(BaseAPIView):
).first() ).first()
if project_member is None: if project_member is None:
return Response( return Response({"error": "Forbidden"}, status=status.HTTP_403_FORBIDDEN)
{"error": "Forbidden"}, status=status.HTTP_403_FORBIDDEN
)
view_props = project_member.view_props view_props = project_member.view_props
default_props = project_member.default_props default_props = project_member.default_props
@ -912,30 +766,17 @@ class ProjectUserViewsEndpoint(BaseAPIView):
sort_order = project_member.sort_order sort_order = project_member.sort_order
project_member.view_props = request.data.get("view_props", view_props) project_member.view_props = request.data.get("view_props", view_props)
project_member.default_props = request.data.get( project_member.default_props = request.data.get("default_props", default_props)
"default_props", default_props
)
project_member.preferences = request.data.get("preferences", preferences) project_member.preferences = request.data.get("preferences", preferences)
project_member.sort_order = request.data.get("sort_order", sort_order) project_member.sort_order = request.data.get("sort_order", sort_order)
project_member.save() project_member.save()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except Project.DoesNotExist:
return Response(
{"error": "The requested resource does not exists"},
status=status.HTTP_404_NOT_FOUND,
)
except Exception as e:
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class ProjectMemberUserEndpoint(BaseAPIView): class ProjectMemberUserEndpoint(BaseAPIView):
def get(self, request, slug, project_id): def get(self, request, slug, project_id):
try:
project_member = ProjectMember.objects.get( project_member = ProjectMember.objects.get(
project_id=project_id, workspace__slug=slug, member=request.user project_id=project_id, workspace__slug=slug, member=request.user
) )
@ -943,18 +784,6 @@ class ProjectMemberUserEndpoint(BaseAPIView):
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
except ProjectMember.DoesNotExist:
return Response(
{"error": "User not a member of the project"},
status=status.HTTP_403_FORBIDDEN,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class ProjectFavoritesViewSet(BaseViewSet): class ProjectFavoritesViewSet(BaseViewSet):
serializer_class = ProjectFavoriteSerializer serializer_class = ProjectFavoriteSerializer
@ -976,50 +805,18 @@ class ProjectFavoritesViewSet(BaseViewSet):
serializer.save(user=self.request.user) serializer.save(user=self.request.user)
def create(self, request, slug): def create(self, request, slug):
try:
serializer = ProjectFavoriteSerializer(data=request.data) serializer = ProjectFavoriteSerializer(data=request.data)
if serializer.is_valid(): if serializer.is_valid():
serializer.save(user=request.user) serializer.save(user=request.user)
return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except IntegrityError as e:
print(str(e))
if "already exists" in str(e):
return Response(
{"error": "The project is already added to favorites"},
status=status.HTTP_410_GONE,
)
else:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_410_GONE,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def destroy(self, request, slug, project_id): def destroy(self, request, slug, project_id):
try:
project_favorite = ProjectFavorite.objects.get( project_favorite = ProjectFavorite.objects.get(
project=project_id, user=request.user, workspace__slug=slug project=project_id, user=request.user, workspace__slug=slug
) )
project_favorite.delete() project_favorite.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except ProjectFavorite.DoesNotExist:
return Response(
{"error": "Project is not in favorites"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class ProjectDeployBoardViewSet(BaseViewSet): class ProjectDeployBoardViewSet(BaseViewSet):
@ -1041,7 +838,6 @@ class ProjectDeployBoardViewSet(BaseViewSet):
) )
def create(self, request, slug, project_id): def create(self, request, slug, project_id):
try:
comments = request.data.get("comments", False) comments = request.data.get("comments", False)
reactions = request.data.get("reactions", False) reactions = request.data.get("reactions", False)
inbox = request.data.get("inbox", None) inbox = request.data.get("inbox", None)
@ -1071,12 +867,6 @@ class ProjectDeployBoardViewSet(BaseViewSet):
serializer = ProjectDeployBoardSerializer(project_deploy_board) serializer = ProjectDeployBoardSerializer(project_deploy_board)
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class ProjectMemberEndpoint(BaseAPIView): class ProjectMemberEndpoint(BaseAPIView):
@ -1085,7 +875,6 @@ class ProjectMemberEndpoint(BaseAPIView):
] ]
def get(self, request, slug, project_id): def get(self, request, slug, project_id):
try:
project_members = ProjectMember.objects.filter( project_members = ProjectMember.objects.filter(
project_id=project_id, project_id=project_id,
workspace__slug=slug, workspace__slug=slug,
@ -1093,12 +882,6 @@ class ProjectMemberEndpoint(BaseAPIView):
).select_related("project", "member", "workspace") ).select_related("project", "member", "workspace")
serializer = ProjectMemberSerializer(project_members, many=True) serializer = ProjectMemberSerializer(project_members, many=True)
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class ProjectDeployBoardPublicSettingsEndpoint(BaseAPIView): class ProjectDeployBoardPublicSettingsEndpoint(BaseAPIView):
@ -1107,23 +890,11 @@ class ProjectDeployBoardPublicSettingsEndpoint(BaseAPIView):
] ]
def get(self, request, slug, project_id): def get(self, request, slug, project_id):
try:
project_deploy_board = ProjectDeployBoard.objects.get( project_deploy_board = ProjectDeployBoard.objects.get(
workspace__slug=slug, project_id=project_id workspace__slug=slug, project_id=project_id
) )
serializer = ProjectDeployBoardSerializer(project_deploy_board) serializer = ProjectDeployBoardSerializer(project_deploy_board)
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
except ProjectDeployBoard.DoesNotExist:
return Response(
{"error": "Project Deploy Board does not exists"},
status=status.HTTP_404_NOT_FOUND,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class WorkspaceProjectDeployBoardEndpoint(BaseAPIView): class WorkspaceProjectDeployBoardEndpoint(BaseAPIView):
@ -1132,7 +903,6 @@ class WorkspaceProjectDeployBoardEndpoint(BaseAPIView):
] ]
def get(self, request, slug): def get(self, request, slug):
try:
projects = ( projects = (
Project.objects.filter(workspace__slug=slug) Project.objects.filter(workspace__slug=slug)
.annotate( .annotate(
@ -1154,12 +924,6 @@ class WorkspaceProjectDeployBoardEndpoint(BaseAPIView):
) )
return Response(projects, status=status.HTTP_200_OK) return Response(projects, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class LeaveProjectEndpoint(BaseAPIView): class LeaveProjectEndpoint(BaseAPIView):
@ -1168,7 +932,6 @@ class LeaveProjectEndpoint(BaseAPIView):
] ]
def delete(self, request, slug, project_id): def delete(self, request, slug, project_id):
try:
project_member = ProjectMember.objects.get( project_member = ProjectMember.objects.get(
workspace__slug=slug, workspace__slug=slug,
member=request.user, member=request.user,
@ -1194,17 +957,6 @@ class LeaveProjectEndpoint(BaseAPIView):
# Delete the member from workspace # Delete the member from workspace
project_member.delete() project_member.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except ProjectMember.DoesNotExist:
return Response(
{"error": "Workspace member does not exists"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class ProjectPublicCoverImagesEndpoint(BaseAPIView): class ProjectPublicCoverImagesEndpoint(BaseAPIView):
@ -1213,7 +965,6 @@ class ProjectPublicCoverImagesEndpoint(BaseAPIView):
] ]
def get(self, request): def get(self, request):
try:
files = [] files = []
s3 = boto3.client( s3 = boto3.client(
"s3", "s3",
@ -1237,6 +988,3 @@ class ProjectPublicCoverImagesEndpoint(BaseAPIView):
) )
return Response(files, status=status.HTTP_200_OK) return Response(files, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response([], status=status.HTTP_200_OK)

View File

@ -168,7 +168,6 @@ class GlobalSearchEndpoint(BaseAPIView):
) )
def get(self, request, slug): def get(self, request, slug):
try:
query = request.query_params.get("search", False) query = request.query_params.get("search", False)
workspace_search = request.query_params.get("workspace_search", "false") workspace_search = request.query_params.get("workspace_search", "false")
project_id = request.query_params.get("project_id", False) project_id = request.query_params.get("project_id", False)
@ -206,17 +205,9 @@ class GlobalSearchEndpoint(BaseAPIView):
results[model] = func(query, slug, project_id, workspace_search) results[model] = func(query, slug, project_id, workspace_search)
return Response({"results": results}, status=status.HTTP_200_OK) return Response({"results": results}, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class IssueSearchEndpoint(BaseAPIView): class IssueSearchEndpoint(BaseAPIView):
def get(self, request, slug, project_id): def get(self, request, slug, project_id):
try:
query = request.query_params.get("search", False) query = request.query_params.get("search", False)
workspace_search = request.query_params.get("workspace_search", "false") workspace_search = request.query_params.get("workspace_search", "false")
parent = request.query_params.get("parent", "false") parent = request.query_params.get("parent", "false")
@ -281,13 +272,3 @@ class IssueSearchEndpoint(BaseAPIView):
), ),
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except Issue.DoesNotExist:
return Response(
{"error": "Issue Does not exist"}, status=status.HTTP_400_BAD_REQUEST
)
except Exception as e:
print(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)

View File

@ -2,7 +2,6 @@
from itertools import groupby from itertools import groupby
# Django imports # Django imports
from django.db import IntegrityError
from django.db.models import Q from django.db.models import Q
# Third party imports # Third party imports
@ -41,26 +40,13 @@ class StateViewSet(BaseViewSet):
) )
def create(self, request, slug, project_id): def create(self, request, slug, project_id):
try:
serializer = StateSerializer(data=request.data) serializer = StateSerializer(data=request.data)
if serializer.is_valid(): if serializer.is_valid():
serializer.save(project_id=project_id) serializer.save(project_id=project_id)
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except IntegrityError:
return Response(
{"error": "State with the name already exists"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def list(self, request, slug, project_id): def list(self, request, slug, project_id):
try:
state_dict = dict() state_dict = dict()
states = StateSerializer(self.get_queryset(), many=True).data states = StateSerializer(self.get_queryset(), many=True).data
@ -71,15 +57,8 @@ class StateViewSet(BaseViewSet):
state_dict[str(key)] = list(value) state_dict[str(key)] = list(value)
return Response(state_dict, status=status.HTTP_200_OK) return Response(state_dict, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def destroy(self, request, slug, project_id, pk): def destroy(self, request, slug, project_id, pk):
try:
state = State.objects.get( state = State.objects.get(
~Q(name="Triage"), ~Q(name="Triage"),
pk=pk, project_id=project_id, workspace__slug=slug, pk=pk, project_id=project_id, workspace__slug=slug,
@ -103,5 +82,3 @@ class StateViewSet(BaseViewSet):
state.delete() state.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except State.DoesNotExist:
return Response({"error": "State does not exists"}, status=status.HTTP_404)

View File

@ -32,68 +32,35 @@ class UserEndpoint(BaseViewSet):
return self.request.user return self.request.user
def retrieve(self, request): def retrieve(self, request):
try:
serialized_data = UserMeSerializer(request.user).data serialized_data = UserMeSerializer(request.user).data
return Response( return Response(
serialized_data, serialized_data,
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def retrieve_user_settings(self, request): def retrieve_user_settings(self, request):
try:
serialized_data = UserMeSettingsSerializer(request.user).data serialized_data = UserMeSettingsSerializer(request.user).data
return Response(serialized_data, status=status.HTTP_200_OK) return Response(serialized_data, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class UpdateUserOnBoardedEndpoint(BaseAPIView): class UpdateUserOnBoardedEndpoint(BaseAPIView):
def patch(self, request): def patch(self, request):
try:
user = User.objects.get(pk=request.user.id) user = User.objects.get(pk=request.user.id)
user.is_onboarded = request.data.get("is_onboarded", False) user.is_onboarded = request.data.get("is_onboarded", False)
user.save() user.save()
return Response( return Response({"message": "Updated successfully"}, status=status.HTTP_200_OK)
{"message": "Updated successfully"}, status=status.HTTP_200_OK
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class UpdateUserTourCompletedEndpoint(BaseAPIView): class UpdateUserTourCompletedEndpoint(BaseAPIView):
def patch(self, request): def patch(self, request):
try:
user = User.objects.get(pk=request.user.id) user = User.objects.get(pk=request.user.id)
user.is_tour_completed = request.data.get("is_tour_completed", False) user.is_tour_completed = request.data.get("is_tour_completed", False)
user.save() user.save()
return Response( return Response({"message": "Updated successfully"}, status=status.HTTP_200_OK)
{"message": "Updated successfully"}, status=status.HTTP_200_OK
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class UserActivityEndpoint(BaseAPIView, BasePaginator): class UserActivityEndpoint(BaseAPIView, BasePaginator):
def get(self, request, slug): def get(self, request, slug):
try:
queryset = IssueActivity.objects.filter( queryset = IssueActivity.objects.filter(
actor=request.user, workspace__slug=slug actor=request.user, workspace__slug=slug
).select_related("actor", "workspace", "issue", "project") ).select_related("actor", "workspace", "issue", "project")
@ -105,9 +72,3 @@ class UserActivityEndpoint(BaseAPIView, BasePaginator):
issue_activities, many=True issue_activities, many=True
).data, ).data,
) )
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)

View File

@ -13,7 +13,6 @@ from django.db.models import (
) )
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.views.decorators.gzip import gzip_page from django.views.decorators.gzip import gzip_page
from django.db import IntegrityError
from django.db.models import Prefetch, OuterRef, Exists from django.db.models import Prefetch, OuterRef, Exists
# Third party imports # Third party imports
@ -97,7 +96,6 @@ class GlobalViewIssuesViewSet(BaseViewSet):
@method_decorator(gzip_page) @method_decorator(gzip_page)
def list(self, request, slug): def list(self, request, slug):
try:
filters = issue_filters(request.query_params, "GET") filters = issue_filters(request.query_params, "GET")
# Custom ordering for priority and state # Custom ordering for priority and state
@ -204,13 +202,6 @@ class GlobalViewIssuesViewSet(BaseViewSet):
return Response(issues, status=status.HTTP_200_OK) return Response(issues, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class IssueViewViewSet(BaseViewSet): class IssueViewViewSet(BaseViewSet):
serializer_class = IssueViewSerializer serializer_class = IssueViewSerializer
@ -257,33 +248,13 @@ class IssueViewFavoriteViewSet(BaseViewSet):
) )
def create(self, request, slug, project_id): def create(self, request, slug, project_id):
try:
serializer = IssueViewFavoriteSerializer(data=request.data) serializer = IssueViewFavoriteSerializer(data=request.data)
if serializer.is_valid(): if serializer.is_valid():
serializer.save(user=request.user, project_id=project_id) serializer.save(user=request.user, project_id=project_id)
return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except IntegrityError as e:
if "already exists" in str(e):
return Response(
{"error": "The view is already added to favorites"},
status=status.HTTP_410_GONE,
)
else:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def destroy(self, request, slug, project_id, view_id): def destroy(self, request, slug, project_id, view_id):
try:
view_favourite = IssueViewFavorite.objects.get( view_favourite = IssueViewFavorite.objects.get(
project=project_id, project=project_id,
user=request.user, user=request.user,
@ -292,14 +263,3 @@ class IssueViewFavoriteViewSet(BaseViewSet):
) )
view_favourite.delete() view_favourite.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except IssueViewFavorite.DoesNotExist:
return Response(
{"error": "View is not in favorites"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)

View File

@ -165,23 +165,12 @@ class WorkSpaceViewSet(BaseViewSet):
status=status.HTTP_400_BAD_REQUEST, status=status.HTTP_400_BAD_REQUEST,
) )
## Handling unique integrity error for now
## TODO: Extend this to handle other common errors which are not automatically handled by APIException
except IntegrityError as e: except IntegrityError as e:
if "already exists" in str(e): if "already exists" in str(e):
return Response( return Response(
{"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,
) )
except Exception as e:
capture_exception(e)
return Response(
{
"error": "Something went wrong please try again later",
"identifier": None,
},
status=status.HTTP_400_BAD_REQUEST,
)
class UserWorkSpacesEndpoint(BaseAPIView): class UserWorkSpacesEndpoint(BaseAPIView):
@ -193,7 +182,6 @@ class UserWorkSpacesEndpoint(BaseAPIView):
] ]
def get(self, request): def get(self, request):
try:
member_count = ( member_count = (
WorkspaceMember.objects.filter( WorkspaceMember.objects.filter(
workspace=OuterRef("id"), member__is_bot=False workspace=OuterRef("id"), member__is_bot=False
@ -213,9 +201,7 @@ class UserWorkSpacesEndpoint(BaseAPIView):
workspace = ( workspace = (
( (
Workspace.objects.prefetch_related( Workspace.objects.prefetch_related(
Prefetch( Prefetch("workspace_member", queryset=WorkspaceMember.objects.all())
"workspace_member", queryset=WorkspaceMember.objects.all()
)
) )
.filter( .filter(
workspace_member__member=request.user, workspace_member__member=request.user,
@ -229,17 +215,9 @@ class UserWorkSpacesEndpoint(BaseAPIView):
serializer = WorkSpaceSerializer(self.filter_queryset(workspace), many=True) serializer = WorkSpaceSerializer(self.filter_queryset(workspace), many=True)
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class WorkSpaceAvailabilityCheckEndpoint(BaseAPIView): class WorkSpaceAvailabilityCheckEndpoint(BaseAPIView):
def get(self, request): def get(self, request):
try:
slug = request.GET.get("slug", False) slug = request.GET.get("slug", False)
if not slug or slug == "": if not slug or slug == "":
@ -250,12 +228,6 @@ class WorkSpaceAvailabilityCheckEndpoint(BaseAPIView):
workspace = Workspace.objects.filter(slug=slug).exists() workspace = Workspace.objects.filter(slug=slug).exists()
return Response({"status": not workspace}, status=status.HTTP_200_OK) return Response({"status": not workspace}, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class InviteWorkspaceEndpoint(BaseAPIView): class InviteWorkspaceEndpoint(BaseAPIView):
@ -264,7 +236,6 @@ class InviteWorkspaceEndpoint(BaseAPIView):
] ]
def post(self, request, slug): def post(self, request, slug):
try:
emails = request.data.get("emails", False) emails = request.data.get("emails", False)
# Check if email is provided # Check if email is provided
if not emails or not len(emails): if not emails or not len(emails):
@ -373,18 +344,6 @@ class InviteWorkspaceEndpoint(BaseAPIView):
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except Workspace.DoesNotExist:
return Response(
{"error": "Workspace does not exists"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class JoinWorkspaceEndpoint(BaseAPIView): class JoinWorkspaceEndpoint(BaseAPIView):
permission_classes = [ permission_classes = [
@ -392,7 +351,6 @@ class JoinWorkspaceEndpoint(BaseAPIView):
] ]
def post(self, request, slug, pk): def post(self, request, slug, pk):
try:
workspace_invite = WorkspaceMemberInvite.objects.get( workspace_invite = WorkspaceMemberInvite.objects.get(
pk=pk, workspace__slug=slug pk=pk, workspace__slug=slug
) )
@ -443,18 +401,6 @@ class JoinWorkspaceEndpoint(BaseAPIView):
status=status.HTTP_400_BAD_REQUEST, status=status.HTTP_400_BAD_REQUEST,
) )
except WorkspaceMemberInvite.DoesNotExist:
return Response(
{"error": "The invitation either got expired or could not be found"},
status=status.HTTP_404_NOT_FOUND,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class WorkspaceInvitationsViewset(BaseViewSet): class WorkspaceInvitationsViewset(BaseViewSet):
serializer_class = WorkSpaceMemberInviteSerializer serializer_class = WorkSpaceMemberInviteSerializer
@ -473,7 +419,6 @@ class WorkspaceInvitationsViewset(BaseViewSet):
) )
def destroy(self, request, slug, pk): def destroy(self, request, slug, pk):
try:
workspace_member_invite = WorkspaceMemberInvite.objects.get( workspace_member_invite = WorkspaceMemberInvite.objects.get(
pk=pk, workspace__slug=slug pk=pk, workspace__slug=slug
) )
@ -484,17 +429,6 @@ class WorkspaceInvitationsViewset(BaseViewSet):
user.delete() user.delete()
workspace_member_invite.delete() workspace_member_invite.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except WorkspaceMemberInvite.DoesNotExist:
return Response(
{"error": "Workspace member invite does not exists"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class UserWorkspaceInvitationsEndpoint(BaseViewSet): class UserWorkspaceInvitationsEndpoint(BaseViewSet):
@ -511,11 +445,8 @@ class UserWorkspaceInvitationsEndpoint(BaseViewSet):
) )
def create(self, request): def create(self, request):
try:
invitations = request.data.get("invitations") invitations = request.data.get("invitations")
workspace_invitations = WorkspaceMemberInvite.objects.filter( workspace_invitations = WorkspaceMemberInvite.objects.filter(pk__in=invitations)
pk__in=invitations
)
WorkspaceMember.objects.bulk_create( WorkspaceMember.objects.bulk_create(
[ [
@ -534,12 +465,6 @@ class UserWorkspaceInvitationsEndpoint(BaseViewSet):
workspace_invitations.delete() workspace_invitations.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class WorkSpaceMemberViewSet(BaseViewSet): class WorkSpaceMemberViewSet(BaseViewSet):
@ -565,7 +490,6 @@ class WorkSpaceMemberViewSet(BaseViewSet):
) )
def partial_update(self, request, slug, pk): def partial_update(self, request, slug, pk):
try:
workspace_member = WorkspaceMember.objects.get(pk=pk, workspace__slug=slug) workspace_member = WorkspaceMember.objects.get(pk=pk, workspace__slug=slug)
if request.user.id == workspace_member.member_id: if request.user.id == workspace_member.member_id:
return Response( return Response(
@ -585,9 +509,7 @@ class WorkSpaceMemberViewSet(BaseViewSet):
> requested_workspace_member.role > requested_workspace_member.role
): ):
return Response( return Response(
{ {"error": "You cannot update a role that is higher than your own role"},
"error": "You cannot update a role that is higher than your own role"
},
status=status.HTTP_400_BAD_REQUEST, status=status.HTTP_400_BAD_REQUEST,
) )
@ -599,20 +521,8 @@ class WorkSpaceMemberViewSet(BaseViewSet):
serializer.save() serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except WorkspaceMember.DoesNotExist:
return Response(
{"error": "Workspace Member does not exist"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
def destroy(self, request, slug, pk): def destroy(self, request, slug, pk):
try:
# Check the user role who is deleting the user # Check the user role who is deleting the user
workspace_member = WorkspaceMember.objects.get(workspace__slug=slug, pk=pk) workspace_member = WorkspaceMember.objects.get(workspace__slug=slug, pk=pk)
@ -677,17 +587,6 @@ class WorkSpaceMemberViewSet(BaseViewSet):
workspace_member.delete() workspace_member.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except WorkspaceMember.DoesNotExist:
return Response(
{"error": "Workspace Member does not exists"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class TeamMemberViewSet(BaseViewSet): class TeamMemberViewSet(BaseViewSet):
@ -712,7 +611,6 @@ class TeamMemberViewSet(BaseViewSet):
) )
def create(self, request, slug): def create(self, request, slug):
try:
members = list( members = list(
WorkspaceMember.objects.filter( WorkspaceMember.objects.filter(
workspace__slug=slug, member__id__in=request.data.get("members", []) workspace__slug=slug, member__id__in=request.data.get("members", [])
@ -737,25 +635,11 @@ class TeamMemberViewSet(BaseViewSet):
workspace = Workspace.objects.get(slug=slug) workspace = Workspace.objects.get(slug=slug)
serializer = TeamSerializer( serializer = TeamSerializer(data=request.data, context={"workspace": workspace})
data=request.data, context={"workspace": workspace}
)
if serializer.is_valid(): if serializer.is_valid():
serializer.save() serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except IntegrityError as e:
if "already exists" in str(e):
return Response(
{"error": "The team with the name already exists"},
status=status.HTTP_410_GONE,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class UserWorkspaceInvitationEndpoint(BaseViewSet): class UserWorkspaceInvitationEndpoint(BaseViewSet):
@ -777,7 +661,6 @@ class UserWorkspaceInvitationEndpoint(BaseViewSet):
class UserLastProjectWithWorkspaceEndpoint(BaseAPIView): class UserLastProjectWithWorkspaceEndpoint(BaseAPIView):
def get(self, request): def get(self, request):
try:
user = User.objects.get(pk=request.user.id) user = User.objects.get(pk=request.user.id)
last_workspace_id = user.last_workspace_id last_workspace_id = user.last_workspace_id
@ -798,9 +681,7 @@ class UserLastProjectWithWorkspaceEndpoint(BaseAPIView):
workspace_id=last_workspace_id, member=request.user workspace_id=last_workspace_id, member=request.user
).select_related("workspace", "project", "member", "workspace__owner") ).select_related("workspace", "project", "member", "workspace__owner")
project_member_serializer = ProjectMemberSerializer( project_member_serializer = ProjectMemberSerializer(project_member, many=True)
project_member, many=True
)
return Response( return Response(
{ {
@ -810,37 +691,18 @@ class UserLastProjectWithWorkspaceEndpoint(BaseAPIView):
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except User.DoesNotExist:
return Response({"error": "Forbidden"}, status=status.HTTP_403_FORBIDDEN)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class WorkspaceMemberUserEndpoint(BaseAPIView): class WorkspaceMemberUserEndpoint(BaseAPIView):
def get(self, request, slug): def get(self, request, slug):
try:
workspace_member = WorkspaceMember.objects.get( workspace_member = WorkspaceMember.objects.get(
member=request.user, workspace__slug=slug member=request.user, workspace__slug=slug
) )
serializer = WorkspaceMemberMeSerializer(workspace_member) serializer = WorkspaceMemberMeSerializer(workspace_member)
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
except (Workspace.DoesNotExist, WorkspaceMember.DoesNotExist):
return Response({"error": "Forbidden"}, status=status.HTTP_403_FORBIDDEN)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class WorkspaceMemberUserViewsEndpoint(BaseAPIView): class WorkspaceMemberUserViewsEndpoint(BaseAPIView):
def post(self, request, slug): def post(self, request, slug):
try:
workspace_member = WorkspaceMember.objects.get( workspace_member = WorkspaceMember.objects.get(
workspace__slug=slug, member=request.user workspace__slug=slug, member=request.user
) )
@ -848,22 +710,10 @@ class WorkspaceMemberUserViewsEndpoint(BaseAPIView):
workspace_member.save() workspace_member.save()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except WorkspaceMember.DoesNotExist:
return Response(
{"error": "User not a member of workspace"},
status=status.HTTP_403_FORBIDDEN,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class UserActivityGraphEndpoint(BaseAPIView): class UserActivityGraphEndpoint(BaseAPIView):
def get(self, request, slug): def get(self, request, slug):
try:
issue_activities = ( issue_activities = (
IssueActivity.objects.filter( IssueActivity.objects.filter(
actor=request.user, actor=request.user,
@ -877,17 +727,10 @@ class UserActivityGraphEndpoint(BaseAPIView):
) )
return Response(issue_activities, status=status.HTTP_200_OK) return Response(issue_activities, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class UserIssueCompletedGraphEndpoint(BaseAPIView): class UserIssueCompletedGraphEndpoint(BaseAPIView):
def get(self, request, slug): def get(self, request, slug):
try:
month = request.GET.get("month", 1) month = request.GET.get("month", 1)
issues = ( issues = (
@ -905,12 +748,6 @@ class UserIssueCompletedGraphEndpoint(BaseAPIView):
) )
return Response(issues, status=status.HTTP_200_OK) return Response(issues, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class WeekInMonth(Func): class WeekInMonth(Func):
@ -920,7 +757,6 @@ class WeekInMonth(Func):
class UserWorkspaceDashboardEndpoint(BaseAPIView): class UserWorkspaceDashboardEndpoint(BaseAPIView):
def get(self, request, slug): def get(self, request, slug):
try:
issue_activities = ( issue_activities = (
IssueActivity.objects.filter( IssueActivity.objects.filter(
actor=request.user, actor=request.user,
@ -1016,13 +852,6 @@ class UserWorkspaceDashboardEndpoint(BaseAPIView):
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class WorkspaceThemeViewSet(BaseViewSet): class WorkspaceThemeViewSet(BaseViewSet):
permission_classes = [ permission_classes = [
@ -1035,29 +864,16 @@ class WorkspaceThemeViewSet(BaseViewSet):
return super().get_queryset().filter(workspace__slug=self.kwargs.get("slug")) return super().get_queryset().filter(workspace__slug=self.kwargs.get("slug"))
def create(self, request, slug): def create(self, request, slug):
try:
workspace = Workspace.objects.get(slug=slug) workspace = Workspace.objects.get(slug=slug)
serializer = WorkspaceThemeSerializer(data=request.data) serializer = WorkspaceThemeSerializer(data=request.data)
if serializer.is_valid(): if serializer.is_valid():
serializer.save(workspace=workspace, actor=request.user) serializer.save(workspace=workspace, actor=request.user)
return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except Workspace.DoesNotExist:
return Response(
{"error": "Workspace does not exist"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class WorkspaceUserProfileStatsEndpoint(BaseAPIView): class WorkspaceUserProfileStatsEndpoint(BaseAPIView):
def get(self, request, slug, user_id): def get(self, request, slug, user_id):
try:
filters = issue_filters(request.query_params, "GET") filters = issue_filters(request.query_params, "GET")
state_distribution = ( state_distribution = (
@ -1180,12 +996,6 @@ class WorkspaceUserProfileStatsEndpoint(BaseAPIView):
"upcoming_cycles": upcoming_cycles, "upcoming_cycles": upcoming_cycles,
} }
) )
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class WorkspaceUserActivityEndpoint(BaseAPIView): class WorkspaceUserActivityEndpoint(BaseAPIView):
@ -1194,7 +1004,6 @@ class WorkspaceUserActivityEndpoint(BaseAPIView):
] ]
def get(self, request, slug, user_id): def get(self, request, slug, user_id):
try:
projects = request.query_params.getlist("project", []) projects = request.query_params.getlist("project", [])
queryset = IssueActivity.objects.filter( queryset = IssueActivity.objects.filter(
@ -1214,17 +1023,10 @@ class WorkspaceUserActivityEndpoint(BaseAPIView):
issue_activities, many=True issue_activities, many=True
).data, ).data,
) )
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class WorkspaceUserProfileEndpoint(BaseAPIView): class WorkspaceUserProfileEndpoint(BaseAPIView):
def get(self, request, slug, user_id): def get(self, request, slug, user_id):
try:
user_data = User.objects.get(pk=user_id) user_data = User.objects.get(pk=user_id)
requesting_workspace_member = WorkspaceMember.objects.get( requesting_workspace_member = WorkspaceMember.objects.get(
@ -1312,14 +1114,6 @@ class WorkspaceUserProfileEndpoint(BaseAPIView):
}, },
status=status.HTTP_200_OK, status=status.HTTP_200_OK,
) )
except WorkspaceMember.DoesNotExist:
return Response({"error": "Forbidden"}, status=status.HTTP_403_FORBIDDEN)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class WorkspaceUserProfileIssuesEndpoint(BaseAPIView): class WorkspaceUserProfileIssuesEndpoint(BaseAPIView):
@ -1328,7 +1122,6 @@ class WorkspaceUserProfileIssuesEndpoint(BaseAPIView):
] ]
def get(self, request, slug, user_id): def get(self, request, slug, user_id):
try:
filters = issue_filters(request.query_params, "GET") filters = issue_filters(request.query_params, "GET")
# Custom ordering for priority and state # Custom ordering for priority and state
@ -1367,9 +1160,7 @@ class WorkspaceUserProfileIssuesEndpoint(BaseAPIView):
.values("count") .values("count")
) )
.annotate( .annotate(
attachment_count=IssueAttachment.objects.filter( attachment_count=IssueAttachment.objects.filter(issue=OuterRef("id"))
issue=OuterRef("id")
)
.order_by() .order_by()
.annotate(count=Func(F("id"), function="Count")) .annotate(count=Func(F("id"), function="Count"))
.values("count") .values("count")
@ -1379,9 +1170,7 @@ class WorkspaceUserProfileIssuesEndpoint(BaseAPIView):
# Priority Ordering # Priority Ordering
if order_by_param == "priority" or order_by_param == "-priority": if order_by_param == "priority" or order_by_param == "-priority":
priority_order = ( priority_order = (
priority_order priority_order if order_by_param == "priority" else priority_order[::-1]
if order_by_param == "priority"
else priority_order[::-1]
) )
issue_queryset = issue_queryset.annotate( issue_queryset = issue_queryset.annotate(
priority_order=Case( priority_order=Case(
@ -1439,17 +1228,9 @@ class WorkspaceUserProfileIssuesEndpoint(BaseAPIView):
## Grouping the results ## Grouping the results
group_by = request.GET.get("group_by", False) group_by = request.GET.get("group_by", False)
if group_by: if group_by:
return Response( return Response(group_results(issues, group_by), status=status.HTTP_200_OK)
group_results(issues, group_by), status=status.HTTP_200_OK
)
return Response(issues, status=status.HTTP_200_OK) return Response(issues, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class WorkspaceLabelsEndpoint(BaseAPIView): class WorkspaceLabelsEndpoint(BaseAPIView):
@ -1458,18 +1239,11 @@ class WorkspaceLabelsEndpoint(BaseAPIView):
] ]
def get(self, request, slug): def get(self, request, slug):
try:
labels = Label.objects.filter( labels = Label.objects.filter(
workspace__slug=slug, workspace__slug=slug,
project__project_projectmember__member=request.user, project__project_projectmember__member=request.user,
).values("parent", "name", "color", "id", "project_id", "workspace__slug") ).values("parent", "name", "color", "id", "project_id", "workspace__slug")
return Response(labels, status=status.HTTP_200_OK) return Response(labels, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class WorkspaceMembersEndpoint(BaseAPIView): class WorkspaceMembersEndpoint(BaseAPIView):
@ -1478,19 +1252,12 @@ class WorkspaceMembersEndpoint(BaseAPIView):
] ]
def get(self, request, slug): def get(self, request, slug):
try:
workspace_members = WorkspaceMember.objects.filter( workspace_members = WorkspaceMember.objects.filter(
workspace__slug=slug, workspace__slug=slug,
member__is_bot=False, member__is_bot=False,
).select_related("workspace", "member") ).select_related("workspace", "member")
serialzier = WorkSpaceMemberSerializer(workspace_members, many=True) serialzier = WorkSpaceMemberSerializer(workspace_members, many=True)
return Response(serialzier.data, status=status.HTTP_200_OK) return Response(serialzier.data, status=status.HTTP_200_OK)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)
class LeaveWorkspaceEndpoint(BaseAPIView): class LeaveWorkspaceEndpoint(BaseAPIView):
@ -1499,7 +1266,6 @@ class LeaveWorkspaceEndpoint(BaseAPIView):
] ]
def delete(self, request, slug): def delete(self, request, slug):
try:
workspace_member = WorkspaceMember.objects.get( workspace_member = WorkspaceMember.objects.get(
workspace__slug=slug, member=request.user workspace__slug=slug, member=request.user
) )
@ -1507,9 +1273,7 @@ class LeaveWorkspaceEndpoint(BaseAPIView):
# Only Admin case # Only Admin case
if ( if (
workspace_member.role == 20 workspace_member.role == 20
and WorkspaceMember.objects.filter( and WorkspaceMember.objects.filter(workspace__slug=slug, role=20).count()
workspace__slug=slug, role=20
).count()
== 1 == 1
): ):
return Response( return Response(
@ -1521,14 +1285,3 @@ class LeaveWorkspaceEndpoint(BaseAPIView):
# Delete the member from workspace # Delete the member from workspace
workspace_member.delete() workspace_member.delete()
return Response(status=status.HTTP_204_NO_CONTENT) return Response(status=status.HTTP_204_NO_CONTENT)
except WorkspaceMember.DoesNotExist:
return Response(
{"error": "Workspace member does not exists"},
status=status.HTTP_400_BAD_REQUEST,
)
except Exception as e:
capture_exception(e)
return Response(
{"error": "Something went wrong please try again later"},
status=status.HTTP_400_BAD_REQUEST,
)