diff --git a/django_etesync/serializers.py b/django_etesync/serializers.py index 185eb6e..1cc4a7e 100644 --- a/django_etesync/serializers.py +++ b/django_etesync/serializers.py @@ -339,6 +339,14 @@ class UserQuerySerializer(serializers.ModelSerializer): fields = (User.USERNAME_FIELD, User.EMAIL_FIELD) +class UserInfoPubkeySerializer(serializers.ModelSerializer): + pubkey = BinaryBase64Field() + + class Meta: + model = models.UserInfo + fields = ('pubkey', ) + + class AuthenticationSignupSerializer(serializers.Serializer): user = UserQuerySerializer(many=False) salt = BinaryBase64Field() diff --git a/django_etesync/views.py b/django_etesync/views.py index a1d6d09..7130eae 100644 --- a/django_etesync/views.py +++ b/django_etesync/views.py @@ -34,7 +34,7 @@ import nacl.secret import nacl.hash from . import app_settings, permissions -from .models import Collection, CollectionItem, CollectionItemRevision, CollectionMember, CollectionInvitation +from .models import Collection, CollectionItem, CollectionItemRevision, CollectionMember, CollectionInvitation, UserInfo from .serializers import ( b64encode, AuthenticationSignupSerializer, @@ -50,6 +50,7 @@ from .serializers import ( CollectionMemberSerializer, CollectionInvitationSerializer, InvitationAcceptSerializer, + UserInfoPubkeySerializer, UserSerializer, ) @@ -456,6 +457,14 @@ class CollectionInvitationViewSet(BaseViewSet): return queryset.filter(fromMember__collection=collection) + @action_decorator(detail=False, allowed_methods=['GET'], methods=['GET']) + def fetch_user_profile(self, request, collection_uid=None): + username = request.GET.get('username') + kwargs = {'owner__' + User.USERNAME_FIELD: username} + user_info = get_object_or_404(UserInfo.objects.all(), **kwargs) + serializer = UserInfoPubkeySerializer(user_info) + return Response(serializer.data) + class InvitationIncomingViewSet(BaseViewSet): allowed_methods = ['GET', 'DELETE']