Skip to content

Commit

Permalink
add ownername and locktime to lock
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <jkoberg@owncloud.com>
  • Loading branch information
kobergj committed Aug 24, 2023
1 parent 6f3a1df commit cd206e6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/add-lock-metadata.md
Original file line number Diff line number Diff line change
@@ -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
26 changes: 23 additions & 3 deletions internal/http/services/owncloud/ocdav/locks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -566,6 +579,13 @@ func writeLockInfo(w io.Writer, token string, ld LockDetails) (int, error) {
if href != "" {
lockdiscovery.WriteString(fmt.Sprintf(" <d:lockroot><d:href>%s</d:href></d:lockroot>\n", prop.Escape(href)))
}
if ld.OwnerName != "" {
lockdiscovery.WriteString(fmt.Sprintf(" <d:ownername>%s</d:ownername>\n", prop.Escape(ld.OwnerName)))
}
if !ld.Locktime.IsZero() {
lockdiscovery.WriteString(fmt.Sprintf(" <d:locktime>%s</d:locktime>\n", prop.Escape(ld.Locktime.Format(time.RFC3339))))
}

lockdiscovery.WriteString("</d:activelock></d:lockdiscovery></d:prop>")

return fmt.Fprint(w, lockdiscovery.String())
Expand Down
11 changes: 11 additions & 0 deletions internal/http/services/owncloud/ocdav/propfind/propfind.go
Original file line number Diff line number Diff line change
Expand Up @@ -1635,6 +1635,17 @@ func activeLocks(log *zerolog.Logger, lock *provider.Lock) string {
}
activelocks.WriteString("</d:owner>")
}

if un := utils.ReadPlainFromOpaque(lock.Opaque, "lockownername"); un != "" {
activelocks.WriteString("<d:ownername>")
activelocks.WriteString(un)
activelocks.WriteString("</d:ownername>")
}
if lt := utils.ReadPlainFromOpaque(lock.Opaque, "locktime"); lt != "" {
activelocks.WriteString("<d:locktime>")
activelocks.WriteString(lt)
activelocks.WriteString("</d:locktime>")
}
activelocks.WriteString("<d:timeout>")
activelocks.WriteString(expiration)
activelocks.WriteString("</d:timeout>")
Expand Down

0 comments on commit cd206e6

Please sign in to comment.