Deleting invalid wiki page version deletes whole page content
|Assignee:||Jean-Philippe Lang||% Done:|
We just found bug in redmine 3.1.1.
We was need to remove version of the redmine wiki, but we dropped whole wiki page (content).
How it was:
- user opened "/projects/some our project/wiki/Some_Name_Of_Wiki_Page/history" in two different tabs
- For example he has 29 versions. And he was need to delete the 29th version.
- he clicked delete link on first tab for the 29 version
- ok, was deleted.
- but user went to the second tab and clicked delete link for the 29th version again
- whole wiki was removed, but there was 28 versions. And error 500 "undefined method `versions' for nil:NilClass"
Some piece of log …redmine/redmine-3.1/app/controllers/wiki_controller.rb: 210:in `history' …k-4.2.4/lib/action_controller/metal/implicit_render.rb: 4:in `send_action' …/gems/actionpack-4.2.4/lib/abstract_controller/base.rb: 198:in `process_action' …ionpack-4.2.4/lib/action_controller/metal/rendering.rb: 10:in `process_action' …/actionpack-4.2.4/lib/abstract_controller/callbacks.rb: 20:in `block in process_action'
Why it was:
wiki_controller.rb -> destroy_version There is 2 lines @content = @page.content_for_version(params[:version]) @content.destroy Method of instance WikiPage (@page is) "content_for_version" did not found version (right, it was deleted) and return instance WikiContent instead (variable content - its assotoation to WikiContent by page_id column). And there is dropped the WikiContent instance in the second line in the controller. def content_for_version(version=nil) if content result = content.versions.find_by_version(version.to_i) if version result ||= content result end endWhat will be best:
- check wiki version existing and return 404 (render_404)
- just move back to refreshed history page
Of cource, user has a lot of pages opened and he mistaked, when he deleted one version twice. But system can catch same misses.
And, by SubmittingBugs instruction:
Database manager version: MySQL 5.5.46 (MariaDB)
Ruby version: 2.2.1
Rails version: 4.2.4
Redmine version: 3.1.1
Plugins: for check bug we made clear redmine on new server, so, no any plugins.
Fixed that #destroy_version with invalid version destroys wiki page content (#21155).