diff --git a/caldav/caldav.go b/caldav/caldav.go index 04b8399..1df6c66 100644 --- a/caldav/caldav.go +++ b/caldav/caldav.go @@ -69,6 +69,9 @@ type Calendar struct { Description string MaxResourceSize int64 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 { diff --git a/caldav/server.go b/caldav/server.go index 1a25479..0606c7b 100644 --- a/caldav/server.go +++ b/caldav/server.go @@ -546,13 +546,7 @@ func (b *backend) propFindCalendar(ctx context.Context, propfind *internal.PropF Comp: components, }, nil }, - // TODO: Gather UserPrivilege from backend to control read-and-write - internal.CurrentUserPrivilegeSetName: internal.PropFindValue(&internal.CurrentUserPrivilegeSet{ - Privilege: []internal.Privilege{{ - Read: &struct{}{}, - Write: &struct{}{}, - }}, - }), + internal.CurrentUserPrivilegeSetName: internal.PropFindValue(internal.NewCurrentUserPrivilegeSet(cal.ReadOnly)), } if cal.Name != "" { diff --git a/carddav/carddav.go b/carddav/carddav.go index ebfd66d..d6a1bf5 100644 --- a/carddav/carddav.go +++ b/carddav/carddav.go @@ -28,6 +28,9 @@ type AddressBook struct { Description string MaxResourceSize int64 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 { diff --git a/carddav/server.go b/carddav/server.go index ea5326f..7520b02 100644 --- a/carddav/server.go +++ b/carddav/server.go @@ -497,13 +497,7 @@ func (b *backend) propFindAddressBook(ctx context.Context, propfind *internal.Pr {ContentType: vcard.MIMEType, Version: "4.0"}, }, }), - // TODO: Gather UserPrivilege from backend to control read-and-write - internal.CurrentUserPrivilegeSetName: internal.PropFindValue(&internal.CurrentUserPrivilegeSet{ - Privilege: []internal.Privilege{{ - Read: &struct{}{}, - Write: &struct{}{}, - }}, - }), + internal.CurrentUserPrivilegeSetName: internal.PropFindValue(internal.NewCurrentUserPrivilegeSet(ab.ReadOnly)), } if ab.Name != "" { diff --git a/internal/elements.go b/internal/elements.go index 77df514..c2bf6a9 100644 --- a/internal/elements.go +++ b/internal/elements.go @@ -471,3 +471,13 @@ type Privilege struct { Read *struct{} `xml:"DAV: read,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}} +}