Vendor modules

This commit is contained in:
André Duffeck
2023-10-24 11:36:37 +02:00
parent ef18395c8c
commit 61fe240cb3
13 changed files with 161 additions and 126 deletions
@@ -122,9 +122,20 @@ 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
receivedShare := &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", "mount_point"}}
for id := range sharesToAccept {
data := h.updateReceivedShare(w, r, id, false, mount)
data := h.updateReceivedShare(w, r, receivedShare, updateMask)
// only render the data for the changed share
if id == shareID && data != nil {
response.WriteOCSSuccess(w, r, []*conversions.ShareData{data})
@@ -135,45 +146,69 @@ 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")
data := h.updateReceivedShare(w, r, shareID, true, "")
// we need to add a path to the share
receivedShare := &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, receivedShare, updateMask)
if data != nil {
response.WriteOCSSuccess(w, r, []*conversions.ShareData{data})
}
}
func (h *Handler) updateReceivedShare(w http.ResponseWriter, r *http.Request, shareID string, rejectShare bool, mountPoint string) *conversions.ShareData {
func (h *Handler) UpdateReceivedShare(w http.ResponseWriter, r *http.Request) {
shareID := chi.URLParam(r, "shareid")
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
}
// we need to add a path to the share
receivedShare := &collaboration.ReceivedShare{
Share: &collaboration.Share{
Id: &collaboration.ShareId{OpaqueId: shareID},
},
Hidden: hideFlag,
}
updateMask := &fieldmaskpb.FieldMask{Paths: []string{"state", "hidden"}}
rs, _ := getReceivedShareFromID(r.Context(), client, shareID)
if rs != nil && rs.Share != nil {
receivedShare.State = rs.Share.State
}
data := h.updateReceivedShare(w, r, receivedShare, updateMask)
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, receivedShare *collaboration.ReceivedShare, fieldMask *fieldmaskpb.FieldMask) *conversions.ShareData {
ctx := r.Context()
logger := appctx.GetLogger(ctx)
updateShareRequest := &collaboration.UpdateReceivedShareRequest{
Share: receivedShare,
UpdateMask: fieldMask,
}
client, err := h.getClient()
if err != nil {
response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "error getting grpc gateway client", err)
return nil
}
hideFlag, _ := strconv.ParseBool(r.URL.Query().Get("hide"))
// we need to add a path to the share
shareRequest := &collaboration.UpdateReceivedShareRequest{
Share: &collaboration.ReceivedShare{
Share: &collaboration.Share{
Id: &collaboration.ShareId{OpaqueId: shareID},
Hide: hideFlag,
},
MountPoint: &provider.Reference{
Path: mountPoint,
},
},
UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{"state", "hide"}},
}
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
}
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
@@ -203,6 +238,7 @@ func (h *Handler) updateReceivedShare(w http.ResponseWriter, r *http.Request, sh
}
data.State = mapState(rs.GetState())
data.Hidden = rs.Hidden
h.addFileInfo(ctx, data, info)
h.mapUserIds(r.Context(), client, data)
@@ -580,9 +580,9 @@ func (h *Handler) GetShare(w http.ResponseWriter, r *http.Request) {
},
})
if err == nil && uRes.GetShare() != nil {
receivedshare = uRes.Share
resourceID = uRes.Share.Share.ResourceId
share, err = conversions.CS3Share2ShareData(ctx, uRes.Share.Share)
share.Hidden = uRes.Share.Hidden
if err != nil {
response.WriteOCSError(w, r, response.MetaServerError.StatusCode, "error mapping share data", err)
return
@@ -739,7 +739,7 @@ func (h *Handler) updateShare(w http.ResponseWriter, r *http.Request, share *col
share.Permissions = &collaboration.SharePermissions{Permissions: role.CS3ResourcePermissions()}
var fieldMaskPaths = []string{"permissions", "hide"}
var fieldMaskPaths = []string{"permissions"}
expireDate := r.PostFormValue("expireDate")
var expirationTs *types.Timestamp
@@ -958,7 +958,7 @@ func (h *Handler) listSharesWithMe(w http.ResponseWriter, r *http.Request) {
// TODO(refs) filter out "invalid" shares
for _, rs := range lrsRes.GetShares() {
if rs.Share.Hide && !showHidden {
if rs.Hidden && !showHidden {
continue
}
if stateFilter != ocsStateUnknown && rs.GetState() != stateFilter {
@@ -122,6 +122,7 @@ func (s *svc) routerInit(log *zerolog.Logger) error {
r.Route("/pending/{shareid}", func(r chi.Router) {
r.Post("/", sharesHandler.AcceptReceivedShare)
r.Delete("/", sharesHandler.RejectReceivedShare)
r.Put("/", sharesHandler.UpdateReceivedShare)
})
r.Route("/remote_shares", func(r chi.Router) {
r.Get("/", sharesHandler.ListFederatedShares)
+1 -2
View File
@@ -172,7 +172,7 @@ type ShareData struct {
Quicklink bool `json:"quicklink,omitempty" xml:"quicklink,omitempty"`
// PasswordProtected represents a public share is password protected
// PasswordProtected bool `json:"password_protected,omitempty" xml:"password_protected,omitempty"`
Hide bool `json:"hide" xml:"hide"`
Hidden bool `json:"hidden" xml:"hidden"`
}
// ShareeData holds share recipient search results
@@ -233,7 +233,6 @@ func CS3Share2ShareData(ctx context.Context, share *collaboration.Share) (*Share
// Displaynames are added later
UIDOwner: LocalUserIDToString(share.GetCreator()),
UIDFileOwner: LocalUserIDToString(share.GetOwner()),
Hide: share.Hide,
}
if share.Grantee.Type == provider.GranteeType_GRANTEE_TYPE_USER {
@@ -23,6 +23,7 @@ import (
"encoding/json"
"io"
"os"
"path/filepath"
"sync"
"time"
@@ -69,6 +70,9 @@ func New(m map[string]interface{}) (share.Repository, error) {
func loadOrCreate(file string) (*shareModel, error) {
_, err := os.Stat(file)
if os.IsNotExist(err) {
if err := os.MkdirAll(filepath.Dir(file), 0700); err != nil {
return nil, errors.Wrap(err, "error creating the base directory: "+filepath.Dir(file))
}
if err := os.WriteFile(file, []byte("{}"), 0700); err != nil {
return nil, errors.Wrap(err, "error creating the file: "+file)
}
+1 -1
View File
@@ -647,7 +647,7 @@ func (m *Manager) UpdateReceivedShare(ctx context.Context, rshare *collaboration
rs.State = rshare.State
case "mount_point":
rs.MountPoint = rshare.MountPoint
case "hide":
case "hidden":
continue
default:
return nil, errtypes.NotSupported("updating " + fieldMask.Paths[i] + " is not supported")
+1 -1
View File
@@ -403,7 +403,7 @@ func (m *mgr) UpdateShare(ctx context.Context, ref *collaboration.ShareReference
m.model.Shares[idx].Permissions = updated.Permissions
case "expiration":
m.model.Shares[idx].Expiration = updated.Expiration
case "hide":
case "hidden":
continue
default:
return nil, errtypes.NotSupported("updating " + fieldMask.Paths[i] + " is not supported")
+4 -6
View File
@@ -511,8 +511,6 @@ func (m *Manager) UpdateShare(ctx context.Context, ref *collaboration.ShareRefer
toUpdate.Permissions = updated.Permissions
case "expiration":
toUpdate.Expiration = updated.Expiration
case "hide":
toUpdate.Hide = updated.Hide
default:
return nil, errtypes.NotSupported("updating " + fieldMask.Paths[i] + " is not supported")
}
@@ -886,11 +884,11 @@ func (m *Manager) ListReceivedShares(ctx context.Context, filters []*collaborati
if share.IsGrantedToUser(s, user) {
if share.MatchesFiltersWithState(s, state.State, filters) {
s.Hide = state.Hide
rs := &collaboration.ReceivedShare{
Share: s,
State: state.State,
MountPoint: state.MountPoint,
Hidden: state.Hidden,
}
select {
case results <- rs:
@@ -942,7 +940,7 @@ func (m *Manager) convert(ctx context.Context, userID string, s *collaboration.S
if err == nil && state != nil {
rs.State = state.State
rs.MountPoint = state.MountPoint
rs.Share.Hide = state.Hide
rs.Hidden = state.Hidden
}
return rs
}
@@ -1007,8 +1005,8 @@ func (m *Manager) UpdateReceivedShare(ctx context.Context, receivedShare *collab
rs.State = receivedShare.State
case "mount_point":
rs.MountPoint = receivedShare.MountPoint
case "hide":
rs.Share.Hide = receivedShare.Share.Hide
case "hidden":
rs.Hidden = receivedShare.Hidden
default:
return nil, errtypes.NotSupported("updating " + fieldMask.Paths[i] + " is not supported")
}
@@ -68,7 +68,7 @@ type Space struct {
type State struct {
State collaboration.ShareState
MountPoint *provider.Reference
Hide bool
Hidden bool
}
// New returns a new Cache instance
@@ -118,7 +118,7 @@ func (c *Cache) Add(ctx context.Context, userID, spaceID string, rs *collaborati
receivedSpace.States[rs.Share.Id.GetOpaqueId()] = &State{
State: rs.State,
MountPoint: rs.MountPoint,
Hide: rs.Share.Hide,
Hidden: rs.Hidden,
}
return c.persist(ctx, userID)
@@ -200,7 +200,7 @@ func (c *Cache) List(ctx context.Context, userID string) (map[string]*Space, err
spaceCopy.States[shareID] = &State{
State: state.State,
MountPoint: state.MountPoint,
Hide: state.Hide,
Hidden: state.Hidden,
}
}
spaces[spaceID] = spaceCopy
+1 -3
View File
@@ -243,8 +243,6 @@ func (m *manager) UpdateShare(ctx context.Context, ref *collaboration.ShareRefer
m.shares[i].Permissions = updated.Permissions
case "expiration":
m.shares[i].Expiration = updated.Expiration
case "hide":
m.shares[i].Hide = updated.Hide
default:
return nil, errtypes.NotSupported("updating " + path + " is not supported")
}
@@ -366,7 +364,7 @@ func (m *manager) UpdateReceivedShare(ctx context.Context, receivedShare *collab
rs.State = receivedShare.State
case "mount_point":
rs.MountPoint = receivedShare.MountPoint
case "hide":
case "hidden":
continue
default:
return nil, errtypes.NotSupported("updating " + fieldMask.Paths[i] + " is not supported")
@@ -454,7 +454,7 @@ func (m *mgr) UpdateReceivedShare(ctx context.Context, receivedShare *collaborat
fields = append(fields, "file_target=?")
rs.MountPoint = receivedShare.MountPoint
params = append(params, rs.MountPoint.Path)
case "hide":
case "hidden":
continue
default:
return nil, errtypes.NotSupported("updating " + fieldMask.Paths[i] + " is not supported")