From a6420c84936d732932bbbf6ee4212a0efd0e55ac Mon Sep 17 00:00:00 2001 From: Roman Perekhod Date: Tue, 14 Nov 2023 16:20:54 +0100 Subject: [PATCH] fix space unlock --- changelog/unreleased/fix-space-unlock.md | 7 +++++++ .../http/services/owncloud/ocdav/locks.go | 20 ++++++++++++++++++- .../http/services/owncloud/ocdav/spaces.go | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 changelog/unreleased/fix-space-unlock.md diff --git a/changelog/unreleased/fix-space-unlock.md b/changelog/unreleased/fix-space-unlock.md new file mode 100644 index 0000000000..4bdc1de773 --- /dev/null +++ b/changelog/unreleased/fix-space-unlock.md @@ -0,0 +1,7 @@ +Bugfix: Fix unlock via space API + +We fixed a bug that caused Error 500 when user try to unlock file using fileid +The handleSpaceUnlock has been added + +https://github.com/cs3org/reva/pull/4338 +https://github.com/owncloud/ocis/issues/7708 diff --git a/internal/http/services/owncloud/ocdav/locks.go b/internal/http/services/owncloud/ocdav/locks.go index b56b6c4d86..332b9d2276 100644 --- a/internal/http/services/owncloud/ocdav/locks.go +++ b/internal/http/services/owncloud/ocdav/locks.go @@ -614,6 +614,24 @@ func (s *svc) handleUnlock(w http.ResponseWriter, r *http.Request, ns string) (s return http.StatusInternalServerError, errtypes.NewErrtypeFromStatus(cs3Status) } + return s.unlockReference(ctx, w, r, ref) +} + +func (s *svc) handleSpaceUnlock(w http.ResponseWriter, r *http.Request, spaceID string) (status int, err error) { + ctx, span := appctx.GetTracerProvider(r.Context()).Tracer(tracerName).Start(r.Context(), fmt.Sprintf("%s %v", r.Method, r.URL.Path)) + defer span.End() + + span.SetAttributes(attribute.String("component", "ocdav")) + + ref, err := spacelookup.MakeStorageSpaceReference(spaceID, r.URL.Path) + if err != nil { + return http.StatusBadRequest, fmt.Errorf("invalid space id") + } + + return s.unlockReference(ctx, w, r, &ref) +} + +func (s *svc) unlockReference(ctx context.Context, _ http.ResponseWriter, r *http.Request, ref *provider.Reference) (retStatus int, retErr error) { // http://www.webdav.org/specs/rfc4918.html#HEADER_Lock-Token says that the // Lock-Token value should be a Coded-URL OR a token. We strip its angle brackets. t := r.Header.Get(net.HeaderLockToken) @@ -621,7 +639,7 @@ func (s *svc) handleUnlock(w http.ResponseWriter, r *http.Request, ns string) (s t = t[1 : len(t)-1] } - switch err = s.LockSystem.Unlock(r.Context(), time.Now(), ref, t); err { + switch err := s.LockSystem.Unlock(ctx, time.Now(), ref, t); err { case nil: return http.StatusNoContent, err case errors.ErrForbidden: diff --git a/internal/http/services/owncloud/ocdav/spaces.go b/internal/http/services/owncloud/ocdav/spaces.go index a5404b102c..e8706becff 100644 --- a/internal/http/services/owncloud/ocdav/spaces.go +++ b/internal/http/services/owncloud/ocdav/spaces.go @@ -86,7 +86,7 @@ func (h *SpacesHandler) Handler(s *svc, trashbinHandler *TrashbinHandler) http.H case MethodLock: status, err = s.handleSpacesLock(w, r, spaceID) case MethodUnlock: - status, err = s.handleUnlock(w, r, spaceID) + status, err = s.handleSpaceUnlock(w, r, spaceID) case MethodMkcol: status, err = s.handleSpacesMkCol(w, r, spaceID) case MethodMove: