When a user performs a revert of a node, there is no record of that action in the revision table, or in the UI (although there is a watchdog message logged that contains the current user). For a production site though, its very possible that watchdog is turned off, making it very difficult to see who actually reverted a revision.
Consider the following:
- User A creates a node (initial revision)
- User B updates the node, saves and creates an additional revision
- User C reverts to initial revision
As far as I can see, there is no reference to User C performing the revert, resulting in a sort of 'data loss'.
I believe the user performing the revert should be marked as the revision author. We still have a reference to the original revision, which contains the original revision author (User A above in this example).
Comment | File | Size | Author |
---|---|---|---|
#25 | interdiff-2944521-24-25.txt | 488 bytes | trwill |
#25 | 2944521-25.patch | 4.34 KB | trwill |
#24 | interdiff-2944521-22-24.txt | 1.28 KB | trwill |
#24 | 2944521-24.patch | 4.34 KB | trwill |
#22 | interdiff-2944521-19-22.txt | 919 bytes | trwill |
Comments
Comment #2
trwill CreditAttribution: trwill commentedI have added a patch which simply sets the revision user to the current user in
NodeRevisionRevertForm::submitForm
methodComment #3
trwill CreditAttribution: trwill commentedComment #4
dpagini CreditAttribution: dpagini as a volunteer commentedComment #5
timmillwoodLooks good, but we need some tests to make sure it does what it says, and make sure we don't get any future regressions.
Comment #6
trwill CreditAttribution: trwill commentedI believe this is an adequate test- when the revision is reverted, verify that the revision author == user performing revert (eg. current user). Nice and simple. Let me know if I've missed anything here.Also included interdiff.
Comment #7
trwill CreditAttribution: trwill commentedGiving this some more thought, I realize this test needs a bit more work to be complete. It should set an arbitrary user (different from user performing revert) as revision author for the revisions before the revert. Otherwise, it’s not a valid test since all 3 revisions are already the current user so of course they will be after revert too.
Comment #8
timmillwoodThanks @trwill, moving back to needs work for #7.
Comment #9
trwill CreditAttribution: trwill commentedAlright @timmillwood, believe this is now complete. I created a property and set an arbitrary user (
$revisionUser
) in the::setUp()
method to access in the assertion itself, as well as the helper to create revisions, and potentially any other tests in the future. Added another assertion to the original test which also ensures the revert revision author is not the revision user. May be a bit redundant, but it feels like a good test there. Let me know if you'd prefer to remove that.Also removed 'Needs Tests' tag. I can finish this up if anything is left.
Comment #10
trwill CreditAttribution: trwill commentedAnything else needed on this?
Comment #11
timmillwoodLooks good now, thanks @trwill.
Comment #12
trwill CreditAttribution: trwill commentedGreat, thanks @timmillwood for the help and quick feedback! My first core patch :)
Comment #13
alexpottI think this change makes sense but given the behaviour change it'd be great to have a +1 from an entity API or node maintainer.
Comment #14
Berdir@timmillwood actually is a node module maintainer (I didn't know we even have that again :)), so it already had that.
I also agree with the change, however, we also need to update NodeRevisionRevertTranslationForm, as that is used when reverting a translation and the two should work consistently.
Comment #15
BerdirMy comment was wrong, I accidently looked at an 8.4 code base, the logic isn't duplicated anymore in 8.5.
However, I think we should have test coverage for that, we seem to be testing translation revision revert in \Drupal\node\Tests\NodeRevisionsTest::testRevisionTranslationRevert(), should be easy to add another line there.
Comment #16
timmillwoodAs you say in #15
NodeRevisionRevertTranslationForm
extendsNodeRevisionRevertForm
and use the same submit handler, but yes, test coverage would be good.Also, yes, I am Node maintainer, after the shock of seeing Node didn't have a maintainer I volunteered as I seem to be in and out of Node module with Workflow issues.
Comment #17
BerdirYeah, its interesting how we didn't have a node maintainer for a very long time, good thing it's not a very important piece of Drupal, right ;) Even better that it's an exception and that no other equally unimportant parts like the base system, system.module or the database layer also don't have any maintainers :)
Comment #18
timmillwoodYou could almost be British with that sarcasm level :D
Comment #19
trwill CreditAttribution: trwill commentedGood catch @Berdir. Attached update for the missed test.
Comment #20
BerdirLooks we don't have separate users here? So you probably need to create another and log in with that for the revert.
Comment #21
BerdirAlso, you shouldn't add additional test runs unless there is a specific reason to, like something that is PHP/database backend specific. Each test run costs ~1h hour of processing resources.
Comment #22
trwill CreditAttribution: trwill commentedWhoops, we do have a different user for the reverted revision, but I didn't realize an extra node revision was initially being added at the top in the setup (expected 3 elements in
$nodes
array, actual is 4). My bad, ran the test with only the first line initially. Updated to use the correct revision.Thanks for the tip on tests - I honestly had never thought about the resources, so used to unlimited builds for our CI.
Comment #23
BerdirHm, I'm a bit confused.
The assert right above your code also checks for $nodes[1]. So it seems that piece expects that the reverted node is in fact $nodes[1] ?
Comment #24
trwill CreditAttribution: trwill commentedYeah, good catch. You are correct $nodes[1] is being reverted. I am getting a bit confused looking at how these nodes are keyed. I think this patch should do it - this now sets a different revision author on $nodes[1] as well, so we can compare revision authors.
Comment #25
trwill CreditAttribution: trwill commentedOops, should be < 2, not <1. Was only running the single method on my local. Updated patch.
Comment #26
trwill CreditAttribution: trwill commentedIt’s funny to me that this passed without the other revision having the editor user - maybe some legacy test set up code?
Comment #27
trwill CreditAttribution: trwill commentedAnything left on this?
Comment #28
timmillwoodI think it'd be good to identify the issue spotted in #26, but I expect this can be done in a follow up.
Comment #29
trwill CreditAttribution: trwill commentedRemoving the needs tests tag
Comment #30
alexpottCommitted and pushed f7cd4d7d94 to 8.6.x and caa2970238 to 8.5.x. Thanks!