diff --git a/changelog/unreleased/ocis-ocs-share-types.md b/changelog/unreleased/ocis-ocs-share-types.md new file mode 100644 index 00000000000..c185458b644 --- /dev/null +++ b/changelog/unreleased/ocis-ocs-share-types.md @@ -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 diff --git a/internal/http/services/owncloud/ocdav/propfind.go b/internal/http/services/owncloud/ocdav/propfind.go index e6fbdd591f3..2b104a5472d 100644 --- a/internal/http/services/owncloud/ocdav/propfind.go +++ b/internal/http/services/owncloud/ocdav/propfind.go @@ -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" @@ -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) @@ -462,7 +502,17 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide // // 1 // - fallthrough + var types []string + if lpsResp.Status.Code == rpc.Code_CODE_OK && len(lpsResp.Share) != 0 { + types = append(types, fmt.Sprintf("%d", conversions.ShareTypePublicLink)) + } + if lsResp.Status.Code == rpc.Code_CODE_OK && len(lsResp.Shares) != 0 { + types = append(types, fmt.Sprintf("%d", 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, "")) }