Skip to content

Commit

Permalink
Fixed bugs, implemented unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Geens committed Dec 16, 2024
1 parent d225c22 commit d79b75b
Show file tree
Hide file tree
Showing 5 changed files with 790 additions and 92 deletions.
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ require (
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-sqlite3 v1.14.24 // indirect
github.com/mileusna/useragent v1.3.4 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
Expand All @@ -58,11 +59,12 @@ require (
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/image v0.13.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gorm.io/driver/sqlite v1.5.7 // indirect
)

replace github.com/cs3org/reva => ../reva
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down Expand Up @@ -206,6 +208,8 @@ golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
Expand Down Expand Up @@ -241,6 +245,8 @@ gorm.io/driver/postgres v1.5.0 h1:u2FXTy14l45qc3UeCJ7QaAXZmZfDDv0YrthvmRq1l0U=
gorm.io/driver/postgres v1.5.0/go.mod h1:FUZXzO+5Uqg5zzwzv4KK49R8lvGIyscBOqYrtI1Ce9A=
gorm.io/driver/sqlite v1.4.3 h1:HBBcZSDnWi5BW3B3rwvVTc510KGkBkexlOg0QrmLUuU=
gorm.io/driver/sqlite v1.4.3/go.mod h1:0Aq3iPO+v9ZKbcdiz8gLWRw5VOPcBOPUQJFLq5e2ecI=
gorm.io/driver/sqlite v1.5.7 h1:8NvsrhP0ifM7LX9G4zPB97NwovUakUxc+2V2uuf3Z1I=
gorm.io/driver/sqlite v1.5.7/go.mod h1:U+J8craQU6Fzkcvu8oLeAQmi50TkwPEhHDEjQZXDah4=
gorm.io/driver/sqlserver v1.4.1 h1:t4r4r6Jam5E6ejqP7N82qAJIJAht27EGT41HyPfXRw0=
gorm.io/driver/sqlserver v1.4.1/go.mod h1:DJ4P+MeZbc5rvY58PnmN1Lnyvb5gw5NPzGshHDnJLig=
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
Expand Down
57 changes: 23 additions & 34 deletions share/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import (
// | notify_uploads_extra_recipients | varchar(2048) | YES | | NULL | |
// +---------------------------------+-----------------+------+-----+---------+----------------+

type protoShare struct {
type ProtoShare struct {
// Including gorm.Model will embed a number of gorm-default fields
// such as creation_time, id etc
gorm.Model
Expand All @@ -66,13 +66,16 @@ type protoShare struct {
}

type Share struct {
protoShare
// Including gorm.Model will embed a number of gorm-default fields
// such as creation_time, id etc

ProtoShare
ShareWith string
SharedWithIsGroup bool
}

type PublicLink struct {
protoShare
ProtoShare
Token string
// Enforce uniqueness in db re: Itemsource
Quicklink bool
Expand All @@ -86,7 +89,7 @@ type PublicLink struct {
// Unique index on combo of (shareid, user)
type ShareState struct {
gorm.Model
ShareId uint //foreign key to share
ShareID uint //foreign key to share
// Can not be uid because of lw accs
User string
Synced bool
Expand All @@ -99,7 +102,7 @@ func (s *Share) AsCS3Share(granteeType userpb.UserType) *collaboration.Share {
}
return &collaboration.Share{
Id: &collaboration.ShareId{
OpaqueId: strconv.Itoa(int(s.ID)),
OpaqueId: strconv.FormatUint(uint64(s.ID), 10),
},
//ResourceId: &provider.Reference{StorageId: s.Prefix, NodeId: s.ItemSource},
ResourceId: &provider.ResourceId{
Expand All @@ -116,9 +119,18 @@ func (s *Share) AsCS3Share(granteeType userpb.UserType) *collaboration.Share {
}

func (s *Share) AsCS3ReceivedShare(state *ShareState, granteeType userpb.UserType) *collaboration.ReceivedShare {
// Currently, some implementations still rely on the ShareState to determine whether a file is hidden
// instead of using the field
var rsharestate resourcespb.ShareState
if state.Hidden {
rsharestate = resourcespb.ShareState_SHARE_STATE_REJECTED
} else {
rsharestate = resourcespb.ShareState_SHARE_STATE_ACCEPTED
}

return &collaboration.ReceivedShare{
Share: s.AsCS3Share(granteeType),
State: resourcespb.ShareState_SHARE_STATE_ACCEPTED,
State: rsharestate,
Hidden: state.Hidden,
}
}
Expand Down Expand Up @@ -166,44 +178,21 @@ func (p *PublicLink) AsCS3PublicShare() *link.PublicShare {
}
}

// The package 'conversions' is currently internal in Reva
// It should become public so we can use it here
// Since it generates CS3ResourcePermissions I'm not sure why it would be private

// IntTosharePerm retrieves read/write permissions from an integer.
func intTosharePerm(p int, itemType string) *provider.ResourcePermissions {
switch p {
case 1:
return conversions.NewViewerRole().CS3ResourcePermissions()
case 15:
if itemType == "folder" {
return conversions.NewEditorRole().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{}
}
}

// ExtractGrantee retrieves the CS3API Grantee from a grantee type and username/groupname.
// The grantee userType is relevant only for users.
func extractGrantee(sharedWithIsGroup bool, g string, gtype userpb.UserType) *provider.Grantee {
var grantee provider.Grantee
if sharedWithIsGroup {
grantee.Type = provider.GranteeType_GRANTEE_TYPE_USER
grantee.Id = &provider.Grantee_UserId{UserId: &userpb.UserId{
grantee.Type = provider.GranteeType_GRANTEE_TYPE_GROUP
grantee.Id = &provider.Grantee_GroupId{GroupId: &grouppb.GroupId{
OpaqueId: g,
Type: gtype,
}}
} else {
grantee.Type = provider.GranteeType_GRANTEE_TYPE_GROUP
grantee.Id = &provider.Grantee_GroupId{GroupId: &grouppb.GroupId{
grantee.Type = provider.GranteeType_GRANTEE_TYPE_USER
grantee.Id = &provider.Grantee_UserId{UserId: &userpb.UserId{
OpaqueId: g,
Type: gtype,
}}
}

return &grantee
}
Loading

0 comments on commit d79b75b

Please sign in to comment.