mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2025-12-30 17:00:57 -06:00
fixed the FileInfo.BreadcrumbFolderURL in a collaboration api
This commit is contained in:
5
changelog/unreleased/fix-onlyoffice-file-location.md
Normal file
5
changelog/unreleased/fix-onlyoffice-file-location.md
Normal file
@@ -0,0 +1,5 @@
|
||||
Bugfix: Fix FileInfo BreadcrumbFolderURL
|
||||
|
||||
We fixed the FileInfo.BreadcrumbFolderURL in a collaboration api"
|
||||
|
||||
https://github.com/owncloud/ocis/pull/10718
|
||||
72955
coverage.out
Normal file
72955
coverage.out
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1206,7 +1206,7 @@ func (f *FileConnector) CheckFileInfo(ctx context.Context) (*ConnectorResponse,
|
||||
}
|
||||
}
|
||||
|
||||
breadcrumbFolderName := path.Dir(statRes.Info.Path)
|
||||
breadcrumbFolderName := path.Dir(statRes.GetInfo().GetPath())
|
||||
if breadcrumbFolderName == "." || breadcrumbFolderName == "" || breadcrumbFolderName == "/" {
|
||||
breadcrumbFolderName = statRes.GetInfo().GetSpace().GetName()
|
||||
}
|
||||
@@ -1222,6 +1222,12 @@ func (f *FileConnector) CheckFileInfo(ctx context.Context) (*ConnectorResponse,
|
||||
privateLinkURL := &url.URL{}
|
||||
*privateLinkURL = *ocisURL
|
||||
privateLinkURL.Path = path.Join(ocisURL.Path, "f", storagespace.FormatResourceID(statRes.GetInfo().GetId()))
|
||||
parentFolderURL := &url.URL{}
|
||||
*parentFolderURL = *ocisURL
|
||||
parentFolderURL.Path = path.Join(ocisURL.Path, "f", storagespace.FormatResourceID(statRes.GetInfo().GetParentId()))
|
||||
if publicShare := wopiContext.GetPublicShare(); publicShare != nil && isPublicShare {
|
||||
parentFolderURL.Path = path.Join(ocisURL.Path, "s", publicShare.GetToken())
|
||||
}
|
||||
// fileinfo map
|
||||
infoMap := map[string]interface{}{
|
||||
fileinfo.KeyOwnerID: hexEncodedOwnerId,
|
||||
@@ -1231,7 +1237,7 @@ func (f *FileConnector) CheckFileInfo(ctx context.Context) (*ConnectorResponse,
|
||||
fileinfo.KeyBreadcrumbDocName: path.Base(statRes.GetInfo().GetPath()),
|
||||
// to get the folder we actually need to do a GetPath() request
|
||||
fileinfo.KeyBreadcrumbFolderName: breadcrumbFolderName,
|
||||
fileinfo.KeyBreadcrumbFolderURL: privateLinkURL.String(),
|
||||
fileinfo.KeyBreadcrumbFolderURL: parentFolderURL.String(),
|
||||
|
||||
fileinfo.KeyHostViewURL: createHostUrl("view", ocisURL, f.cfg.App.Name, statRes.GetInfo()),
|
||||
fileinfo.KeyHostEditURL: createHostUrl("write", ocisURL, f.cfg.App.Name, statRes.GetInfo()),
|
||||
|
||||
@@ -1686,6 +1686,11 @@ var _ = Describe("FileConnector", func() {
|
||||
OpaqueId: "opaqueid",
|
||||
SpaceId: "spaceid",
|
||||
},
|
||||
ParentId: &providerv1beta1.ResourceId{
|
||||
StorageId: "storageid",
|
||||
OpaqueId: "parentopaqueid",
|
||||
SpaceId: "spaceid",
|
||||
},
|
||||
},
|
||||
}, nil)
|
||||
|
||||
@@ -1696,7 +1701,7 @@ var _ = Describe("FileConnector", func() {
|
||||
BaseFileName: "test.txt",
|
||||
BreadcrumbDocName: "test.txt",
|
||||
BreadcrumbFolderName: "/path/to",
|
||||
BreadcrumbFolderURL: "https://ocis.example.prv/f/storageid$spaceid%21opaqueid",
|
||||
BreadcrumbFolderURL: "https://ocis.example.prv/f/storageid$spaceid%21parentopaqueid",
|
||||
UserCanNotWriteRelative: false,
|
||||
SupportsExtendedLockLength: true,
|
||||
SupportsGetLock: true,
|
||||
@@ -1755,6 +1760,11 @@ var _ = Describe("FileConnector", func() {
|
||||
OpaqueId: "opaqueid",
|
||||
SpaceId: "spaceid",
|
||||
},
|
||||
ParentId: &providerv1beta1.ResourceId{
|
||||
StorageId: "storageid",
|
||||
OpaqueId: "parentopaqueid",
|
||||
SpaceId: "spaceid",
|
||||
},
|
||||
// Other properties aren't used for now.
|
||||
},
|
||||
}, nil)
|
||||
@@ -1830,6 +1840,11 @@ var _ = Describe("FileConnector", func() {
|
||||
OpaqueId: "opaqueid",
|
||||
SpaceId: "spaceid",
|
||||
},
|
||||
ParentId: &providerv1beta1.ResourceId{
|
||||
StorageId: "storageid",
|
||||
OpaqueId: "parentopaqueid",
|
||||
SpaceId: "spaceid",
|
||||
},
|
||||
},
|
||||
}, nil)
|
||||
|
||||
@@ -1898,6 +1913,11 @@ var _ = Describe("FileConnector", func() {
|
||||
OpaqueId: "opaqueid",
|
||||
SpaceId: "spaceid",
|
||||
},
|
||||
ParentId: &providerv1beta1.ResourceId{
|
||||
StorageId: "storageid",
|
||||
OpaqueId: "parentopaqueid",
|
||||
SpaceId: "spaceid",
|
||||
},
|
||||
},
|
||||
}, nil)
|
||||
|
||||
@@ -1906,7 +1926,7 @@ var _ = Describe("FileConnector", func() {
|
||||
BaseFileName: "test.txt",
|
||||
BreadcrumbDocName: "test.txt",
|
||||
BreadcrumbFolderName: "/path/to",
|
||||
BreadcrumbFolderURL: "https://ocis.example.prv/f/storageid$spaceid%21opaqueid",
|
||||
BreadcrumbFolderURL: "https://ocis.example.prv/f/storageid$spaceid%21parentopaqueid",
|
||||
UserCanNotWriteRelative: false,
|
||||
SupportsLocks: true,
|
||||
SupportsUpdate: true,
|
||||
|
||||
@@ -12,9 +12,11 @@ import (
|
||||
"time"
|
||||
|
||||
appproviderv1beta1 "github.com/cs3org/go-cs3apis/cs3/app/provider/v1beta1"
|
||||
link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1"
|
||||
providerv1beta1 "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
ctxpkg "github.com/cs3org/reva/v2/pkg/ctx"
|
||||
rjwt "github.com/cs3org/reva/v2/pkg/token/manager/jwt"
|
||||
"github.com/cs3org/reva/v2/pkg/utils"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
"github.com/owncloud/ocis/v2/services/collaboration/pkg/config"
|
||||
"github.com/owncloud/ocis/v2/services/collaboration/pkg/helpers"
|
||||
@@ -36,6 +38,23 @@ type WopiContext struct {
|
||||
FileReference *providerv1beta1.Reference
|
||||
TemplateReference *providerv1beta1.Reference
|
||||
ViewMode appproviderv1beta1.ViewMode
|
||||
publicShare *link.PublicShare
|
||||
}
|
||||
|
||||
// GetPublicShare returns the public share from the WopiContext or nil if it doesn't exist
|
||||
func (w *WopiContext) GetPublicShare() *link.PublicShare {
|
||||
if w != nil {
|
||||
return w.publicShare
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EvaluatePublicShare unmashals the public share from the scope and
|
||||
func (w *WopiContext) EvaluatePublicShare() *link.PublicShare {
|
||||
if w != nil {
|
||||
return w.publicShare
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// WopiContextAuthMiddleware will prepare an HTTP handler to be used as
|
||||
@@ -120,12 +139,26 @@ func WopiContextAuthMiddleware(cfg *config.Config, st microstore.Store, next htt
|
||||
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
user, _, err := tokenManager.DismantleToken(ctx, wopiContextAccessToken)
|
||||
user, scope, err := tokenManager.DismantleToken(ctx, wopiContextAccessToken)
|
||||
if err != nil {
|
||||
wopiLogger.Error().Err(err).Msg("failed to dismantle reva token manager")
|
||||
http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
for k, v := range scope {
|
||||
if strings.HasPrefix(k, "publicshare:") && v.Resource.Decoder == "json" {
|
||||
share := &link.PublicShare{}
|
||||
err := utils.UnmarshalJSONToProtoV1(v.Resource.Value, share)
|
||||
if err != nil {
|
||||
wopiLogger.Error().Err(err).Msg("can't unmarshal public share from scope")
|
||||
} else {
|
||||
claims.WopiContext.publicShare = share
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
claims.WopiContext.AccessToken = wopiContextAccessToken
|
||||
|
||||
ctx = context.WithValue(ctx, wopiContextKey, claims.WopiContext)
|
||||
|
||||
Reference in New Issue
Block a user