caldav, carddav: derive current-user-privilege-set from a read-only flag

The server hard-coded DAV:read + DAV:write in current-user-privilege-set for
every collection (with a TODO). Add a ReadOnly field to Calendar and AddressBook
that the backend sets per request; report DAV:write only when it is false, so
clients (e.g. DAVx5, Apple) correctly mark read-only collections. Default
(false) keeps the previous read-write behavior.
This commit is contained in:
Anton Skorochod 2026-06-23 23:04:19 +02:00 committed by Simon Ser
parent 0463911636
commit 1901d193ce
5 changed files with 18 additions and 14 deletions

View File

@ -69,6 +69,9 @@ type Calendar struct {
Description string Description string
MaxResourceSize int64 MaxResourceSize int64
SupportedComponentSet []string SupportedComponentSet []string
// ReadOnly reports that the current user may only read this calendar. It
// controls the DAV:current-user-privilege-set reported by the server.
ReadOnly bool
} }
type CalendarCompRequest struct { type CalendarCompRequest struct {

View File

@ -546,13 +546,7 @@ func (b *backend) propFindCalendar(ctx context.Context, propfind *internal.PropF
Comp: components, Comp: components,
}, nil }, nil
}, },
// TODO: Gather UserPrivilege from backend to control read-and-write internal.CurrentUserPrivilegeSetName: internal.PropFindValue(internal.NewCurrentUserPrivilegeSet(cal.ReadOnly)),
internal.CurrentUserPrivilegeSetName: internal.PropFindValue(&internal.CurrentUserPrivilegeSet{
Privilege: []internal.Privilege{{
Read: &struct{}{},
Write: &struct{}{},
}},
}),
} }
if cal.Name != "" { if cal.Name != "" {

View File

@ -28,6 +28,9 @@ type AddressBook struct {
Description string Description string
MaxResourceSize int64 MaxResourceSize int64
SupportedAddressData []AddressDataType SupportedAddressData []AddressDataType
// ReadOnly reports that the current user may only read this address book.
// It controls the DAV:current-user-privilege-set reported by the server.
ReadOnly bool
} }
func (ab *AddressBook) SupportsAddressData(contentType, version string) bool { func (ab *AddressBook) SupportsAddressData(contentType, version string) bool {

View File

@ -497,13 +497,7 @@ func (b *backend) propFindAddressBook(ctx context.Context, propfind *internal.Pr
{ContentType: vcard.MIMEType, Version: "4.0"}, {ContentType: vcard.MIMEType, Version: "4.0"},
}, },
}), }),
// TODO: Gather UserPrivilege from backend to control read-and-write internal.CurrentUserPrivilegeSetName: internal.PropFindValue(internal.NewCurrentUserPrivilegeSet(ab.ReadOnly)),
internal.CurrentUserPrivilegeSetName: internal.PropFindValue(&internal.CurrentUserPrivilegeSet{
Privilege: []internal.Privilege{{
Read: &struct{}{},
Write: &struct{}{},
}},
}),
} }
if ab.Name != "" { if ab.Name != "" {

View File

@ -471,3 +471,13 @@ type Privilege struct {
Read *struct{} `xml:"DAV: read,omitempty"` Read *struct{} `xml:"DAV: read,omitempty"`
Write *struct{} `xml:"DAV: write,omitempty"` Write *struct{} `xml:"DAV: write,omitempty"`
} }
// NewCurrentUserPrivilegeSet returns a privilege set granting DAV:read, plus
// DAV:write unless readOnly is set.
func NewCurrentUserPrivilegeSet(readOnly bool) *CurrentUserPrivilegeSet {
priv := Privilege{Read: &struct{}{}}
if !readOnly {
priv.Write = &struct{}{}
}
return &CurrentUserPrivilegeSet{Privilege: []Privilege{priv}}
}