From cd206e67e2ea9b7627ce8891d4a0f0870204733d Mon Sep 17 00:00:00 2001 From: jkoberg Date: Wed, 23 Aug 2023 16:38:14 +0200 Subject: [PATCH 1/2] add ownername and locktime to lock Signed-off-by: jkoberg --- changelog/unreleased/add-lock-metadata.md | 5 ++++ .../http/services/owncloud/ocdav/locks.go | 26 ++++++++++++++++--- .../owncloud/ocdav/propfind/propfind.go | 11 ++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 changelog/unreleased/add-lock-metadata.md diff --git a/changelog/unreleased/add-lock-metadata.md b/changelog/unreleased/add-lock-metadata.md new file mode 100644 index 0000000000..019ac4c099 --- /dev/null +++ b/changelog/unreleased/add-lock-metadata.md @@ -0,0 +1,5 @@ +Enhancement: Add more metadata to locks + +Adds the owners name and the time of locking to the lock metadata + +https://github.com/cs3org/reva/pull/4133 diff --git a/internal/http/services/owncloud/ocdav/locks.go b/internal/http/services/owncloud/ocdav/locks.go index 54d69a1e21..4dea29b5eb 100644 --- a/internal/http/services/owncloud/ocdav/locks.go +++ b/internal/http/services/owncloud/ocdav/locks.go @@ -42,6 +42,7 @@ import ( ctxpkg "github.com/cs3org/reva/v2/pkg/ctx" "github.com/cs3org/reva/v2/pkg/errtypes" "github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool" + "github.com/cs3org/reva/v2/pkg/utils" "github.com/google/uuid" "go.opentelemetry.io/otel/attribute" ) @@ -190,11 +191,18 @@ func (cls *cs3LS) Create(ctx context.Context, now time.Time, details LockDetails // see: http://www.webdav.org/specs/rfc2518.html#n-lock-tokens token := uuid.New() + u := ctxpkg.ContextMustGetUser(ctx) + + // add metadata via opaque + o := utils.AppendPlainToOpaque(nil, "lockownername", u.GetDisplayName()) + o = utils.AppendPlainToOpaque(o, "locktime", now.Format(time.RFC3339)) + r := &provider.SetLockRequest{ Ref: details.Root, Lock: &provider.Lock{ - Type: provider.LockType_LOCK_TYPE_EXCL, - User: details.UserID, // no way to set an app lock? TODO maybe via the ownerxml + Opaque: o, + Type: provider.LockType_LOCK_TYPE_EXCL, + User: details.UserID, // no way to set an app lock? TODO maybe via the ownerxml //AppName: , // TODO use a urn scheme? LockId: lockTokenPrefix + token.String(), // can be a token or a Coded-URL }, @@ -278,6 +286,10 @@ type LockDetails struct { // ZeroDepth is whether the lock has zero depth. If it does not have zero // depth, it has infinite depth. ZeroDepth bool + // OwnerName is the name of the lock owner + OwnerName string + // Locktime is the time the lock was created + Locktime time.Time } func readLockInfo(r io.Reader) (li lockInfo, status int, err error) { @@ -440,7 +452,8 @@ func (s *svc) lockReference(ctx context.Context, w http.ResponseWriter, r *http. } u := ctxpkg.ContextMustGetUser(ctx) - token, ld, now, created := "", LockDetails{UserID: u.Id, Root: ref, Duration: duration}, time.Now(), false + token, now, created := "", time.Now(), false + ld := LockDetails{UserID: u.Id, Root: ref, Duration: duration, OwnerName: u.GetDisplayName(), Locktime: now} if li == (lockInfo{}) { // An empty lockInfo means to refresh the lock. ih, ok := parseIfHeader(r.Header.Get(net.HeaderIf)) @@ -566,6 +579,13 @@ func writeLockInfo(w io.Writer, token string, ld LockDetails) (int, error) { if href != "" { lockdiscovery.WriteString(fmt.Sprintf(" %s\n", prop.Escape(href))) } + if ld.OwnerName != "" { + lockdiscovery.WriteString(fmt.Sprintf(" %s\n", prop.Escape(ld.OwnerName))) + } + if !ld.Locktime.IsZero() { + lockdiscovery.WriteString(fmt.Sprintf(" %s\n", prop.Escape(ld.Locktime.Format(time.RFC3339)))) + } + lockdiscovery.WriteString("") return fmt.Fprint(w, lockdiscovery.String()) diff --git a/internal/http/services/owncloud/ocdav/propfind/propfind.go b/internal/http/services/owncloud/ocdav/propfind/propfind.go index 0600f1b14a..9c2bb5f016 100644 --- a/internal/http/services/owncloud/ocdav/propfind/propfind.go +++ b/internal/http/services/owncloud/ocdav/propfind/propfind.go @@ -1635,6 +1635,17 @@ func activeLocks(log *zerolog.Logger, lock *provider.Lock) string { } activelocks.WriteString("") } + + if un := utils.ReadPlainFromOpaque(lock.Opaque, "lockownername"); un != "" { + activelocks.WriteString("") + activelocks.WriteString(un) + activelocks.WriteString("") + } + if lt := utils.ReadPlainFromOpaque(lock.Opaque, "locktime"); lt != "" { + activelocks.WriteString("") + activelocks.WriteString(lt) + activelocks.WriteString("") + } activelocks.WriteString("") activelocks.WriteString(expiration) activelocks.WriteString("") From a80cc3e78b51cee7c42909db6576dca649bde324 Mon Sep 17 00:00:00 2001 From: kobergj Date: Thu, 24 Aug 2023 12:59:56 +0200 Subject: [PATCH 2/2] use owncloud namespace for lock details MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jörn Friedrich Dreyer Signed-off-by: jkoberg --- internal/http/services/owncloud/ocdav/locks.go | 7 ++++--- .../http/services/owncloud/ocdav/propfind/propfind.go | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/internal/http/services/owncloud/ocdav/locks.go b/internal/http/services/owncloud/ocdav/locks.go index 4dea29b5eb..43ca6dde62 100644 --- a/internal/http/services/owncloud/ocdav/locks.go +++ b/internal/http/services/owncloud/ocdav/locks.go @@ -194,6 +194,7 @@ func (cls *cs3LS) Create(ctx context.Context, now time.Time, details LockDetails u := ctxpkg.ContextMustGetUser(ctx) // add metadata via opaque + // TODO: upate cs3api: https://github.com/cs3org/cs3apis/issues/213 o := utils.AppendPlainToOpaque(nil, "lockownername", u.GetDisplayName()) o = utils.AppendPlainToOpaque(o, "locktime", now.Format(time.RFC3339)) @@ -560,7 +561,7 @@ func writeLockInfo(w io.Writer, token string, ld LockDetails) (int, error) { lockdiscovery := strings.Builder{} lockdiscovery.WriteString(xml.Header) - lockdiscovery.WriteString("\n") + lockdiscovery.WriteString("\n") lockdiscovery.WriteString(" \n") lockdiscovery.WriteString(" \n") lockdiscovery.WriteString(fmt.Sprintf(" %s\n", depth)) @@ -580,10 +581,10 @@ func writeLockInfo(w io.Writer, token string, ld LockDetails) (int, error) { lockdiscovery.WriteString(fmt.Sprintf(" %s\n", prop.Escape(href))) } if ld.OwnerName != "" { - lockdiscovery.WriteString(fmt.Sprintf(" %s\n", prop.Escape(ld.OwnerName))) + lockdiscovery.WriteString(fmt.Sprintf(" %s\n", prop.Escape(ld.OwnerName))) } if !ld.Locktime.IsZero() { - lockdiscovery.WriteString(fmt.Sprintf(" %s\n", prop.Escape(ld.Locktime.Format(time.RFC3339)))) + lockdiscovery.WriteString(fmt.Sprintf(" %s\n", prop.Escape(ld.Locktime.Format(time.RFC3339)))) } lockdiscovery.WriteString("") diff --git a/internal/http/services/owncloud/ocdav/propfind/propfind.go b/internal/http/services/owncloud/ocdav/propfind/propfind.go index 9c2bb5f016..ea0be352e0 100644 --- a/internal/http/services/owncloud/ocdav/propfind/propfind.go +++ b/internal/http/services/owncloud/ocdav/propfind/propfind.go @@ -1637,14 +1637,14 @@ func activeLocks(log *zerolog.Logger, lock *provider.Lock) string { } if un := utils.ReadPlainFromOpaque(lock.Opaque, "lockownername"); un != "" { - activelocks.WriteString("") + activelocks.WriteString("") activelocks.WriteString(un) - activelocks.WriteString("") + activelocks.WriteString("") } if lt := utils.ReadPlainFromOpaque(lock.Opaque, "locktime"); lt != "" { - activelocks.WriteString("") + activelocks.WriteString("") activelocks.WriteString(lt) - activelocks.WriteString("") + activelocks.WriteString("") } activelocks.WriteString("") activelocks.WriteString(expiration)