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

Make user share indicators read from the share provider service #2929

Open
wants to merge 2 commits into
base: edge
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions changelog/unreleased/user-share-indicators.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Enhancement: Make user share indicators read from the share provider service

https://github.com/cs3org/reva/pull/2929
39 changes: 29 additions & 10 deletions internal/http/services/owncloud/ocdav/propfind/propfind.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (

gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/v2/internal/grpc/services/storageprovider"
Expand All @@ -46,6 +47,7 @@ import (
ctxpkg "github.com/cs3org/reva/v2/pkg/ctx"
"github.com/cs3org/reva/v2/pkg/publicshare"
"github.com/cs3org/reva/v2/pkg/rhttp/router"
"github.com/cs3org/reva/v2/pkg/share"
"github.com/cs3org/reva/v2/pkg/storagespace"
rtrace "github.com/cs3org/reva/v2/pkg/trace"
"github.com/cs3org/reva/v2/pkg/utils"
Expand Down Expand Up @@ -290,10 +292,11 @@ func (p *Handler) propfindResponse(ctx context.Context, w http.ResponseWriter, r
ctx, span := rtrace.Provider.Tracer("ocdav").Start(ctx, "propfind_response")
defer span.End()

filters := make([]*link.ListPublicSharesRequest_Filter, 0, len(resourceInfos))
linkFilters := make([]*link.ListPublicSharesRequest_Filter, 0, len(resourceInfos))
shareFilters := make([]*collaboration.Filter, 0, len(resourceInfos))
for i := range resourceInfos {
// the list of filters grows with every public link in a folder
filters = append(filters, publicshare.ResourceIDFilter(resourceInfos[i].Id))
linkFilters = append(linkFilters, publicshare.ResourceIDFilter(resourceInfos[i].Id))
shareFilters = append(shareFilters, share.ResourceIDFilter(resourceInfos[i].Id))
}

client, err := p.getClient()
Expand All @@ -306,19 +309,31 @@ func (p *Handler) propfindResponse(ctx context.Context, w http.ResponseWriter, r
var linkshares map[string]struct{}
// public link access does not show share-types
if namespace != "/public" {
listResp, err := client.ListPublicShares(ctx, &link.ListPublicSharesRequest{Filters: filters})
listResp, err := client.ListPublicShares(ctx, &link.ListPublicSharesRequest{Filters: linkFilters})
if err == nil {
linkshares = make(map[string]struct{}, len(listResp.Share))
for i := range listResp.Share {
linkshares[listResp.Share[i].ResourceId.OpaqueId] = struct{}{}
linkshares[storagespace.FormatResourceID(*listResp.Share[i].ResourceId)] = struct{}{}
}
} else {
log.Error().Err(err).Msg("propfindResponse: couldn't list public shares")
span.SetStatus(codes.Error, err.Error())
}
}

propRes, err := MultistatusResponse(ctx, &pf, resourceInfos, p.PublicURL, namespace, spaceType, linkshares)
var usershares map[string]struct{}
listSharesResp, err := client.ListShares(ctx, &collaboration.ListSharesRequest{Filters: shareFilters})
if err == nil {
usershares = make(map[string]struct{}, len(listSharesResp.Shares))
for i := range listSharesResp.Shares {
usershares[storagespace.FormatResourceID(*listSharesResp.Shares[i].ResourceId)] = struct{}{}
}
} else {
log.Error().Err(err).Msg("propfindResponse: couldn't list user shares")
span.SetStatus(codes.Error, err.Error())
}

propRes, err := MultistatusResponse(ctx, &pf, resourceInfos, p.PublicURL, namespace, spaceType, usershares, linkshares)
if err != nil {
log.Error().Err(err).Msg("error formatting propfind")
w.WriteHeader(http.StatusInternalServerError)
Expand Down Expand Up @@ -672,10 +687,10 @@ func ReadPropfind(r io.Reader) (pf XML, status int, err error) {
}

// MultistatusResponse converts a list of resource infos into a multistatus response string
func MultistatusResponse(ctx context.Context, pf *XML, mds []*provider.ResourceInfo, publicURL, ns, spaceType string, linkshares map[string]struct{}) ([]byte, error) {
func MultistatusResponse(ctx context.Context, pf *XML, mds []*provider.ResourceInfo, publicURL, ns, spaceType string, usershares, linkshares map[string]struct{}) ([]byte, error) {
responses := make([]*ResponseXML, 0, len(mds))
for i := range mds {
res, err := mdToPropResponse(ctx, pf, mds[i], publicURL, ns, spaceType, linkshares)
res, err := mdToPropResponse(ctx, pf, mds[i], publicURL, ns, spaceType, usershares, linkshares)
if err != nil {
return nil, err
}
Expand All @@ -694,7 +709,7 @@ func MultistatusResponse(ctx context.Context, pf *XML, mds []*provider.ResourceI
// mdToPropResponse converts the CS3 metadata into a webdav PropResponse
// ns is the CS3 namespace that needs to be removed from the CS3 path before
// prefixing it with the baseURI
func mdToPropResponse(ctx context.Context, pf *XML, md *provider.ResourceInfo, publicURL, ns, spaceType string, linkshares map[string]struct{}) (*ResponseXML, error) {
func mdToPropResponse(ctx context.Context, pf *XML, md *provider.ResourceInfo, publicURL, ns, spaceType string, usershares, linkshares map[string]struct{}) (*ResponseXML, error) {
sublog := appctx.GetLogger(ctx).With().Interface("md", md).Str("ns", ns).Logger()
md.Path = strings.TrimPrefix(md.Path, ns)

Expand Down Expand Up @@ -1036,10 +1051,14 @@ func mdToPropResponse(ctx context.Context, pf *XML, md *provider.ResourceInfo, p
types.WriteString("<oc:share-type>")
types.WriteString(amdv)
types.WriteString("</oc:share-type>")
} else if md.Id != nil {
if _, ok := usershares[storagespace.FormatResourceID(*md.Id)]; ok {
types.WriteString("<oc:share-type>0</oc:share-type>")
}
}

if md.Id != nil {
if _, ok := linkshares[md.Id.OpaqueId]; ok {
if _, ok := linkshares[storagespace.FormatResourceID(*md.Id)]; ok {
types.WriteString("<oc:share-type>3</oc:share-type>")
}
}
Expand Down
27 changes: 27 additions & 0 deletions internal/http/services/owncloud/ocdav/propfind/propfind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"strings"

gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1"
sprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
Expand Down Expand Up @@ -277,6 +278,32 @@ var _ = Describe("Propfind", func() {
Share: shares,
}
}, nil)

client.On("ListShares", mock.Anything, mock.Anything).Return(
func(_ context.Context, req *collaboration.ListSharesRequest, _ ...grpc.CallOption) *collaboration.ListSharesResponse {

var shares []*collaboration.Share
if len(req.Filters) == 0 {
shares = []*collaboration.Share{}
} else {
term := req.Filters[0].Term.(*collaboration.Filter_ResourceId)
switch {
case term != nil && term.ResourceId != nil && term.ResourceId.OpaqueId == "foospacebar":
shares = []*collaboration.Share{
{
Id: &collaboration.ShareId{OpaqueId: "share1"},
ResourceId: &sprovider.ResourceId{StorageId: "foospace", OpaqueId: "foospacebar"},
},
}
default:
shares = []*collaboration.Share{}
}
}
return &collaboration.ListSharesResponse{
Status: status.NewOK(ctx),
Shares: shares,
}
}, nil)
})

Describe("NewHandler", func() {
Expand Down
2 changes: 1 addition & 1 deletion internal/http/services/owncloud/ocdav/publicfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (s *svc) handlePropfindOnToken(w http.ResponseWriter, r *http.Request, ns s

infos := s.getPublicFileInfos(onContainer, depth == net.DepthZero, tokenStatInfo)

propRes, err := propfind.MultistatusResponse(ctx, &pf, infos, s.c.PublicURL, ns, "", nil)
propRes, err := propfind.MultistatusResponse(ctx, &pf, infos, s.c.PublicURL, ns, "", nil, nil)
if err != nil {
sublog.Error().Err(err).Msg("error formatting propfind")
w.WriteHeader(http.StatusInternalServerError)
Expand Down
2 changes: 1 addition & 1 deletion internal/http/services/owncloud/ocdav/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (s *svc) doFilterFiles(w http.ResponseWriter, r *http.Request, ff *reportFi
infos = append(infos, statRes.Info)
}

responsesXML, err := propfind.MultistatusResponse(ctx, &propfind.XML{Prop: ff.Prop}, infos, s.c.PublicURL, namespace, "", nil)
responsesXML, err := propfind.MultistatusResponse(ctx, &propfind.XML{Prop: ff.Prop}, infos, s.c.PublicURL, namespace, "", nil, nil)
if err != nil {
log.Error().Err(err).Msg("error formatting propfind")
w.WriteHeader(http.StatusInternalServerError)
Expand Down
2 changes: 1 addition & 1 deletion internal/http/services/owncloud/ocdav/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (h *VersionsHandler) doListVersions(w http.ResponseWriter, r *http.Request,
infos = append(infos, vi)
}

propRes, err := propfind.MultistatusResponse(ctx, &pf, infos, s.c.PublicURL, "", "", nil)
propRes, err := propfind.MultistatusResponse(ctx, &pf, infos, s.c.PublicURL, "", "", nil, nil)
if err != nil {
sublog.Error().Err(err).Msg("error formatting propfind")
w.WriteHeader(http.StatusInternalServerError)
Expand Down
1 change: 0 additions & 1 deletion pkg/cbox/publicshare/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ func (m *manager) ListPublicShares(ctx context.Context, u *user.User, filters []
var resourceFilters, ownerFilters, creatorFilters string
var resourceParams, ownerParams, creatorParams []interface{}
params := []interface{}{uid, uid, publicShareType}

for _, f := range filters {
switch f.Type {
case link.ListPublicSharesRequest_Filter_TYPE_RESOURCE_ID:
Expand Down