Fix a few FIXMEs.

master
Tom Hacohen 4 years ago
parent 13d4121fc2
commit ec8c69b3f3

@ -24,7 +24,7 @@ from django_etebase.models import UserInfo
from django_etebase.signals import user_signed_up from django_etebase.signals import user_signed_up
from django_etebase.token_auth.models import AuthToken from django_etebase.token_auth.models import AuthToken
from django_etebase.token_auth.models import get_default_expiry from django_etebase.token_auth.models import get_default_expiry
from django_etebase.utils import create_user from django_etebase.utils import create_user, get_user_queryset, CallbackContext
from django_etebase.views import msgpack_encode, msgpack_decode from django_etebase.views import msgpack_encode, msgpack_decode
from .exceptions import AuthenticationFailed, transform_validation_error, ValidationError from .exceptions import AuthenticationFailed, transform_validation_error, ValidationError
from .msgpack import MsgpackResponse, MsgpackRoute from .msgpack import MsgpackResponse, MsgpackRoute
@ -268,20 +268,21 @@ async def change_password(data: ChangePassword, request: Request, user: User = D
return Response(status_code=status.HTTP_204_NO_CONTENT) return Response(status_code=status.HTTP_204_NO_CONTENT)
def signup_save(data: SignupIn) -> User: def signup_save(data: SignupIn, request: Request) -> User:
user_data = data.user user_data = data.user
with transaction.atomic(): with transaction.atomic():
try: try:
# XXX-TOM user_queryset = get_user_queryset(User.objects.all(), CallbackContext(request.path_params))
# view = self.context.get("view", None)
# user_queryset = get_user_queryset(User.objects.all(), view)
user_queryset = User.objects.all()
instance = user_queryset.get(**{User.USERNAME_FIELD: user_data.username.lower()}) instance = user_queryset.get(**{User.USERNAME_FIELD: user_data.username.lower()})
except User.DoesNotExist: except User.DoesNotExist:
# Create the user and save the casing the user chose as the first name # Create the user and save the casing the user chose as the first name
try: try:
# XXX-TOM instance = create_user(
instance = create_user(**user_data.dict(), password=None, first_name=user_data.username, view=None) **user_data.dict(),
password=None,
first_name=user_data.username,
context=CallbackContext(request.path_params),
)
instance.full_clean() instance.full_clean()
except EtebaseValidationError as e: except EtebaseValidationError as e:
raise e raise e
@ -298,8 +299,8 @@ def signup_save(data: SignupIn) -> User:
@authentication_router.post("/signup/") @authentication_router.post("/signup/")
async def signup(data: SignupIn): async def signup(data: SignupIn, request: Request):
user = await sync_to_async(signup_save)(data) user = await sync_to_async(signup_save)(data, request)
# XXX-TOM # XXX-TOM
data = await sync_to_async(LoginOut.from_orm)(user) data = await sync_to_async(LoginOut.from_orm)(user)
await sync_to_async(user_signed_up.send)(sender=user.__class__, request=None, user=user) await sync_to_async(user_signed_up.send)(sender=user.__class__, request=None, user=user)

@ -2,7 +2,7 @@ from django.conf import settings
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.db import transaction from django.db import transaction
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from fastapi import APIRouter, Response, status from fastapi import APIRouter, Request, Response, status
from django_etebase.utils import get_user_queryset from django_etebase.utils import get_user_queryset
from etebase_fastapi.authentication import SignupIn, signup_save from etebase_fastapi.authentication import SignupIn, signup_save
@ -13,7 +13,7 @@ User = get_user_model()
@test_reset_view_router.post("/reset/") @test_reset_view_router.post("/reset/")
def reset(data: SignupIn): def reset(data: SignupIn, request: Request):
# Only run when in DEBUG mode! It's only used for tests # Only run when in DEBUG mode! It's only used for tests
if not settings.DEBUG: if not settings.DEBUG:
return Response("Only allowed in debug mode.", status_code=status.HTTP_400_BAD_REQUEST) return Response("Only allowed in debug mode.", status_code=status.HTTP_400_BAD_REQUEST)
@ -28,7 +28,7 @@ def reset(data: SignupIn):
if hasattr(user, "userinfo"): if hasattr(user, "userinfo"):
user.userinfo.delete() user.userinfo.delete()
signup_save(data) signup_save(data, request)
# Delete all of the journal data for this user for a clear test env # Delete all of the journal data for this user for a clear test env
user.collection_set.all().delete() user.collection_set.all().delete()
user.collectionmember_set.all().delete() user.collectionmember_set.all().delete()

Loading…
Cancel
Save