+32
-8
@@ -31,6 +31,7 @@ import (
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
|
||||
gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
||||
user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||
link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1"
|
||||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
@@ -39,6 +40,7 @@ import (
|
||||
"github.com/cs3org/reva/v2/pkg/errtypes"
|
||||
"github.com/cs3org/reva/v2/pkg/publicshare"
|
||||
"github.com/cs3org/reva/v2/pkg/publicshare/manager/registry"
|
||||
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
|
||||
"github.com/cs3org/reva/v2/pkg/utils"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/pkg/errors"
|
||||
@@ -59,11 +61,13 @@ type config struct {
|
||||
DbHost string `mapstructure:"db_host"`
|
||||
DbPort int `mapstructure:"db_port"`
|
||||
DbName string `mapstructure:"db_name"`
|
||||
GatewaySvc string `mapstructure:"gatewaysvc"`
|
||||
}
|
||||
|
||||
type manager struct {
|
||||
c *config
|
||||
db *sql.DB
|
||||
c *config
|
||||
db *sql.DB
|
||||
client gatewayv1beta1.GatewayAPIClient
|
||||
}
|
||||
|
||||
func (c *config) init() {
|
||||
@@ -107,9 +111,15 @@ func New(m map[string]interface{}) (publicshare.Manager, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
gw, err := pool.GetGatewayServiceClient(c.GatewaySvc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mgr := manager{
|
||||
c: c,
|
||||
db: db,
|
||||
c: c,
|
||||
db: db,
|
||||
client: gw,
|
||||
}
|
||||
go mgr.startJanitorRun()
|
||||
|
||||
@@ -259,7 +269,11 @@ func (m *manager) getByToken(ctx context.Context, token string, u *user.User) (*
|
||||
}
|
||||
return nil, "", err
|
||||
}
|
||||
return conversions.ConvertToCS3PublicShare(s), s.ShareWith, nil
|
||||
share, err := conversions.ConvertToCS3PublicShare(ctx, m.client, s)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
return share, s.ShareWith, nil
|
||||
}
|
||||
|
||||
func (m *manager) getByID(ctx context.Context, id *link.PublicShareId, u *user.User) (*link.PublicShare, string, error) {
|
||||
@@ -272,7 +286,11 @@ func (m *manager) getByID(ctx context.Context, id *link.PublicShareId, u *user.U
|
||||
}
|
||||
return nil, "", err
|
||||
}
|
||||
return conversions.ConvertToCS3PublicShare(s), s.ShareWith, nil
|
||||
share, err := conversions.ConvertToCS3PublicShare(ctx, m.client, s)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
return share, s.ShareWith, nil
|
||||
}
|
||||
|
||||
func (m *manager) GetPublicShare(ctx context.Context, u *user.User, ref *link.PublicShareReference, sign bool) (*link.PublicShare, error) {
|
||||
@@ -362,7 +380,10 @@ func (m *manager) ListPublicShares(ctx context.Context, u *user.User, filters []
|
||||
if err := rows.Scan(&s.UIDOwner, &s.UIDInitiator, &s.ShareWith, &s.Prefix, &s.ItemSource, &s.ItemType, &s.Token, &s.Expiration, &s.ShareName, &s.ID, &s.STime, &s.Permissions); err != nil {
|
||||
continue
|
||||
}
|
||||
cs3Share := conversions.ConvertToCS3PublicShare(s)
|
||||
cs3Share, err := conversions.ConvertToCS3PublicShare(ctx, m.client, s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if expired(cs3Share) {
|
||||
_ = m.cleanupExpiredShares()
|
||||
} else {
|
||||
@@ -425,7 +446,10 @@ func (m *manager) GetPublicShareByToken(ctx context.Context, token string, auth
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
cs3Share := conversions.ConvertToCS3PublicShare(s)
|
||||
cs3Share, err := conversions.ConvertToCS3PublicShare(ctx, m.client, s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if s.ShareWith != "" {
|
||||
if !authenticate(cs3Share, s.ShareWith, auth) {
|
||||
// if check := checkPasswordHash(auth.Password, s.ShareWith); !check {
|
||||
|
||||
+45
-11
@@ -27,6 +27,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
||||
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
|
||||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
@@ -34,6 +35,7 @@ import (
|
||||
conversions "github.com/cs3org/reva/v2/pkg/cbox/utils"
|
||||
ctxpkg "github.com/cs3org/reva/v2/pkg/ctx"
|
||||
"github.com/cs3org/reva/v2/pkg/errtypes"
|
||||
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
|
||||
"github.com/cs3org/reva/v2/pkg/share"
|
||||
"github.com/cs3org/reva/v2/pkg/share/manager/registry"
|
||||
"github.com/cs3org/reva/v2/pkg/utils"
|
||||
@@ -60,11 +62,13 @@ type config struct {
|
||||
DbHost string `mapstructure:"db_host"`
|
||||
DbPort int `mapstructure:"db_port"`
|
||||
DbName string `mapstructure:"db_name"`
|
||||
GatewaySvc string `mapstructure:"gatewaysvc"`
|
||||
}
|
||||
|
||||
type mgr struct {
|
||||
c *config
|
||||
db *sql.DB
|
||||
c *config
|
||||
db *sql.DB
|
||||
client gatewayv1beta1.GatewayAPIClient
|
||||
}
|
||||
|
||||
// New returns a new share manager.
|
||||
@@ -80,9 +84,15 @@ func New(m map[string]interface{}) (share.Manager, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
gw, err := pool.GetGatewayServiceClient(c.GatewaySvc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &mgr{
|
||||
c: c,
|
||||
db: db,
|
||||
c: c,
|
||||
db: db,
|
||||
client: gw,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -175,7 +185,11 @@ func (m *mgr) getByID(ctx context.Context, id *collaboration.ShareId) (*collabor
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return conversions.ConvertToCS3Share(s), nil
|
||||
share, err := conversions.ConvertToCS3Share(ctx, m.client, s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return share, nil
|
||||
}
|
||||
|
||||
func (m *mgr) getByKey(ctx context.Context, key *collaboration.ShareKey) (*collaboration.Share, error) {
|
||||
@@ -191,7 +205,11 @@ func (m *mgr) getByKey(ctx context.Context, key *collaboration.ShareKey) (*colla
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return conversions.ConvertToCS3Share(s), nil
|
||||
share, err := conversions.ConvertToCS3Share(ctx, m.client, s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return share, nil
|
||||
}
|
||||
|
||||
func (m *mgr) GetShare(ctx context.Context, ref *collaboration.ShareReference) (*collaboration.Share, error) {
|
||||
@@ -313,7 +331,11 @@ func (m *mgr) ListShares(ctx context.Context, filters []*collaboration.Filter) (
|
||||
if err := rows.Scan(&s.UIDOwner, &s.UIDInitiator, &s.ShareWith, &s.Prefix, &s.ItemSource, &s.ItemType, &s.ID, &s.STime, &s.Permissions, &s.ShareType); err != nil {
|
||||
continue
|
||||
}
|
||||
shares = append(shares, conversions.ConvertToCS3Share(s))
|
||||
share, err := conversions.ConvertToCS3Share(ctx, m.client, s)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
shares = append(shares, share)
|
||||
}
|
||||
if err = rows.Err(); err != nil {
|
||||
return nil, err
|
||||
@@ -323,7 +345,7 @@ func (m *mgr) ListShares(ctx context.Context, filters []*collaboration.Filter) (
|
||||
}
|
||||
|
||||
// we list the shares that are targeted to the user in context or to the user groups.
|
||||
func (m *mgr) ListReceivedShares(ctx context.Context, filters []*collaboration.Filter) ([]*collaboration.ReceivedShare, error) {
|
||||
func (m *mgr) ListReceivedShares(ctx context.Context, filters []*collaboration.Filter, _ *userpb.UserId) ([]*collaboration.ReceivedShare, error) {
|
||||
user := ctxpkg.ContextMustGetUser(ctx)
|
||||
uid := conversions.FormatUserID(user.Id)
|
||||
|
||||
@@ -365,7 +387,11 @@ func (m *mgr) ListReceivedShares(ctx context.Context, filters []*collaboration.F
|
||||
if err := rows.Scan(&s.UIDOwner, &s.UIDInitiator, &s.ShareWith, &s.Prefix, &s.ItemSource, &s.ItemType, &s.FileTarget, &s.ID, &s.STime, &s.Permissions, &s.ShareType, &s.State); err != nil {
|
||||
continue
|
||||
}
|
||||
shares = append(shares, conversions.ConvertToCS3ReceivedShare(s))
|
||||
share, err := conversions.ConvertToCS3ReceivedShare(ctx, m.client, s)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
shares = append(shares, share)
|
||||
}
|
||||
if err = rows.Err(); err != nil {
|
||||
return nil, err
|
||||
@@ -400,7 +426,11 @@ func (m *mgr) getReceivedByID(ctx context.Context, id *collaboration.ShareId) (*
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return conversions.ConvertToCS3ReceivedShare(s), nil
|
||||
share, err := conversions.ConvertToCS3ReceivedShare(ctx, m.client, s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return share, nil
|
||||
}
|
||||
|
||||
func (m *mgr) getReceivedByKey(ctx context.Context, key *collaboration.ShareKey) (*collaboration.ReceivedShare, error) {
|
||||
@@ -431,7 +461,11 @@ func (m *mgr) getReceivedByKey(ctx context.Context, key *collaboration.ShareKey)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return conversions.ConvertToCS3ReceivedShare(s), nil
|
||||
share, err := conversions.ConvertToCS3ReceivedShare(ctx, m.client, s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return share, nil
|
||||
}
|
||||
|
||||
func (m *mgr) GetReceivedShare(ctx context.Context, ref *collaboration.ShareReference) (*collaboration.ReceivedShare, error) {
|
||||
|
||||
+139
-71
@@ -1,4 +1,4 @@
|
||||
// Copyright 2018-2021 CERN
|
||||
// Copyright 2018-2023 CERN
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@@ -19,11 +19,14 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
||||
grouppb "github.com/cs3org/go-cs3apis/cs3/identity/group/v1beta1"
|
||||
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||
rpcv1beta1 "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"
|
||||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
@@ -33,24 +36,28 @@ import (
|
||||
|
||||
// DBShare stores information about user and public shares.
|
||||
type DBShare struct {
|
||||
ID string
|
||||
UIDOwner string
|
||||
UIDInitiator string
|
||||
Prefix string
|
||||
ItemSource string
|
||||
ItemType string
|
||||
ShareWith string
|
||||
Token string
|
||||
Expiration string
|
||||
Permissions int
|
||||
ShareType int
|
||||
ShareName string
|
||||
STime int
|
||||
FileTarget string
|
||||
State int
|
||||
ID string
|
||||
UIDOwner string
|
||||
UIDInitiator string
|
||||
Prefix string
|
||||
ItemSource string
|
||||
ItemType string
|
||||
ShareWith string
|
||||
Token string
|
||||
Expiration string
|
||||
Permissions int
|
||||
ShareType int
|
||||
ShareName string
|
||||
STime int
|
||||
FileTarget string
|
||||
State int
|
||||
Quicklink bool
|
||||
Description string
|
||||
NotifyUploads bool
|
||||
NotifyUploadsExtraRecipients string
|
||||
}
|
||||
|
||||
// FormatGrantee formats a CS3API grantee to a string
|
||||
// FormatGrantee formats a CS3API grantee to a string.
|
||||
func FormatGrantee(g *provider.Grantee) (int, string) {
|
||||
var granteeType int
|
||||
var formattedID string
|
||||
@@ -67,23 +74,31 @@ func FormatGrantee(g *provider.Grantee) (int, string) {
|
||||
return granteeType, formattedID
|
||||
}
|
||||
|
||||
// ExtractGrantee retrieves the CS3API grantee from a formatted string
|
||||
func ExtractGrantee(t int, g string) *provider.Grantee {
|
||||
// ExtractGrantee retrieves the CS3API grantee from a formatted string.
|
||||
func ExtractGrantee(ctx context.Context, gateway gatewayv1beta1.GatewayAPIClient, t int, g string) (*provider.Grantee, error) {
|
||||
var grantee provider.Grantee
|
||||
switch t {
|
||||
case 0:
|
||||
grantee.Type = provider.GranteeType_GRANTEE_TYPE_USER
|
||||
grantee.Id = &provider.Grantee_UserId{UserId: ExtractUserID(g)}
|
||||
user, err := ExtractUserID(ctx, gateway, g)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
grantee.Id = &provider.Grantee_UserId{UserId: user}
|
||||
case 1:
|
||||
grantee.Type = provider.GranteeType_GRANTEE_TYPE_GROUP
|
||||
grantee.Id = &provider.Grantee_GroupId{GroupId: ExtractGroupID(g)}
|
||||
group, err := ExtractGroupID(ctx, gateway, g)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
grantee.Id = &provider.Grantee_GroupId{GroupId: group}
|
||||
default:
|
||||
grantee.Type = provider.GranteeType_GRANTEE_TYPE_INVALID
|
||||
}
|
||||
return &grantee
|
||||
return &grantee, nil
|
||||
}
|
||||
|
||||
// ResourceTypeToItem maps a resource type to a string
|
||||
// ResourceTypeToItem maps a resource type to a string.
|
||||
func ResourceTypeToItem(r provider.ResourceType) string {
|
||||
switch r {
|
||||
case provider.ResourceType_RESOURCE_TYPE_FILE:
|
||||
@@ -99,7 +114,7 @@ func ResourceTypeToItem(r provider.ResourceType) string {
|
||||
}
|
||||
}
|
||||
|
||||
// ResourceTypeToItemInt maps a resource type to an integer
|
||||
// ResourceTypeToItemInt maps a resource type to an integer.
|
||||
func ResourceTypeToItemInt(r provider.ResourceType) int {
|
||||
switch r {
|
||||
case provider.ResourceType_RESOURCE_TYPE_CONTAINER:
|
||||
@@ -111,7 +126,7 @@ func ResourceTypeToItemInt(r provider.ResourceType) int {
|
||||
}
|
||||
}
|
||||
|
||||
// SharePermToInt maps read/write permissions to an integer
|
||||
// SharePermToInt maps read/write permissions to an integer.
|
||||
func SharePermToInt(p *provider.ResourcePermissions) int {
|
||||
var perm int
|
||||
switch {
|
||||
@@ -126,13 +141,25 @@ func SharePermToInt(p *provider.ResourcePermissions) int {
|
||||
return perm
|
||||
}
|
||||
|
||||
// IntTosharePerm retrieves read/write permissions from an integer
|
||||
// IntTosharePerm retrieves read/write permissions from an integer.
|
||||
func IntTosharePerm(p int, itemType string) *provider.ResourcePermissions {
|
||||
perms, _ := conversions.NewPermissions(p)
|
||||
return conversions.RoleFromOCSPermissions(perms).CS3ResourcePermissions()
|
||||
switch p {
|
||||
case 1:
|
||||
return conversions.NewViewerRole(false).CS3ResourcePermissions()
|
||||
case 15:
|
||||
if itemType == "folder" {
|
||||
return conversions.NewEditorRole(false).CS3ResourcePermissions()
|
||||
}
|
||||
return conversions.NewFileEditorRole().CS3ResourcePermissions()
|
||||
case 4:
|
||||
return conversions.NewUploaderRole().CS3ResourcePermissions()
|
||||
default:
|
||||
// TODO we may have other options, for now this is a denial
|
||||
return &provider.ResourcePermissions{}
|
||||
}
|
||||
}
|
||||
|
||||
// IntToShareState retrieves the received share state from an integer
|
||||
// IntToShareState retrieves the received share state from an integer.
|
||||
func IntToShareState(g int) collaboration.ShareState {
|
||||
switch g {
|
||||
case 0:
|
||||
@@ -146,66 +173,95 @@ func IntToShareState(g int) collaboration.ShareState {
|
||||
}
|
||||
}
|
||||
|
||||
// FormatUserID formats a CS3API user ID to a string
|
||||
// FormatUserID formats a CS3API user ID to a string.
|
||||
func FormatUserID(u *userpb.UserId) string {
|
||||
return u.OpaqueId
|
||||
}
|
||||
|
||||
// ExtractUserID retrieves a CS3API user ID from a string
|
||||
func ExtractUserID(u string) *userpb.UserId {
|
||||
t := userpb.UserType_USER_TYPE_PRIMARY
|
||||
if strings.HasPrefix(u, "guest:") {
|
||||
t = userpb.UserType_USER_TYPE_LIGHTWEIGHT
|
||||
} else if strings.Contains(u, "@") {
|
||||
t = userpb.UserType_USER_TYPE_FEDERATED
|
||||
// ExtractUserID retrieves a CS3API user ID from a string.
|
||||
func ExtractUserID(ctx context.Context, gateway gatewayv1beta1.GatewayAPIClient, u string) (*userpb.UserId, error) {
|
||||
userRes, err := gateway.GetUser(ctx, &userpb.GetUserRequest{
|
||||
UserId: &userpb.UserId{OpaqueId: u},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &userpb.UserId{OpaqueId: u, Type: t}
|
||||
if userRes.Status.Code != rpcv1beta1.Code_CODE_OK {
|
||||
return nil, errors.New(userRes.Status.Message)
|
||||
}
|
||||
|
||||
return userRes.User.Id, nil
|
||||
}
|
||||
|
||||
// FormatGroupID formats a CS3API group ID to a string
|
||||
// FormatGroupID formats a CS3API group ID to a string.
|
||||
func FormatGroupID(u *grouppb.GroupId) string {
|
||||
return u.OpaqueId
|
||||
}
|
||||
|
||||
// ExtractGroupID retrieves a CS3API group ID from a string
|
||||
func ExtractGroupID(u string) *grouppb.GroupId {
|
||||
return &grouppb.GroupId{OpaqueId: u}
|
||||
// ExtractGroupID retrieves a CS3API group ID from a string.
|
||||
func ExtractGroupID(ctx context.Context, gateway gatewayv1beta1.GatewayAPIClient, u string) (*grouppb.GroupId, error) {
|
||||
groupRes, err := gateway.GetGroup(ctx, &grouppb.GetGroupRequest{
|
||||
GroupId: &grouppb.GroupId{OpaqueId: u},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if groupRes.Status.Code != rpcv1beta1.Code_CODE_OK {
|
||||
return nil, errors.New(groupRes.Status.Message)
|
||||
}
|
||||
return groupRes.Group.Id, nil
|
||||
}
|
||||
|
||||
// ConvertToCS3Share converts a DBShare to a CS3API collaboration share
|
||||
func ConvertToCS3Share(s DBShare) *collaboration.Share {
|
||||
// ConvertToCS3Share converts a DBShare to a CS3API collaboration share.
|
||||
func ConvertToCS3Share(ctx context.Context, gateway gatewayv1beta1.GatewayAPIClient, s DBShare) (*collaboration.Share, error) {
|
||||
ts := &typespb.Timestamp{
|
||||
Seconds: uint64(s.STime),
|
||||
}
|
||||
owner, err := ExtractUserID(ctx, gateway, s.UIDOwner)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
creator, err := ExtractUserID(ctx, gateway, s.UIDInitiator)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
grantee, err := ExtractGrantee(ctx, gateway, s.ShareType, s.ShareWith)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &collaboration.Share{
|
||||
Id: &collaboration.ShareId{
|
||||
OpaqueId: s.ID,
|
||||
},
|
||||
//ResourceId: &provider.Reference{StorageId: s.Prefix, NodeId: s.ItemSource},
|
||||
ResourceId: &provider.ResourceId{
|
||||
SpaceId: s.Prefix,
|
||||
OpaqueId: s.ItemSource,
|
||||
StorageId: s.Prefix,
|
||||
OpaqueId: s.ItemSource,
|
||||
},
|
||||
Permissions: &collaboration.SharePermissions{Permissions: IntTosharePerm(s.Permissions, s.ItemType)},
|
||||
Grantee: ExtractGrantee(s.ShareType, s.ShareWith),
|
||||
Owner: ExtractUserID(s.UIDOwner),
|
||||
Creator: ExtractUserID(s.UIDInitiator),
|
||||
Grantee: grantee,
|
||||
Owner: owner,
|
||||
Creator: creator,
|
||||
Ctime: ts,
|
||||
Mtime: ts,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ConvertToCS3ReceivedShare converts a DBShare to a CS3API collaboration received share
|
||||
func ConvertToCS3ReceivedShare(s DBShare) *collaboration.ReceivedShare {
|
||||
// ConvertToCS3ReceivedShare converts a DBShare to a CS3API collaboration received share.
|
||||
func ConvertToCS3ReceivedShare(ctx context.Context, gateway gatewayv1beta1.GatewayAPIClient, s DBShare) (*collaboration.ReceivedShare, error) {
|
||||
share, err := ConvertToCS3Share(ctx, gateway, s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &collaboration.ReceivedShare{
|
||||
Share: ConvertToCS3Share(s),
|
||||
State: IntToShareState(s.State),
|
||||
MountPoint: &provider.Reference{Path: strings.TrimLeft(s.FileTarget, "/")},
|
||||
}
|
||||
Share: share,
|
||||
State: IntToShareState(s.State),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ConvertToCS3PublicShare converts a DBShare to a CS3API public share
|
||||
func ConvertToCS3PublicShare(s DBShare) *link.PublicShare {
|
||||
// ConvertToCS3PublicShare converts a DBShare to a CS3API public share.
|
||||
func ConvertToCS3PublicShare(ctx context.Context, gateway gatewayv1beta1.GatewayAPIClient, s DBShare) (*link.PublicShare, error) {
|
||||
ts := &typespb.Timestamp{
|
||||
Seconds: uint64(s.STime),
|
||||
}
|
||||
@@ -222,22 +278,34 @@ func ConvertToCS3PublicShare(s DBShare) *link.PublicShare {
|
||||
}
|
||||
}
|
||||
}
|
||||
owner, err := ExtractUserID(ctx, gateway, s.UIDOwner)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
creator, err := ExtractUserID(ctx, gateway, s.UIDInitiator)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &link.PublicShare{
|
||||
Id: &link.PublicShareId{
|
||||
OpaqueId: s.ID,
|
||||
},
|
||||
ResourceId: &provider.ResourceId{
|
||||
SpaceId: s.Prefix,
|
||||
OpaqueId: s.ItemSource,
|
||||
StorageId: s.Prefix,
|
||||
OpaqueId: s.ItemSource,
|
||||
},
|
||||
Permissions: &link.PublicSharePermissions{Permissions: IntTosharePerm(s.Permissions, s.ItemType)},
|
||||
Owner: ExtractUserID(s.UIDOwner),
|
||||
Creator: ExtractUserID(s.UIDInitiator),
|
||||
Token: s.Token,
|
||||
DisplayName: s.ShareName,
|
||||
PasswordProtected: pwd,
|
||||
Expiration: expires,
|
||||
Ctime: ts,
|
||||
Mtime: ts,
|
||||
}
|
||||
Permissions: &link.PublicSharePermissions{Permissions: IntTosharePerm(s.Permissions, s.ItemType)},
|
||||
Owner: owner,
|
||||
Creator: creator,
|
||||
Token: s.Token,
|
||||
DisplayName: s.ShareName,
|
||||
PasswordProtected: pwd,
|
||||
Expiration: expires,
|
||||
Ctime: ts,
|
||||
Mtime: ts,
|
||||
Quicklink: s.Quicklink,
|
||||
Description: s.Description,
|
||||
NotifyUploads: s.NotifyUploads,
|
||||
NotifyUploadsExtraRecipients: s.NotifyUploadsExtraRecipients,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user