Skip to content

Commit

Permalink
Resolving more comments on PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Geens committed Jan 13, 2025
1 parent 5391b34 commit ad9587a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
2 changes: 0 additions & 2 deletions share/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 32 additions & 6 deletions share/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit ad9587a

Please sign in to comment.