Skip to content
Snippets Groups Projects
Commit 0571b427 authored by Jonas Braathen's avatar Jonas Braathen
Browse files

Move IdentityDuplicateError

parent aebf03d9
No related branches found
No related tags found
1 merge request!299Show invitation status
Pipeline #120566 passed
from rest_framework.exceptions import APIException
from rest_framework import status
from greg.models import Identity
class IdentityDuplicateError(APIException):
"""
Used to signal the there is already an identity registered with the same value
for the type given as input parameter.
"""
status_code = status.HTTP_400_BAD_REQUEST
default_detail = "Validation error"
_type: Identity.IdentityType
def __init__(self, identity_type: Identity.IdentityType, code: str):
super().__init__()
self._type = identity_type
self.code = code
self.detail = {"code": code, "message": "Duplicate identity"}
......@@ -16,8 +16,10 @@ from greg.models import (
InvitationLink,
)
from greg.utils import is_identity_duplicate
from gregui.api.serializers.IdentityDuplicateError import IdentityDuplicateError
from gregui.api.serializers.identity import PartialIdentitySerializer
from gregui.api.serializers.identity import (
PartialIdentitySerializer,
IdentityDuplicateError,
)
from gregui.api.serializers.role import ExtendedRoleSerializer
from gregui.validation import (
validate_phone_number,
......
from django.conf import settings
from django.utils import timezone
from rest_framework import serializers
from rest_framework.exceptions import ValidationError
from rest_framework import status
from rest_framework.exceptions import APIException, ValidationError
from greg.models import Identity
from gregui.models import GregUserProfile
class IdentityDuplicateError(APIException):
"""
Used to signal the there is already an identity registered with the same value
for the type given as input parameter.
"""
status_code = status.HTTP_400_BAD_REQUEST
default_detail = "Validation error"
_type: Identity.IdentityType
def __init__(self, identity_type: Identity.IdentityType, code: str):
super().__init__()
self._type = identity_type
self.code = code
self.detail = {"code": code, "message": "Duplicate identity"}
class IdentitySerializer(serializers.ModelSerializer):
"""Serializer for the Identity model with validation of various fields"""
......
......@@ -7,7 +7,7 @@ from rest_framework import serializers
from greg.models import Invitation, InvitationLink, Person, Role, Identity
from greg.utils import is_identity_duplicate
from gregui.api.serializers.IdentityDuplicateError import IdentityDuplicateError
from gregui.api.serializers.identity import IdentityDuplicateError
from gregui.api.serializers.role import InviteRoleSerializerUi
from gregui.models import GregUserProfile
......
......@@ -10,8 +10,11 @@ from greg.models import Identity, Person
from greg.permissions import IsSponsor
from greg.utils import is_identity_duplicate
from gregui import validation
from gregui.api.serializers.IdentityDuplicateError import IdentityDuplicateError
from gregui.api.serializers.guest import GuestSerializer, create_identity_or_update
from gregui.api.serializers.guest import (
GuestSerializer,
create_identity_or_update,
)
from gregui.api.serializers.identity import IdentityDuplicateError
from gregui.models import GregUserProfile
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment