From 1bdfd95fde117316b4df8cc376315f98f56ae9a7 Mon Sep 17 00:00:00 2001 From: Hermes CI Fix Date: Tue, 11 Aug 2026 11:34:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B4=A6=E5=A5=97=E9=9A=94=E7=A6=BB=20?= =?UTF-8?q?=E2=80=94=20register=E4=B8=8D=E5=86=8D=E6=8E=88=E4=BA=88?= =?UTF-8?q?=E5=85=A8=E9=83=A8=E4=BC=81=E4=B8=9A=EF=BC=8C=E4=BB=85=E6=8E=88?= =?UTF-8?q?=E7=AC=AC=E4=B8=80=E4=B8=AAactive=E4=BC=81=E4=B8=9A=EF=BC=88?= =?UTF-8?q?=E9=98=B2=E6=96=B0=E7=94=A8=E6=88=B7=E8=B6=8A=E6=9D=83=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/auth.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/app/api/auth.py b/backend/app/api/auth.py index 6ac573f9..499f3457 100644 --- a/backend/app/api/auth.py +++ b/backend/app/api/auth.py @@ -79,8 +79,12 @@ def register(data: dict, db: Session = Depends(get_db)): ) db.add(user) db.commit() - # 新用户默认授予所有active企业 - _ensure_default_grants(db, user.id) + db.refresh(user) + # 注册默认授权第一个active企业(不授予全部,保证账套隔离) + first_ent = db.query(Entity).filter(Entity.status == "active").order_by(Entity.id).first() + if first_ent: + db.add(UserEntity(user_id=user.id, entity_id=first_ent.id)) + db.commit() return {"message": "注册成功"}