mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-10-30 18:18:37 -04:00
Use the reva constant for the ancestor-grants key
This commit is contained in:
1 parent
a9e408bf7f
commit
a257d20ef2
2 files changed
+10
-12
No files matched your search
@@ -21,15 +21,13 @@ import (
|
||||
"github.com/opencloud-eu/opencloud/pkg/log"
|
||||
)
|
||||
|
||||
// ancestorGrantsKey makes a stat return the active grants on the resource and its ancestors,
|
||||
// excluding the space root. The storage only returns them to service accounts.
|
||||
const ancestorGrantsKey = "ancestor-grants"
|
||||
|
||||
// The storage returns the active grants on a resource and its ancestors, excluding the space
|
||||
// root, only to service accounts.
|
||||
var (
|
||||
// resourceFieldMask returns the complete resource info including the ancestor grants
|
||||
resourceFieldMask = &fieldmaskpb.FieldMask{Paths: []string{"*", ancestorGrantsKey}}
|
||||
resourceFieldMask = &fieldmaskpb.FieldMask{Paths: []string{"*", utils.AncestorGrantsKey}}
|
||||
// ancestorGrantsFieldMask returns the basic resource info and the ancestor grants
|
||||
ancestorGrantsFieldMask = &fieldmaskpb.FieldMask{Paths: []string{ancestorGrantsKey}}
|
||||
ancestorGrantsFieldMask = &fieldmaskpb.FieldMask{Paths: []string{utils.AncestorGrantsKey}}
|
||||
)
|
||||
|
||||
// addShareRecipients adds the grantees of shares on the resource or on one of its ancestors
|
||||
@@ -70,11 +68,11 @@ func addParentShareRecipients(ctx context.Context, gwc gateway.GatewayAPIClient,
|
||||
// getShareRecipients returns the grantees of the ancestor grants of the resource and the users
|
||||
// that were denied access on the resource or one of its ancestors.
|
||||
func getShareRecipients(ctx context.Context, gwc gateway.GatewayAPIClient, info *provider.ResourceInfo) (recipients, denied []string, err error) {
|
||||
if !utils.ExistsInOpaque(info.GetOpaque(), ancestorGrantsKey) {
|
||||
if !utils.ExistsInOpaque(info.GetOpaque(), utils.AncestorGrantsKey) {
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
gs, err := utils.ReadGrantsFromOpaque(info.GetOpaque(), ancestorGrantsKey)
|
||||
gs, err := utils.ReadGrantsFromOpaque(info.GetOpaque(), utils.AncestorGrantsKey)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ var _ = Describe("share recipients", func() {
|
||||
|
||||
// resourceInfo returns a resource info as stat'ed with the ancestor grants
|
||||
resourceInfo := func(id *provider.ResourceId, grants ...*provider.Grant) *provider.ResourceInfo {
|
||||
o, err := utils.AppendGrantsToOpaque(nil, ancestorGrantsKey, grants)
|
||||
o, err := utils.AppendGrantsToOpaque(nil, utils.AncestorGrantsKey, grants)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
return &provider.ResourceInfo{Id: id, Opaque: o}
|
||||
}
|
||||
@@ -114,7 +114,7 @@ var _ = Describe("share recipients", func() {
|
||||
|
||||
It("fails when the ancestor grants can't be decoded", func() {
|
||||
info := &provider.ResourceInfo{Id: fileID, Opaque: &types.Opaque{Map: map[string]*types.OpaqueEntry{
|
||||
ancestorGrantsKey: {Decoder: "json", Value: []byte("not json")},
|
||||
utils.AncestorGrantsKey: {Decoder: "json", Value: []byte("not json")},
|
||||
}}}
|
||||
_, _, err := getShareRecipients(ctx, gwc, info)
|
||||
Expect(err).To(HaveOccurred())
|
||||
@@ -144,7 +144,7 @@ var _ = Describe("share recipients", func() {
|
||||
gwc.EXPECT().Stat(mock.Anything, mock.MatchedBy(func(req *provider.StatRequest) bool {
|
||||
return utils.ResourceIDEqual(req.GetRef().GetResourceId(), rootID) &&
|
||||
req.GetRef().GetPath() == "./a" &&
|
||||
req.GetFieldMask().GetPaths()[0] == ancestorGrantsKey
|
||||
req.GetFieldMask().GetPaths()[0] == utils.AncestorGrantsKey
|
||||
})).Return(&provider.StatResponse{
|
||||
Status: okStatus,
|
||||
Info: resourceInfo(folderA, userGrant(&user.UserId{OpaqueId: "bob"}, viewer)),
|
||||
@@ -178,7 +178,7 @@ var _ = Describe("share recipients", func() {
|
||||
info.ParentId = folderA
|
||||
info.Space = &provider.StorageSpace{Id: &provider.StorageSpaceId{OpaqueId: storageID + "$" + spaceID}}
|
||||
gwc.EXPECT().Stat(mock.Anything, mock.MatchedBy(func(req *provider.StatRequest) bool {
|
||||
return req.GetFieldMask().GetPaths()[1] == ancestorGrantsKey
|
||||
return req.GetFieldMask().GetPaths()[1] == utils.AncestorGrantsKey
|
||||
})).Return(&provider.StatResponse{Status: okStatus, Info: info}, nil).Once()
|
||||
|
||||
members := utils.AppendJSONToOpaque(nil, "grants", map[string]*provider.ResourcePermissions{
|
||||
|
||||
Reference in new issue
Block a user