mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-25 06:18:42 -05:00
graph/sharedbyme: Add user and group names to permissions
This commit is contained in:
committed by
Ralf Haferkamp
parent
580a4e0d92
commit
d2cff38ab4
@@ -6,12 +6,14 @@ import (
|
||||
"net/url"
|
||||
"path"
|
||||
|
||||
group "github.com/cs3org/go-cs3apis/cs3/identity/group/v1beta1"
|
||||
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
|
||||
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
|
||||
link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1"
|
||||
storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
"github.com/cs3org/reva/v2/pkg/share"
|
||||
"github.com/cs3org/reva/v2/pkg/storagespace"
|
||||
revautils "github.com/cs3org/reva/v2/pkg/utils"
|
||||
"github.com/go-chi/render"
|
||||
libregraph "github.com/owncloud/libre-graph-api-go"
|
||||
"github.com/owncloud/ocis/v2/services/graph/pkg/service/v0/errorcode"
|
||||
@@ -124,14 +126,52 @@ func (g Graph) cs3UserSharesToDriveItems(ctx context.Context, shares []*collabor
|
||||
grantedTo := libregraph.SharePointIdentitySet{}
|
||||
switch s.Grantee.Type {
|
||||
case storageprovider.GranteeType_GRANTEE_TYPE_USER:
|
||||
gatewayClient, err := g.gatewaySelector.Next()
|
||||
if err != nil {
|
||||
g.logger.Error().Err(err).Msg("could not select next gateway client")
|
||||
return driveItems, errorcode.New(errorcode.GeneralException, err.Error())
|
||||
}
|
||||
user := libregraph.NewIdentityWithDefaults()
|
||||
user.SetId(s.Grantee.GetUserId().GetOpaqueId())
|
||||
grantedTo.SetUser(*user)
|
||||
cs3User, err := revautils.GetUser(s.GetGrantee().GetUserId(), gatewayClient)
|
||||
switch {
|
||||
case revautils.IsErrNotFound(err):
|
||||
g.logger.Warn().Str("userid", s.Grantee.GetUserId().GetOpaqueId()).Msg("User not found by id")
|
||||
// User does not seem to exist anymore, don't add a permission for this
|
||||
continue
|
||||
case err != nil:
|
||||
return driveItems, errorcode.New(errorcode.GeneralException, err.Error())
|
||||
default:
|
||||
user.SetDisplayName(cs3User.GetDisplayName())
|
||||
grantedTo.SetUser(*user)
|
||||
}
|
||||
case storageprovider.GranteeType_GRANTEE_TYPE_GROUP:
|
||||
gatewayClient, err := g.gatewaySelector.Next()
|
||||
if err != nil {
|
||||
g.logger.Error().Err(err).Msg("could not select next gateway client")
|
||||
return driveItems, errorcode.New(errorcode.GeneralException, err.Error())
|
||||
}
|
||||
req := group.GetGroupRequest{
|
||||
GroupId: s.Grantee.GetGroupId(),
|
||||
}
|
||||
res, err := gatewayClient.GetGroup(ctx, &req)
|
||||
if err != nil {
|
||||
return driveItems, errorcode.New(errorcode.GeneralException, err.Error())
|
||||
}
|
||||
grp := libregraph.NewIdentityWithDefaults()
|
||||
grp.SetId(s.Grantee.GetGroupId().GetOpaqueId())
|
||||
grantedTo.SetGroup(*grp)
|
||||
|
||||
switch res.Status.Code {
|
||||
case rpc.Code_CODE_OK:
|
||||
cs3Group := res.GetGroup()
|
||||
grp.SetDisplayName(cs3Group.GetDisplayName())
|
||||
grantedTo.SetGroup(*grp)
|
||||
case rpc.Code_CODE_NOT_FOUND:
|
||||
g.logger.Warn().Str("groupid", s.Grantee.GetGroupId().GetOpaqueId()).Msg("Group not found by id")
|
||||
// Group does not seem to exist anymore, don't add a permission for this
|
||||
continue
|
||||
default:
|
||||
return driveItems, errorcode.New(errorcode.GeneralException, res.Status.Message)
|
||||
}
|
||||
}
|
||||
|
||||
// set expiration date
|
||||
|
||||
@@ -120,6 +120,7 @@ var _ = Describe("sharedbyme", func() {
|
||||
|
||||
pool.RemoveSelector("GatewaySelector" + "com.owncloud.api.gateway")
|
||||
gatewayClient = &cs3mocks.GatewayAPIClient{}
|
||||
|
||||
gatewayClient.On("Stat",
|
||||
mock.Anything,
|
||||
mock.MatchedBy(
|
||||
@@ -153,6 +154,52 @@ var _ = Describe("sharedbyme", func() {
|
||||
Id: userShare.ResourceId,
|
||||
},
|
||||
}, nil)
|
||||
|
||||
gatewayClient.On("GetUser",
|
||||
mock.Anything,
|
||||
mock.MatchedBy(func(req *userpb.GetUserRequest) bool {
|
||||
return req.UserId.OpaqueId == "user-id"
|
||||
})).
|
||||
Return(&userpb.GetUserResponse{
|
||||
Status: status.NewOK(ctx),
|
||||
User: &userpb.User{
|
||||
Id: &userpb.UserId{
|
||||
Idp: "idp",
|
||||
OpaqueId: "user-id",
|
||||
},
|
||||
DisplayName: "User Name",
|
||||
},
|
||||
}, nil)
|
||||
gatewayClient.On("GetUser",
|
||||
mock.Anything,
|
||||
mock.Anything).
|
||||
Return(&userpb.GetUserResponse{
|
||||
Status: status.NewNotFound(ctx, "mock user not found"),
|
||||
User: nil,
|
||||
}, nil)
|
||||
gatewayClient.On("GetGroup",
|
||||
mock.Anything,
|
||||
mock.MatchedBy(func(req *grouppb.GetGroupRequest) bool {
|
||||
return req.GroupId.OpaqueId == "group-id"
|
||||
})).
|
||||
Return(&grouppb.GetGroupResponse{
|
||||
Status: status.NewOK(ctx),
|
||||
Group: &grouppb.Group{
|
||||
Id: &grouppb.GroupId{
|
||||
Idp: "idp",
|
||||
OpaqueId: "group-id",
|
||||
},
|
||||
DisplayName: "Group Name",
|
||||
},
|
||||
}, nil)
|
||||
gatewayClient.On("GetGroup",
|
||||
mock.Anything,
|
||||
mock.Anything).
|
||||
Return(&grouppb.GetGroupResponse{
|
||||
Status: status.NewNotFound(ctx, "mock group not found"),
|
||||
Group: nil,
|
||||
}, nil)
|
||||
|
||||
gatewaySelector = pool.GetSelector[gateway.GatewayAPIClient](
|
||||
"GatewaySelector",
|
||||
"com.owncloud.api.gateway",
|
||||
|
||||
Reference in New Issue
Block a user