1
0
mirror of https://github.com/etesync/server synced 2024-11-19 07:18:08 +00:00

Fix a few FIXMEs.

This commit is contained in:
Tom Hacohen 2020-12-27 20:36:11 +02:00
parent 13d4121fc2
commit ec8c69b3f3
2 changed files with 14 additions and 13 deletions

View File

@ -24,7 +24,7 @@ from django_etebase.models import UserInfo
from django_etebase.signals import user_signed_up
from django_etebase.token_auth.models import AuthToken
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 .exceptions import AuthenticationFailed, transform_validation_error, ValidationError
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)
def signup_save(data: SignupIn) -> User:
def signup_save(data: SignupIn, request: Request) -> User:
user_data = data.user
with transaction.atomic():
try:
# XXX-TOM
# view = self.context.get("view", None)
# user_queryset = get_user_queryset(User.objects.all(), view)
user_queryset = User.objects.all()
user_queryset = get_user_queryset(User.objects.all(), CallbackContext(request.path_params))
instance = user_queryset.get(**{User.USERNAME_FIELD: user_data.username.lower()})
except User.DoesNotExist:
# Create the user and save the casing the user chose as the first name
try:
# XXX-TOM
instance = create_user(**user_data.dict(), password=None, first_name=user_data.username, view=None)
instance = create_user(
**user_data.dict(),
password=None,
first_name=user_data.username,
context=CallbackContext(request.path_params),
)
instance.full_clean()
except EtebaseValidationError as e:
raise e
@ -298,8 +299,8 @@ def signup_save(data: SignupIn) -> User:
@authentication_router.post("/signup/")
async def signup(data: SignupIn):
user = await sync_to_async(signup_save)(data)
async def signup(data: SignupIn, request: Request):
user = await sync_to_async(signup_save)(data, request)
# XXX-TOM
data = await sync_to_async(LoginOut.from_orm)(user)
await sync_to_async(user_signed_up.send)(sender=user.__class__, request=None, user=user)

View File

@ -2,7 +2,7 @@ from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import transaction
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 etebase_fastapi.authentication import SignupIn, signup_save
@ -13,7 +13,7 @@ User = get_user_model()
@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
if not settings.DEBUG:
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"):
user.userinfo.delete()
signup_save(data)
signup_save(data, request)
# Delete all of the journal data for this user for a clear test env
user.collection_set.all().delete()
user.collectionmember_set.all().delete()