Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions carddav/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,13 @@ func (b *backend) propFindRoot(ctx context.Context, propfind *internal.PropFind)
}

props := map[xml.Name]internal.PropFindFunc{
internal.CurrentUserPrivilegeSetName: func(*internal.RawXMLValue) (interface{}, error) {
return &internal.CurrentUserPrivilegeSet{
Privileges: []internal.Privilege{
{Read: true, Write: true},
},
}, nil
},
internal.CurrentUserPrincipalName: func(*internal.RawXMLValue) (interface{}, error) {
return &internal.CurrentUserPrincipal{Href: internal.Href{Path: principalPath}}, nil
},
Expand All @@ -452,6 +459,13 @@ func (b *backend) propFindUserPrincipal(ctx context.Context, propfind *internal.
}

props := map[xml.Name]internal.PropFindFunc{
internal.CurrentUserPrivilegeSetName: func(*internal.RawXMLValue) (interface{}, error) {
return &internal.CurrentUserPrivilegeSet{
Privileges: []internal.Privilege{
{Read: true, Write: true},
},
}, nil
},
internal.CurrentUserPrincipalName: func(*internal.RawXMLValue) (interface{}, error) {
return &internal.CurrentUserPrincipal{Href: internal.Href{Path: principalPath}}, nil
},
Expand All @@ -477,6 +491,13 @@ func (b *backend) propFindHomeSet(ctx context.Context, propfind *internal.PropFi

// TODO anything else to return here?
props := map[xml.Name]internal.PropFindFunc{
internal.CurrentUserPrivilegeSetName: func(*internal.RawXMLValue) (interface{}, error) {
return &internal.CurrentUserPrivilegeSet{
Privileges: []internal.Privilege{
{Read: true, Write: true},
},
}, nil
},
internal.CurrentUserPrincipalName: func(*internal.RawXMLValue) (interface{}, error) {
return &internal.CurrentUserPrincipal{Href: internal.Href{Path: principalPath}}, nil
},
Expand All @@ -489,6 +510,13 @@ func (b *backend) propFindHomeSet(ctx context.Context, propfind *internal.PropFi

func (b *backend) propFindAddressBook(ctx context.Context, propfind *internal.PropFind, ab *AddressBook) (*internal.Response, error) {
props := map[xml.Name]internal.PropFindFunc{
internal.CurrentUserPrivilegeSetName: func(*internal.RawXMLValue) (interface{}, error) {
return &internal.CurrentUserPrivilegeSet{
Privileges: []internal.Privilege{
{Read: true, Write: true},
},
}, nil
},
internal.CurrentUserPrincipalName: func(*internal.RawXMLValue) (interface{}, error) {
path, err := b.Backend.CurrentUserPrincipal(ctx)
if err != nil {
Expand Down Expand Up @@ -554,6 +582,13 @@ func (b *backend) propFindAllAddressBooks(ctx context.Context, propfind *interna

func (b *backend) propFindAddressObject(ctx context.Context, propfind *internal.PropFind, ao *AddressObject) (*internal.Response, error) {
props := map[xml.Name]internal.PropFindFunc{
internal.CurrentUserPrivilegeSetName: func(*internal.RawXMLValue) (interface{}, error) {
return &internal.CurrentUserPrivilegeSet{
Privileges: []internal.Privilege{
{Read: true, Write: true},
},
}, nil
},
internal.CurrentUserPrincipalName: func(*internal.RawXMLValue) (interface{}, error) {
path, err := b.Backend.CurrentUserPrincipal(ctx)
if err != nil {
Expand Down
12 changes: 11 additions & 1 deletion internal/elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ var (
GetLastModifiedName = xml.Name{Namespace, "getlastmodified"}
GetETagName = xml.Name{Namespace, "getetag"}

CurrentUserPrincipalName = xml.Name{Namespace, "current-user-principal"}
CurrentUserPrincipalName = xml.Name{Namespace, "current-user-principal"}
CurrentUserPrivilegeSetName = xml.Name{Namespace, "current-user-privilege-set"}
)

type Status struct {
Expand Down Expand Up @@ -417,6 +418,15 @@ type CurrentUserPrincipal struct {
Unauthenticated *struct{} `xml:"unauthenticated,omitempty"`
}

// https://datatracker.ietf.org/doc/html/rfc3744#section-5.4
type CurrentUserPrivilegeSet struct {
XMLName xml.Name `xml:"DAV: current-user-privilege-set"`
Privileges []Privilege `xml:"privilege>dynamic"`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this file use the same name as the XML element even if there may be multiple.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why dynamic? This doesn't appear in the RFC AFAIK.

}
type Privilege struct {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a list, could we use a struct with fields for read/write?

XMLName xml.Name
}

// https://tools.ietf.org/html/rfc4918#section-14.19
type PropertyUpdate struct {
XMLName xml.Name `xml:"DAV: propertyupdate"`
Expand Down