Skip to content
12 changes: 11 additions & 1 deletion auth_backend/auth_method/outer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
from abc import ABCMeta, abstractmethod
from typing import Any

from event_schema.auth import UserInfo, UserLogin, UserLoginKey
from fastapi import Depends
from fastapi.background import BackgroundTasks
from fastapi.exceptions import HTTPException
from fastapi_sqlalchemy import db
from starlette.status import HTTP_403_FORBIDDEN, HTTP_404_NOT_FOUND, HTTP_409_CONFLICT, HTTP_424_FAILED_DEPENDENCY

from auth_backend.auth_method.base import AuthPluginMeta
from auth_backend.base import Base
from auth_backend.kafka.kafka import get_kafka_producer
from auth_backend.models.db import AuthMethod, UserSession
from auth_backend.utils.security import UnionAuth

Expand Down Expand Up @@ -165,7 +168,7 @@ async def _get_link(

Получить данные может администратор или сам пользователь
"""
if cls.get_scope() not in (s.name for s in request_user.scopes) and request_user.id != user_id:
if cls.get_scope() not in (s.name for s in request_user.scopes) and request_user.user_id != user_id:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а ты проверял, что там реально так нужно? странно что не просто id

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

да, там в структуре у request_user поле id это просто обычный айдишник, который ничего не значит, а user_id отдельное поле связанное с таблицей юзера. Плюс я это протестил и работает только мой вариант

raise HTTPException(status_code=HTTP_403_FORBIDDEN, detail="Not authorized")
username = await cls.__get_username(user_id)
if not username:
Expand Down Expand Up @@ -197,6 +200,7 @@ async def _link(
async def _unlink(
cls,
user_id: int,
background_tasks: BackgroundTasks,
request_user: UserSession = Depends(UnionAuth()),
):
"""Отвязать внешний аккаунт пользователю
Expand All @@ -210,3 +214,9 @@ async def _unlink(
raise UserNotLinked(user_id)
username.is_deleted = True
db.session.commit()
background_tasks.add_task(
get_kafka_producer().produce,
cls.settings.KAFKA_USER_LOGIN_TOPIC_NAME,
UserLoginKey(user_id=user_id),
UserLogin(source=cls.get_name(), items=[UserInfo(category=cls.get_name(), param="username", value=None)]),
)
1 change: 0 additions & 1 deletion auth_backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from annotated_types import Gt
from pydantic import PostgresDsn
from pydantic.types import PathType
from pydantic_settings import BaseSettings, SettingsConfigDict


Expand Down