You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.6 KiB
Python
39 lines
1.6 KiB
Python
4 years ago
|
from django.conf import settings
|
||
|
from django.db import transaction
|
||
|
from django.shortcuts import get_object_or_404
|
||
4 years ago
|
from fastapi import APIRouter, Request, status
|
||
4 years ago
|
|
||
3 years ago
|
from etebase_server.django.utils import get_user_queryset, CallbackContext
|
||
4 years ago
|
from .authentication import SignupIn, signup_save
|
||
|
from ..msgpack import MsgpackRoute
|
||
|
from ..exceptions import HttpError
|
||
3 years ago
|
from etebase_server.myauth.models import get_typed_user_model
|
||
4 years ago
|
|
||
4 years ago
|
test_reset_view_router = APIRouter(route_class=MsgpackRoute, tags=["test helpers"])
|
||
4 years ago
|
User = get_typed_user_model()
|
||
4 years ago
|
|
||
|
|
||
4 years ago
|
@test_reset_view_router.post("/reset/", status_code=status.HTTP_204_NO_CONTENT)
|
||
4 years ago
|
def reset(data: SignupIn, request: Request):
|
||
4 years ago
|
# Only run when in DEBUG mode! It's only used for tests
|
||
|
if not settings.DEBUG:
|
||
4 years ago
|
raise HttpError(code="generic", detail="Only allowed in debug mode.")
|
||
4 years ago
|
|
||
|
with transaction.atomic():
|
||
4 years ago
|
user_queryset = get_user_queryset(User.objects.all(), CallbackContext(request.path_params))
|
||
4 years ago
|
user = get_object_or_404(user_queryset, username=data.user.username)
|
||
|
# Only allow test users for extra safety
|
||
|
if not getattr(user, User.USERNAME_FIELD).startswith("test_user"):
|
||
4 years ago
|
raise HttpError(code="generic", detail="Endpoint not allowed for user.")
|
||
4 years ago
|
|
||
|
if hasattr(user, "userinfo"):
|
||
|
user.userinfo.delete()
|
||
4 years ago
|
|
||
4 years ago
|
signup_save(data, request)
|
||
4 years ago
|
# Delete all of the journal data for this user for a clear test env
|
||
|
user.collection_set.all().delete()
|
||
|
user.collectionmember_set.all().delete()
|
||
|
user.incoming_invitations.all().delete()
|
||
|
|
||
|
# FIXME: also delete chunk files!!!
|