mirror of
https://github.com/langflow-ai/langflow.git
synced 2026-07-25 13:17:34 +08:00
feat(rbac): add uniqueness constraint, role inheritance, workspace support, and rbac_ table prefix
This commit is contained in:
@ -10,20 +10,37 @@ from langflow.schema.serialize import UUIDstr
|
||||
|
||||
|
||||
class Role(SQLModel, table=True): # type: ignore[call-arg]
|
||||
__tablename__ = "role"
|
||||
__tablename__ = "rbac_role"
|
||||
|
||||
id: UUIDstr = Field(default_factory=uuid4, primary_key=True)
|
||||
name: str = Field(unique=True, index=True)
|
||||
description: str | None = Field(default=None)
|
||||
is_system: bool = Field(default=False)
|
||||
permissions: dict[str, Any] = Field(sa_column=Column(JSON, nullable=False))
|
||||
parent_role_id: UUIDstr | None = Field(
|
||||
default=None,
|
||||
sa_column=Column(
|
||||
sa.Uuid(),
|
||||
ForeignKey("rbac_role.id", ondelete="SET NULL"),
|
||||
nullable=True,
|
||||
),
|
||||
)
|
||||
workspace_id: UUIDstr | None = Field(default=None, nullable=True, index=True)
|
||||
created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
|
||||
updated_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
|
||||
created_by: UUIDstr | None = Field(
|
||||
default=None,
|
||||
sa_column=Column(
|
||||
sa.Uuid(),
|
||||
ForeignKey("user.id", ondelete="SET NULL"),
|
||||
nullable=True,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class UserRole(SQLModel, table=True): # type: ignore[call-arg]
|
||||
__tablename__ = "user_role"
|
||||
__table_args__ = (Index("uq_user_role_user_role", "user_id", "role_id", unique=True),)
|
||||
__tablename__ = "rbac_user_role"
|
||||
__table_args__ = (Index("uq_rbac_user_role_user_role", "user_id", "role_id", unique=True),)
|
||||
|
||||
id: UUIDstr = Field(default_factory=uuid4, primary_key=True)
|
||||
user_id: UUIDstr = Field(
|
||||
@ -37,7 +54,7 @@ class UserRole(SQLModel, table=True): # type: ignore[call-arg]
|
||||
role_id: UUIDstr = Field(
|
||||
sa_column=Column(
|
||||
sa.Uuid(),
|
||||
ForeignKey("role.id", ondelete="CASCADE"),
|
||||
ForeignKey("rbac_role.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
@ -54,8 +71,17 @@ class UserRole(SQLModel, table=True): # type: ignore[call-arg]
|
||||
|
||||
|
||||
class ResourcePermission(SQLModel, table=True): # type: ignore[call-arg]
|
||||
__tablename__ = "resource_permission"
|
||||
__table_args__ = (Index("ix_resource_permission_user_resource", "user_id", "resource_type", "resource_id"),)
|
||||
__tablename__ = "rbac_resource_permission"
|
||||
__table_args__ = (
|
||||
Index(
|
||||
"uq_rbac_resource_permission_user_resource_perm",
|
||||
"user_id",
|
||||
"resource_type",
|
||||
"resource_id",
|
||||
"permission",
|
||||
unique=True,
|
||||
),
|
||||
)
|
||||
|
||||
id: UUIDstr = Field(default_factory=uuid4, primary_key=True)
|
||||
user_id: UUIDstr = Field(
|
||||
@ -81,10 +107,10 @@ class ResourcePermission(SQLModel, table=True): # type: ignore[call-arg]
|
||||
|
||||
|
||||
class AuditLog(SQLModel, table=True): # type: ignore[call-arg]
|
||||
__tablename__ = "audit_log"
|
||||
__tablename__ = "rbac_audit_log"
|
||||
__table_args__ = (
|
||||
Index("ix_audit_log_user_timestamp", "user_id", "timestamp"),
|
||||
Index("ix_audit_log_resource", "resource_type", "resource_id"),
|
||||
Index("ix_rbac_audit_log_user_timestamp", "user_id", "timestamp"),
|
||||
Index("ix_rbac_audit_log_resource", "resource_type", "resource_id"),
|
||||
)
|
||||
|
||||
id: UUIDstr = Field(default_factory=uuid4, primary_key=True)
|
||||
|
||||
Reference in New Issue
Block a user