mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-05-22 08:47:21 +08:00
fix user
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import json
|
||||
from datetime import timedelta
|
||||
from typing import Any, List
|
||||
|
||||
@@ -72,7 +73,8 @@ async def login_access_token(
|
||||
super_user=user.is_superuser,
|
||||
user_name=user.name,
|
||||
avatar=user.avatar,
|
||||
level=level
|
||||
level=level,
|
||||
permissions=json.loads(user.permissions or '{}')
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -454,6 +454,7 @@ class ChainBase(metaclass=ABCMeta):
|
||||
:param message: 消息体
|
||||
:return: 成功或失败
|
||||
"""
|
||||
# TODO 根据消息场景开关决定发给谁
|
||||
logger.info(f"发送消息:channel={message.channel},"
|
||||
f"source={message.source},"
|
||||
f"title={message.title}, "
|
||||
|
||||
@@ -339,7 +339,7 @@ class DownloadChain(ChainBase):
|
||||
if files_to_add:
|
||||
self.downloadhis.add_files(files_to_add)
|
||||
|
||||
# 发送消息(群发,不带channel和userid)
|
||||
# 发送消息 TODO 根据消息场景开关决定发给谁
|
||||
self.post_download_message(meta=_meta, mediainfo=_media, torrent=_torrent,
|
||||
username=username, download_episodes=download_episodes)
|
||||
# 下载成功后处理
|
||||
|
||||
@@ -81,11 +81,11 @@ class MediaServerChain(ChainBase):
|
||||
if not mediaserver:
|
||||
continue
|
||||
server_name = mediaserver.name
|
||||
sync_blacklist = mediaserver.config.get("sync_blacklist") or []
|
||||
sync_blacklist = mediaserver.sync_libraries or []
|
||||
logger.info(f"开始同步媒体库 {server_name} 的数据 ...")
|
||||
for library in self.librarys(server_name):
|
||||
# 同步黑名单 跳过
|
||||
if library.name in sync_blacklist:
|
||||
if library.id in sync_blacklist:
|
||||
continue
|
||||
logger.info(f"正在同步 {server_name} 媒体库 {library.name} ...")
|
||||
library_count = 0
|
||||
|
||||
@@ -179,7 +179,6 @@ class SubscribeChain(ChainBase):
|
||||
text = f"评分:{mediainfo.vote_average},来自用户:{username}"
|
||||
else:
|
||||
text = f"评分:{mediainfo.vote_average}"
|
||||
# 群发
|
||||
if mediainfo.type == MediaType.TV:
|
||||
link = settings.MP_DOMAIN('#/subscribe-tv?tab=mysub')
|
||||
else:
|
||||
|
||||
@@ -3,9 +3,9 @@ from typing import Tuple, Optional
|
||||
from sqlalchemy import Boolean, Column, Integer, String, Sequence
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app import schemas
|
||||
from app.core.security import verify_password
|
||||
from app.db import db_query, db_update, Base
|
||||
from app.schemas import User
|
||||
from app.utils.otp import OtpUtils
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@ class User(Base):
|
||||
"""
|
||||
# ID
|
||||
id = Column(Integer, Sequence('id'), primary_key=True, index=True)
|
||||
# 用户名
|
||||
# 用户名,唯一值
|
||||
name = Column(String, index=True, nullable=False)
|
||||
# 邮箱,未启用
|
||||
# 邮箱
|
||||
email = Column(String)
|
||||
# 加密后密码
|
||||
hashed_password = Column(String)
|
||||
@@ -31,10 +31,15 @@ class User(Base):
|
||||
is_otp = Column(Boolean(), default=False)
|
||||
# otp秘钥
|
||||
otp_secret = Column(String, default=None)
|
||||
# 用户权限 json
|
||||
permissions = Column(String, default='')
|
||||
# 用户个性化设置 json
|
||||
settings = Column(String, default='')
|
||||
|
||||
@staticmethod
|
||||
@db_query
|
||||
def authenticate(db: Session, name: str, password: str, otp_password: str) -> Tuple[bool, Optional[User]]:
|
||||
def authenticate(db: Session, name: str, password: str,
|
||||
otp_password: str) -> Tuple[bool, Optional[schemas.User]]:
|
||||
user = db.query(User).filter(User.name == name).first()
|
||||
if not user:
|
||||
return False, None
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from typing import List
|
||||
|
||||
from app.db.systemconfig_oper import SystemConfigOper
|
||||
from app.schemas import NotificationConf
|
||||
from app.schemas import NotificationConf, NotificationSwitchConf
|
||||
from app.schemas.types import SystemConfigKey
|
||||
|
||||
|
||||
@@ -13,11 +13,20 @@ class NotificationHelper:
|
||||
def __init__(self):
|
||||
self.systemconfig = SystemConfigOper()
|
||||
|
||||
def get_notifications(self) -> List[NotificationConf]:
|
||||
def get_clients(self) -> List[NotificationConf]:
|
||||
"""
|
||||
获取消息通知渠道
|
||||
"""
|
||||
notification_confs: List[dict] = self.systemconfig.get(SystemConfigKey.Notifications)
|
||||
if not notification_confs:
|
||||
client_confs: List[dict] = self.systemconfig.get(SystemConfigKey.Notifications)
|
||||
if not client_confs:
|
||||
return []
|
||||
return [NotificationConf(**conf) for conf in notification_confs]
|
||||
return [NotificationConf(**conf) for conf in client_confs]
|
||||
|
||||
def get_switchs(self) -> List[dict]:
|
||||
"""
|
||||
获取消息通知场景开关
|
||||
"""
|
||||
switchs: List[dict] = self.systemconfig.get(SystemConfigKey.NotificationSwitchs)
|
||||
if not switchs:
|
||||
return []
|
||||
return [NotificationSwitchConf(**switch) for switch in switchs]
|
||||
|
||||
@@ -20,7 +20,7 @@ class SlackModule(_ModuleBase):
|
||||
"""
|
||||
初始化模块
|
||||
"""
|
||||
clients = NotificationHelper().get_notifications()
|
||||
clients = NotificationHelper().get_clients()
|
||||
if not clients:
|
||||
return
|
||||
self._configs = {}
|
||||
|
||||
@@ -17,7 +17,7 @@ class SynologyChatModule(_ModuleBase):
|
||||
"""
|
||||
初始化模块
|
||||
"""
|
||||
clients = NotificationHelper().get_notifications()
|
||||
clients = NotificationHelper().get_clients()
|
||||
if not clients:
|
||||
return
|
||||
self._configs = {}
|
||||
|
||||
@@ -19,7 +19,7 @@ class TelegramModule(_ModuleBase):
|
||||
"""
|
||||
初始化模块
|
||||
"""
|
||||
clients = NotificationHelper().get_notifications()
|
||||
clients = NotificationHelper().get_clients()
|
||||
if not clients:
|
||||
return
|
||||
self._configs = {}
|
||||
|
||||
@@ -18,7 +18,7 @@ class VoceChatModule(_ModuleBase):
|
||||
初始化模块
|
||||
"""
|
||||
self._clients = {}
|
||||
clients = NotificationHelper().get_notifications()
|
||||
clients = NotificationHelper().get_clients()
|
||||
if not clients:
|
||||
return
|
||||
for client in clients:
|
||||
|
||||
@@ -21,7 +21,7 @@ class WechatModule(_ModuleBase):
|
||||
"""
|
||||
初始化模块
|
||||
"""
|
||||
clients = NotificationHelper().get_notifications()
|
||||
clients = NotificationHelper().get_clients()
|
||||
if not clients:
|
||||
return
|
||||
self._configs = {}
|
||||
|
||||
@@ -2,6 +2,8 @@ from typing import Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from app.schemas import NotificationType
|
||||
|
||||
|
||||
class MediaServerConf(BaseModel):
|
||||
"""
|
||||
@@ -15,6 +17,8 @@ class MediaServerConf(BaseModel):
|
||||
config: Optional[dict] = {}
|
||||
# 是否启用
|
||||
enabled: Optional[bool] = False
|
||||
# 同步媒体体库列表
|
||||
sync_libraries: Optional[list] = []
|
||||
|
||||
|
||||
class DownloaderConf(BaseModel):
|
||||
@@ -49,6 +53,16 @@ class NotificationConf(BaseModel):
|
||||
enabled: Optional[bool] = False
|
||||
|
||||
|
||||
class NotificationSwitchConf(BaseModel):
|
||||
"""
|
||||
通知场景开关配置
|
||||
"""
|
||||
# 场景名称
|
||||
type: NotificationType = None
|
||||
# 通知范围 all/user/admin/userandadmin
|
||||
action: Optional[str] = 'all'
|
||||
|
||||
|
||||
class StorageConf(BaseModel):
|
||||
"""
|
||||
存储配置
|
||||
|
||||
@@ -64,6 +64,8 @@ class SystemConfigKey(Enum):
|
||||
MediaServers = "MediaServers"
|
||||
# 消息通知配置
|
||||
Notifications = "Notifications"
|
||||
# 通知场景开关设置
|
||||
NotificationSwitchs = "NotificationSwitchs"
|
||||
# 目录配置
|
||||
Directories = "Directories"
|
||||
# 存储配置
|
||||
|
||||
Reference in New Issue
Block a user