fix: CardDAV-Aenderungen loesen SSE-Refresh im Web-UI aus

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stefan Hacker 2026-04-13 03:56:52 +02:00
parent 1762437528
commit b2567d379c
1 changed files with 16 additions and 3 deletions

View File

@ -19,7 +19,10 @@ from flask import Response, request
from app.extensions import db
from app.models.contact import AddressBook, Contact, AddressBookShare
from app.models.user import User
from app.api.contacts import _apply_fields_to_contact, _build_vcard, parse_vcard
from app.api.contacts import (
_apply_fields_to_contact, _build_vcard, parse_vcard,
_notify_addressbook, _book_recipients,
)
from . import dav_bp
from .caldav import (
@ -277,7 +280,8 @@ def ab_put(username, ab_part, filename):
if if_match and existing and if_match.strip() != _etag_for_contact(existing):
return Response('', 412)
if not existing:
is_new = existing is None
if is_new:
existing = Contact(address_book_id=book.id, uid=body_uid, vcard_data=raw)
db.session.add(existing)
@ -288,7 +292,9 @@ def ab_put(username, ab_part, filename):
existing.vcard_data = raw.strip() or _build_vcard(existing)
existing.updated_at = datetime.now(timezone.utc)
db.session.commit()
status = 201 if not if_match else 204
_notify_addressbook(book.owner_id, book.id, 'contact',
shared_with=_book_recipients(book))
status = 201 if is_new else 204
return Response('', status, {'ETag': _etag_for_contact(existing)})
@ -308,6 +314,8 @@ def ab_delete(username, ab_part, filename):
return Response('', 404)
db.session.delete(contact)
db.session.commit()
_notify_addressbook(book.owner_id, book.id, 'contact',
shared_with=_book_recipients(book))
return Response('', 204)
@ -324,8 +332,12 @@ def ab_delete_collection(username, ab_part):
book = _addressbook_for(user, book_id) if book_id else None
if not book:
return Response('', 404)
recipients = _book_recipients(book)
owner_id = book.owner_id
book_id = book.id
db.session.delete(book)
db.session.commit()
_notify_addressbook(owner_id, book_id, 'deleted', shared_with=recipients)
return Response('', 204)
@ -351,4 +363,5 @@ def ab_mkcol(username, ab_part):
book = AddressBook(owner_id=user.id, name=name)
db.session.add(book)
db.session.commit()
_notify_addressbook(user.id, book.id, 'created')
return Response('', 201, {'Location': _href_addressbook(user.username, book.id)})