mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-04-24 13:08:26 -05:00
Generated
Vendored
+8
-2
@@ -22,16 +22,22 @@ import (
|
||||
"context"
|
||||
|
||||
userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
ctxpkg "github.com/cs3org/reva/v2/pkg/ctx"
|
||||
)
|
||||
|
||||
// IsCurrentUserOwner returns whether the context user is the given owner or not
|
||||
func IsCurrentUserOwner(ctx context.Context, owner *userv1beta1.UserId) bool {
|
||||
// IsCurrentUserOwnerOrManager returns whether the context user is the given owner or not
|
||||
func IsCurrentUserOwnerOrManager(ctx context.Context, owner *userv1beta1.UserId, md *provider.ResourceInfo) bool {
|
||||
contextUser, ok := ctxpkg.ContextGetUser(ctx)
|
||||
// personal spaces have owners
|
||||
if ok && contextUser.Id != nil && owner != nil &&
|
||||
contextUser.Id.Idp == owner.Idp &&
|
||||
contextUser.Id.OpaqueId == owner.OpaqueId {
|
||||
return true
|
||||
}
|
||||
// check if the user is space manager
|
||||
if md != nil && md.Owner != nil && md.Owner.GetType() == userv1beta1.UserType_USER_TYPE_SPACE_OWNER {
|
||||
return md.GetPermissionSet().AddGrant
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Generated
Vendored
+4
-4
@@ -1031,7 +1031,7 @@ func mdToPropResponse(ctx context.Context, pf *XML, md *provider.ResourceInfo, p
|
||||
}
|
||||
var wdp string
|
||||
isPublic := ls != nil
|
||||
isShared := shareTypes != "" && !net.IsCurrentUserOwner(ctx, md.Owner)
|
||||
isShared := shareTypes != "" && !net.IsCurrentUserOwnerOrManager(ctx, md.Owner, md)
|
||||
if md.PermissionSet != nil {
|
||||
wdp = role.WebDAVPermissions(
|
||||
md.Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER,
|
||||
@@ -1253,7 +1253,7 @@ func mdToPropResponse(ctx context.Context, pf *XML, md *provider.ResourceInfo, p
|
||||
}
|
||||
case "public-link-share-owner":
|
||||
if ls != nil && ls.Owner != nil {
|
||||
if net.IsCurrentUserOwner(ctx, ls.Owner) {
|
||||
if net.IsCurrentUserOwnerOrManager(ctx, ls.Owner, nil) {
|
||||
u := ctxpkg.ContextMustGetUser(ctx)
|
||||
appendToOK(prop.Escaped("oc:public-link-share-owner", u.Username))
|
||||
} else {
|
||||
@@ -1285,7 +1285,7 @@ func mdToPropResponse(ctx context.Context, pf *XML, md *provider.ResourceInfo, p
|
||||
}
|
||||
case "owner-id": // phoenix only
|
||||
if md.Owner != nil {
|
||||
if net.IsCurrentUserOwner(ctx, md.Owner) {
|
||||
if net.IsCurrentUserOwnerOrManager(ctx, md.Owner, md) {
|
||||
u := ctxpkg.ContextMustGetUser(ctx)
|
||||
appendToOK(prop.Escaped("oc:owner-id", u.Username))
|
||||
} else {
|
||||
@@ -1375,7 +1375,7 @@ func mdToPropResponse(ctx context.Context, pf *XML, md *provider.ResourceInfo, p
|
||||
}
|
||||
case "owner-display-name": // phoenix only
|
||||
if md.Owner != nil {
|
||||
if net.IsCurrentUserOwner(ctx, md.Owner) {
|
||||
if net.IsCurrentUserOwnerOrManager(ctx, md.Owner, md) {
|
||||
u := ctxpkg.ContextMustGetUser(ctx)
|
||||
appendToOK(prop.Escaped("oc:owner-display-name", u.DisplayName))
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -338,7 +338,7 @@ func (s *svc) handleTusPost(ctx context.Context, w http.ResponseWriter, r *http.
|
||||
isPublic = ls != nil
|
||||
}
|
||||
}
|
||||
isShared := !net.IsCurrentUserOwner(ctx, info.Owner)
|
||||
isShared := !net.IsCurrentUserOwnerOrManager(ctx, info.Owner, info)
|
||||
role := conversions.RoleFromResourcePermissions(info.PermissionSet, isPublic)
|
||||
permissions := role.WebDAVPermissions(
|
||||
info.Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER,
|
||||
|
||||
+17
-5
@@ -276,11 +276,23 @@ func (fs *Decomposedfs) Postprocessing(ch <-chan events.Event) {
|
||||
failed = true
|
||||
}
|
||||
|
||||
getParent := func() *node.Node {
|
||||
p, err := up.Node.Parent(ctx)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("uploadID", ev.UploadID).Msg("could not read parent")
|
||||
return nil
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
if p, err := node.ReadNode(ctx, fs.lu, up.Info.Storage["SpaceRoot"], n.ParentID, false, nil, true); err != nil {
|
||||
log.Error().Err(err).Str("uploadID", ev.UploadID).Msg("could not read parent")
|
||||
} else {
|
||||
// update parent tmtime to propagate etag change
|
||||
if failed {
|
||||
// propagate sizeDiff after failed postprocessing
|
||||
if err := fs.tp.Propagate(ctx, up.Node, -up.SizeDiff); err != nil {
|
||||
log.Error().Err(err).Str("uploadID", ev.UploadID).Msg("could not propagate tree size change")
|
||||
}
|
||||
} else if p := getParent(); p != nil {
|
||||
// update parent tmtime to propagate etag change after successful postprocessing
|
||||
_ = p.SetTMTime(ctx, &now)
|
||||
if err := fs.tp.Propagate(ctx, p, 0); err != nil {
|
||||
log.Error().Err(err).Str("uploadID", ev.UploadID).Msg("could not propagate etag change")
|
||||
@@ -900,7 +912,7 @@ func (fs *Decomposedfs) ListFolder(ctx context.Context, ref *provider.Reference,
|
||||
for child := range work {
|
||||
np := rp
|
||||
// add this childs permissions
|
||||
pset, _ := n.PermissionSet(ctx)
|
||||
pset, _ := child.PermissionSet(ctx)
|
||||
node.AddPermissions(&np, &pset)
|
||||
ri, err := child.AsResourceInfo(ctx, &np, mdKeys, fieldMask, utils.IsRelativeReference(ref))
|
||||
if err != nil {
|
||||
|
||||
Generated
Vendored
+5
-5
@@ -234,7 +234,7 @@ func Get(ctx context.Context, id string, lu *lookup.Lookup, tp Tree, fsRoot stri
|
||||
|
||||
up := buildUpload(ctx, info, info.Storage["BinPath"], infoPath, lu, tp, pub, async, tknopts)
|
||||
up.versionsPath = info.MetaData["versionsPath"]
|
||||
up.sizeDiff, _ = strconv.ParseInt(info.MetaData["sizeDiff"], 10, 64)
|
||||
up.SizeDiff, _ = strconv.ParseInt(info.MetaData["sizeDiff"], 10, 64)
|
||||
return up, nil
|
||||
}
|
||||
|
||||
@@ -364,8 +364,8 @@ func initNewNode(upload *Upload, n *node.Node, fsize uint64) (*lockedfile.File,
|
||||
}
|
||||
|
||||
// on a new file the sizeDiff is the fileSize
|
||||
upload.sizeDiff = int64(fsize)
|
||||
upload.Info.MetaData["sizeDiff"] = strconv.Itoa(int(upload.sizeDiff))
|
||||
upload.SizeDiff = int64(fsize)
|
||||
upload.Info.MetaData["sizeDiff"] = strconv.Itoa(int(upload.SizeDiff))
|
||||
return f, nil
|
||||
}
|
||||
|
||||
@@ -393,9 +393,9 @@ func updateExistingNode(upload *Upload, n *node.Node, spaceID string, fsize uint
|
||||
}
|
||||
|
||||
upload.versionsPath = upload.lu.InternalPath(spaceID, n.ID+node.RevisionIDDelimiter+tmtime.UTC().Format(time.RFC3339Nano))
|
||||
upload.sizeDiff = int64(fsize) - old.Blobsize
|
||||
upload.SizeDiff = int64(fsize) - old.Blobsize
|
||||
upload.Info.MetaData["versionsPath"] = upload.versionsPath
|
||||
upload.Info.MetaData["sizeDiff"] = strconv.Itoa(int(upload.sizeDiff))
|
||||
upload.Info.MetaData["sizeDiff"] = strconv.Itoa(int(upload.SizeDiff))
|
||||
|
||||
targetPath := n.InternalPath()
|
||||
|
||||
|
||||
+3
-3
@@ -91,6 +91,8 @@ type Upload struct {
|
||||
Info tusd.FileInfo
|
||||
// node for easy access
|
||||
Node *node.Node
|
||||
// SizeDiff size difference between new and old file version
|
||||
SizeDiff int64
|
||||
// infoPath is the path to the .info file
|
||||
infoPath string
|
||||
// binPath is the path to the binary file (which has no extension)
|
||||
@@ -100,8 +102,6 @@ type Upload struct {
|
||||
tp Tree
|
||||
// versionsPath will be empty if there was no file before
|
||||
versionsPath string
|
||||
// sizeDiff size difference between new and old file version
|
||||
sizeDiff int64
|
||||
// and a logger as well
|
||||
log zerolog.Logger
|
||||
// publisher used to publish events
|
||||
@@ -296,7 +296,7 @@ func (upload *Upload) FinishUpload(_ context.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
return upload.tp.Propagate(upload.Ctx, n, upload.sizeDiff)
|
||||
return upload.tp.Propagate(upload.Ctx, n, upload.SizeDiff)
|
||||
}
|
||||
|
||||
// Terminate terminates the upload
|
||||
|
||||
Reference in New Issue
Block a user