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

fixed the activity when file with file-id gives move activity instead of rename #4874

Merged
merged 2 commits into from
Oct 10, 2024
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
6 changes: 6 additions & 0 deletions changelog/unreleased/fix-activity-rename.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Fix rename activity

We fixed the activity when file with file-id gives move activity instead of rename.

https://github.com/cs3org/reva/pull/4874
https://github.com/owncloud/ocis/issues/9744
5 changes: 1 addition & 4 deletions internal/grpc/interceptors/eventsmiddleware/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func NewUnary(m map[string]interface{}) (grpc.UnaryServerInterceptor, int, error

executant, _ := revactx.ContextGetUser(ctx)

// The MoveResponse event is moved to the decomposedfs
var ev interface{}
switch v := res.(type) {
case *collaboration.CreateShareResponse:
Expand Down Expand Up @@ -141,10 +142,6 @@ func NewUnary(m map[string]interface{}) (grpc.UnaryServerInterceptor, int, error
if isSuccess(v) {
ev = ItemTrashed(v, req.(*provider.DeleteRequest), ownerID, executant)
}
case *provider.MoveResponse:
if isSuccess(v) {
ev = ItemMoved(v, req.(*provider.MoveRequest), ownerID, executant)
}
case *provider.PurgeRecycleResponse:
if isSuccess(v) {
ev = ItemPurged(v, req.(*provider.PurgeRecycleRequest), executant)
Expand Down
53 changes: 44 additions & 9 deletions pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,13 +836,13 @@ func (fs *Decomposedfs) Move(ctx context.Context, oldRef, newRef *provider.Refer
return
}

rp, err := fs.p.AssemblePermissions(ctx, oldNode)
orp, err := fs.p.AssemblePermissions(ctx, oldNode)
switch {
case err != nil:
return err
case !rp.Move:
case !orp.Move:
f, _ := storagespace.FormatReference(oldRef)
if rp.Stat {
if orp.Stat {
return errtypes.PermissionDenied(f)
}
return errtypes.NotFound(f)
Expand All @@ -856,19 +856,19 @@ func (fs *Decomposedfs) Move(ctx context.Context, oldRef, newRef *provider.Refer
return
}

rp, err = fs.p.AssemblePermissions(ctx, newNode)
nrp, err := fs.p.AssemblePermissions(ctx, newNode)
switch {
case err != nil:
return err
case oldNode.IsDir(ctx) && !rp.CreateContainer:
case oldNode.IsDir(ctx) && !nrp.CreateContainer:
f, _ := storagespace.FormatReference(newRef)
if rp.Stat {
if nrp.Stat {
return errtypes.PermissionDenied(f)
}
return errtypes.NotFound(f)
case !oldNode.IsDir(ctx) && !rp.InitiateFileUpload:
case !oldNode.IsDir(ctx) && !nrp.InitiateFileUpload:
f, _ := storagespace.FormatReference(newRef)
if rp.Stat {
if nrp.Stat {
return errtypes.PermissionDenied(f)
}
return errtypes.NotFound(f)
Expand All @@ -882,7 +882,13 @@ func (fs *Decomposedfs) Move(ctx context.Context, oldRef, newRef *provider.Refer
return err
}

return fs.tp.Move(ctx, oldNode, newNode)
if err := fs.tp.Move(ctx, oldNode, newNode); err != nil {
return err
}

fs.publishEvent(ctx, fs.moveEvent(ctx, oldRef, newRef, oldNode, newNode, orp, nrp))

return nil
}

// GetMD returns the metadata for the specified resource
Expand Down Expand Up @@ -1241,3 +1247,32 @@ func (fs *Decomposedfs) PurgeRecycleItem(ctx context.Context, ref *provider.Refe
func (fs *Decomposedfs) EmptyRecycle(ctx context.Context, ref *provider.Reference) error {
return fs.trashbin.EmptyRecycle(ctx, ref)
}

func (fs *Decomposedfs) getNodePath(ctx context.Context, n *node.Node, perms *provider.ResourcePermissions) (string, error) {
hp := func(n *node.Node) bool {
return perms.GetGetPath()
}
return fs.lu.Path(ctx, n, hp)
}

func (fs *Decomposedfs) refFromNode(ctx context.Context, n *node.Node, storageId string, perms *provider.ResourcePermissions) (*provider.Reference, error) {
var err error
if perms == nil {
perms, err = fs.p.AssemblePermissions(ctx, n)
if err != nil {
return nil, err
}
}
path, err := fs.getNodePath(ctx, n, perms)
if err != nil {
return nil, err
}
return &provider.Reference{
ResourceId: &provider.ResourceId{
StorageId: storageId,
OpaqueId: n.SpaceID,
SpaceId: n.SpaceID,
},
Path: path,
}, nil
}
83 changes: 83 additions & 0 deletions pkg/storage/utils/decomposedfs/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright 2018-2021 CERN
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// In applying this license, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

package decomposedfs

import (
"context"

user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/v2/pkg/appctx"
revactx "github.com/cs3org/reva/v2/pkg/ctx"
"github.com/cs3org/reva/v2/pkg/events"
"github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/node"
"github.com/cs3org/reva/v2/pkg/utils"
)

func (fs *Decomposedfs) publishEvent(ctx context.Context, evf func() (any, error)) {
log := appctx.GetLogger(ctx)
if fs.stream == nil {
log.Error().Msg("Failed to publish event, stream is undefined")
return
}
ev, err := evf()
if err != nil || ev == nil {
log.Error().Err(err).Msg("Failed to crete the event")
return
}
if err := events.Publish(ctx, fs.stream, ev); err != nil {
log.Error().Err(err).Msg("Failed to publish event")
}
}

func (fs *Decomposedfs) moveEvent(ctx context.Context, oldRef, newRef *provider.Reference, oldNode, newNode *node.Node, orp, nrp *provider.ResourcePermissions) func() (any, error) {
return func() (any, error) {
executant, _ := revactx.ContextGetUser(ctx)
ev := events.ItemMoved{
SpaceOwner: newNode.Owner(),
Executant: executant.GetId(),
Ref: newRef,
OldReference: oldRef,
Timestamp: utils.TSNow(),
ImpersonatingUser: extractImpersonator(executant),
}
log := appctx.GetLogger(ctx)
if nref, err := fs.refFromNode(ctx, newNode, newRef.GetResourceId().GetStorageId(), nrp); err == nil {
ev.Ref = nref
} else {
log.Error().Err(err).Msg("Failed to get destination reference")
}

if oref, err := fs.refFromNode(ctx, oldNode, oldRef.GetResourceId().GetStorageId(), orp); err == nil {
ev.OldReference = oref
} else {
log.Error().Err(err).Msg("Failed to get source reference")
}

return ev, nil
}
}

func extractImpersonator(u *user.User) *user.User {
var impersonator user.User
if err := utils.ReadJSONFromOpaque(u.Opaque, "impersonating-user", &impersonator); err != nil {
return nil
}
return &impersonator
}
3 changes: 2 additions & 1 deletion tests/integration/grpc/storageprovider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,9 @@ var _ = Describe("storage providers", func() {

targetRef := &storagep.Reference{ResourceId: subdirRef.ResourceId, Path: "/new_subdir"}
res, err := providerClient.Move(ctx, &storagep.MoveRequest{Source: subdirRef, Destination: targetRef})
Expect(res.Status.Code).To(Equal(rpcv1beta1.Code_CODE_OK))

Expect(err).ToNot(HaveOccurred())
Expect(res.GetStatus().GetCode()).To(Equal(rpcv1beta1.Code_CODE_OK))

statRes, err = providerClient.Stat(ctx, &storagep.StatRequest{Ref: subdirRef})
Expect(err).ToNot(HaveOccurred())
Expand Down
Loading