权限组全自定义、月度分独立、绑定邮箱免密与样式统一

1. 权限组:去掉锁定/预置限制,所有组可编辑/删除/分配;管理员新增/编辑可选任意组;管理员列表不再显示锁定徽标
2. 个人查询:月度分独立计算(当月净得分,与基础分无关),总分=基础分+加分-减分
3. 绑定邮箱:发送验证码与确认绑定不再需要密码(解绑仍需密码)
4. 权限组编辑UI:权限项按 学生/操行分/教务/系统管理 分区,支持全选/清空,上限两行布局,弹窗加宽
5. 样式统一:颜色变量化(硬编码色值清零)、check-grid/check-item 统一复选框网格、cell-wrap、subject-status 全局化、success-msg
6. 旧库升级期兼容保留(登录/权限降级、待升级提示)
7. 文档同步更新
This commit is contained in:
canglan committed 2026-09-18 09:56:39 +08:00
1 parent 8cd2c83412
commit ed3189096d
25 files changed
+237 -159

No files matched your search

+8 -16
View File
@@ -73,8 +73,8 @@ def build_legacy_group(role_type: Optional[str]) -> Optional[Dict[str, Any]]:
"max_add_points": max_add,
"can_subtract_points": can_subtract,
"max_subtract_points": max_subtract,
"is_system": 1 if role_type in DEFAULT_GROUP_PERMISSIONS else 0,
"is_locked": 1 if role_type == "班主任" else 0,
"is_system": 0,
"is_locked": 0,
}
@@ -114,17 +114,9 @@ class PermissionGroupModel:
except (ValueError, TypeError):
logger.warning(f"权限组[{row.get('group_id')}]权限配置解析失败")
parsed = {}
if row.get("is_locked"):
# 锁定组(班主任)始终为最高权限:全权限 + 无限制上限,防止误配置锁死
row["permissions_data"] = {key: True for key in PERMISSION_KEYS}
row["can_add_points"] = True
row["max_add_points"] = None
row["can_subtract_points"] = True
row["max_subtract_points"] = None
else:
row["permissions_data"] = {key: bool(parsed.get(key, False)) for key in PERMISSION_KEYS}
row["can_add_points"] = bool(row.get("can_add_points"))
row["can_subtract_points"] = bool(row.get("can_subtract_points"))
row["permissions_data"] = {key: bool(parsed.get(key, False)) for key in PERMISSION_KEYS}
row["can_add_points"] = bool(row.get("can_add_points"))
row["can_subtract_points"] = bool(row.get("can_subtract_points"))
return row
@staticmethod
@@ -156,7 +148,7 @@ class PermissionGroupModel:
fallback_groups = []
for group_name in DEFAULT_GROUP_PERMISSIONS:
group = build_legacy_group(group_name)
group["is_locked"] = 1 # 待升级期间只读,避免误操作
group["readonly"] = True # 待升级期间只读,避免误操作
group["member_count"] = 0
fallback_groups.append(group)
return fallback_groups
@@ -199,7 +191,7 @@ class PermissionGroupModel:
SET group_name = %s, description = %s, permissions = %s,
can_add_points = %s, max_add_points = %s,
can_subtract_points = %s, max_subtract_points = %s
WHERE group_id = %s AND is_locked = 0
WHERE group_id = %s
"""
result = await execute_update(sql, (
group_name, description or None, json.dumps(permissions, ensure_ascii=False),
@@ -212,7 +204,7 @@ class PermissionGroupModel:
@staticmethod
async def delete(group_id: int) -> bool:
result = await execute_update(
"DELETE FROM permission_groups WHERE group_id = %s AND is_system = 0 AND is_locked = 0",
"DELETE FROM permission_groups WHERE group_id = %s",
(group_id,)
)
return result > 0
+1 -2
View File
@@ -151,14 +151,13 @@ async def reset_password_by_token(request: Request, req: ResetPasswordRequest):
@router.post("/email/send-code")
async def send_bind_email_code(request: Request, req: SendEmailCodeRequest):
"""
发送邮箱绑定验证码(需当前密码,验证码发送至待绑定邮箱)
发送邮箱绑定验证码(验证码发送至待绑定邮箱)
"""
user = await get_current_user(request)
if user["user_type"] != "admin":
return error_response(message="仅管理员可绑定邮箱", code=403)
result = await AuthService.send_bind_email_code(
user_id=user["user_id"],
password=req.password,
email=req.email
)
if result["success"]:
+1 -2
View File
@@ -64,8 +64,7 @@ async def debug_add_admin(request: Request, req: AddAdminDebugRequest):
real_name=req.real_name,
password=req.password,
group_id=group["group_id"],
operator_id=0,
allow_locked=True
operator_id=0
)
if result["success"]:
-1
View File
@@ -69,7 +69,6 @@ class ResetPasswordRequest(BaseModel):
class SendEmailCodeRequest(BaseModel):
"""发送邮箱绑定验证码请求"""
password: str = Field(..., min_length=1, max_length=50, description="当前密码")
email: str = Field(..., min_length=3, max_length=100, description="待绑定的邮箱")
+1 -10
View File
@@ -307,8 +307,7 @@ class AdminService:
password: Optional[str],
group_id: int,
operator_id: int,
email: Optional[str] = None,
allow_locked: bool = False
email: Optional[str] = None
) -> Dict[str, Any]:
"""添加管理员(支持重新激活已删除的管理员)"""
try:
@@ -318,8 +317,6 @@ class AdminService:
return {"success": False, "message": "数据库待升级,请先完成系统升级"}
if not group:
return {"success": False, "message": "权限组不存在"}
if group.get("is_locked") and not allow_locked:
return {"success": False, "message": "该权限组不可分配"}
role_type = group["group_name"]
# 邮箱校验(留空表示不绑定)
@@ -413,8 +410,6 @@ class AdminService:
return {"success": False, "message": "数据库待升级,请先完成系统升级"}
if not group:
return {"success": False, "message": "权限组不存在"}
if group.get("is_locked"):
return {"success": False, "message": "该权限组不可分配"}
# 邮箱校验(留空表示解除绑定)
normalized_email = None
@@ -504,8 +499,6 @@ class AdminService:
return {"success": False, "message": "数据库待升级,请先完成系统升级"}
if not group:
return {"success": False, "message": "权限组不存在"}
if group.get("is_locked"):
return {"success": False, "message": "该权限组已锁定,不可编辑"}
normalized = _normalize_group_payload(
group_name, description, permissions,
@@ -555,8 +548,6 @@ class AdminService:
return {"success": False, "message": "数据库待升级,请先完成系统升级"}
if not group:
return {"success": False, "message": "权限组不存在"}
if group.get("is_system") or group.get("is_locked"):
return {"success": False, "message": "系统预置权限组不可删除"}
try:
member_count = await PermissionGroupModel.count_members(group_id)
+5 -5
View File
@@ -344,14 +344,14 @@ class AuthService:
return user, None
@staticmethod
async def send_bind_email_code(user_id: int, password: str, email: str) -> Dict[str, Any]:
"""向待绑定邮箱发送验证码(验证码绑定邮箱第一步)"""
async def send_bind_email_code(user_id: int, email: str) -> Dict[str, Any]:
"""向待绑定邮箱发送验证码(验证码绑定邮箱第一步,无需密码)"""
if not EmailSender.is_configured():
return {"success": False, "message": "系统未配置邮件服务,请联系班主任或系统管理员"}
_, error = await AuthService._get_admin_by_password(user_id, password)
if error:
return {"success": False, "message": error}
user = await UserModel.get_by_user_id(user_id)
if not user or user.get("user_type") != "admin":
return {"success": False, "message": "仅管理员可绑定邮箱"}
normalized_email = (email or "").strip()
if not is_valid_email(normalized_email):
+3 -5
View File
@@ -451,13 +451,11 @@ class ConductService:
record_count += cnt
months = []
running_score = base_points
for month in sorted(months_map.keys()):
entry = months_map[month]
entry["start_score"] = running_score
entry["net"] = entry["bonus"] + entry["deduction"]
running_score += entry["net"]
entry["end_score"] = running_score
# 月度分独立计算,与基础分无关;总分才使用基础分
entry["month_score"] = entry["bonus"] + entry["deduction"]
entry["net"] = entry["month_score"]
months.append(entry)
return {