feat: implement collaboration module

- Backend (FastAPI):
  - Task comments with nested replies and soft delete
  - @mention parsing with 10-mention limit per comment
  - Notification system with read/unread tracking
  - Blocker management with project owner notification
  - WebSocket endpoint with JWT auth and keepalive
  - User search API for @mention autocomplete
  - Alembic migration for 4 new tables

- Frontend (React + Vite):
  - Comments component with @mention autocomplete
  - NotificationBell with real-time WebSocket updates
  - BlockerDialog for task blocking workflow
  - NotificationContext for state management

- OpenSpec:
  - 4 requirements with scenarios defined
  - add-collaboration change archived

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
beabigegg
2025-12-29 20:45:07 +08:00
parent 61fe01cb6b
commit 3470428411
38 changed files with 3088 additions and 4 deletions

View File

@@ -6,5 +6,12 @@ from app.models.project import Project
from app.models.task_status import TaskStatus
from app.models.task import Task
from app.models.workload_snapshot import WorkloadSnapshot
from app.models.comment import Comment
from app.models.mention import Mention
from app.models.notification import Notification
from app.models.blocker import Blocker
__all__ = ["User", "Role", "Department", "Space", "Project", "TaskStatus", "Task", "WorkloadSnapshot"]
__all__ = [
"User", "Role", "Department", "Space", "Project", "TaskStatus", "Task", "WorkloadSnapshot",
"Comment", "Mention", "Notification", "Blocker"
]

View File

@@ -0,0 +1,23 @@
import uuid
from sqlalchemy import Column, String, Text, DateTime, ForeignKey
from sqlalchemy.sql import func
from sqlalchemy.orm import relationship
from app.core.database import Base
class Blocker(Base):
__tablename__ = "pjctrl_blockers"
id = Column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
task_id = Column(String(36), ForeignKey("pjctrl_tasks.id", ondelete="CASCADE"), nullable=False)
reported_by = Column(String(36), ForeignKey("pjctrl_users.id"), nullable=False)
reason = Column(Text, nullable=False)
resolved_by = Column(String(36), ForeignKey("pjctrl_users.id"), nullable=True)
resolution_note = Column(Text, nullable=True)
created_at = Column(DateTime, server_default=func.now(), nullable=False)
resolved_at = Column(DateTime, nullable=True)
# Relationships
task = relationship("Task", back_populates="blockers")
reporter = relationship("User", foreign_keys=[reported_by], back_populates="reported_blockers")
resolver = relationship("User", foreign_keys=[resolved_by], back_populates="resolved_blockers")

View File

@@ -0,0 +1,26 @@
import uuid
from sqlalchemy import Column, String, Text, Boolean, DateTime, ForeignKey
from sqlalchemy.sql import func
from sqlalchemy.orm import relationship
from app.core.database import Base
class Comment(Base):
__tablename__ = "pjctrl_comments"
id = Column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
task_id = Column(String(36), ForeignKey("pjctrl_tasks.id", ondelete="CASCADE"), nullable=False)
parent_comment_id = Column(String(36), ForeignKey("pjctrl_comments.id", ondelete="CASCADE"), nullable=True)
author_id = Column(String(36), ForeignKey("pjctrl_users.id"), nullable=False)
content = Column(Text, nullable=False)
is_edited = Column(Boolean, default=False, nullable=False)
is_deleted = Column(Boolean, default=False, nullable=False)
created_at = Column(DateTime, server_default=func.now(), nullable=False)
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), nullable=False)
# Relationships
task = relationship("Task", back_populates="comments")
author = relationship("User", back_populates="comments")
parent_comment = relationship("Comment", remote_side=[id], back_populates="replies")
replies = relationship("Comment", back_populates="parent_comment", cascade="all, delete-orphan")
mentions = relationship("Mention", back_populates="comment", cascade="all, delete-orphan")

View File

@@ -0,0 +1,18 @@
import uuid
from sqlalchemy import Column, String, DateTime, ForeignKey
from sqlalchemy.sql import func
from sqlalchemy.orm import relationship
from app.core.database import Base
class Mention(Base):
__tablename__ = "pjctrl_mentions"
id = Column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
comment_id = Column(String(36), ForeignKey("pjctrl_comments.id", ondelete="CASCADE"), nullable=False)
mentioned_user_id = Column(String(36), ForeignKey("pjctrl_users.id"), nullable=False)
created_at = Column(DateTime, server_default=func.now(), nullable=False)
# Relationships
comment = relationship("Comment", back_populates="mentions")
mentioned_user = relationship("User", back_populates="mentions")

View File

@@ -0,0 +1,37 @@
import uuid
from sqlalchemy import Column, String, Text, Boolean, DateTime, ForeignKey, Enum
from sqlalchemy.sql import func
from sqlalchemy.orm import relationship
from app.core.database import Base
import enum
class NotificationType(str, enum.Enum):
MENTION = "mention"
ASSIGNMENT = "assignment"
BLOCKER = "blocker"
STATUS_CHANGE = "status_change"
COMMENT = "comment"
BLOCKER_RESOLVED = "blocker_resolved"
class Notification(Base):
__tablename__ = "pjctrl_notifications"
id = Column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
user_id = Column(String(36), ForeignKey("pjctrl_users.id", ondelete="CASCADE"), nullable=False)
type = Column(
Enum("mention", "assignment", "blocker", "status_change", "comment", "blocker_resolved",
name="notification_type_enum"),
nullable=False
)
reference_type = Column(String(50), nullable=False)
reference_id = Column(String(36), nullable=False)
title = Column(String(200), nullable=False)
message = Column(Text, nullable=True)
is_read = Column(Boolean, default=False, nullable=False)
created_at = Column(DateTime, server_default=func.now(), nullable=False)
read_at = Column(DateTime, nullable=True)
# Relationships
user = relationship("User", back_populates="notifications")

View File

@@ -43,3 +43,7 @@ class Task(Base):
assignee = relationship("User", foreign_keys=[assignee_id], back_populates="assigned_tasks")
creator = relationship("User", foreign_keys=[created_by], back_populates="created_tasks")
status = relationship("TaskStatus", back_populates="tasks")
# Collaboration relationships
comments = relationship("Comment", back_populates="task", cascade="all, delete-orphan")
blockers = relationship("Blocker", back_populates="task", cascade="all, delete-orphan")

View File

@@ -29,3 +29,10 @@ class User(Base):
owned_projects = relationship("Project", foreign_keys="Project.owner_id", back_populates="owner")
assigned_tasks = relationship("Task", foreign_keys="Task.assignee_id", back_populates="assignee")
created_tasks = relationship("Task", foreign_keys="Task.created_by", back_populates="creator")
# Collaboration relationships
comments = relationship("Comment", back_populates="author")
mentions = relationship("Mention", back_populates="mentioned_user")
notifications = relationship("Notification", back_populates="user", cascade="all, delete-orphan")
reported_blockers = relationship("Blocker", foreign_keys="Blocker.reported_by", back_populates="reporter")
resolved_blockers = relationship("Blocker", foreign_keys="Blocker.resolved_by", back_populates="resolver")