a143325bbe
Sharing-Fix: Calendar-Model hatte keine owner-Relation zu User - list_calendars stuerzte beim Listen geteilter Kalender ab (c.owner.username -> AttributeError). Jetzt mit explizitem foreign_keys Relationship. Benutzer-Autocomplete: "Kalender teilen" nutzt jetzt /users/search wie bei Dateien. Tippt man 2+ Zeichen, erscheint ein Dropdown mit passenden Benutzernamen. Klick uebernimmt den Namen. Bestehende Freigaben werden im Menue angezeigt mit Muelleimer zum Entfernen. Privat-Flag fuer Termine: CalendarEvent bekommt is_private-Spalte. Checkbox im Termin- Dialog "🔒 Privat (Teilnehmer sehen nur den Zeitblock)". Redaction greift an drei Stellen: * GET /events: Nicht-Owner sehen summary="Privat", description und location = null. Zeitfenster bleibt voll sichtbar. * iCal-Export (/ical/<token>): Privat-Events werden mit CLASS:PRIVATE ausgegeben und SUMMARY/DESCRIPTION/LOCATION werden gestrippt. * CalDAV: aktuell werden eh nur eigene Kalender exportiert, also keine Redaction noetig. Kommt bei Share-Support rein. Der Eigentuemer sieht natuerlich in seiner eigenen Ansicht alle Details seines privaten Termins. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
91 lines
4.0 KiB
Python
91 lines
4.0 KiB
Python
from datetime import datetime, timezone
|
|
|
|
from app.extensions import db
|
|
|
|
|
|
class Calendar(db.Model):
|
|
__tablename__ = 'calendars'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
owner_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False, index=True)
|
|
name = db.Column(db.String(255), nullable=False)
|
|
color = db.Column(db.String(7), default='#3788d8')
|
|
description = db.Column(db.Text, nullable=True)
|
|
ical_token = db.Column(db.String(64), unique=True, nullable=True, index=True)
|
|
ical_password_hash = db.Column(db.String(255), nullable=True)
|
|
created_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc))
|
|
updated_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc),
|
|
onupdate=lambda: datetime.now(timezone.utc))
|
|
|
|
events = db.relationship('CalendarEvent', backref='calendar', lazy='dynamic',
|
|
cascade='all, delete-orphan')
|
|
shares = db.relationship('CalendarShare', backref='calendar', lazy='dynamic',
|
|
cascade='all, delete-orphan')
|
|
owner = db.relationship('User', foreign_keys=[owner_id])
|
|
|
|
def to_dict(self):
|
|
return {
|
|
'id': self.id,
|
|
'owner_id': self.owner_id,
|
|
'name': self.name,
|
|
'color': self.color,
|
|
'description': self.description,
|
|
'ical_token': self.ical_token,
|
|
'ical_has_password': bool(self.ical_password_hash),
|
|
'created_at': self.created_at.isoformat() if self.created_at else None,
|
|
}
|
|
|
|
|
|
class CalendarEvent(db.Model):
|
|
__tablename__ = 'calendar_events'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
calendar_id = db.Column(db.Integer, db.ForeignKey('calendars.id'), nullable=False, index=True)
|
|
uid = db.Column(db.String(255), unique=True, nullable=False)
|
|
ical_data = db.Column(db.Text, nullable=False) # Full VCALENDAR component
|
|
summary = db.Column(db.String(500), nullable=True)
|
|
description = db.Column(db.Text, nullable=True)
|
|
location = db.Column(db.String(500), nullable=True)
|
|
dtstart = db.Column(db.DateTime, nullable=True, index=True)
|
|
dtend = db.Column(db.DateTime, nullable=True)
|
|
all_day = db.Column(db.Boolean, default=False)
|
|
recurrence_rule = db.Column(db.Text, nullable=True)
|
|
exdates = db.Column(db.Text, nullable=True) # Komma-separiert, ISO-Datum (YYYY-MM-DD)
|
|
is_private = db.Column(db.Boolean, default=False, nullable=False)
|
|
created_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc))
|
|
updated_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc),
|
|
onupdate=lambda: datetime.now(timezone.utc))
|
|
|
|
def to_dict(self):
|
|
return {
|
|
'id': self.id,
|
|
'calendar_id': self.calendar_id,
|
|
'uid': self.uid,
|
|
'summary': self.summary,
|
|
'description': self.description,
|
|
'location': self.location,
|
|
'dtstart': self.dtstart.isoformat() if self.dtstart else None,
|
|
'dtend': self.dtend.isoformat() if self.dtend else None,
|
|
'all_day': self.all_day,
|
|
'recurrence_rule': self.recurrence_rule,
|
|
'exdates': self.exdates.split(',') if self.exdates else [],
|
|
'is_private': bool(self.is_private),
|
|
'created_at': self.created_at.isoformat() if self.created_at else None,
|
|
'updated_at': self.updated_at.isoformat() if self.updated_at else None,
|
|
}
|
|
|
|
|
|
class CalendarShare(db.Model):
|
|
__tablename__ = 'calendar_shares'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
calendar_id = db.Column(db.Integer, db.ForeignKey('calendars.id'), nullable=False, index=True)
|
|
shared_with_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False, index=True)
|
|
permission = db.Column(db.String(20), nullable=False, default='read') # 'read' or 'readwrite'
|
|
|
|
shared_with = db.relationship('User', backref='shared_calendars')
|
|
|
|
__table_args__ = (
|
|
db.UniqueConstraint('calendar_id', 'shared_with_id', name='uq_calendar_share'),
|
|
)
|