@@ -42,7 +42,6 @@ import (
42
42
"github.com/cs3org/reva/internal/http/services/owncloud/ocs/conversions"
43
43
"github.com/cs3org/reva/pkg/appctx"
44
44
ctxpkg "github.com/cs3org/reva/pkg/ctx"
45
- "github.com/cs3org/reva/pkg/errtypes"
46
45
"github.com/cs3org/reva/pkg/publicshare"
47
46
"github.com/cs3org/reva/pkg/share"
48
47
rtrace "github.com/cs3org/reva/pkg/trace"
@@ -659,13 +658,6 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
659
658
// TODO return other properties ... but how do we put them in a namespace?
660
659
} else {
661
660
// otherwise return only the requested properties
662
- var ownerUsername , ownerDisplayName string
663
- owner , err := s .getOwnerInfo (ctx , md .Owner )
664
- if err == nil {
665
- ownerUsername = owner .Username
666
- ownerDisplayName = owner .DisplayName
667
- }
668
-
669
661
for i := range pf .Prop {
670
662
switch pf .Prop [i ].Space {
671
663
case _nsOwncloud :
@@ -755,8 +747,14 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
755
747
propstatNotFound .Prop = append (propstatNotFound .Prop , s .newProp ("oc:size" , "" ))
756
748
}
757
749
case "owner-id" : // phoenix only
758
- if ownerUsername != "" {
759
- propstatOK .Prop = append (propstatOK .Prop , s .newProp ("oc:owner-id" , ownerUsername ))
750
+ if md .Owner != nil {
751
+ if isCurrentUserOwner (ctx , md .Owner ) {
752
+ u := ctxpkg .ContextMustGetUser (ctx )
753
+ propstatOK .Prop = append (propstatOK .Prop , s .newProp ("oc:owner-id" , u .Username ))
754
+ } else {
755
+ sublog .Debug ().Msg ("TODO fetch user username" )
756
+ propstatNotFound .Prop = append (propstatNotFound .Prop , s .newProp ("oc:owner-id" , "" ))
757
+ }
760
758
} else {
761
759
propstatNotFound .Prop = append (propstatNotFound .Prop , s .newProp ("oc:owner-id" , "" ))
762
760
}
@@ -838,8 +836,14 @@ func (s *svc) mdToPropResponse(ctx context.Context, pf *propfindXML, md *provide
838
836
propstatNotFound .Prop = append (propstatNotFound .Prop , s .newProp ("oc:" + pf .Prop [i ].Local , "" ))
839
837
}
840
838
case "owner-display-name" : // phoenix only
841
- if ownerDisplayName != "" {
842
- propstatOK .Prop = append (propstatOK .Prop , s .newProp ("oc:owner-display-name" , ownerDisplayName ))
839
+ if md .Owner != nil {
840
+ if isCurrentUserOwner (ctx , md .Owner ) {
841
+ u := ctxpkg .ContextMustGetUser (ctx )
842
+ propstatOK .Prop = append (propstatOK .Prop , s .newProp ("oc:owner-display-name" , u .DisplayName ))
843
+ } else {
844
+ sublog .Debug ().Msg ("TODO fetch user displayname" )
845
+ propstatNotFound .Prop = append (propstatNotFound .Prop , s .newProp ("oc:owner-display-name" , "" ))
846
+ }
843
847
} else {
844
848
propstatNotFound .Prop = append (propstatNotFound .Prop , s .newProp ("oc:owner-display-name" , "" ))
845
849
}
@@ -1013,44 +1017,6 @@ func quoteEtag(etag string) string {
1013
1017
return `"` + strings .Trim (etag , `"` ) + `"`
1014
1018
}
1015
1019
1016
- func (s * svc ) getOwnerInfo (ctx context.Context , owner * userv1beta1.UserId ) (* userv1beta1.User , error ) {
1017
- if owner == nil {
1018
- return nil , errtypes .NotFound ("owner is nil" )
1019
- }
1020
-
1021
- if isCurrentUserOwner (ctx , owner ) {
1022
- return ctxpkg .ContextMustGetUser (ctx ), nil
1023
- }
1024
-
1025
- log := appctx .GetLogger (ctx )
1026
- if idIf , err := s .userIdentifierCache .Get (owner .OpaqueId ); err == nil {
1027
- log .Debug ().Msg ("cache hit" )
1028
- return idIf .(* userv1beta1.User ), nil
1029
- }
1030
-
1031
- client , err := s .getClient ()
1032
- if err != nil {
1033
- log .Error ().Err (err ).Msg ("error getting grpc client" )
1034
- return nil , err
1035
- }
1036
-
1037
- res , err := client .GetUser (ctx , & userv1beta1.GetUserRequest {UserId : owner })
1038
- if err != nil {
1039
- log .Err (err ).Msg ("could not look up user" )
1040
- return nil , err
1041
- }
1042
- if res .GetStatus ().GetCode () != rpc .Code_CODE_OK {
1043
- log .Err (err ).Msg ("get user call failed" )
1044
- return nil , err
1045
- }
1046
- if res .User == nil {
1047
- log .Debug ().Msg ("user not found" )
1048
- return nil , err
1049
- }
1050
- _ = s .userIdentifierCache .Set (owner .OpaqueId , res .User )
1051
- return res .User , nil
1052
- }
1053
-
1054
1020
// a file is only yours if you are the owner
1055
1021
func isCurrentUserOwner (ctx context.Context , owner * userv1beta1.UserId ) bool {
1056
1022
contextUser , ok := ctxpkg .ContextGetUser (ctx )
0 commit comments