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

fix ocs sharing #580

Merged
merged 1 commit into from
Mar 19, 2020
Merged
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
98 changes: 80 additions & 18 deletions internal/http/services/owncloud/ocs/shares.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,21 @@ func (h *SharesHandler) createShare(w http.ResponseWriter, r *http.Request) {
return
}

sClient, err := pool.GetGatewayServiceClient(h.gatewayAddr)
if err != nil {
WriteOCSError(w, r, MetaServerError.StatusCode, "error getting storage grpc client", err)
return
}

// prefix the path with the owners home, because ocs share requests are relative to the home dir
// TODO the path actually depends on the configured webdav_namespace
hRes, err := sClient.GetHome(ctx, &provider.GetHomeRequest{})
if err != nil {
WriteOCSError(w, r, MetaServerError.StatusCode, "error sending a grpc get home request", err)
return
}
prefix := hRes.GetPath()

if shareType == int(conversions.ShareTypeUser) {

// if user sharing is disabled
Expand Down Expand Up @@ -222,16 +237,10 @@ func (h *SharesHandler) createShare(w http.ResponseWriter, r *http.Request) {
return
}

sClient, err := pool.GetGatewayServiceClient(h.gatewayAddr)
if err != nil {
WriteOCSError(w, r, MetaServerError.StatusCode, "error getting storage grpc client", err)
return
}

statReq := &provider.StatRequest{
Ref: &provider.Reference{
Spec: &provider.Reference_Path{
Path: r.FormValue("path"),
Path: path.Join(prefix, r.FormValue("path")),
},
},
}
Expand Down Expand Up @@ -308,7 +317,7 @@ func (h *SharesHandler) createShare(w http.ResponseWriter, r *http.Request) {
statReq := provider.StatRequest{
Ref: &provider.Reference{
Spec: &provider.Reference_Path{
Path: r.FormValue("path"),
Path: path.Join(prefix, r.FormValue("path")),
},
},
}
Expand Down Expand Up @@ -610,7 +619,21 @@ func (h *SharesHandler) listShares(w http.ResponseWriter, r *http.Request) {
// shared with others
p := r.URL.Query().Get("path")
if p != "" {
filters, err = h.addFilters(w, r)
sClient, err := pool.GetGatewayServiceClient(h.gatewayAddr)
if err != nil {
WriteOCSError(w, r, MetaServerError.StatusCode, "error getting storage grpc client", err)
return
}

// prefix the path with the owners home, because ocs share requests are relative to the home dir
// TODO the path actually depends on the configured webdav_namespace
hRes, err := sClient.GetHome(r.Context(), &provider.GetHomeRequest{})
if err != nil {
WriteOCSError(w, r, MetaServerError.StatusCode, "error sending a grpc get home request", err)
return
}

filters, err = h.addFilters(w, r, hRes.GetPath())
if err != nil {
WriteOCSError(w, r, MetaServerError.StatusCode, err.Error(), err)
return
Expand Down Expand Up @@ -716,7 +739,7 @@ func (h *SharesHandler) listPublicShares(r *http.Request) ([]*conversions.ShareD
return nil, errors.New("bad request")
}

func (h *SharesHandler) addFilters(w http.ResponseWriter, r *http.Request) ([]*collaboration.ListSharesRequest_Filter, error) {
func (h *SharesHandler) addFilters(w http.ResponseWriter, r *http.Request, prefix string) ([]*collaboration.ListSharesRequest_Filter, error) {
filters := []*collaboration.ListSharesRequest_Filter{}
var info *provider.ResourceInfo
ctx := r.Context()
Expand All @@ -728,10 +751,12 @@ func (h *SharesHandler) addFilters(w http.ResponseWriter, r *http.Request) ([]*c
return nil, err
}

target := path.Join(prefix, r.FormValue("path"))

statReq := &provider.StatRequest{
Ref: &provider.Reference{
Spec: &provider.Reference_Path{
Path: r.FormValue("path"),
Path: target,
},
},
}
Expand Down Expand Up @@ -843,7 +868,7 @@ func (h *SharesHandler) addFileInfo(ctx context.Context, s *conversions.ShareDat
s.ItemSource = info.Id.OpaqueId
s.FileSource = info.Id.OpaqueId
s.FileTarget = path.Join("/", path.Base(info.Path))
s.Path = info.Path // TODO hm this might have to be relative to the users home ...
s.Path = info.Path // TODO hm this might have to be relative to the users home ... depends on the webdav_namespace config
// TODO FileParent:
// item type
s.ItemType = conversions.ResourceType(info.GetType()).String()
Expand Down Expand Up @@ -895,34 +920,71 @@ func (h *SharesHandler) userShare2ShareData(ctx context.Context, share *collabor
return nil, err
}

log := appctx.GetLogger(ctx)

if share.Creator != nil {
if creator, err := c.GetUser(ctx, &userpb.GetUserRequest{
creator, err := c.GetUser(ctx, &userpb.GetUserRequest{
UserId: share.Creator,
}); err == nil {
})
if err != nil {
return nil, err
}

if creator.Status.Code == rpc.Code_CODE_OK {
// TODO the user from GetUser might not have an ID set, so we are using the one we have
sd.UIDOwner = UserIDToString(share.Creator)
sd.DisplaynameOwner = creator.GetUser().DisplayName
} else {
err := errors.New("could not look up creator")
log.Err(err).
Str("user_idp", share.Creator.GetIdp()).
Str("user_opaque_id", share.Creator.GetOpaqueId()).
Str("code", creator.Status.Code.String()).
Msg(creator.Status.Message)
return nil, err
}
}
if share.Owner != nil {
if owner, err := c.GetUser(ctx, &userpb.GetUserRequest{
owner, err := c.GetUser(ctx, &userpb.GetUserRequest{
UserId: share.Owner,
}); err == nil {
})
if err != nil {
return nil, err
}

if owner.Status.Code == rpc.Code_CODE_OK {
// TODO the user from GetUser might not have an ID set, so we are using the one we have
sd.UIDFileOwner = UserIDToString(share.Owner)
sd.DisplaynameFileOwner = owner.GetUser().DisplayName
} else {
err := errors.New("could not look up creator")
log.Err(err).
Str("user_idp", share.Owner.GetIdp()).
Str("user_opaque_id", share.Owner.GetOpaqueId()).
Str("code", owner.Status.Code.String()).
Msg(owner.Status.Message)
return nil, err
}
}
if share.Grantee.Id != nil {
if grantee, err := c.GetUser(ctx, &userpb.GetUserRequest{
grantee, err := c.GetUser(ctx, &userpb.GetUserRequest{
UserId: share.Grantee.GetId(),
}); err == nil {
})
if err != nil {
return nil, err
}

if grantee.Status.Code == rpc.Code_CODE_OK {
// TODO the user from GetUser might not have an ID set, so we are using the one we have
sd.ShareWith = UserIDToString(share.Grantee.Id)
sd.ShareWithDisplayname = grantee.GetUser().DisplayName
} else {
err := errors.New("could not look up creator")
log.Err(err).
Str("user_idp", share.Grantee.GetId().GetIdp()).
Str("user_opaque_id", share.Grantee.GetId().GetOpaqueId()).
Str("code", grantee.Status.Code.String()).
Msg(grantee.Status.Message)
return nil, err
}
}
Expand Down