Skip to content

Commit

Permalink
Use permissions of share to access the shared resources
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck committed Sep 22, 2023
1 parent 81e41c5 commit f9c26e1
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,7 @@ func (s *service) resolveToken(ctx context.Context, share interface{}) (*provide
}

resourceID := &provider.ResourceId{}
perms := &provider.ResourcePermissions{}
switch v := share.(type) {
case *link.PublicShare:
publicShareResponse, err := gatewayClient.GetPublicShare(
Expand All @@ -951,6 +952,7 @@ func (s *service) resolveToken(ctx context.Context, share interface{}) (*provide
return nil, errtypes.NewErrtypeFromStatus(publicShareResponse.Status)
}
resourceID = publicShareResponse.GetShare().GetResourceId()
perms = publicShareResponse.GetShare().GetPermissions().GetPermissions()
case *ocm.Share:
gsr, err := gatewayClient.GetOCMShareByToken(ctx, &ocm.GetOCMShareByTokenRequest{
Token: v.Token,
Expand All @@ -961,7 +963,11 @@ func (s *service) resolveToken(ctx context.Context, share interface{}) (*provide
case gsr.Status.Code != rpc.Code_CODE_OK:
return nil, errtypes.NewErrtypeFromStatus(gsr.Status)
}
resourceID = gsr.GetShare().GetResourceId()
accessMethods := gsr.GetShare().GetAccessMethods()
if accessMethods == nil || len(accessMethods) > 0 {
return nil, errtypes.PermissionDenied("failed to get access to the requested resource")
}
perms = accessMethods[0].GetWebdavOptions().Permissions
}

sRes, err := gatewayClient.Stat(ctx, &provider.StatRequest{
Expand All @@ -975,5 +981,8 @@ func (s *service) resolveToken(ctx context.Context, share interface{}) (*provide
case sRes.Status.Code != rpc.Code_CODE_OK:
return nil, errtypes.NewErrtypeFromStatus(sRes.Status)
}

// Set permissions
sRes.Info.PermissionSet = perms
return sRes.Info, nil
}

0 comments on commit f9c26e1

Please sign in to comment.