Skip to content

Commit

Permalink
return share-types in ocs propfind responses
Browse files Browse the repository at this point in the history
  • Loading branch information
David Christofas committed Nov 23, 2020
1 parent b2c4af4 commit 51d19ec
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
6 changes: 6 additions & 0 deletions changelog/unreleased/ocis-ocs-share-types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: include share types in ocs propfind responses

Added the share types to the ocs propfind response when a resource has been shared.

https://github.com/owncloud/ocis/issues/929
https://github.com/cs3org/reva/pull/1329
52 changes: 51 additions & 1 deletion internal/http/services/owncloud/ocdav/propfind.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (
"go.opencensus.io/trace"

rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
collaborationv1beta1 "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
linkv1beta1 "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/internal/http/services/owncloud/ocs/conversions"
"github.com/cs3org/reva/pkg/appctx"
Expand Down Expand Up @@ -283,6 +285,44 @@ func (s *svc) newProp(key, val string) *propertyXML {
// ns is the CS3 namespace that needs to be removed from the CS3 path before
// prefixing it with the baseURI
func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provider.ResourceInfo, ns string) (*responseXML, error) {
log := appctx.GetLogger(ctx)

client, err := s.getClient()
if err != nil {
log.Error().Err(err).Msg("error getting grpc client")
return nil, err
}

lsReq := &collaborationv1beta1.ListSharesRequest{
Filters: []*collaborationv1beta1.ListSharesRequest_Filter{
{
Type: collaborationv1beta1.ListSharesRequest_Filter_TYPE_RESOURCE_ID,
Term: &collaborationv1beta1.ListSharesRequest_Filter_ResourceId{
ResourceId: md.Id,
},
},
},
}
lsResp, err := client.ListShares(ctx, lsReq)
if err != nil {
log.Error().Err(err).Msg("error getting shares")
}

lpsReq := &linkv1beta1.ListPublicSharesRequest{
Filters: []*linkv1beta1.ListPublicSharesRequest_Filter{
{
Type: linkv1beta1.ListPublicSharesRequest_Filter_TYPE_RESOURCE_ID,
Term: &linkv1beta1.ListPublicSharesRequest_Filter_ResourceId{
ResourceId: md.Id,
},
},
},
}

lpsResp, err := client.ListPublicShares(ctx, lpsReq)
if err != nil {
log.Error().Err(err).Msg("error getting public shares")
}

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

Expand Down Expand Up @@ -462,7 +502,17 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
// <oc:share-types>
// <oc:share-type>1</oc:share-type>
// </oc:share-types>
fallthrough
var types []string
if lpsResp.Status.Code == rpc.Code_CODE_OK && len(lpsResp.Share) != 0 {
types = append(types, fmt.Sprintf("<oc:share-type>%d</oc:share-type>", conversions.ShareTypePublicLink))
}
if lsResp.Status.Code == rpc.Code_CODE_OK && len(lsResp.Shares) != 0 {
types = append(types, fmt.Sprintf("<oc:share-type>%d</oc:share-type>", conversions.ShareTypeUser))
}

if len(types) > 0 {
propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:share-types", strings.Join(types, "")))
}
default:
propstatNotFound.Prop = append(propstatNotFound.Prop, s.newProp("oc:"+pf.Prop[i].Local, ""))
}
Expand Down

0 comments on commit 51d19ec

Please sign in to comment.