From d2f446e4f5ea4119509e535ca6c22be05e0ea562 Mon Sep 17 00:00:00 2001 From: Jesse Geens Date: Thu, 9 Jan 2025 14:06:43 +0100 Subject: [PATCH] resolving comments on PR --- go.mod | 2 +- share/model.go | 56 +++++++++++++++--------------------------------- share/sql/sql.go | 22 ++++++------------- 3 files changed, 25 insertions(+), 55 deletions(-) diff --git a/go.mod b/go.mod index d25d1f3..e691c45 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/share/model.go b/share/model.go index 8621398..56d4609 100644 --- a/share/model.go +++ b/share/model.go @@ -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 @@ -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 @@ -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 @@ -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), @@ -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()), } @@ -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, diff --git a/share/sql/sql.go b/share/sql/sql.go index 4f3924f..dd8d443 100644 --- a/share/sql/sql.go +++ b/share/sql/sql.go @@ -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)) @@ -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) @@ -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) } @@ -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) @@ -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) { @@ -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 } @@ -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 }