Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle removal of public shares by token or ID #1334

Merged
merged 2 commits into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}