This commit is contained in:
@@ -87,7 +87,7 @@ async def create_internal_session(author, device_info: dict | None = None) -> st
|
||||
author.reset_failed_login()
|
||||
|
||||
# Обновляем last_seen
|
||||
author.last_seen = int(time.time()) # type: ignore[assignment]
|
||||
author.last_seen = int(time.time())
|
||||
|
||||
# Создаем сессию, используя token для идентификации
|
||||
return await TokenManager.create_session(
|
||||
|
||||
@@ -81,20 +81,20 @@ class Author(Base):
|
||||
"""Проверяет пароль пользователя"""
|
||||
return Password.verify(password, str(self.password)) if self.password else False
|
||||
|
||||
def set_password(self, password: str):
|
||||
def set_password(self, password: str) -> None:
|
||||
"""Устанавливает пароль пользователя"""
|
||||
self.password = Password.encode(password) # type: ignore[assignment]
|
||||
self.password = Password.encode(password)
|
||||
|
||||
def increment_failed_login(self):
|
||||
def increment_failed_login(self) -> None:
|
||||
"""Увеличивает счетчик неудачных попыток входа"""
|
||||
self.failed_login_attempts += 1 # type: ignore[assignment]
|
||||
self.failed_login_attempts += 1
|
||||
if self.failed_login_attempts >= 5:
|
||||
self.account_locked_until = int(time.time()) + 300 # type: ignore[assignment] # 5 минут
|
||||
self.account_locked_until = int(time.time()) + 300 # 5 минут
|
||||
|
||||
def reset_failed_login(self):
|
||||
def reset_failed_login(self) -> None:
|
||||
"""Сбрасывает счетчик неудачных попыток входа"""
|
||||
self.failed_login_attempts = 0 # type: ignore[assignment]
|
||||
self.account_locked_until = None # type: ignore[assignment]
|
||||
self.failed_login_attempts = 0
|
||||
self.account_locked_until = None
|
||||
|
||||
def is_locked(self) -> bool:
|
||||
"""Проверяет, заблокирован ли аккаунт"""
|
||||
@@ -150,7 +150,7 @@ class Author(Base):
|
||||
authors = session.query(cls).where(cls.oauth.isnot(None)).all()
|
||||
for author in authors:
|
||||
if author.oauth and provider in author.oauth:
|
||||
oauth_data = author.oauth[provider] # type: ignore[index]
|
||||
oauth_data = author.oauth[provider]
|
||||
if isinstance(oauth_data, dict) and oauth_data.get("id") == provider_id:
|
||||
return author
|
||||
return None
|
||||
@@ -165,13 +165,13 @@ class Author(Base):
|
||||
email (Optional[str]): Email от провайдера
|
||||
"""
|
||||
if not self.oauth:
|
||||
self.oauth = {} # type: ignore[assignment]
|
||||
self.oauth = {}
|
||||
|
||||
oauth_data: Dict[str, str] = {"id": provider_id}
|
||||
if email:
|
||||
oauth_data["email"] = email
|
||||
|
||||
self.oauth[provider] = oauth_data # type: ignore[index]
|
||||
self.oauth[provider] = oauth_data
|
||||
|
||||
def get_oauth_account(self, provider: str) -> Dict[str, Any] | None:
|
||||
"""
|
||||
|
||||
@@ -227,19 +227,19 @@ class Community(BaseModel):
|
||||
|
||||
members = []
|
||||
for ca in community_authors:
|
||||
member_info = {
|
||||
member_info: dict[str, Any] = {
|
||||
"author_id": ca.author_id,
|
||||
"joined_at": ca.joined_at,
|
||||
}
|
||||
|
||||
if with_roles:
|
||||
member_info["roles"] = ca.role_list # type: ignore[assignment]
|
||||
member_info["roles"] = ca.role_list
|
||||
# Получаем разрешения синхронно
|
||||
try:
|
||||
member_info["permissions"] = asyncio.run(ca.get_permissions()) # type: ignore[assignment]
|
||||
member_info["permissions"] = asyncio.run(ca.get_permissions())
|
||||
except Exception:
|
||||
# Если не удается получить разрешения асинхронно, используем пустой список
|
||||
member_info["permissions"] = [] # type: ignore[assignment]
|
||||
member_info["permissions"] = []
|
||||
|
||||
members.append(member_info)
|
||||
|
||||
@@ -275,9 +275,9 @@ class Community(BaseModel):
|
||||
roles: Список ID ролей для назначения по умолчанию
|
||||
"""
|
||||
if not self.settings:
|
||||
self.settings = {} # type: ignore[assignment]
|
||||
self.settings = {}
|
||||
|
||||
self.settings["default_roles"] = roles # type: ignore[index]
|
||||
self.settings["default_roles"] = roles
|
||||
|
||||
async def initialize_role_permissions(self) -> None:
|
||||
"""
|
||||
@@ -307,13 +307,13 @@ class Community(BaseModel):
|
||||
roles: Список ID ролей, доступных в сообществе
|
||||
"""
|
||||
if not self.settings:
|
||||
self.settings = {} # type: ignore[assignment]
|
||||
self.settings = {}
|
||||
|
||||
self.settings["available_roles"] = roles # type: ignore[index]
|
||||
self.settings["available_roles"] = roles
|
||||
|
||||
def set_slug(self, slug: str) -> None:
|
||||
"""Устанавливает slug сообщества"""
|
||||
self.slug = slug # type: ignore[assignment]
|
||||
self.update({"slug": slug})
|
||||
|
||||
def get_followers(self):
|
||||
"""
|
||||
@@ -420,7 +420,7 @@ class CommunityAuthor(BaseModel):
|
||||
@role_list.setter
|
||||
def role_list(self, value: list[str]) -> None:
|
||||
"""Устанавливает список ролей из списка строк"""
|
||||
self.roles = ",".join(value) if value else None # type: ignore[assignment]
|
||||
self.update({"roles": ",".join(value) if value else None})
|
||||
|
||||
def add_role(self, role: str) -> None:
|
||||
"""
|
||||
|
||||
@@ -369,7 +369,7 @@ async def admin_merge_topics(_: None, _info: GraphQLResolveInfo, merge_input: di
|
||||
# Обновляем parent_ids дочерних топиков
|
||||
for source_topic in source_topics:
|
||||
# Находим всех детей исходной темы
|
||||
child_topics = session.query(Topic).where(Topic.parent_ids.contains(int(source_topic.id))).all() # type: ignore[arg-type]
|
||||
child_topics = session.query(Topic).where(Topic.parent_ids.contains(int(source_topic.id))).all()
|
||||
|
||||
for child_topic in child_topics:
|
||||
current_parent_ids = list(child_topic.parent_ids or [])
|
||||
@@ -747,10 +747,10 @@ async def admin_update_reaction(_: None, _info: GraphQLResolveInfo, reaction: di
|
||||
if "body" in reaction:
|
||||
db_reaction.body = reaction["body"]
|
||||
if "deleted_at" in reaction:
|
||||
db_reaction.deleted_at = int(time.time()) # type: ignore[assignment]
|
||||
db_reaction.deleted_at = int(time.time())
|
||||
|
||||
# Обновляем время изменения
|
||||
db_reaction.updated_at = int(time.time()) # type: ignore[assignment]
|
||||
db_reaction.updated_at = int(time.time())
|
||||
|
||||
session.commit()
|
||||
|
||||
@@ -774,7 +774,7 @@ async def admin_delete_reaction(_: None, _info: GraphQLResolveInfo, reaction_id:
|
||||
return {"success": False, "error": "Реакция не найдена"}
|
||||
|
||||
# Устанавливаем время удаления
|
||||
db_reaction.deleted_at = int(time.time()) # type: ignore[assignment]
|
||||
db_reaction.deleted_at = int(time.time())
|
||||
|
||||
session.commit()
|
||||
|
||||
|
||||
@@ -987,11 +987,11 @@ def create_author(**kwargs) -> Author:
|
||||
"""
|
||||
author = Author()
|
||||
# Use setattr to avoid MyPy complaints about Column assignment
|
||||
author.id = kwargs.get("user_id") # type: ignore[assignment] # Связь с user_id из системы авторизации # type: ignore[assignment]
|
||||
author.slug = kwargs.get("slug") # type: ignore[assignment] # Идентификатор из системы авторизации # type: ignore[assignment]
|
||||
author.created_at = int(time.time()) # type: ignore[assignment]
|
||||
author.updated_at = int(time.time()) # type: ignore[assignment]
|
||||
author.name = kwargs.get("name") or kwargs.get("slug") # type: ignore[assignment] # если не указано # type: ignore[assignment]
|
||||
author.id = kwargs.get("user_id") # Связь с user_id из системы авторизации
|
||||
author.slug = kwargs.get("slug") # Идентификатор из системы авторизации
|
||||
author.created_at = int(time.time())
|
||||
author.updated_at = int(time.time())
|
||||
author.name = kwargs.get("name") or kwargs.get("slug") # если не указано
|
||||
|
||||
with local_session() as session:
|
||||
session.add(author)
|
||||
|
||||
@@ -259,8 +259,7 @@ async def set_featured(session: Session, shout_id: int) -> None:
|
||||
s = session.query(Shout).where(Shout.id == shout_id).first()
|
||||
if s:
|
||||
current_time = int(time.time())
|
||||
# Use setattr to avoid MyPy complaints about Column assignment
|
||||
s.featured_at = current_time # type: ignore[assignment]
|
||||
s.update({"featured_at": current_time})
|
||||
session.commit()
|
||||
author = session.query(Author).where(Author.id == s.created_by).first()
|
||||
if author:
|
||||
|
||||
@@ -77,8 +77,8 @@ def query_with_stat(info: GraphQLResolveInfo, force_topics: bool = False) -> Sel
|
||||
"""
|
||||
q = select(Shout).where(
|
||||
and_(
|
||||
Shout.published_at.is_not(None), # type: ignore[union-attr]
|
||||
Shout.deleted_at.is_(None), # type: ignore[union-attr]
|
||||
Shout.published_at.is_not(None),
|
||||
Shout.deleted_at.is_(None),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user