Merge branch 'master' of http://192.168.0.200/knowledge-base-bj/deerflow-server into dhk-1
This commit is contained in:
commit
44d7304f8e
14 files changed
+436
-49
No files matched your search
+56
@@ -0,0 +1,56 @@
|
||||
"""Add users.login_password (per-account 登录口令, 明文).
|
||||
|
||||
Backs the 白名单管理「设置登录口令」feature: an admin assigns an individual
|
||||
plaintext password to a specific account, and that account's username login
|
||||
(``POST /api/v1/auth/login/username``) then requires a matching ``?password=``
|
||||
(it takes precedence over the global shared-password gate). The column is
|
||||
nullable — NULL/empty means "no personal password" and the account keeps the
|
||||
existing shared-gate / passwordless behavior.
|
||||
|
||||
Stored in plaintext on purpose: the password rides in the login URL's query
|
||||
string anyway, and keeping it readable lets the admin re-copy the full login
|
||||
link ``…/login/<username>?password=xxxx`` at any time. The ``/users`` list that
|
||||
exposes it is admin-only.
|
||||
|
||||
Revision ID: 20260625_04
|
||||
Revises: 20260625_03
|
||||
Create Date: 2026-06-27
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy import inspect
|
||||
|
||||
|
||||
revision = "20260625_04"
|
||||
down_revision = "20260625_03"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def _has_table(table_name: str) -> bool:
|
||||
inspector = inspect(op.get_bind())
|
||||
return table_name in inspector.get_table_names()
|
||||
|
||||
|
||||
def _has_column(table_name: str, column_name: str) -> bool:
|
||||
if not _has_table(table_name):
|
||||
return False
|
||||
inspector = inspect(op.get_bind())
|
||||
return any(col["name"] == column_name for col in inspector.get_columns(table_name))
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# A brand-new DB gets the column from create_all; only patch existing tables.
|
||||
if _has_table("users") and not _has_column("users", "login_password"):
|
||||
op.add_column(
|
||||
"users",
|
||||
sa.Column("login_password", sa.String(length=255), nullable=True),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
if _has_column("users", "login_password"):
|
||||
op.drop_column("users", "login_password")
|
||||
@@ -56,6 +56,13 @@ class UserRow(Base):
|
||||
# 时把已存在行置为已放行。
|
||||
approved: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True, server_default=text("1"))
|
||||
|
||||
# 管理员在「白名单管理」页给个别账号设置的「登录口令」(**明文**)。非空 → 该账号的
|
||||
# 用户名直登(``POST /api/v1/auth/login/username``)必须带 ``?password=`` 且与此值
|
||||
# 完全一致才放行(优先于全局共享口令门);为空/NULL → 走原有逻辑(全局共享口令门
|
||||
# 或免口令)。明文存储是有意为之:口令本就以 URL query 明文传输,存明文才能让管理员
|
||||
# 随时复制完整登录链接 ``…/login/<用户名>?password=xxxx``。仅 admin 可读写。
|
||||
login_password: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
|
||||
# 岗位 (position) the user is assigned to (1:1). NULL = no explicit
|
||||
# position → the user inherits the ``is_default`` position's grants. Drives
|
||||
# the subscription sync engine (see ``deerflow.services.position_sync``).
|
||||
|
||||
Reference in new issue
Block a user