Repository navigation
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
e0c3ce4 to
c0adbda
Compare
c0adbda to
6646d1b
Compare
| // keys in the opaque of a version's ResourceInfo, set by the versions handler | ||
| OpaqueVersionAuthorUsername = "version-author-username" | ||
| OpaqueVersionAuthorDisplayName = "version-author-displayname" |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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.
| 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 | ||
| } |
There was a problem hiding this comment.
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.
| 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>` | ||
|
|
There was a problem hiding this comment.
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()), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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{ |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
Opaquehurts the reusability of the function. Is it something this function should do, or it can be delegated to the caller function?
| // 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()) | ||
| } |
There was a problem hiding this comment.
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.
| var _ = Describe("Revision author", func() { | ||
| for _, backend := range []string{"xattrs", "messagepack"} { | ||
| backend := backend | ||
| Describe("with the "+backend+" metadata backend", Ordered, func() { revisionAuthorSpecs(backend) }) | ||
| } | ||
| }) |
There was a problem hiding this comment.
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.
|
Some general points:
|
Description
Record who uploaded each file version and return it in the versions listing.
user.ocis.author.{id,idp,type}on the nodewhen an upload is prepared.
They are copied back on restore, so the author follows the content and is not the user who
restored it.
the node, so the restored content is not attributed to the user it replaced.
ListRevisionsreturns the author as a JSONUserIdinFileVersion.Opaqueunder thekey
author.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.
oc:meta-version-edited-by(username)and
oc:meta-version-edited-by-name(display name). A version without a recorded authoranswers 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?
xattrsandmessagepackmetadata backendsTypes of changes