* Forbidden exception when failing to cancel the order

This commit is contained in:
Phil Zhitnikov 2024-05-26 16:18:31 +04:00
parent d88eeb790a
commit 8b6a5ca95c
2 changed files with 5 additions and 2 deletions

View File

@ -14,7 +14,7 @@ from rest_framework.response import Response
from external_api.cdek import CDEKClient, CDEKWebhookTypes, CDEK_STATUS_TO_ORDER_STATUS from external_api.cdek import CDEKClient, CDEKWebhookTypes, CDEK_STATUS_TO_ORDER_STATUS
from external_api.poizon import PoizonClient from external_api.poizon import PoizonClient
from utils.exceptions import CRMException from utils.exceptions import CRMException, Forbidden
from store.filters import GiftFilter, ChecklistFilter from store.filters import GiftFilter, ChecklistFilter
from store.models import Checklist, Category, PaymentMethod, Promocode, Gift from store.models import Checklist, Category, PaymentMethod, Promocode, Gift
from core.models import GlobalSettings from core.models import GlobalSettings
@ -92,7 +92,7 @@ class ChecklistAPI(viewsets.ModelViewSet):
# Non-managers can cancel orders only in certain statuses # Non-managers can cancel orders only in certain statuses
if (not getattr(self.request.user, 'is_manager', False) if (not getattr(self.request.user, 'is_manager', False)
and obj.status not in Checklist.Status.CANCELLABLE_ORDER_STATUSES): and obj.status not in Checklist.Status.CANCELLABLE_ORDER_STATUSES):
raise CRMException("Can't delete the order") raise Forbidden("Can't delete the order")
obj.cancel() obj.cancel()

View File

@ -12,4 +12,7 @@ class CRMException(APIException):
self.detail = {'error': detail} self.detail = {'error': detail}
class Forbidden(CRMException):
status_code = status.HTTP_403_FORBIDDEN
# TODO: exceptions with a same template: ok / error_code / error_message # TODO: exceptions with a same template: ok / error_code / error_message