diff --git a/changelog/unreleased/fix-onlyoffice-file-location-upd.md b/changelog/unreleased/fix-onlyoffice-file-location-upd.md new file mode 100644 index 00000000000..691f1cc2be8 --- /dev/null +++ b/changelog/unreleased/fix-onlyoffice-file-location-upd.md @@ -0,0 +1,5 @@ +Bugfix: Fix FileInfo BreadcrumbFolderURL upd + +Made GetScopeByKeyPrefix function as a private method of the FileConnector + +https://github.com/owncloud/ocis/pull/10757 diff --git a/services/collaboration/pkg/connector/fileconnector.go b/services/collaboration/pkg/connector/fileconnector.go index 3109bc4bdac..21522e53b51 100644 --- a/services/collaboration/pkg/connector/fileconnector.go +++ b/services/collaboration/pkg/connector/fileconnector.go @@ -6,6 +6,7 @@ import ( "encoding/base64" "encoding/binary" "encoding/hex" + "fmt" "io" "net/url" "path" @@ -13,6 +14,7 @@ import ( "time" appproviderv1beta1 "github.com/cs3org/go-cs3apis/cs3/app/provider/v1beta1" + auth "github.com/cs3org/go-cs3apis/cs3/auth/provider/v1beta1" gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1" @@ -23,6 +25,7 @@ import ( "github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool" "github.com/cs3org/reva/v2/pkg/storagespace" "github.com/cs3org/reva/v2/pkg/utils" + "github.com/golang/protobuf/proto" "github.com/google/uuid" "github.com/owncloud/ocis/v2/services/collaboration/pkg/config" "github.com/owncloud/ocis/v2/services/collaboration/pkg/connector/fileinfo" @@ -1230,7 +1233,7 @@ func (f *FileConnector) CheckFileInfo(ctx context.Context) (*ConnectorResponse, } else { if scopes, ok := ctxpkg.ContextGetScopes(ctx); ok { publicShare := &link.PublicShare{} - if err := helpers.GetScopeByKeyPrefix(scopes, "publicshare:", publicShare); err == nil { + if err := f.getScopeByKeyPrefix(scopes, "publicshare:", publicShare); err == nil { parentFolderURL.Path = path.Join(ocisURL.Path, "s", publicShare.GetToken()) } else { logger.Error().Err(err).Msg("CheckFileInfo: error getting public share scope") @@ -1483,3 +1486,17 @@ func (f *FileConnector) adjustWopiReference(ctx context.Context, wopiContext *mi return newStatRes.GetInfo(), nil } + +// getScopeByKeyPrefix returns the scope from the AccessToken Scope map by key prefix +func (f *FileConnector) getScopeByKeyPrefix(scopes map[string]*auth.Scope, keyPrefix string, m proto.Message) error { + for k, v := range scopes { + if strings.HasPrefix(k, keyPrefix) && v.Resource.Decoder == "json" { + err := utils.UnmarshalJSONToProtoV1(v.Resource.Value, m) + if err != nil { + return fmt.Errorf("can't unmarshal public share from scope: %w", err) + } + return nil + } + } + return fmt.Errorf("scope %s not found", keyPrefix) +} diff --git a/services/collaboration/pkg/helpers/scope.go b/services/collaboration/pkg/helpers/scope.go deleted file mode 100644 index 1fe0ae472f2..00000000000 --- a/services/collaboration/pkg/helpers/scope.go +++ /dev/null @@ -1,24 +0,0 @@ -package helpers - -import ( - "fmt" - "strings" - - auth "github.com/cs3org/go-cs3apis/cs3/auth/provider/v1beta1" - "github.com/cs3org/reva/v2/pkg/utils" - "github.com/golang/protobuf/proto" -) - -// GetScopeByKeyPrefix returns the scope from the AccessToken Scope map by key prefix -func GetScopeByKeyPrefix(scopes map[string]*auth.Scope, keyPrefix string, m proto.Message) error { - for k, v := range scopes { - if strings.HasPrefix(k, keyPrefix) && v.Resource.Decoder == "json" { - err := utils.UnmarshalJSONToProtoV1(v.Resource.Value, m) - if err != nil { - return fmt.Errorf("can't unmarshal public share from scope: %w", err) - } - return nil - } - } - return fmt.Errorf("scope %s not found", keyPrefix) -}