Files
PROJECT-CONTORL/backend/app/models/user.py
beabigegg 3bdc6ff1c9 feat: implement 8 OpenSpec proposals for security, reliability, and UX improvements
## Security Enhancements (P0)
- Add input validation with max_length and numeric range constraints
- Implement WebSocket token authentication via first message
- Add path traversal prevention in file storage service

## Permission Enhancements (P0)
- Add project member management for cross-department access
- Implement is_department_manager flag for workload visibility

## Cycle Detection (P0)
- Add DFS-based cycle detection for task dependencies
- Add formula field circular reference detection
- Display user-friendly cycle path visualization

## Concurrency & Reliability (P1)
- Implement optimistic locking with version field (409 Conflict on mismatch)
- Add trigger retry mechanism with exponential backoff (1s, 2s, 4s)
- Implement cascade restore for soft-deleted tasks

## Rate Limiting (P1)
- Add tiered rate limits: standard (60/min), sensitive (20/min), heavy (5/min)
- Apply rate limits to tasks, reports, attachments, and comments

## Frontend Improvements (P1)
- Add responsive sidebar with hamburger menu for mobile
- Improve touch-friendly UI with proper tap target sizes
- Complete i18n translations for all components

## Backend Reliability (P2)
- Configure database connection pool (size=10, overflow=20)
- Add Redis fallback mechanism with message queue
- Add blocker check before task deletion

## API Enhancements (P3)
- Add standardized response wrapper utility
- Add /health/ready and /health/live endpoints
- Implement project templates with status/field copying

## Tests Added
- test_input_validation.py - Schema and path traversal tests
- test_concurrency_reliability.py - Optimistic locking and retry tests
- test_backend_reliability.py - Connection pool and Redis tests
- test_api_enhancements.py - Health check and template tests

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 22:13:43 +08:00

53 lines
2.6 KiB
Python

import uuid
from sqlalchemy import Column, String, ForeignKey, JSON, Boolean, DateTime, Numeric
from sqlalchemy.sql import func
from sqlalchemy.orm import relationship
from app.core.database import Base
class User(Base):
__tablename__ = "pjctrl_users"
id = Column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
email = Column(String(200), unique=True, nullable=False, index=True)
employee_id = Column(String(50), unique=True, nullable=True, index=True)
name = Column(String(200), nullable=False)
department_id = Column(String(36), ForeignKey("pjctrl_departments.id"), nullable=True)
role_id = Column(String(36), ForeignKey("pjctrl_roles.id"), nullable=True)
skills = Column(JSON, nullable=True)
capacity = Column(Numeric(5, 2), default=40.00)
is_active = Column(Boolean, default=True)
is_system_admin = Column(Boolean, default=False)
is_department_manager = Column(Boolean, default=False)
created_at = Column(DateTime, server_default=func.now())
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
# Relationships
department = relationship("Department", backref="users")
role = relationship("Role", backref="users")
# Task management relationships
owned_spaces = relationship("Space", back_populates="owner")
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")
# Automation relationships
created_triggers = relationship("Trigger", back_populates="creator")
scheduled_reports = relationship("ScheduledReport", back_populates="recipient", cascade="all, delete-orphan")
# Project membership relationships (for cross-department collaboration)
project_memberships = relationship(
"ProjectMember",
foreign_keys="ProjectMember.user_id",
back_populates="user",
cascade="all, delete-orphan"
)