From ad9587a01d28aa17fcb2af5517ccdcc091cd0cc3 Mon Sep 17 00:00:00 2001 From: Jesse Geens Date: Mon, 13 Jan 2025 09:01:39 +0100 Subject: [PATCH] Resolving more comments on PR --- share/model.go | 2 -- share/sql/sql.go | 38 ++++++++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/share/model.go b/share/model.go index ac65af2..7807a0d 100644 --- a/share/model.go +++ b/share/model.go @@ -38,8 +38,6 @@ type ProtoShare struct { ItemType ItemType // file | folder | reference | symlink InitialPath string Inode string - FileSource int64 - FileTarget string Permissions uint8 Instance string Orphan bool diff --git a/share/sql/sql.go b/share/sql/sql.go index 71b227d..c12bce9 100644 --- a/share/sql/sql.go +++ b/share/sql/sql.go @@ -264,7 +264,21 @@ func (m *mgr) GetShare(ctx context.Context, ref *collaboration.ShareReference) ( } func (m *mgr) Unshare(ctx context.Context, ref *collaboration.ShareReference) error { - share, err := m.getShare(ctx, ref) + var share *model.Share + var err error + if id := ref.GetId(); id != nil { + var intId int + intId, err = strconv.Atoi(id.OpaqueId) + share = &model.Share{ + ProtoShare: model.ProtoShare{ + Model: gorm.Model{ + ID: uint(intId), + }, + }, + } + } else { + share, err = m.getShare(ctx, ref) + } if err != nil { return err } @@ -273,15 +287,27 @@ func (m *mgr) Unshare(ctx context.Context, ref *collaboration.ShareReference) er } func (m *mgr) UpdateShare(ctx context.Context, ref *collaboration.ShareReference, p *collaboration.SharePermissions) (*collaboration.Share, error) { - permissions := conversions.SharePermToInt(p.Permissions) - share, err := m.getShare(ctx, ref) + var share *model.Share + var err error + if id := ref.GetId(); id != nil { + var intId int + intId, err = strconv.Atoi(id.OpaqueId) + share = &model.Share{ + ProtoShare: model.ProtoShare{ + Model: gorm.Model{ + ID: uint(intId), + }, + }, + } + } else { + share, err = m.getShare(ctx, ref) + } if err != nil { return nil, err } - share.Permissions = uint8(permissions) - - res := m.db.Save(&share) + permissions := conversions.SharePermToInt(p.Permissions) + res := m.db.Model(&share).Update("permissions", uint8(permissions)) if res.Error != nil { return nil, res.Error }