Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implements CurrentUserPrivilegeSet to add compatibility with thunderb… #170

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 12 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,16 @@ 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-principal"`
mheers marked this conversation as resolved.
Show resolved Hide resolved
Privileges []Privilege `xml:"privilege"`
}
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?

Read bool `xml:"read"`
Write bool `xml:"write"`
}

Choose a reason for hiding this comment

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

In my case, I got it to work with Thunderbird locally with the following structure (didn't tried yours TBH):

Suggested change
Privileges []Privilege `xml:"privilege"`
}
type Privilege struct {
Read bool `xml:"read"`
Write bool `xml:"write"`
}
Privileges []Privilege `xml:"privilege>dynamic"`
}
type Privilege struct {
XMLName xml.Name
}

And then return read, write like this:

return &internal.CurrentUserPrivilegeSet{Privileges: []internal.Privilege{{XMLName: xml.Name{"", "read"}}, {XMLName: xml.Name{"", "write"}}}}, nil

(ideally the read/write privileges information should come from the backend)

Copy link
Owner

Choose a reason for hiding this comment

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

Seems like the second part of the suggestion hasn't been applied. (But I prefer the struct approach.)


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