Skip to content

Commit

Permalink
Merge pull request #4338 from 2403905/issue-7708
Browse files Browse the repository at this point in the history
fix space unlock
  • Loading branch information
2403905 authored Nov 14, 2023
2 parents f25c231 + a6420c8 commit d3790d2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
7 changes: 7 additions & 0 deletions changelog/unreleased/fix-space-unlock.md
Original file line number Diff line number Diff line change
@@ -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
20 changes: 19 additions & 1 deletion internal/http/services/owncloud/ocdav/locks.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,14 +614,32 @@ 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)
if len(t) > 2 && t[0] == '<' && t[len(t)-1] == '>' {
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:
Expand Down
2 changes: 1 addition & 1 deletion internal/http/services/owncloud/ocdav/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit d3790d2

Please sign in to comment.