mirror of
https://github.com/DRYTRIX/TimeTracker.git
synced 2026-04-30 09:19:46 -05:00
443a797e2d
Implement comprehensive CalDAV calendar integration to import calendar events as time entries from CalDAV-compatible servers (Zimbra, Nextcloud, ownCloud). Features: - CalDAV client with calendar discovery and event fetching - Automatic calendar discovery from server URL - Import calendar events (VEVENT) as time entries - Project matching from event titles with fallback to default project - Idempotent sync using IntegrationExternalEventLink to prevent duplicates - Per-user integration setup (similar to Google Calendar) - Support for both server URL (with discovery) and direct calendar URL - SSL certificate verification toggle for self-signed certificates - Configurable lookback period for event import Components: - CalDAVCalendarConnector: Main integration connector with sync logic - CalDAVClient: Low-level CalDAV client using PROPFIND/REPORT requests - IntegrationExternalEventLink: Model for tracking imported events (idempotency) - Setup UI: User-friendly form for configuration - Comprehensive validation and error handling - Full test coverage (unit, integration, route tests) - Documentation: Setup guide and troubleshooting Technical details: - Uses icalendar library for parsing VEVENT components - Handles timezone conversion (CalDAV UTC to app local timezone) - Skips all-day events (only imports timed events) - Stores credentials securely (password in access_token, username in extra_data) - Automatic calendar discovery on first sync if only server URL provided Migration: - Adds integration_external_event_links table for sync tracking - Unique constraint on (integration_id, external_uid) prevents duplicates Documentation: - CALDAV_INTEGRATION.md: Complete feature documentation - CALDAV_QUICK_SETUP.md: Step-by-step setup guide with examples Closes feature request for CalDAV/Zimbra integration.
39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
"""
|
|
External event link table for integration-driven sync.
|
|
|
|
Used for idempotency when importing calendar events (e.g., CalDAV -> TimeEntry).
|
|
"""
|
|
|
|
from datetime import datetime
|
|
|
|
from app import db
|
|
|
|
|
|
class IntegrationExternalEventLink(db.Model):
|
|
__tablename__ = "integration_external_event_links"
|
|
__table_args__ = (
|
|
db.UniqueConstraint("integration_id", "external_uid", name="uq_integration_external_uid"),
|
|
{"extend_existing": True},
|
|
)
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
integration_id = db.Column(
|
|
db.Integer, db.ForeignKey("integrations.id", ondelete="CASCADE"), nullable=False, index=True
|
|
)
|
|
time_entry_id = db.Column(db.Integer, db.ForeignKey("time_entries.id", ondelete="CASCADE"), nullable=False, index=True)
|
|
|
|
# External identifiers
|
|
external_uid = db.Column(db.String(255), nullable=False, index=True)
|
|
external_href = db.Column(db.String(500), nullable=True)
|
|
|
|
created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
|
|
|
|
integration = db.relationship("Integration", backref=db.backref("external_event_links", cascade="all, delete-orphan"))
|
|
time_entry = db.relationship("TimeEntry", backref=db.backref("external_event_links", cascade="all, delete-orphan"))
|
|
|
|
def __repr__(self):
|
|
return f"<IntegrationExternalEventLink integration_id={self.integration_id} uid={self.external_uid}>"
|
|
|
|
|