feat: implement automation module
- Event-based triggers (Phase 1): - Trigger/TriggerLog models with field_change type - TriggerService for condition evaluation and action execution - Trigger CRUD API endpoints - Task integration (status, assignee, priority changes) - Frontend: TriggerList, TriggerForm components - Weekly reports (Phase 2): - ScheduledReport/ReportHistory models - ReportService for stats generation - APScheduler for Friday 16:00 job - Report preview/generate/history API - Frontend: WeeklyReportPreview, ReportHistory components - Tests: 23 new tests (14 triggers + 9 reports) - OpenSpec: add-automation 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:
35
backend/app/models/trigger.py
Normal file
35
backend/app/models/trigger.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import uuid
|
||||
import enum
|
||||
from sqlalchemy import Column, String, Text, Boolean, DateTime, ForeignKey, Enum, JSON
|
||||
from sqlalchemy.sql import func
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class TriggerType(str, enum.Enum):
|
||||
FIELD_CHANGE = "field_change"
|
||||
SCHEDULE = "schedule"
|
||||
|
||||
|
||||
class Trigger(Base):
|
||||
__tablename__ = "pjctrl_triggers"
|
||||
|
||||
id = Column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
||||
project_id = Column(String(36), ForeignKey("pjctrl_projects.id", ondelete="CASCADE"), nullable=False)
|
||||
name = Column(String(200), nullable=False)
|
||||
description = Column(Text, nullable=True)
|
||||
trigger_type = Column(
|
||||
Enum("field_change", "schedule", name="trigger_type_enum"),
|
||||
nullable=False
|
||||
)
|
||||
conditions = Column(JSON, nullable=False)
|
||||
actions = Column(JSON, nullable=False)
|
||||
is_active = Column(Boolean, default=True, nullable=False)
|
||||
created_by = Column(String(36), ForeignKey("pjctrl_users.id", ondelete="SET NULL"), nullable=True)
|
||||
created_at = Column(DateTime, server_default=func.now(), nullable=False)
|
||||
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), nullable=False)
|
||||
|
||||
# Relationships
|
||||
project = relationship("Project", back_populates="triggers")
|
||||
creator = relationship("User", back_populates="created_triggers")
|
||||
logs = relationship("TriggerLog", back_populates="trigger", cascade="all, delete-orphan")
|
||||
Reference in New Issue
Block a user