Skip to content

Commit

Permalink
Add auth_type to current user serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewelwell authored and dabeeeenster committed May 31, 2020
1 parent 43f2fce commit 4b79c2f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/app/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@
'SEND_ACTIVATION_EMAIL': False,
'SERIALIZERS': {
'token': 'custom_auth.serializers.CustomTokenSerializer',
'user_create': 'custom_auth.serializers.CustomUserCreateSerializer'
'user_create': 'custom_auth.serializers.CustomUserCreateSerializer',
'current_user': 'users.serializers.CustomCurrentUserSerializer',
},
'SET_PASSWORD_RETYPE': True,
'PASSWORD_RESET_CONFIRM_RETYPE': True,
Expand Down
6 changes: 6 additions & 0 deletions src/users/auth_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from enum import Enum


class AuthType(Enum):
GOOGLE = "GOOGLE"
EMAIL = "EMAIL"
5 changes: 5 additions & 0 deletions src/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
Identity
from organisations.models import Organisation, UserOrganisation, OrganisationRole, organisation_roles
from projects.models import UserProjectPermission, UserPermissionGroupProjectPermission, Project
from users.auth_type import AuthType
from users.exceptions import InvalidInviteError

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -79,6 +80,10 @@ class Meta:
def __str__(self):
return "%s %s" % (self.first_name, self.last_name)

@property
def auth_type(self):
return AuthType.GOOGLE.value if self.google_user_id else AuthType.EMAIL.value

def get_full_name(self):
if not self.first_name:
return None
Expand Down
9 changes: 9 additions & 0 deletions src/users/serializers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from djoser.serializers import UserSerializer as DjoserUserSerializer
from rest_framework import serializers
from rest_framework.exceptions import ValidationError

Expand Down Expand Up @@ -99,3 +100,11 @@ class Meta:
class UserPermissionGroupSerializerDetail(UserPermissionGroupSerializerList):
# TODO: remove users from here and just add a summary of number of users
users = UserListSerializer(many=True, read_only=True)


class CustomCurrentUserSerializer(DjoserUserSerializer):
auth_type = serializers.CharField(read_only=True)

class Meta(DjoserUserSerializer.Meta):
fields = DjoserUserSerializer.Meta.fields + ('auth_type',)

0 comments on commit 4b79c2f

Please sign in to comment.