Merge authors operation should be a HTTP PUT or POST, not a GET
Because the merge authors operation mutates data on the server, it should be POST, not a GET, according to HTTP principals. Doing this will cause the browser to warn users when they're about to redo an operation which they might not want to .
This is low frequency occurrence, but it's happened to me twice now where I:
- merge some authors
- notice that the merge is wrong in some way and undo it
- go back to redo the merge correctly, but in the process the browser's Back button causes the problematic merge to be done again
- have to undo the bad merge yet again
If the operation were a PUT or POST, the browser would automatically ask if I wanted to redo the operation, allowing me the time to come to my senses. :)
As an aside, while looking at this, I noticed that it takes 5 (!) redirects before the merge operation is finally resolved:
merge | 303 | document / Redirect | Other | 165 B | 170 ms
?merge=true&duplicates=OL12227665A,OL6119964A,OL7444033A,OL9883714A | 303 | document / Redirect | /authors/merge | (ServiceWorker) | 93 ms
⚙ ?merge=true&duplicates=OL12227665A,OL6119964A,OL7444033A,OL9883714A | 303 | fetch / Redirect | sw.js:2 | 99 B | 87 ms
-?merge=true&duplicates=OL12227665A,OL6119964A,OL7444033A,OL9883714A | 301 | document / Redirect | /authors/OL6812710A/-/?merge=true&duplicates=OL12227665A,OL6119964A,OL7444033A,OL9883714A | (ServiceWorker) | 106 ms
⚙ -?merge=true&duplicates=OL12227665A,OL6119964A,OL7444033A,OL9883714A | 301 | fetch / Redirect | sw.js:2 | 112 B | 101 ms
James_Patterson?merge=true&duplicates=OL12227665A,OL6119964A,OL7444033A,OL9883714A | 200 | document | /authors/OL6812710A/-?merge=true&duplicates=OL12227665A,OL6119964A,OL7444033A,OL9883714A | (ServiceWorker) | 2.11 s
Stakeholders
@mekarpeles @cdrini
Hi, I'd like to work on this if nobody else has it.
Here's what I see on master: the merge form POSTs to /authors/merge, and that handler redirects to /authors/{master}/-/?merge=true&duplicates=.... When the author page loads with those parameters, initAuthorView in merge.js immediately POSTs to /authors/merge.json. So the merge actually runs whenever that URL is loaded, and Back or refresh runs it again.
My plan is to have initAuthorView remove merge, duplicates, mrid and comment from the address bar with history.replaceState before it sends the merge request. After that, refreshing the page or coming back to it with Back shows the plain author page, and the merge doesn't run a second time. This fixes the repeated merge without changing any server endpoints. I'd add a JS unit test checking that the parameters are gone before the request goes out.
Turning the whole flow into a single POST, which would also cut down the redirect chain in the issue, is a bigger change to the template and the handler. I'm happy to do that instead if you'd prefer it, but I'd suggest starting with the small fix.
While reading the handler I also noticed that comment goes into the redirect URL without URL encoding, so a comment containing & or # gets cut short. I can fix that in the same PR if that's okay.
@jasperwchen go for it. I'll assign you when you open a PR. Please try your best to follow Tom's advice and best practices from other sources about http methods