fix(critical): automation plugin User.tenant_id does not exist — use UserTenant join
Check Cross-Plugin Imports / check (push) Has been cancelled
Check Cross-Plugin Imports / check (push) Has been cancelled
User model has no tenant_id column. Users are linked to tenants via UserTenant join table. This bug blocked all plugin activation in prestart.sh.
This commit is contained in:
@@ -248,13 +248,16 @@ class AutomationPlugin(BasePlugin):
|
|||||||
from sqlalchemy import select as sa_select
|
from sqlalchemy import select as sa_select
|
||||||
|
|
||||||
# Get first tenant + admin user for seeding
|
# Get first tenant + admin user for seeding
|
||||||
from app.models.user import User
|
from app.models.user import User, UserTenant
|
||||||
from app.models.tenant import Tenant
|
from app.models.tenant import Tenant
|
||||||
tenant_result = await db.execute(sa_select(Tenant).limit(1))
|
tenant_result = await db.execute(sa_select(Tenant).limit(1))
|
||||||
tenant = tenant_result.scalar_one_or_none()
|
tenant = tenant_result.scalar_one_or_none()
|
||||||
if tenant:
|
if tenant:
|
||||||
user_result = await db.execute(
|
user_result = await db.execute(
|
||||||
sa_select(User).where(User.tenant_id == tenant.id).limit(1)
|
sa_select(User)
|
||||||
|
.join(UserTenant, UserTenant.user_id == User.id)
|
||||||
|
.where(UserTenant.tenant_id == tenant.id)
|
||||||
|
.limit(1)
|
||||||
)
|
)
|
||||||
user = user_result.scalar_one_or_none()
|
user = user_result.scalar_one_or_none()
|
||||||
if user:
|
if user:
|
||||||
|
|||||||
Reference in New Issue
Block a user