Skip to content

Add user filter #3046

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

Merged
merged 12 commits into from
Jul 15, 2022
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
8 changes: 4 additions & 4 deletions .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ def virtualViews():
"PATH_TO_CORE": "/drone/src/tmp/testrunner",
"TEST_SERVER_URL": "http://revad-services:20180",
"OCIS_REVA_DATA_ROOT": "/drone/src/tmp/reva/data/",
"DELETE_USER_DATA_CMD": "rm -rf /drone/src/tmp/reva/data/spaces/* /drone/src/tmp/reva/data/blobs/* /drone/src/tmp/reva/data/spacetypes/*",
"DELETE_USER_DATA_CMD": "rm -rf /drone/src/tmp/reva/data/spaces/* /drone/src/tmp/reva/data/blobs/* /drone/src/tmp/reva/data/indexes",
"STORAGE_DRIVER": "OCIS",
"SKELETON_DIR": "/drone/src/tmp/testing/data/apiSkeleton",
"TEST_REVA": "true",
Expand Down Expand Up @@ -756,7 +756,7 @@ def litmusOcisSpacesDav():
"commands": [
# The spaceid is randomly generated during the first login so we need this hack to construct the correct url.
"curl -s -k -u einstein:relativity -I http://revad-services:20080/remote.php/dav/files/einstein",
"export LITMUS_URL=http://revad-services:20080/remote.php/dav/spaces/$(ls /drone/src/tmp/reva/data/spacetypes/personal/)",
"export LITMUS_URL=http://revad-services:20080/remote.php/dav/spaces/$(ls /drone/src/tmp/reva/data/indexes/by-type/personal/)",
"/usr/local/bin/litmus-wrapper",
],
},
Expand Down Expand Up @@ -929,7 +929,7 @@ def ocisIntegrationTests(parallelRuns, skipExceptParts = []):
"environment": {
"TEST_SERVER_URL": "http://revad-services:20080",
"OCIS_REVA_DATA_ROOT": "/drone/src/tmp/reva/data/",
"DELETE_USER_DATA_CMD": "rm -rf /drone/src/tmp/reva/data/spaces/* /drone/src/tmp/reva/data/blobs/* /drone/src/tmp/reva/data/spacetypes/*",
"DELETE_USER_DATA_CMD": "rm -rf /drone/src/tmp/reva/data/spaces/* /drone/src/tmp/reva/data/blobs/* /drone/src/tmp/reva/data/indexes/by-type/*",
"STORAGE_DRIVER": "OCIS",
"SKELETON_DIR": "/drone/src/tmp/testing/data/apiSkeleton",
"TEST_WITH_LDAP": "true",
Expand Down Expand Up @@ -1008,7 +1008,7 @@ def s3ngIntegrationTests(parallelRuns, skipExceptParts = []):
"environment": {
"TEST_SERVER_URL": "http://revad-services:20080",
"OCIS_REVA_DATA_ROOT": "/drone/src/tmp/reva/data/",
"DELETE_USER_DATA_CMD": "rm -rf /drone/src/tmp/reva/data/spaces/* /drone/src/tmp/reva/data/blobs/* /drone/src/tmp/reva/data/spacetypes/*",
"DELETE_USER_DATA_CMD": "rm -rf /drone/src/tmp/reva/data/spaces/* /drone/src/tmp/reva/data/blobs/* /drone/src/tmp/reva/data/indexes/by-type/*",
"STORAGE_DRIVER": "S3NG",
"SKELETON_DIR": "/drone/src/tmp/testing/data/apiSkeleton",
"TEST_WITH_LDAP": "true",
Expand Down
5 changes: 5 additions & 0 deletions changelog/unreleased/add-user-filter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Add user filter

This PR adds the ability to filter spaces by user-id

https://github.com/owncloud/ocis/pull/4072
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/cheggaaa/pb v1.0.29
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e
github.com/cs3org/go-cs3apis v0.0.0-20220621145831-c38cca0796c2
github.com/cs3org/go-cs3apis v0.0.0-20220711084433-8f71d4e812a3
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8
github.com/dgraph-io/ristretto v0.1.0
github.com/eventials/go-tus v0.0.0-20200718001131-45c7ec8f5d59
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e h1:tqSPWQeueWTKnJVMJffz4pz0o1WuQxJ28+5x5JgaHD8=
github.com/cs3org/cato v0.0.0-20200828125504-e418fc54dd5e/go.mod h1:XJEZ3/EQuI3BXTp/6DUzFr850vlxq11I6satRtz0YQ4=
github.com/cs3org/go-cs3apis v0.0.0-20220621145831-c38cca0796c2 h1:o/ovJzS4pyL/rZgp0MtC4Q7JIle5DikimilTLBw2TjY=
github.com/cs3org/go-cs3apis v0.0.0-20220621145831-c38cca0796c2/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/go-cs3apis v0.0.0-20220711084433-8f71d4e812a3 h1:QSQ2DGKPMChB4vHSs1Os9TnOJl21BrzKX9D5EtQfDog=
github.com/cs3org/go-cs3apis v0.0.0-20220711084433-8f71d4e812a3/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY=
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
Expand Down
3 changes: 3 additions & 0 deletions internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ func (s *svc) ListStorageSpaces(ctx context.Context, req *provider.ListStorageSp
filters["owner_id"] = f.GetOwner().OpaqueId
case provider.ListStorageSpacesRequest_Filter_TYPE_SPACE_TYPE:
filters["space_type"] = f.GetSpaceType()
case provider.ListStorageSpacesRequest_Filter_TYPE_USER:
filters["user_idp"] = f.GetUser().GetIdp()
filters["user_id"] = f.GetUser().GetOpaqueId()
default:
return &provider.ListStorageSpacesResponse{
Status: status.NewInvalidArg(ctx, fmt.Sprintf("unknown filter %v", f.Type)),
Expand Down
2 changes: 2 additions & 0 deletions pkg/storage/fs/owncloudsql/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func (fs *owncloudsqlfs) ListStorageSpaces(ctx context.Context, filter []*provid
filteringUnsupportedSpaceTypes = (t != "personal" && !strings.HasPrefix(t, "+"))
case provider.ListStorageSpacesRequest_Filter_TYPE_ID:
_, spaceID, _, _ = storagespace.SplitID(filter[i].GetId().OpaqueId)
case provider.ListStorageSpacesRequest_Filter_TYPE_USER:
_, spaceID, _, _ = storagespace.SplitID(filter[i].GetId().OpaqueId)
}
}
if filteringUnsupportedSpaceTypes {
Expand Down
11 changes: 11 additions & 0 deletions pkg/storage/registry/spaces/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,17 @@ func (r *registry) buildFilters(filterMap map[string]string) []*providerpb.ListS
})
}
}
if filterMap["user_id"] != "" {
filters = append(filters, &providerpb.ListStorageSpacesRequest_Filter{
Type: providerpb.ListStorageSpacesRequest_Filter_TYPE_USER,
Term: &providerpb.ListStorageSpacesRequest_Filter_User{
User: &userpb.UserId{
Idp: filterMap["user_idp"],
OpaqueId: filterMap["user_id"],
},
},
})
}
if filterMap["owner_id"] != "" && filterMap["owner_idp"] != "" {
filters = append(filters, &providerpb.ListStorageSpacesRequest_Filter{
Type: providerpb.ListStorageSpacesRequest_Filter_TYPE_OWNER,
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ func (fs *Decomposedfs) GetMD(ctx context.Context, ref *provider.Reference, mdKe
}
}
if addSpace {
if md.Space, err = fs.storageSpaceFromNode(ctx, node, node.InternalPath(), false, false); err != nil {
if md.Space, err = fs.storageSpaceFromNode(ctx, node, true); err != nil {
return nil, err
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/grants.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (fs *Decomposedfs) storeGrant(ctx context.Context, n *node.Node, g *provide

// when a grant is added to a space, do not add a new space under "shares"
if spaceGrant := ctx.Value(utils.SpaceGrant); spaceGrant == nil {
err := fs.linkStorageSpaceType(ctx, spaceTypeShare, n.ID)
err := fs.updateIndexes(ctx, g.GetGrantee().GetUserId().GetOpaqueId(), spaceTypeShare, n.ID)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/grants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ var _ = Describe("Grants", func() {
err := env.Fs.AddGrant(env.Ctx, ref, grant)
Expect(err).ToNot(HaveOccurred())

spaceTypesPath := filepath.Join(env.Root, "spacetypes")
spaceTypesPath := filepath.Join(env.Root, "indexes", "by-type")
tfs.root = spaceTypesPath
entries, err := fs.ReadDir(tfs, "share")
Expect(err).ToNot(HaveOccurred())
Expand Down
Loading