mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 16:24:14 +00:00
webdav: rename ServeUserPrincipal to ServePrincipal
A principal may represent something else than a user, for instance it may represent a group. Also rename UserPrincipalPath to CurrentUserPrincipalPath, because the principal being served may not represent the current user.
This commit is contained in:
parent
303aef52f3
commit
346cfadd34
16
server.go
16
server.go
@ -261,13 +261,13 @@ type UserPrincipalBackend interface {
|
|||||||
CurrentUserPrincipal(ctx context.Context) (string, error)
|
CurrentUserPrincipal(ctx context.Context) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServeUserPrincipalOptions struct {
|
type ServePrincipalOptions struct {
|
||||||
UserPrincipalPath string
|
CurrentUserPrincipalPath string
|
||||||
HomeSets []BackendSuppliedHomeSet
|
HomeSets []BackendSuppliedHomeSet
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServeUserPrincipal replies to requests for the user principal URL
|
// ServePrincipal replies to requests for a principal URL.
|
||||||
func ServeUserPrincipal(w http.ResponseWriter, r *http.Request, options *ServeUserPrincipalOptions) {
|
func ServePrincipal(w http.ResponseWriter, r *http.Request, options *ServePrincipalOptions) {
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case http.MethodOptions:
|
case http.MethodOptions:
|
||||||
caps := []string{"1", "3"}
|
caps := []string{"1", "3"}
|
||||||
@ -276,7 +276,7 @@ func ServeUserPrincipal(w http.ResponseWriter, r *http.Request, options *ServeUs
|
|||||||
w.Header().Add("Allow", strings.Join(allow, ", "))
|
w.Header().Add("Allow", strings.Join(allow, ", "))
|
||||||
w.WriteHeader(http.StatusNoContent)
|
w.WriteHeader(http.StatusNoContent)
|
||||||
case "PROPFIND":
|
case "PROPFIND":
|
||||||
if err := serveUserPrincipalPropfind(w, r, options); err != nil {
|
if err := servePrincipalPropfind(w, r, options); err != nil {
|
||||||
internal.ServeError(w, err)
|
internal.ServeError(w, err)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -284,7 +284,7 @@ func ServeUserPrincipal(w http.ResponseWriter, r *http.Request, options *ServeUs
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func serveUserPrincipalPropfind(w http.ResponseWriter, r *http.Request, options *ServeUserPrincipalOptions) error {
|
func servePrincipalPropfind(w http.ResponseWriter, r *http.Request, options *ServePrincipalOptions) error {
|
||||||
var propfind internal.Propfind
|
var propfind internal.Propfind
|
||||||
if err := internal.DecodeXMLRequest(r, &propfind); err != nil {
|
if err := internal.DecodeXMLRequest(r, &propfind); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -294,7 +294,7 @@ func serveUserPrincipalPropfind(w http.ResponseWriter, r *http.Request, options
|
|||||||
return internal.NewResourceType(principalName), nil
|
return internal.NewResourceType(principalName), nil
|
||||||
},
|
},
|
||||||
internal.CurrentUserPrincipalName: func(*internal.RawXMLValue) (interface{}, error) {
|
internal.CurrentUserPrincipalName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||||
return &internal.CurrentUserPrincipal{Href: internal.Href{Path: options.UserPrincipalPath}}, nil
|
return &internal.CurrentUserPrincipal{Href: internal.Href{Path: options.CurrentUserPrincipalPath}}, nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user