清理全局角色残留并修复项目权限判断

This commit is contained in:
Cheng Zhou
2026-05-29 10:20:42 +08:00
parent 63457aab11
commit 44d69c2d7b
63 changed files with 739 additions and 443 deletions
+3 -6
View File
@@ -1,7 +1,5 @@
from __future__ import annotations
from __future__ import annotations
import uuid
from typing import Sequence
@@ -16,7 +14,7 @@ from app.core.config import (
)
from app.core.security import hash_password
from app.models.study_member import StudyMember
from app.models.user import User, UserRole, UserStatus
from app.models.user import User, UserStatus
from app.schemas.user import UserCreate, UserRegisterRequest, UserUpdate
@@ -46,7 +44,6 @@ async def create_user(
email=user_in.email,
password_hash=hash_password(user_in.password),
full_name=user_in.full_name,
role=UserRole.PV,
clinical_department=user_in.clinical_department,
status=status_value,
)
@@ -114,7 +111,7 @@ async def count_active_admins(db: AsyncSession) -> int:
result = await db.execute(
select(func.count())
.select_from(User)
.where(User.role == UserRole.ADMIN, User.status == UserStatus.ACTIVE)
.where(User.is_admin.is_(True), User.status == UserStatus.ACTIVE)
)
return int(result.scalar_one() or 0)
@@ -138,7 +135,7 @@ async def ensure_admin_exists(db: AsyncSession, *, default_password: str = PROTE
email=PROTECTED_ADMIN_EMAIL,
password_hash=hash_password(default_password),
full_name=PROTECTED_ADMIN_FULL_NAME,
role=UserRole.ADMIN,
is_admin=True,
clinical_department=PROTECTED_ADMIN_CLINICAL_DEPARTMENT,
status=UserStatus.ACTIVE,
)