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

[tests-only] [cbox-commit-7]: Revert "Populate owner data in the ocs and ocdav serv… #3056

Merged
merged 2 commits into from
Jul 11, 2022
Merged
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: 0 additions & 3 deletions changelog/1.18.0_2022-02-11/ocs-user-data.md

This file was deleted.

17 changes: 6 additions & 11 deletions internal/http/services/owncloud/ocdav/ocdav.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"strings"
"time"

"github.com/ReneKroon/ttlcache/v2"
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
Expand Down Expand Up @@ -117,12 +116,11 @@ func (c *Config) init() {
}

type svc struct {
c *Config
webDavHandler *WebDavHandler
davHandler *DavHandler
favoritesManager favorite.Manager
client *http.Client
userIdentifierCache *ttlcache.Cache
c *Config
webDavHandler *WebDavHandler
davHandler *DavHandler
favoritesManager favorite.Manager
client *http.Client
}

func getFavoritesManager(c *Config) (favorite.Manager, error) {
Expand Down Expand Up @@ -154,11 +152,8 @@ func New(m map[string]interface{}, log *zerolog.Logger) (global.Service, error)
rhttp.Timeout(time.Duration(conf.Timeout*int64(time.Second))),
rhttp.Insecure(conf.Insecure),
),
favoritesManager: fm,
userIdentifierCache: ttlcache.NewCache(),
favoritesManager: fm,
}
_ = s.userIdentifierCache.SetTTL(60 * time.Second)

// initialize handlers and set default configs
if err := s.webDavHandler.init(conf.WebdavNamespace, true); err != nil {
return nil, err
Expand Down
66 changes: 16 additions & 50 deletions internal/http/services/owncloud/ocdav/propfind.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import (
"github.com/cs3org/reva/internal/http/services/owncloud/ocs/conversions"
"github.com/cs3org/reva/pkg/appctx"
ctxpkg "github.com/cs3org/reva/pkg/ctx"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/publicshare"
"github.com/cs3org/reva/pkg/share"
rtrace "github.com/cs3org/reva/pkg/trace"
Expand Down Expand Up @@ -659,13 +658,6 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
// TODO return other properties ... but how do we put them in a namespace?
} else {
// otherwise return only the requested properties
var ownerUsername, ownerDisplayName string
owner, err := s.getOwnerInfo(ctx, md.Owner)
if err == nil {
ownerUsername = owner.Username
ownerDisplayName = owner.DisplayName
}

for i := range pf.Prop {
switch pf.Prop[i].Space {
case _nsOwncloud:
Expand Down Expand Up @@ -755,8 +747,14 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
propstatNotFound.Prop = append(propstatNotFound.Prop, s.newProp("oc:size", ""))
}
case "owner-id": // phoenix only
if ownerUsername != "" {
propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:owner-id", ownerUsername))
if md.Owner != nil {
if isCurrentUserOwner(ctx, md.Owner) {
u := ctxpkg.ContextMustGetUser(ctx)
propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:owner-id", u.Username))
} else {
sublog.Debug().Msg("TODO fetch user username")
propstatNotFound.Prop = append(propstatNotFound.Prop, s.newProp("oc:owner-id", ""))
}
} else {
propstatNotFound.Prop = append(propstatNotFound.Prop, s.newProp("oc:owner-id", ""))
}
Expand Down Expand Up @@ -838,8 +836,14 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
propstatNotFound.Prop = append(propstatNotFound.Prop, s.newProp("oc:"+pf.Prop[i].Local, ""))
}
case "owner-display-name": // phoenix only
if ownerDisplayName != "" {
propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:owner-display-name", ownerDisplayName))
if md.Owner != nil {
if isCurrentUserOwner(ctx, md.Owner) {
u := ctxpkg.ContextMustGetUser(ctx)
propstatOK.Prop = append(propstatOK.Prop, s.newProp("oc:owner-display-name", u.DisplayName))
} else {
sublog.Debug().Msg("TODO fetch user displayname")
propstatNotFound.Prop = append(propstatNotFound.Prop, s.newProp("oc:owner-display-name", ""))
}
} else {
propstatNotFound.Prop = append(propstatNotFound.Prop, s.newProp("oc:owner-display-name", ""))
}
Expand Down Expand Up @@ -1013,44 +1017,6 @@ func quoteEtag(etag string) string {
return `"` + strings.Trim(etag, `"`) + `"`
}

func (s *svc) getOwnerInfo(ctx context.Context, owner *userv1beta1.UserId) (*userv1beta1.User, error) {
if owner == nil {
return nil, errtypes.NotFound("owner is nil")
}

if isCurrentUserOwner(ctx, owner) {
return ctxpkg.ContextMustGetUser(ctx), nil
}

log := appctx.GetLogger(ctx)
if idIf, err := s.userIdentifierCache.Get(owner.OpaqueId); err == nil {
log.Debug().Msg("cache hit")
return idIf.(*userv1beta1.User), nil
}

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

res, err := client.GetUser(ctx, &userv1beta1.GetUserRequest{UserId: owner})
if err != nil {
log.Err(err).Msg("could not look up user")
return nil, err
}
if res.GetStatus().GetCode() != rpc.Code_CODE_OK {
log.Err(err).Msg("get user call failed")
return nil, err
}
if res.User == nil {
log.Debug().Msg("user not found")
return nil, err
}
_ = s.userIdentifierCache.Set(owner.OpaqueId, res.User)
return res.User, nil
}

// a file is only yours if you are the owner
func isCurrentUserOwner(ctx context.Context, owner *userv1beta1.UserId) bool {
contextUser, ok := ctxpkg.ContextGetUser(ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,7 @@ func (h *Handler) Init(c *config.Config) {
// GetGroups handles GET requests on /cloud/users/groups
// TODO: implement
func (h *Handler) GetGroups(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

user := chi.URLParam(r, "userid")
// FIXME use ldap to fetch user info
u, ok := ctxpkg.ContextGetUser(ctx)
if !ok {
response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "missing user in context", fmt.Errorf("missing user in context"))
return
}
if user != u.Username {
// FIXME allow fetching other users info? only for admins
response.WriteOCSError(w, r, http.StatusForbidden, "user id mismatch", fmt.Errorf("%s tried to access %s user info endpoint", u.Id.OpaqueId, user))
return
}

response.WriteOCSSuccess(w, r, &Groups{Groups: u.Groups})
response.WriteOCSSuccess(w, r, &Groups{})
}

// Quota holds quota information
Expand Down