Skip to content

Commit

Permalink
fix permissions in propfind reponses (#2713)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Christofas authored Apr 5, 2022
1 parent 19fd0b2 commit 25d1edb
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/fix-permissions-propfind.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Fix the permissions attribute in propfind responses

Fixed the permissions that are returned when doing a propfind on a project space.

https://github.com/owncloud/ocis/issues/3373
https://github.com/cs3org/reva/pull/2713
20 changes: 12 additions & 8 deletions internal/http/services/owncloud/ocdav/propfind/propfind.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ import (

//go:generate make --no-print-directory -C ../../../../../.. mockery NAME=GatewayClient

const (
_spaceTypeProject = "project"
)

type countingReader struct {
n int
r io.Reader
Expand Down Expand Up @@ -217,7 +221,7 @@ func (p *Handler) HandlePathPropfind(w http.ResponseWriter, r *http.Request, ns
// getResourceInfos handles responses in case of an error so we can just return here.
return
}
p.propfindResponse(ctx, w, r, ns, pf, sendTusHeaders, resourceInfos, sublog)
p.propfindResponse(ctx, w, r, ns, spaces[0].SpaceType, pf, sendTusHeaders, resourceInfos, sublog)
}

// HandleSpacesPropfind handles a spaces based propfind request
Expand Down Expand Up @@ -264,11 +268,11 @@ func (p *Handler) HandleSpacesPropfind(w http.ResponseWriter, r *http.Request, s
resourceInfos[i].Path = path.Join("/", spaceID, resourceInfos[i].Path)
}

p.propfindResponse(ctx, w, r, "", pf, sendTusHeaders, resourceInfos, sublog)
p.propfindResponse(ctx, w, r, "", space.SpaceType, pf, sendTusHeaders, resourceInfos, sublog)

}

func (p *Handler) propfindResponse(ctx context.Context, w http.ResponseWriter, r *http.Request, namespace string, pf XML, sendTusHeaders bool, resourceInfos []*provider.ResourceInfo, log zerolog.Logger) {
func (p *Handler) propfindResponse(ctx context.Context, w http.ResponseWriter, r *http.Request, namespace, spaceType string, pf XML, sendTusHeaders bool, resourceInfos []*provider.ResourceInfo, log zerolog.Logger) {
ctx, span := rtrace.Provider.Tracer("ocdav").Start(ctx, "propfind_response")
defer span.End()

Expand Down Expand Up @@ -300,7 +304,7 @@ func (p *Handler) propfindResponse(ctx context.Context, w http.ResponseWriter, r
}
}

propRes, err := MultistatusResponse(ctx, &pf, resourceInfos, p.PublicURL, namespace, linkshares)
propRes, err := MultistatusResponse(ctx, &pf, resourceInfos, p.PublicURL, namespace, spaceType, linkshares)
if err != nil {
log.Error().Err(err).Msg("error formatting propfind")
w.WriteHeader(http.StatusInternalServerError)
Expand Down Expand Up @@ -638,10 +642,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 string, linkshares map[string]struct{}) ([]byte, error) {
func MultistatusResponse(ctx context.Context, pf *XML, mds []*provider.ResourceInfo, publicURL, ns, spaceType string, 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, linkshares)
res, err := mdToPropResponse(ctx, pf, mds[i], publicURL, ns, spaceType, linkshares)
if err != nil {
return nil, err
}
Expand All @@ -660,7 +664,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 string, linkshares map[string]struct{}) (*ResponseXML, error) {
func mdToPropResponse(ctx context.Context, pf *XML, md *provider.ResourceInfo, publicURL, ns, spaceType string, 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 @@ -708,7 +712,7 @@ func mdToPropResponse(ctx context.Context, pf *XML, md *provider.ResourceInfo, p

role := conversions.RoleFromResourcePermissions(md.PermissionSet)

isShared := !net.IsCurrentUserOwner(ctx, md.Owner)
isShared := spaceType != _spaceTypeProject && !net.IsCurrentUserOwner(ctx, md.Owner)
var wdp string
isPublic := ls != nil
if md.PermissionSet != nil {
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)
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 @@ -115,7 +115,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)
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 @@ -165,7 +165,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)
if err != nil {
sublog.Error().Err(err).Msg("error formatting propfind")
w.WriteHeader(http.StatusInternalServerError)
Expand Down

0 comments on commit 25d1edb

Please sign in to comment.