diff --git a/backend/admin/users.py b/backend/admin/users.py
index 53c80dc..f087824 100644
--- a/backend/admin/users.py
+++ b/backend/admin/users.py
@@ -75,6 +75,8 @@ def list_users(db: Session) -> list[dict]:
rows.append(
{
"employee_id": account.employee_id,
+ "user_name": account.user_name or "",
+ "company": account.company or "",
"has_credential": bool(account.credential_cipher),
"refresh_paused": bool(account.refresh_paused),
"last_refresh_at": _iso_time(account.last_refresh_at),
diff --git a/backend/alembic/versions/0012_account_profile.py b/backend/alembic/versions/0012_account_profile.py
new file mode 100644
index 0000000..8fce5bc
--- /dev/null
+++ b/backend/alembic/versions/0012_account_profile.py
@@ -0,0 +1,21 @@
+"""账号记下首页上的姓名和部门,供管理端用户列表显示。"""
+
+from alembic import op
+import sqlalchemy as sa
+
+revision = "0012_account_profile"
+down_revision = "0011_drop_proxy_list"
+branch_labels = None
+depends_on = None
+
+
+def upgrade() -> None:
+ with op.batch_alter_table("accounts") as batch:
+ batch.add_column(sa.Column("user_name", sa.String(length=64), server_default="", nullable=False))
+ batch.add_column(sa.Column("company", sa.String(length=300), server_default="", nullable=False))
+
+
+def downgrade() -> None:
+ with op.batch_alter_table("accounts") as batch:
+ batch.drop_column("company")
+ batch.drop_column("user_name")
diff --git a/backend/euniv/models.py b/backend/euniv/models.py
index 3b475d1..860423d 100644
--- a/backend/euniv/models.py
+++ b/backend/euniv/models.py
@@ -56,6 +56,8 @@ class Account(Base):
last_refresh_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
credential_valid: Mapped[bool | None] = mapped_column(Boolean, nullable=True)
month_hours: Mapped[str] = mapped_column(String(32), nullable=False, default="", server_default=text("''"))
+ user_name: Mapped[str] = mapped_column(String(64), nullable=False, default="", server_default=text("''"))
+ company: Mapped[str] = mapped_column(String(300), nullable=False, default="", server_default=text("''"))
hours_month: Mapped[str] = mapped_column(String(7), nullable=False, default="", server_default=text("''"))
monthly_target: Mapped[int] = mapped_column(nullable=False, default=600, server_default="600")
proxy_scheme: Mapped[str] = mapped_column(String(16), nullable=False, default="", server_default=text("''"))
diff --git a/backend/euniv/service.py b/backend/euniv/service.py
index a27fc54..76b664a 100644
--- a/backend/euniv/service.py
+++ b/backend/euniv/service.py
@@ -369,6 +369,7 @@ def poll_qr_login(db: Session, attempt_id: str) -> dict:
def fetch_home_summary(db: Session, employee_id: str, client_factory=EunivClient) -> dict:
data = _live(db, employee_id, client_factory, lambda client: _apply_hours_source(client, client.home_summary()))
_remember_month_hours(db, employee_id, data)
+ _remember_profile(db, employee_id, data)
return data
@@ -470,6 +471,34 @@ def _remember_month_hours(db: Session, employee_id: str, payload: dict) -> None:
db.commit()
+def _profile_text(value: object, limit: int) -> str:
+ if not isinstance(value, str):
+ return ""
+ return value.strip()[:limit]
+
+
+def _remember_profile(db: Session, employee_id: str, payload: dict) -> None:
+ """首页已经取到姓名和部门时,顺手写回用户列表。不记录职级。"""
+ if not isinstance(payload, dict):
+ return
+ name = _profile_text(payload.get("name"), 64)
+ company = _profile_text(payload.get("department"), 300)
+ if not name and not company:
+ return
+ account = db.get(Account, employee_id)
+ if account is None:
+ return
+ changed = False
+ if name and account.user_name != name:
+ account.user_name = name
+ changed = True
+ if company and account.company != company:
+ account.company = company
+ changed = True
+ if changed:
+ db.commit()
+
+
def _hour_fields(data: dict) -> dict:
fields = {
"hours_source": data.get("hours_source") or "api",
diff --git a/backend/tests/test_admin.py b/backend/tests/test_admin.py
index 5f2459d..57cc87f 100644
--- a/backend/tests/test_admin.py
+++ b/backend/tests/test_admin.py
@@ -498,6 +498,8 @@ def test_check_skips_empty_credential_and_updates_saved_one(monkeypatch) -> None
saved = next(item for item in body if item["employee_id"] == "saved-user")
assert set(saved) == {
"employee_id",
+ "user_name",
+ "company",
"has_credential",
"refresh_paused",
"last_refresh_at",
@@ -524,6 +526,8 @@ def test_check_skips_empty_credential_and_updates_saved_one(monkeypatch) -> None
assert saved["refresh_paused"] is False
assert saved["credential_valid"] is True
assert saved["month_hours"] == ""
+ assert saved["user_name"] == ""
+ assert saved["company"] == ""
assert isinstance(saved["last_refresh_at"], str)
calls.clear()
again = client.get("/api/admin/users")
diff --git a/backend/tests/test_api.py b/backend/tests/test_api.py
index 6cad719..9be9c7e 100644
--- a/backend/tests/test_api.py
+++ b/backend/tests/test_api.py
@@ -150,6 +150,8 @@ def test_login_stores_password_and_credential_only(monkeypatch) -> None:
"last_refresh_at",
"credential_valid",
"month_hours",
+ "user_name",
+ "company",
"hours_month",
"monthly_target",
"proxy_scheme",
@@ -185,6 +187,18 @@ def test_login_stores_password_and_credential_only(monkeypatch) -> None:
assert updated["yxt_token"] == "yxt-2"
assert "测试用户" not in decrypt_secret(account.credential_cipher)
assert "测试用户" not in decrypt_secret(account.password_cipher)
+ assert account.user_name == "测试用户"
+ assert account.company == "测试部门"
+ from euniv.service import _remember_profile
+
+ _remember_profile(db, "6650000146", {"name": " ", "department": "", "level": "Scientist"})
+ db.refresh(account)
+ assert account.user_name == "测试用户"
+ assert account.company == "测试部门"
+ _remember_profile(db, "6650000146", {"name": "新名字", "department": "广州瀚信广州处", "level": "Scientist"})
+ db.refresh(account)
+ assert account.user_name == "新名字"
+ assert account.company == "广州瀚信广州处"
def test_qr_mark_cannot_password_login_and_unicode_password_is_safe(monkeypatch) -> None:
diff --git a/web/src/features/admin/UsersView.vue b/web/src/features/admin/UsersView.vue
index 2414ce6..1dd022c 100644
--- a/web/src/features/admin/UsersView.vue
+++ b/web/src/features/admin/UsersView.vue
@@ -9,6 +9,8 @@ import { isRecord, textOf } from "../../shared/text";
interface UserRow {
employee_id: string;
+ user_name: string;
+ company: string;
has_credential: boolean;
refresh_paused: boolean;
last_refresh_at: string | null;
@@ -164,6 +166,8 @@ function asUser(value: unknown): UserRow | null {
if (!isRecord(value) || (typeof value.employee_id !== "string" && typeof value.employee_id !== "number")) return null;
return {
employee_id: String(value.employee_id),
+ user_name: textOf(value.user_name),
+ company: textOf(value.company),
has_credential: value.has_credential === true,
refresh_paused: value.refresh_paused === true,
last_refresh_at: typeof value.last_refresh_at === "string" && value.last_refresh_at ? value.last_refresh_at : null,
@@ -892,6 +896,8 @@ onMounted(() => {