Skip to content

Commit

Permalink
incorporate requested changes
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Richter <[email protected]>
  • Loading branch information
dragonchaser committed Oct 23, 2023
1 parent c2c637a commit f1610ef
Showing 1 changed file with 51 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,22 @@ func (h *Handler) AcceptReceivedShare(w http.ResponseWriter, r *http.Request) {
// TODO we could delete shares here if the stat returns code NOT FOUND ... but listening for file deletes would be better
}
}
// we need to add a path to the share
shareRequest := &collaboration.UpdateReceivedShareRequest{
Share: &collaboration.ReceivedShare{
Share: &collaboration.Share{
Id: &collaboration.ShareId{OpaqueId: shareID},
},
State: collaboration.ShareState_SHARE_STATE_ACCEPTED,
MountPoint: &provider.Reference{
Path: mount,
},
},
UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{"state", "hidden"}},
}

for id := range sharesToAccept {
data := h.updateReceivedShare(w, r, id, mount, &fieldmaskpb.FieldMask{})
data := h.updateReceivedShare(w, r, shareRequest)
// only render the data for the changed share
if id == shareID && data != nil {
response.WriteOCSSuccess(w, r, []*conversions.ShareData{data})
Expand All @@ -135,41 +148,36 @@ func (h *Handler) AcceptReceivedShare(w http.ResponseWriter, r *http.Request) {
// RejectReceivedShare handles DELETE Requests on /apps/files_sharing/api/v1/shares/{shareid}
func (h *Handler) RejectReceivedShare(w http.ResponseWriter, r *http.Request) {
shareID := chi.URLParam(r, "shareid")
fieldMask := &fieldmaskpb.FieldMask{Paths: []string{"rejectshare"}}
data := h.updateReceivedShare(w, r, shareID, "", fieldMask)
// we need to add a path to the share
shareRequest := &collaboration.UpdateReceivedShareRequest{
Share: &collaboration.ReceivedShare{
Share: &collaboration.Share{
Id: &collaboration.ShareId{OpaqueId: shareID},
},
State: collaboration.ShareState_SHARE_STATE_REJECTED,
},
UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{"state", "hidden"}},
}
data := h.updateReceivedShare(w, r, shareRequest)
if data != nil {
response.WriteOCSSuccess(w, r, []*conversions.ShareData{data})
}
}

func (h *Handler) UpdateReceivedShare(w http.ResponseWriter, r *http.Request) {
shareID := chi.URLParam(r, "shareid")
fieldMask := &fieldmaskpb.FieldMask{Paths: []string{"hidden"}}
data := h.updateReceivedShare(w, r, shareID, "", fieldMask)
if data != nil {
response.WriteOCSSuccess(w, r, []*conversions.ShareData{data})
}
}

func (h *Handler) updateReceivedShare(w http.ResponseWriter, r *http.Request, shareID, mountPoint string, fieldmask *fieldmaskpb.FieldMask) *conversions.ShareData {
var rejectShare, hideFlag bool
for i := range fieldmask.Paths {
switch fieldmask.Paths[i] {
case "rejectshare":
rejectShare = true
case "mountpoint":
continue
case "hidden":
hideFlag, _ = strconv.ParseBool(r.URL.Query().Get("hidden"))
}
}
ctx := r.Context()
logger := appctx.GetLogger(ctx)
hideFlag, _ := strconv.ParseBool(r.URL.Query().Get("hidden"))

// unfortunately we need to get the share first to read the state
client, err := h.getClient()
if err != nil {
response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "error getting grpc gateway client", err)
return nil
return
}

rs, _ := getReceivedShareFromID(r.Context(), client, shareID)
if rs == nil {
response.WriteOCSError(w, r, response.MetaNotFound.StatusCode, "could not get share", nil)
}

// we need to add a path to the share
Expand All @@ -178,21 +186,30 @@ func (h *Handler) updateReceivedShare(w http.ResponseWriter, r *http.Request, sh
Share: &collaboration.Share{
Id: &collaboration.ShareId{OpaqueId: shareID},
},
MountPoint: &provider.Reference{
Path: mountPoint,
},
Hidden: hideFlag,
State: rs.Share.State,
},
UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{"state", "hidden"}},
}
if rejectShare {
shareRequest.Share.State = collaboration.ShareState_SHARE_STATE_REJECTED
} else {
shareRequest.UpdateMask.Paths = append(shareRequest.UpdateMask.Paths, "mount_point")
shareRequest.Share.State = collaboration.ShareState_SHARE_STATE_ACCEPTED

data := h.updateReceivedShare(w, r, shareRequest)
if data != nil {
response.WriteOCSSuccess(w, r, []*conversions.ShareData{data})
}
// TODO: do we need error handling here?
}

func (h *Handler) updateReceivedShare(w http.ResponseWriter, r *http.Request, updateShareRequest *collaboration.UpdateReceivedShareRequest) *conversions.ShareData {
ctx := r.Context()
logger := appctx.GetLogger(ctx)

client, err := h.getClient()
if err != nil {
response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "error getting grpc gateway client", err)
return nil
}

shareRes, err := client.UpdateReceivedShare(ctx, shareRequest)
shareRes, err := client.UpdateReceivedShare(ctx, updateShareRequest)
if err != nil {
response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "grpc update received share request failed", err)
return nil
Expand Down

0 comments on commit f1610ef

Please sign in to comment.