Skip to content

Commit 51d19ec

Browse files
author
David Christofas
committed
return share-types in ocs propfind responses
Implements owncloud/ocis#929
1 parent b2c4af4 commit 51d19ec

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Enhancement: include share types in ocs propfind responses
2+
3+
Added the share types to the ocs propfind response when a resource has been shared.
4+
5+
https://github.com/owncloud/ocis/issues/929
6+
https://github.com/cs3org/reva/pull/1329

internal/http/services/owncloud/ocdav/propfind.go

+51-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import (
3434
"go.opencensus.io/trace"
3535

3636
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
37+
collaborationv1beta1 "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
38+
linkv1beta1 "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1"
3739
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
3840
"github.com/cs3org/reva/internal/http/services/owncloud/ocs/conversions"
3941
"github.com/cs3org/reva/pkg/appctx"
@@ -283,6 +285,44 @@ func (s *svc) newProp(key, val string) *propertyXML {
283285
// ns is the CS3 namespace that needs to be removed from the CS3 path before
284286
// prefixing it with the baseURI
285287
func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provider.ResourceInfo, ns string) (*responseXML, error) {
288+
log := appctx.GetLogger(ctx)
289+
290+
client, err := s.getClient()
291+
if err != nil {
292+
log.Error().Err(err).Msg("error getting grpc client")
293+
return nil, err
294+
}
295+
296+
lsReq := &collaborationv1beta1.ListSharesRequest{
297+
Filters: []*collaborationv1beta1.ListSharesRequest_Filter{
298+
{
299+
Type: collaborationv1beta1.ListSharesRequest_Filter_TYPE_RESOURCE_ID,
300+
Term: &collaborationv1beta1.ListSharesRequest_Filter_ResourceId{
301+
ResourceId: md.Id,
302+
},
303+
},
304+
},
305+
}
306+
lsResp, err := client.ListShares(ctx, lsReq)
307+
if err != nil {
308+
log.Error().Err(err).Msg("error getting shares")
309+
}
310+
311+
lpsReq := &linkv1beta1.ListPublicSharesRequest{
312+
Filters: []*linkv1beta1.ListPublicSharesRequest_Filter{
313+
{
314+
Type: linkv1beta1.ListPublicSharesRequest_Filter_TYPE_RESOURCE_ID,
315+
Term: &linkv1beta1.ListPublicSharesRequest_Filter_ResourceId{
316+
ResourceId: md.Id,
317+
},
318+
},
319+
},
320+
}
321+
322+
lpsResp, err := client.ListPublicShares(ctx, lpsReq)
323+
if err != nil {
324+
log.Error().Err(err).Msg("error getting public shares")
325+
}
286326

287327
md.Path = strings.TrimPrefix(md.Path, ns)
288328

@@ -462,7 +502,17 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
462502
// <oc:share-types>
463503
// <oc:share-type>1</oc:share-type>
464504
// </oc:share-types>
465-
fallthrough
505+
var types []string
506+
if lpsResp.Status.Code == rpc.Code_CODE_OK && len(lpsResp.Share) != 0 {
507+
types = append(types, fmt.Sprintf("<oc:share-type>%d</oc:share-type>", conversions.ShareTypePublicLink))
508+
}
509+
if lsResp.Status.Code == rpc.Code_CODE_OK && len(lsResp.Shares) != 0 {
510+
types = append(types, fmt.Sprintf("<oc:share-type>%d</oc:share-type>", conversions.ShareTypeUser))
511+
}
512+
513+
if len(types) > 0 {
514+
propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:share-types", strings.Join(types, "")))
515+
}
466516
default:
467517
propstatNotFound.Prop = append(propstatNotFound.Prop, s.newProp("oc:"+pf.Prop[i].Local, ""))
468518
}

0 commit comments

Comments
 (0)