Skip to content

Commit

Permalink
resolving comments on PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Geens committed Jan 10, 2025
1 parent 2cf6e37 commit d2f446e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 55 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/cernbox/reva-plugins

go 1.21.0
go 1.22.7

require (
github.com/Masterminds/sprig v2.22.0+incompatible
Expand Down
56 changes: 17 additions & 39 deletions share/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,25 @@ import (
"gorm.io/gorm"
)

// +---------------------------------+-----------------+------+-----+---------+----------------+
// | Field | Type | Null | Key | Default | Extra |
// +---------------------------------+-----------------+------+-----+---------+----------------+
// | id | int | NO | PRI | NULL | auto_increment |
// | share_type | smallint | NO | | 0 | |
// | share_with | varchar(255) | YES | | NULL | |
// | uid_owner | varchar(64) | NO | | | |
// | uid_initiator | varchar(64) | YES | | NULL | |
// | parent | int | YES | | NULL | |
// | item_type | varchar(64) | NO | MUL | | |
// | item_source | varchar(255) | YES | | NULL | |
// | item_target | varchar(255) | YES | | NULL | |
// | file_source | bigint unsigned | YES | MUL | NULL | |
// | file_target | varchar(512) | YES | | NULL | |
// | permissions | smallint | NO | | 0 | |
// | stime | bigint | NO | | 0 | |
// | accepted | smallint | NO | | 0 | |
// | expiration | datetime | YES | | NULL | |
// | token | varchar(32) | YES | MUL | NULL | |
// | mail_send | smallint | NO | | 0 | |
// | fileid_prefix | varchar(255) | YES | | NULL | |
// | orphan | tinyint | YES | | NULL | |
// | share_name | varchar(255) | YES | | NULL | |
// | quicklink | tinyint(1) | NO | | 0 | |
// | description | varchar(1024) | NO | | | |
// | internal | tinyint(1) | NO | MUL | 0 | |
// | notify_uploads | tinyint(1) | NO | | 0 | |
// | notify_uploads_extra_recipients | varchar(2048) | YES | | NULL | |
// +---------------------------------+-----------------+------+-----+---------+----------------+
type ItemType string

const (
ItemTypeFile ItemType = "file"
ItemTypeFolder ItemType = "folder"
ItemTypeReference ItemType = "reference"
ItemTypeSymlink ItemType = "symlink"
)

func (i ItemType) String() string {
return string(i)
}

type ProtoShare struct {
// Including gorm.Model will embed a number of gorm-default fields
// such as creation_time, id etc
gorm.Model
UIDOwner string
UIDInitiator string
ItemType string // file | folder
ItemType ItemType // file | folder | reference | symlink
InitialPath string
Inode string
FileSource int64
Expand All @@ -66,9 +48,6 @@ type ProtoShare struct {
}

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

ProtoShare
ShareWith string
SharedWithIsGroup bool
Expand All @@ -86,10 +65,9 @@ type PublicLink struct {
ShareName string
}

// Unique index on combo of (shareid, user)
type ShareState struct {
gorm.Model
ShareID uint //foreign key to share
Share Share
// Can not be uid because of lw accs
User string
Synced bool
Expand All @@ -109,7 +87,7 @@ func (s *Share) AsCS3Share(granteeType userpb.UserType) *collaboration.Share {
StorageId: s.Instance,
OpaqueId: s.Inode,
},
Permissions: &collaboration.SharePermissions{Permissions: conversions.IntTosharePerm(int(s.Permissions), s.ItemType)},
Permissions: &collaboration.SharePermissions{Permissions: conversions.IntTosharePerm(int(s.Permissions), s.ItemType.String())},
Grantee: extractGrantee(s.SharedWithIsGroup, s.ShareWith, granteeType),
Owner: conversions.MakeUserID(s.UIDOwner),
Creator: conversions.MakeUserID(s.UIDInitiator),
Expand Down Expand Up @@ -146,8 +124,8 @@ func (p *PublicLink) AsCS3PublicShare() *link.PublicShare {
var expires *typespb.Timestamp
if p.Expiration.Valid {
exp, err := p.Expiration.V.Value()
expiration := exp.(time.Time)
if err == nil {
expiration := exp.(time.Time)
expires = &typespb.Timestamp{
Seconds: uint64(expiration.Unix()),
}
Expand All @@ -162,7 +140,7 @@ func (p *PublicLink) AsCS3PublicShare() *link.PublicShare {
StorageId: p.Instance,
OpaqueId: p.Inode,
},
Permissions: &link.PublicSharePermissions{Permissions: conversions.IntTosharePerm(int(p.Permissions), p.ItemType)},
Permissions: &link.PublicSharePermissions{Permissions: conversions.IntTosharePerm(int(p.Permissions), p.ItemType.String())},
Owner: conversions.MakeUserID(p.UIDOwner),
Creator: conversions.MakeUserID(p.UIDInitiator),
Token: p.Token,
Expand Down
22 changes: 7 additions & 15 deletions share/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (m *mgr) Share(ctx context.Context, md *provider.ResourceInfo, g *collabora
share.UIDOwner = conversions.FormatUserID(md.Owner)
share.UIDInitiator = conversions.FormatUserID(user.Id)
share.InitialPath = md.Path
share.ItemType = conversions.ResourceTypeToItem(md.Type)
share.ItemType = model.ItemType(conversions.ResourceTypeToItem(md.Type))
share.Inode = md.Id.OpaqueId
share.Instance = md.Id.StorageId
share.Permissions = uint8(conversions.SharePermToInt(g.Permissions.Permissions))
Expand Down Expand Up @@ -189,7 +189,6 @@ func (m *mgr) getByID(ctx context.Context, id *collaboration.ShareId) (*model.Sh
// Get Share by Key. Does not return orphans.
func (m *mgr) getByKey(ctx context.Context, key *collaboration.ShareKey, checkOwner bool) (*model.Share, error) {
owner := conversions.FormatUserID(key.Owner)
uid := conversions.FormatUserID(appctx.ContextMustGetUser(ctx).Id)

var share model.Share
_, shareWith := conversions.FormatGrantee(key.Grantee)
Expand All @@ -203,6 +202,7 @@ func (m *mgr) getByKey(ctx context.Context, key *collaboration.ShareKey, checkOw
Where("share_with = ?", strings.ToLower(shareWith))

if checkOwner {
uid := conversions.FormatUserID(appctx.ContextMustGetUser(ctx).Id)
query = query.
Where("uid_owner = ? or uid_initiator = ?", uid, uid)
}
Expand All @@ -222,16 +222,13 @@ func (m *mgr) getShare(ctx context.Context, ref *collaboration.ShareReference) (
switch {
case ref.GetId() != nil:
s, err = m.getByID(ctx, ref.GetId())
if err != nil {
return nil, err
}
case ref.GetKey() != nil:
s, err = m.getByKey(ctx, ref.GetKey(), false)
if err != nil {
return nil, err
}
default:
return nil, errtypes.NotFound(ref.String())
err = errtypes.NotFound(ref.String())
}
if err != nil {
return nil, err
}

user := appctx.ContextMustGetUser(ctx)
Expand All @@ -251,7 +248,7 @@ func (m *mgr) getShare(ctx context.Context, ref *collaboration.ShareReference) (
return s, nil
}

return s, nil
return nil, errtypes.NotFound(ref.String())
}

func (m *mgr) GetShare(ctx context.Context, ref *collaboration.ShareReference) (*collaboration.Share, error) {
Expand Down Expand Up @@ -360,10 +357,6 @@ func (m *mgr) ListShares(ctx context.Context, filters []*collaboration.Filter) (
cs3shares = append(cs3shares, cs3share)
}

if len(shares) > 0 {
fmt.Printf("First cs3share has id %s\n", cs3shares[0].Id.OpaqueId)
}

return cs3shares, nil
}

Expand Down Expand Up @@ -531,7 +524,6 @@ func (m *mgr) UpdateReceivedShare(ctx context.Context, share *collaboration.Rece
case collaboration.ShareState_SHARE_STATE_ACCEPTED:
shareState.Hidden = false
case collaboration.ShareState_SHARE_STATE_REJECTED:
fmt.Printf("Updating share state to hidden\n")
shareState.Hidden = true
}

Expand Down

0 comments on commit d2f446e

Please sign in to comment.