Skip to content

Commit cdabde0

Browse files
committed
добавил связь с kafka для удаления userdata
1 parent 5eef9a7 commit cdabde0

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

auth_backend/auth_method/outer.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
from abc import ABCMeta, abstractmethod
33
from typing import Any
44

5+
from event_schema.auth import UserLoginKey
56
from fastapi import Depends
7+
from fastapi.background import BackgroundTasks
68
from fastapi.exceptions import HTTPException
79
from fastapi_sqlalchemy import db
810
from starlette.status import HTTP_403_FORBIDDEN, HTTP_404_NOT_FOUND, HTTP_409_CONFLICT, HTTP_424_FAILED_DEPENDENCY
911

1012
from auth_backend.auth_method.base import AuthPluginMeta
1113
from auth_backend.base import Base
12-
from auth_backend.models.db import AuthMethod, User, UserSession
14+
from auth_backend.kafka.kafka import get_kafka_producer
15+
from auth_backend.models.db import AuthMethod, UserSession
1316
from auth_backend.utils.security import UnionAuth
1417

1518

@@ -197,6 +200,7 @@ async def _link(
197200
async def _unlink(
198201
cls,
199202
user_id: int,
203+
background_tasks: BackgroundTasks,
200204
request_user: UserSession = Depends(UnionAuth()),
201205
):
202206
"""Отвязать внешний аккаунт пользователю
@@ -205,7 +209,14 @@ async def _unlink(
205209
"""
206210
if cls.delete_scope() not in (s.name for s in request_user.scopes):
207211
raise HTTPException(status_code=HTTP_403_FORBIDDEN, detail="Not authorized")
208-
user = User.get(user_id, session=db.session)
209-
if not user:
212+
username = await cls.__get_username(user_id)
213+
if not username:
210214
raise UserNotLinked(user_id)
211-
await cls._delete_auth_methods(user, db_session=db.session)
215+
username.is_deleted = True
216+
db.session.commit()
217+
background_tasks.add_task(
218+
get_kafka_producer().produce,
219+
cls.settings.KAFKA_USER_LOGIN_TOPIC_NAME,
220+
UserLoginKey(user_id=user_id, auth_method=cls.get_name()),
221+
None,
222+
)

0 commit comments

Comments
 (0)