Files
pear-admin-flask/applications/schemas/admin_cookie.py
T
bwstudio 6f4af8664e feat(cookieManager): 登录用户去掉Cookie值/域名,登录网站增加关联用户下拉
登录用户:
- 模型删除 cookie_value / domain 两列(连同 to_dict)
- 列表表头、新增/编辑表单移除对应控件;保存/更新不再校验 Cookie 值
  (改为只校验 用户名 + 网站URL)

登录网站:
- CookieSite 新增 cookie_user_id(关联 admin_cookie_user.id,可空)
- 列表新增「关联用户」列,未关联显示灰色「未关联」标签;查询栏支持按用户筛选
- 新增/编辑页用 layui 下拉框选择登录用户(lay-search 可搜索,显示
  “昵称(用户名)· 网站名”),编辑时自动回显已关联项
- Schema 增加 cookie_username 输出字段,视图一次性查用户表做映射,避免逐行查库

迁移 e5f6a7b8c9d0:
- admin_cookie_user 删 cookie_value、domain(SQLite 用 batch 重建表)
- admin_cookie_site 加 cookie_user_id
- 每步先判断列是否存在,可重复执行;downgrade 可还原

注意:升级会丢弃 admin_cookie_user.cookie_value / domain 的历史数据。

已 Playwright 真机验证(本机 :5000):
列表无 Cookie值/域名列、新增页无对应控件、保存成功;
网站新增选中用户后落库 cookie_user_id=1、列表显示“验证用户”、编辑页正确回显。
2026-09-10 20:19:25 +08:00

29 lines
911 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Cookie管理Schema"""
from flask_marshmallow.sqla import SQLAlchemyAutoSchema
from marshmallow import fields
from applications.extensions import ma
from applications.models import CookieUser, CookieSite
class CookieUserManageSchema(SQLAlchemyAutoSchema):
"""登录用户管理用:序列化为表格数据 / 表单回填"""
class Meta:
model = CookieUser
include_fk = True
load_instance = True
class CookieSiteManageSchema(SQLAlchemyAutoSchema):
"""登录网站管理用:序列化为表格数据 / 表单回填"""
# 关联登录用户的显示名(视图层预先挂到对象上的 _cookie_username
cookie_username = fields.Method('get_cookie_username')
class Meta:
model = CookieSite
include_fk = True
load_instance = True
def get_cookie_username(self, obj):
return getattr(obj, '_cookie_username', '') or ''