From ed3b907f168820ecc1a3e88881e72e9b223833f2 Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Thu, 8 Oct 2020 11:29:57 +0200 Subject: [PATCH] Use string ID in dbShare --- pkg/share/manager/sql/conversions.go | 3 +-- pkg/share/manager/sql/sql.go | 16 +++------------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/pkg/share/manager/sql/conversions.go b/pkg/share/manager/sql/conversions.go index 33abb7c07b2..bfc6fb3aa71 100644 --- a/pkg/share/manager/sql/conversions.go +++ b/pkg/share/manager/sql/conversions.go @@ -20,7 +20,6 @@ package sql import ( "fmt" - "strconv" "strings" userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" @@ -145,7 +144,7 @@ func convertToCS3Share(s dbShare) *collaboration.Share { } return &collaboration.Share{ Id: &collaboration.ShareId{ - OpaqueId: strconv.Itoa(s.ID), + OpaqueId: s.ID, }, ResourceId: &provider.ResourceId{OpaqueId: s.ItemSource, StorageId: s.Prefix}, Permissions: &collaboration.SharePermissions{Permissions: intTosharePerm(s.Permissions)}, diff --git a/pkg/share/manager/sql/sql.go b/pkg/share/manager/sql/sql.go index af56376f71f..5d1e78b5613 100644 --- a/pkg/share/manager/sql/sql.go +++ b/pkg/share/manager/sql/sql.go @@ -59,7 +59,7 @@ type mgr struct { } type dbShare struct { - ID int + ID string UIDOwner string UIDInitiator string Prefix string @@ -172,12 +172,7 @@ func (m *mgr) Share(ctx context.Context, md *provider.ResourceInfo, g *collabora } func (m *mgr) getByID(ctx context.Context, id *collaboration.ShareId) (*collaboration.Share, error) { - intID, err := strconv.ParseInt(id.OpaqueId, 10, 64) - if err != nil { - return nil, err - } - - s := dbShare{ID: int(intID)} + s := dbShare{ID: id.OpaqueId} query := "select coalesce(uid_owner, '') as uid_owner, coalesce(uid_initiator, '') as uid_initiator, coalesce(share_with, '') as share_with, coalesce(fileid_prefix, '') as fileid_prefix, coalesce(item_source, '') as item_source, stime, permissions, share_type FROM oc_share WHERE (orphan = 0 or orphan IS NULL) AND id=?" if err := m.db.QueryRow(query, id.OpaqueId).Scan(&s.UIDOwner, &s.UIDInitiator, &s.ShareWith, &s.Prefix, &s.ItemSource, &s.STime, &s.Permissions, &s.ShareType); err != nil { if err == sql.ErrNoRows { @@ -376,17 +371,12 @@ func (m *mgr) ListReceivedShares(ctx context.Context) ([]*collaboration.Received func (m *mgr) getReceivedByID(ctx context.Context, id *collaboration.ShareId) (*collaboration.ReceivedShare, error) { user := user.ContextMustGetUser(ctx) - intID, err := strconv.ParseInt(id.OpaqueId, 10, 64) - if err != nil { - return nil, err - } - params := []interface{}{id.OpaqueId, formatUserID(user.Id), formatUserID(user.Id)} for _, v := range user.Groups { params = append(params, v) } - s := dbShare{ID: int(intID)} + s := dbShare{ID: id.OpaqueId} query := "select coalesce(uid_owner, '') as uid_owner, coalesce(uid_initiator, '') as uid_initiator, coalesce(share_with, '') as share_with, coalesce(fileid_prefix, '') as fileid_prefix, coalesce(item_source, '') as item_source, stime, permissions, share_type, accepted FROM oc_share WHERE (orphan = 0 or orphan IS NULL) AND id=? AND id not in (SELECT distinct(id) FROM oc_share_acl WHERE rejected_by=?)" if len(user.Groups) > 0 { query += "AND (share_with=? OR share_with in (?" + strings.Repeat(",?", len(user.Groups)-1) + "))"