fixed the FileInfo.BreadcrumbFolderURL in a collaboration api

This commit is contained in:
Roman Perekhod
2024-12-03 23:06:17 +01:00
parent b7ba553e90
commit 8d83ac4459
5 changed files with 73024 additions and 5 deletions

View 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

File diff suppressed because it is too large Load Diff

View File

@@ -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()),

View File

@@ -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,

View File

@@ -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)