mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 08:14:15 +00:00
caldav, carddav: stop hardcoding current user principal
Add Backend.CurrentUserPrincipal to fetch the current user principal.
This commit is contained in:
parent
c7b85859a2
commit
a419541835
@ -25,6 +25,7 @@ func CalendarHomeSetXML(path string) (xml.Name, xml.Marshaler) {
|
||||
|
||||
// Backend is a CalDAV server backend.
|
||||
type Backend interface {
|
||||
CurrentUserPrincipal(ctx context.Context) (string, error)
|
||||
Calendar(ctx context.Context) (*Calendar, error)
|
||||
GetCalendarObject(ctx context.Context, path string, req *CalendarCompRequest) (*CalendarObject, error)
|
||||
ListCalendarObjects(ctx context.Context, req *CalendarCompRequest) ([]CalendarObject, error)
|
||||
@ -225,7 +226,7 @@ func (b *backend) Propfind(r *http.Request, propfind *internal.Propfind, depth i
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := b.propfindCalendar(propfind, cal)
|
||||
resp, err := b.propfindCalendar(r.Context(), propfind, cal)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -239,7 +240,7 @@ func (b *backend) Propfind(r *http.Request, propfind *internal.Propfind, depth i
|
||||
return internal.NewMultistatus(resps...), nil
|
||||
}
|
||||
|
||||
func (b *backend) propfindCalendar(propfind *internal.Propfind, cal *Calendar) (*internal.Response, error) {
|
||||
func (b *backend) propfindCalendar(ctx context.Context, propfind *internal.Propfind, cal *Calendar) (*internal.Response, error) {
|
||||
props := map[xml.Name]internal.PropfindFunc{
|
||||
internal.ResourceTypeName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||
return internal.NewResourceType(internal.CollectionName, calendarName), nil
|
||||
@ -263,7 +264,11 @@ func (b *backend) propfindCalendar(propfind *internal.Propfind, cal *Calendar) (
|
||||
},
|
||||
// TODO: this should be set on all resources
|
||||
internal.CurrentUserPrincipalName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||
return &internal.CurrentUserPrincipal{Href: internal.Href{Path: "/"}}, nil
|
||||
path, err := b.Backend.CurrentUserPrincipal(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &internal.CurrentUserPrincipal{Href: internal.Href{Path: path}}, nil
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@ type PutAddressObjectOptions struct {
|
||||
|
||||
// Backend is a CardDAV server backend.
|
||||
type Backend interface {
|
||||
CurrentUserPrincipal(ctx context.Context) (string, error)
|
||||
AddressBook(ctx context.Context) (*AddressBook, error)
|
||||
GetAddressObject(ctx context.Context, path string, req *AddressDataRequest) (*AddressObject, error)
|
||||
ListAddressObjects(ctx context.Context, req *AddressDataRequest) ([]AddressObject, error)
|
||||
@ -305,7 +306,7 @@ func (b *backend) Propfind(r *http.Request, propfind *internal.Propfind, depth i
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := b.propfindAddressBook(propfind, ab)
|
||||
resp, err := b.propfindAddressBook(r.Context(), propfind, ab)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -341,7 +342,7 @@ func (b *backend) Propfind(r *http.Request, propfind *internal.Propfind, depth i
|
||||
return internal.NewMultistatus(resps...), nil
|
||||
}
|
||||
|
||||
func (b *backend) propfindAddressBook(propfind *internal.Propfind, ab *AddressBook) (*internal.Response, error) {
|
||||
func (b *backend) propfindAddressBook(ctx context.Context, propfind *internal.Propfind, ab *AddressBook) (*internal.Response, error) {
|
||||
props := map[xml.Name]internal.PropfindFunc{
|
||||
internal.ResourceTypeName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||
return internal.NewResourceType(internal.CollectionName, addressBookName), nil
|
||||
@ -362,7 +363,11 @@ func (b *backend) propfindAddressBook(propfind *internal.Propfind, ab *AddressBo
|
||||
},
|
||||
// TODO: this should be set on all resources
|
||||
internal.CurrentUserPrincipalName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||
return &internal.CurrentUserPrincipal{Href: internal.Href{Path: "/"}}, nil
|
||||
path, err := b.Backend.CurrentUserPrincipal(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &internal.CurrentUserPrincipal{Href: internal.Href{Path: path}}, nil
|
||||
},
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user