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