Search dav spaces (#4661)

* Add a Ref option to SearchRequest, e.g. for limiting the search to a space

* Enable REPORT requests for /dav/spaces URLs

* Limit the search to the according space in case of /dav/spaces searches

* Add changelog

* Adapt expected failures

* Comment exported functions
This commit is contained in:
Andre Duffeck
2022-09-27 10:38:15 +02:00
committed by GitHub
parent 918bc85879
commit 68b17eb68d
15 changed files with 286 additions and 201 deletions
+23 -2
View File
@@ -8,6 +8,7 @@ import (
"net/http"
"path"
"strconv"
"strings"
"time"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
@@ -46,10 +47,30 @@ func (g Webdav) Search(w http.ResponseWriter, r *http.Request) {
t := r.Header.Get(TokenHeader)
ctx := revactx.ContextSetToken(r.Context(), t)
ctx = metadata.Set(ctx, revactx.TokenHeader, t)
rsp, err := g.searchClient.Search(ctx, &searchsvc.SearchRequest{
req := &searchsvc.SearchRequest{
Query: rep.SearchFiles.Search.Pattern,
PageSize: int32(rep.SearchFiles.Search.Limit),
})
}
// Limit search to the according space when searching /dav/spaces/
if strings.HasPrefix(r.URL.Path, "/dav/spaces") {
space := strings.TrimPrefix(r.URL.Path, "/dav/spaces/")
rid, err := storagespace.ParseID(space)
if err != nil {
g.log.Error().Err(err).Msg("error parsing the space id for filtering")
} else {
req.Ref = &searchmsg.Reference{
ResourceId: &searchmsg.ResourceID{
StorageId: rid.StorageId,
SpaceId: rid.SpaceId,
OpaqueId: rid.SpaceId,
},
}
}
}
rsp, err := g.searchClient.Search(ctx, req)
if err != nil {
e := merrors.Parse(err.Error())
switch e.Code {
+3 -1
View File
@@ -113,8 +113,10 @@ func NewService(opts ...Option) (Service, error) {
// back to using `chi.RegisterMethod`.
m.MethodNotAllowed(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
routePrefix := path.Join(options.Config.HTTP.Root, "/remote.php/dav/files/")
spacesPrefix := path.Join(options.Config.HTTP.Root, "/dav/spaces/")
legacyRoutePrefix := path.Join(options.Config.HTTP.Root, "/remote.php/webdav")
if req.Method == "REPORT" && (strings.HasPrefix(req.URL.Path, routePrefix) || strings.HasPrefix(req.URL.Path, legacyRoutePrefix)) {
if req.Method == "REPORT" &&
(strings.HasPrefix(req.URL.Path, spacesPrefix) || strings.HasPrefix(req.URL.Path, routePrefix) || strings.HasPrefix(req.URL.Path, legacyRoutePrefix)) {
// The URLParam will not be available here. If it is needed it
// needs to be passed manually or chi needs to be fixed
// To use it properly.