feat: implement workspace management and member invitations
- Added tenant API for managing workspaces, including listing, creating, and inviting members. - Introduced new models for organizations, workspaces, and workspace memberships in the backend. - Created frontend components for workspace administration, allowing users to manage workspaces and invite members. - Updated document listing to support workspace-specific filtering. - Implemented account settings page for user profile management and password changes. - Added end-to-end tests for workspace administration and dashboard functionalities.
This commit is contained in:
parent
809235e962
commit
bf5cd44dc1
20 changed files with 928 additions and 27 deletions
64
backend/app/models/tenant.py
Normal file
64
backend/app/models/tenant.py
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import Boolean, DateTime, ForeignKey, String, UniqueConstraint, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class Organization(Base):
|
||||
__tablename__ = "organizations"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
name: Mapped[str] = mapped_column(String(160), nullable=False)
|
||||
slug: Mapped[str] = mapped_column(String(180), unique=True, index=True, nullable=False)
|
||||
owner_id: Mapped[int] = mapped_column(ForeignKey("users.id"), index=True, nullable=False)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), nullable=False)
|
||||
|
||||
|
||||
class Workspace(Base):
|
||||
__tablename__ = "workspaces"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
organization_id: Mapped[int] = mapped_column(ForeignKey("organizations.id"), index=True, nullable=False)
|
||||
name: Mapped[str] = mapped_column(String(160), nullable=False)
|
||||
slug: Mapped[str] = mapped_column(String(180), nullable=False)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), nullable=False)
|
||||
__table_args__ = (UniqueConstraint("organization_id", "slug", name="uq_workspace_org_slug"),)
|
||||
|
||||
|
||||
class WorkspaceMembership(Base):
|
||||
__tablename__ = "workspace_memberships"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
workspace_id: Mapped[int] = mapped_column(ForeignKey("workspaces.id"), index=True, nullable=False)
|
||||
user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), index=True, nullable=False)
|
||||
role: Mapped[str] = mapped_column(String(30), default="member", nullable=False)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), nullable=False)
|
||||
__table_args__ = (UniqueConstraint("workspace_id", "user_id", name="uq_workspace_member"),)
|
||||
|
||||
|
||||
class WorkspaceInvitation(Base):
|
||||
__tablename__ = "workspace_invitations"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
workspace_id: Mapped[int] = mapped_column(ForeignKey("workspaces.id"), index=True, nullable=False)
|
||||
inviter_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=False)
|
||||
email: Mapped[str] = mapped_column(String(255), index=True, nullable=False)
|
||||
role: Mapped[str] = mapped_column(String(30), default="member", nullable=False)
|
||||
token: Mapped[str] = mapped_column(String(128), unique=True, index=True, nullable=False)
|
||||
accepted: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
||||
expires_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), nullable=False)
|
||||
|
||||
|
||||
class TenantAuditEvent(Base):
|
||||
__tablename__ = "tenant_audit_events"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
organization_id: Mapped[int] = mapped_column(ForeignKey("organizations.id"), index=True, nullable=False)
|
||||
workspace_id: Mapped[int | None] = mapped_column(ForeignKey("workspaces.id"), index=True)
|
||||
actor_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=False)
|
||||
action: Mapped[str] = mapped_column(String(80), nullable=False)
|
||||
target: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), nullable=False)
|
||||
Loading…
Add table
Add a link
Reference in a new issue