Skip to content

Commit 2cd3c0c

Browse files
downdawnwu-clan
andauthored
sync (#66)
* sync * sync and fix --------- Co-authored-by: Wu Clan <jianhengwu0407@gmail.com>
1 parent 134d877 commit 2cd3c0c

25 files changed

Lines changed: 1029 additions & 666 deletions

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repos:
1111
- id: check-toml
1212

1313
- repo: https://github.com/charliermarsh/ruff-pre-commit
14-
rev: v0.14.10
14+
rev: v0.14.13
1515
hooks:
1616
- id: ruff-check
1717
args:
@@ -21,7 +21,7 @@ repos:
2121
- id: ruff-format
2222

2323
- repo: https://github.com/astral-sh/uv-pre-commit
24-
rev: 0.9.18
24+
rev: 0.9.26
2525
hooks:
2626
- id: uv-lock
2727
- id: uv-export

.ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ ignore = [
136136
"RUF003",
137137
"RUF006",
138138
"RUF012",
139+
"RUF067",
139140
"TRY400",
140141
"TRY003",
141142
"TRY301"

backend/app/admin/api/v1/sys/user.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,11 @@ async def get_userinfo(
4444
)
4545
async def get_users_paginated(
4646
db: CurrentSession,
47-
dept: Annotated[int | None, Query(description='部门 ID')] = None,
4847
username: Annotated[str | None, Query(description='用户名')] = None,
4948
phone: Annotated[str | None, Query(description='手机号')] = None,
5049
status: Annotated[int | None, Query(description='状态')] = None,
5150
) -> ResponseSchemaModel[PageData[GetUserInfoWithRelationDetail]]:
52-
page_data = await user_service.get_list(db=db, dept=dept, username=username, phone=phone, status=status)
51+
page_data = await user_service.get_list(db=db, username=username, phone=phone, status=status)
5352
return response_base.success(data=page_data)
5453

5554

backend/app/admin/crud/crud_user.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,17 @@ async def check_email(self, db: AsyncSession, email: str) -> User | None:
6363
"""
6464
return await self.select_model_by_column(db, email=email)
6565

66-
async def get_select(self, dept: int | None, username: str | None, phone: str | None, status: int | None) -> Select:
66+
async def get_select(self, username: str | None, phone: str | None, status: int | None) -> Select:
6767
"""
6868
获取用户列表查询表达式
6969
70-
:param dept: 部门 ID
7170
:param username: 用户名
7271
:param phone: 电话号码
7372
:param status: 用户状态
7473
:return:
7574
"""
7675
filters = {}
7776

78-
if dept:
79-
filters['dept_id'] = dept
8077
if username:
8178
filters['username__like'] = f'%{username}%'
8279
if phone:

backend/app/admin/service/user_service.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,17 @@ async def get_userinfo(*, db: AsyncSession, pk: int | None = None, username: str
4141
return user
4242

4343
@staticmethod
44-
async def get_list(*, db: AsyncSession, dept: int, username: str, phone: str, status: int) -> dict[str, Any]:
44+
async def get_list(*, db: AsyncSession, username: str, phone: str, status: int) -> dict[str, Any]:
4545
"""
4646
获取用户列表
4747
4848
:param db: 数据库会话
49-
:param dept: 部门 ID
5049
:param username: 用户名
5150
:param phone: 手机号
5251
:param status: 状态
5352
:return:
5453
"""
55-
user_select = await user_dao.get_select(dept=dept, username=username, phone=phone, status=status)
54+
user_select = await user_dao.get_select(username=username, phone=phone, status=status)
5655
data = await paging_data(db, user_select)
5756
if data['items']:
5857
serialized_items = select_join_serialize(data['items'])

backend/cli.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from rich.text import Text
1818
from sqlalchemy import text
1919
from sqlalchemy.ext.asyncio import AsyncConnection, AsyncSession
20-
from watchfiles import PythonFilter
20+
from watchfiles import Change, PythonFilter
2121

2222
from backend import __version__
2323
from backend.common.enums import DataBaseType, PrimaryKeyType
@@ -29,6 +29,7 @@
2929
ENV_FILE_PATH,
3030
MYSQL_SCRIPT_DIR,
3131
POSTGRESQL_SCRIPT_DIR,
32+
RELOAD_LOCK_FILE,
3233
)
3334
from backend.database.db import (
3435
async_db_session,
@@ -51,6 +52,11 @@ class CustomReloadFilter(PythonFilter):
5152
def __init__(self) -> None:
5253
super().__init__(extra_extensions=['.json', '.yaml', '.yml'])
5354

55+
def __call__(self, change: Change, path: str) -> bool:
56+
if RELOAD_LOCK_FILE.exists():
57+
return False
58+
return super().__call__(change, path)
59+
5460

5561
def setup_env_file() -> bool:
5662
if not ENV_EXAMPLE_FILE_PATH.exists():
@@ -307,6 +313,9 @@ async def install_plugin(
307313
db_type: DataBaseType,
308314
pk_type: PrimaryKeyType,
309315
) -> None:
316+
if settings.ENVIRONMENT != 'dev':
317+
raise cappa.Exit('插件安装仅在开发环境可用', code=1)
318+
310319
if not path and not repo_url:
311320
raise cappa.Exit('path 或 repo_url 必须指定其中一项', code=1)
312321
if path and repo_url:

backend/common/enums.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ class FileType(StrEnum):
110110
video = 'video'
111111

112112

113+
class PluginLevelType(StrEnum):
114+
"""插件级别类型"""
115+
116+
app = 'app'
117+
extend = 'extend'
118+
119+
113120
class PluginType(StrEnum):
114121
"""插件类型"""
115122

backend/core/conf.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
from typing import Any, Literal
66

77
from pydantic import model_validator
8-
from pydantic_settings import BaseSettings, SettingsConfigDict
8+
from pydantic_settings import BaseSettings, PydanticBaseSettingsSource, SettingsConfigDict
99

1010
from backend.core.path_conf import ENV_EXAMPLE_FILE_PATH, ENV_FILE_PATH
11+
from backend.plugin.settings_source import PluginSettingsSource
1112

1213

1314
class Settings(BaseSettings):
@@ -16,10 +17,22 @@ class Settings(BaseSettings):
1617
model_config = SettingsConfigDict(
1718
env_file=ENV_FILE_PATH,
1819
env_file_encoding='utf-8',
19-
extra='ignore',
20+
extra='allow',
2021
case_sensitive=True,
2122
)
2223

24+
@classmethod
25+
def settings_customise_sources(
26+
cls,
27+
settings_cls: type[BaseSettings],
28+
init_settings: PydanticBaseSettingsSource,
29+
env_settings: PydanticBaseSettingsSource,
30+
dotenv_settings: PydanticBaseSettingsSource,
31+
file_secret_settings: PydanticBaseSettingsSource,
32+
) -> tuple[PydanticBaseSettingsSource, ...]:
33+
"""自定义配置源优先级"""
34+
return env_settings, dotenv_settings, PluginSettingsSource(settings_cls)
35+
2336
# .env 当前环境
2437
ENVIRONMENT: Literal['dev', 'prod']
2538

backend/core/path_conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@
3232

3333
# PostgreSQL 脚本目录
3434
POSTGRESQL_SCRIPT_DIR = BASE_PATH / 'sql' / 'postgresql'
35+
36+
# 热重载锁文件
37+
RELOAD_LOCK_FILE = BASE_PATH / '.reload.lock'

backend/plugin/config/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
## 参数配置
1+
# Config
22

3-
内置插件,可直接使用
3+
参数配置插件,通常用于动态配置系统参数和前端工程数据展示

0 commit comments

Comments
 (0)