Skip to content

Commit

Permalink
Handle removal of public shares by token or ID (#1334)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 authored Nov 24, 2020
1 parent a7b3cb9 commit 1e6ca25
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
7 changes: 7 additions & 0 deletions changelog/unreleased/remove-public-share-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Bugfix: Handle removal of public shares by token or ID

Previously different drivers handled removing public shares using different
means, either the token or the ID. Now, both the drivers support both these
methods.

https://github.com/cs3org/reva/pull/1334
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (s *service) RemovePublicShare(ctx context.Context, req *link.RemovePublicS
log.Info().Str("publicshareprovider", "remove").Msg("remove public share")

user := user.ContextMustGetUser(ctx)
err := s.sm.RevokePublicShare(ctx, user, req.Ref.GetId().OpaqueId)
err := s.sm.RevokePublicShare(ctx, user, req.Ref)
if err != nil {
return &link.RemovePublicShareResponse{
Status: status.NewInternal(ctx, err, "error deleting public share"),
Expand Down
15 changes: 13 additions & 2 deletions pkg/publicshare/manager/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func (m *manager) ListPublicShares(ctx context.Context, u *user.User, filters []
}

// RevokePublicShare undocumented.
func (m *manager) RevokePublicShare(ctx context.Context, u *user.User, id string) error {
func (m *manager) RevokePublicShare(ctx context.Context, u *user.User, ref *link.PublicShareReference) error {
m.mutex.Lock()
defer m.mutex.Unlock()

Expand All @@ -370,7 +370,18 @@ func (m *manager) RevokePublicShare(ctx context.Context, u *user.User, id string
return err
}

delete(db, id)
switch {
case ref.GetId().OpaqueId != "":
delete(db, ref.GetId().OpaqueId)
case ref.GetToken() != "":
share, err := m.getByToken(ctx, ref.GetToken())
if err != nil {
return err
}
delete(db, share.Id.OpaqueId)
default:
return errors.New("reference does not exist")
}

return m.writeDb(db)
}
Expand Down
19 changes: 15 additions & 4 deletions pkg/publicshare/manager/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,24 @@ func (m *manager) ListPublicShares(ctx context.Context, u *user.User, filters []
return shares, nil
}

func (m *manager) RevokePublicShare(ctx context.Context, u *user.User, id string) (err error) {
func (m *manager) RevokePublicShare(ctx context.Context, u *user.User, ref *link.PublicShareReference) error {
// check whether the reference exists
if _, err := m.GetPublicShareByToken(ctx, id, ""); err != nil {
switch {
case ref.GetId().OpaqueId != "":
s, err := m.getPublicShareByTokenID(ctx, *ref.GetId())
if err != nil {
return errors.New("reference does not exist")
}
m.shares.Delete(s.Token)
case ref.GetToken() != "":
if _, err := m.GetPublicShareByToken(ctx, ref.GetToken(), ""); err != nil {
return errors.New("reference does not exist")
}
m.shares.Delete(ref.GetToken())
default:
return errors.New("reference does not exist")
}
m.shares.Delete(id)
return
return nil
}

func (m *manager) GetPublicShareByToken(ctx context.Context, token string, password string) (*link.PublicShare, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/publicshare/publicshare.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ type Manager interface {
UpdatePublicShare(ctx context.Context, u *user.User, req *link.UpdatePublicShareRequest, g *link.Grant) (*link.PublicShare, error)
GetPublicShare(ctx context.Context, u *user.User, ref *link.PublicShareReference) (*link.PublicShare, error)
ListPublicShares(ctx context.Context, u *user.User, filters []*link.ListPublicSharesRequest_Filter, md *provider.ResourceInfo) ([]*link.PublicShare, error)
RevokePublicShare(ctx context.Context, u *user.User, id string) error
RevokePublicShare(ctx context.Context, u *user.User, ref *link.PublicShareReference) error
GetPublicShareByToken(ctx context.Context, token, password string) (*link.PublicShare, error)
}

0 comments on commit 1e6ca25

Please sign in to comment.