Skip to content

Commit

Permalink
Use string ID in dbShare
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Nov 9, 2020
1 parent 3197eb0 commit fc30778
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
3 changes: 1 addition & 2 deletions pkg/share/manager/sql/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package sql

import (
"fmt"
"strconv"
"strings"

userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
Expand Down Expand Up @@ -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)},
Expand Down
16 changes: 3 additions & 13 deletions pkg/share/manager/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type mgr struct {
}

type dbShare struct {
ID int
ID string
UIDOwner string
UIDInitiator string
Prefix string
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) + "))"
Expand Down

0 comments on commit fc30778

Please sign in to comment.