Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix space unlock #4338

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading