Skip to content

Commit a45f09a

Browse files
committed
Initiate user deletion endpoint
1 parent 0b303bd commit a45f09a

File tree

7 files changed

+44
-0
lines changed

7 files changed

+44
-0
lines changed

.env.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ ENABLE_SENTRY=false
4242
SEND_EMAILS=true
4343
COUNT_API_REQUESTS=true
4444
USER_SIGNUP=ture
45+
USER_DELETION=false

futuramaapi/apps/fastapi.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def _exception_handler(self, _: Request, exc) -> Response:
106106
RegistrationDisabledError,
107107
ServiceError,
108108
UnauthorizedError,
109+
UserDeletionDisabledError,
109110
)
110111

111112
exception_to_value: dict[type[ServiceError], _ExceptionValue] = {
@@ -125,6 +126,10 @@ def _exception_handler(self, _: Request, exc) -> Response:
125126
status_code=status.HTTP_403_FORBIDDEN,
126127
default_message="User registration is currently disabled.",
127128
),
129+
UserDeletionDisabledError: _ExceptionValue(
130+
status_code=status.HTTP_403_FORBIDDEN,
131+
default_message="User deletion is currently disabled.",
132+
),
128133
EmptyUpdateError: _ExceptionValue(
129134
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
130135
default_message="No data to update.",

futuramaapi/core/_settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ class FeatureFlags(BaseSettings):
257257
enable_sentry: bool = False
258258
count_api_requests: bool = True
259259
user_signup: bool = True
260+
user_deletion: bool = False
260261

261262

262263
feature_flags = FeatureFlags()

futuramaapi/routers/rest/users_new/api.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
RequestChangeUserPasswordRequest,
2323
RequestChangeUserPasswordService,
2424
)
25+
from futuramaapi.routers.services.users.request_user_deletion import RequestUserDeletionService
2526
from futuramaapi.routers.services.users.resend_user_confirmation import ResendUserConfirmationService
2627
from futuramaapi.routers.services.users.update_user import (
2728
UpdateUserRequest,
@@ -151,6 +152,26 @@ async def update_user(
151152
return await service()
152153

153154

155+
@router.post(
156+
"/ddd",
157+
status_code=status.HTTP_202_ACCEPTED,
158+
responses={
159+
status.HTTP_401_UNAUTHORIZED: {
160+
"model": UnauthorizedResponse,
161+
},
162+
status.HTTP_403_FORBIDDEN: {
163+
"description": "User deletion is currently disabled.",
164+
},
165+
},
166+
name="request_user_deletion",
167+
)
168+
async def request_user_deletion(
169+
token: Annotated[str, Depends(_oauth2_scheme)],
170+
) -> None:
171+
service: RequestUserDeletionService = RequestUserDeletionService(token=token)
172+
return await service()
173+
174+
154175
@router.post(
155176
"/confirmations/resend",
156177
status_code=status.HTTP_202_ACCEPTED,

futuramaapi/routers/services/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
RegistrationDisabledError,
99
ServiceError,
1010
UnauthorizedError,
11+
UserDeletionDisabledError,
1112
ValidationError,
1213
)
1314
from ._base_template import BaseTemplateService
@@ -23,5 +24,6 @@
2324
"RegistrationDisabledError",
2425
"ServiceError",
2526
"UnauthorizedError",
27+
"UserDeletionDisabledError",
2628
"ValidationError",
2729
]

futuramaapi/routers/services/_base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ class EmptyUpdateError(ValidationError):
4848
"""Empty Update Error."""
4949

5050

51+
class UserDeletionDisabledError(ServiceError):
52+
"""User Deletion Disabled Error."""
53+
54+
5155
class BaseService[TResponse](BaseModel, ABC):
5256
"""Base interface for async application services."""
5357

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from futuramaapi.core import feature_flags
2+
from futuramaapi.routers.services import BaseUserAuthenticatedService, UserDeletionDisabledError
3+
4+
5+
class RequestUserDeletionService(BaseUserAuthenticatedService[None]):
6+
async def process(self, *args, **kwargs) -> None:
7+
if not feature_flags.user_deletion:
8+
raise UserDeletionDisabledError()
9+
10+
raise NotImplementedError()

0 commit comments

Comments
 (0)