Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Metadata to lock #4133

Merged
merged 2 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
29 changes: 25 additions & 4 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,19 @@ 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
// 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))

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
kobergj marked this conversation as resolved.
Show resolved Hide resolved
//AppName: , // TODO use a urn scheme?
LockId: lockTokenPrefix + token.String(), // can be a token or a Coded-URL
},
Expand Down Expand Up @@ -278,6 +287,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 +453,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 @@ -547,7 +561,7 @@ func writeLockInfo(w io.Writer, token string, ld LockDetails) (int, error) {

lockdiscovery := strings.Builder{}
lockdiscovery.WriteString(xml.Header)
lockdiscovery.WriteString("<d:prop xmlns:d=\"DAV:\"><d:lockdiscovery><d:activelock>\n")
lockdiscovery.WriteString("<d:prop xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\"><d:lockdiscovery><d:activelock>\n")
lockdiscovery.WriteString(" <d:locktype><d:write/></d:locktype>\n")
lockdiscovery.WriteString(" <d:lockscope><d:exclusive/></d:lockscope>\n")
lockdiscovery.WriteString(fmt.Sprintf(" <d:depth>%s</d:depth>\n", depth))
Expand All @@ -566,6 +580,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(" <oc:ownername>%s</oc:ownername>\n", prop.Escape(ld.OwnerName)))
}
if !ld.Locktime.IsZero() {
lockdiscovery.WriteString(fmt.Sprintf(" <oc:locktime>%s</oc: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("<oc:ownername>")
activelocks.WriteString(un)
activelocks.WriteString("</oc:ownername>")
}
if lt := utils.ReadPlainFromOpaque(lock.Opaque, "locktime"); lt != "" {
activelocks.WriteString("<oc:locktime>")
activelocks.WriteString(lt)
activelocks.WriteString("</oc:locktime>")
}
activelocks.WriteString("<d:timeout>")
activelocks.WriteString(expiration)
activelocks.WriteString("</d:timeout>")
Expand Down
Loading