Skip to content

feat: expose the author of file versions in the versions PROPFIND - #816

Open
Jonher937 wants to merge 1 commit into
owncloud:mainfrom
Jonher937:draft/version-author
Open

Jonher937 wants to merge 1 commit into
owncloud:mainfrom
Jonher937:draft/version-author

Conversation

@Jonher937

Copy link
Copy Markdown

Description

Record who uploaded each file version and return it in the versions listing.

  • decomposedfs stores the uploading user as user.ocis.author.{id,idp,type} on the node
    when an upload is prepared.
  • The author attributes are copied to a revision when a later upload archives the content.
    They are copied back on restore, so the author follows the content and is not the user who
    restored it.
  • Restoring a revision that has no author (created before this change) clears the author on
    the node, so the restored content is not attributed to the user it replaced.
  • ListRevisions returns the author as a JSON UserId in FileVersion.Opaque under the
    key author.
  • The ocdav versions handler resolves the author to a username and display name through the
    gateway. It asks the user provider once per distinct user per request. A user that cannot be
    resolved (for example, deleted) leaves the properties unset and does not fail the listing.
  • The versions PROPFIND supports two new properties: oc:meta-version-edited-by (username)
    and oc:meta-version-edited-by-name (display name). A version without a recorded author
    answers 404 for both.

Related Issue

Motivation and Context

Clients that show the version history of a file can show when a version was created, but not
who created it. Recording the author at upload time and returning it in the versions
PROPFIND lets clients show who edited each version.

How Has This Been Tested?

  • test environment: reva unit tests, both the xattrs and messagepack metadata backends
  • test case 1: with three uploads by different users, each archived version keeps its author and the current node has the latest uploader as author
  • test case 2: restoring a version moves its author onto the node, not the restoring user
  • test case 3: restoring a version without an author clears the node's author
  • test case 4: the versions PROPFIND returns username and display name for an author, and 404 when there is none
  • test case 5: author lookup happens once per distinct user, and an unresolvable user does not fail the listing
  • acceptance tests: not run yet (TODO)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Technical debt
  • Tests only (no source changes)

@Jonher937
Jonher937 requested a review from a team as a code owner November 14, 2026 22:59
@kw-security

kw-security commented Nov 14, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues
✅ Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@Jonher937
Jonher937 force-pushed the draft/version-author branch from e0c3ce4 to c0adbda Compare November 24, 2026 12:07
@Jonher937
Jonher937 force-pushed the draft/version-author branch from c0adbda to 6646d1b Compare November 24, 2026 12:08
Comment on lines +68 to +70
// keys in the opaque of a version's ResourceInfo, set by the versions handler
OpaqueVersionAuthorUsername = "version-author-username"
OpaqueVersionAuthorDisplayName = "version-author-displayname"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes more sense for these constants to be part of the "pkg/utils" package.

From my point of view, either follow what is already done and use the string directly, or move all those opaque strings (including "owner-display-name", "downloadURL", etc) as constants in the "pkg/utils" package.
I'm fine to keep using the string directly and leave it as a technical debt for a followup PR if the amount of changes needed is too big.

"github.com/owncloud/reva/v2/pkg/utils"
)

var _ = Describe("version author properties", func() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better move these tests inside the "propfind_test.go" file.
There is no "version_author.go" file inside the package, so this test file will throw people off thinking there is a missing file. In addition, the target of the tests is in the "propfind.go" file, so it make sense for these tests to be in the "propfind_test.go" file.

Comment on lines +21 to +36
respond := func(md *provider.ResourceInfo) string {
pf, _, err := propfind.ReadPropfind(strings.NewReader(body))
Expect(err).ToNot(HaveOccurred())
ctx := context.WithValue(context.Background(), net.CtxKeyBaseURI, "/remote.php/dav/meta/id/versions")
b, err := propfind.MultistatusResponse(ctx, &pf, []*provider.ResourceInfo{md}, "", "", nil, false)
Expect(err).ToNot(HaveOccurred())
return string(b)
}
version := func(o interface{}) *provider.ResourceInfo {
md := &provider.ResourceInfo{Type: provider.ResourceType_RESOURCE_TYPE_FILE, Path: "v/key"}
if o != nil {
md.Opaque = utils.AppendPlainToOpaque(nil, propfind.OpaqueVersionAuthorUsername, "carol")
md.Opaque = utils.AppendPlainToOpaque(md.Opaque, propfind.OpaqueVersionAuthorDisplayName, "Carol King")
}
return md
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to move these functions inside the tests. Yes, there will be some code duplication, but the test should be easier and more straightforward to read.
Basically, the test should be: prepare data, do the thing, check the result.

Comment on lines +16 to +20
body := `<?xml version="1.0"?>
<d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns"><d:prop>
<oc:meta-version-edited-by /><oc:meta-version-edited-by-name />
</d:prop></d:propfind>`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved to a BeforeEach section. At the moment, there is a risk that a test overwrites the variable, and that will cause a mess.

var _ = Describe(......
    var body string

    BeforeEach(func() {
        body = "<?xml version......."
    })

    It(......)
)

This way we can ensure that the tests will receive the same data.

authors := &versionAuthors{client: client, users: map[string]*userpb.User{}}
for i := range versions {
vi := &provider.ResourceInfo{
Opaque: authors.opaqueFor(ctx, versions[i].GetOpaque()),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to just copy the information here. The opaque should contain just the user ID of the author; we only want to resolve his displayname if needed. This seems a wrong place to get a displayname when we don't know if it has been requested.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition, I'm not sure if we need a cache.
As said, the displayname should be fetched by the propfind package, around https://github.com/owncloud/reva/pull/816/changes#diff-fa4130be45a2f0a202cc47c8f7ab33722e36ceccb5ba67e881b772e077a59251R1526 . That happens only if it's explicitly requested. I think we can also limit it to propfinds of depth 0, or at least check what is the expected use case (likely we only want to show the author of a specific file, as part of the file details)

if id == "" {
return nil
}
return utils.AppendJSONToOpaque(nil, storage.RevisionAuthorOpaqueKey, &userpb.UserId{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RevisionAuthorOpaqueKey constant should be in the "pkg/utils" package.


// revisionAuthorOpaque reads the author of a revision. It returns nil for a
// revision without one, e.g. one created before authors were recorded.
func (fs *Decomposedfs) revisionAuthorOpaque(ctx context.Context, revisionPath string) *typespb.Opaque {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not against this function, but there are some things that itches...

  • The name is barely descriptive.
  • The functionality seems too specific, for just one use case in one place. If it's going to be difficult to reuse, why not move this function closer to the code that is going to use it?
  • Returning an Opaque hurts the reusability of the function. Is it something this function should do, or it can be delegated to the caller function?

Comment on lines +309 to +314
// CopyMetadata only adds and overwrites. A revision from before authors were
// recorded has none, so drop the author of the content that was just replaced
// instead of attributing the restored content to them.
if err := fs.dropStaleAuthor(ctx, restoredRevisionPath, nodePath); err != nil {
return nil, errtypes.InternalError("failed to reset author on node: " + err.Error())
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you point me where the author is replaced? In theory, this shouldn't be needed: if there is no "author" attribute in the "source" revision, the restored revision shouldn't have any author neither.
Maybe I'm wrong, but each revision should have its own blob and metadata file, so it shouldn't matter if a new revision has an author if the one we want to restore doesn't have an author.

Comment on lines +20 to +25
var _ = Describe("Revision author", func() {
for _, backend := range []string{"xattrs", "messagepack"} {
backend := backend
Describe("with the "+backend+" metadata backend", Ordered, func() { revisionAuthorSpecs(backend) })
}
})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to follow a standard approach.
I'm not sure if we need to test each backend (they probably should be mocked), but having different sections for each backend seems fine to me.

@jvillafanez

Copy link
Copy Markdown
Member

Some general points:

  • We should use the user ID of the author as information to be transferred through the opaque. The displayname is only relevant to whoever wants to show the author, so its his responsibility to figure out how to get the displayname.
  • Ideally, the user ID should use only one key in the opaque. However, there are some reasons to use multiple keys (to be evaluated):
    • We'll likely need to pack and unpack the information somehow (either with json, msgpack, or any custom mechanism), this might add some additional complexity that might be not worthy.
    • I'm not sure if there is already some code using multiple keys. If so, it might be fine to follow the same approach.
  • I'd try to avoid using a cache for the username -> displayname if possible. We probably need to check the expected use cases for this feature to evaluate whether we need a cache or not. I've already commented a possible use case where we don't need the cache, but there might be more use case we might need to support. Note that the performance is important and we can't send an uncontrolled number of requests.
  • Regarding files:
    • I don't think the "versions_author.go" has different enough functionality to justify its own file. The functionality can be included in the "versions.go" file. I'd prefer to have a specific package in charge of loading and caching users that could be reused, but it seems out of scope.
    • Something similar happens with the "author.go" file. It feels like the only "connection" among those functions is that they use authors, but I don't see any cohesion.
    • For the "*_test.go" files, as said, I'd expect the corresponding regular file, otherwise it seems that files are missing. I'd recommend to move the tests to a different file.
  • For the tests, I'd prioritize clarity and readability. There are several examples in the ginkgo documentation, so I'd expect the tests to be close to those examples. There are always exceptions, but I don't think this is the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

file versions do not report the version author

3 participants