From d0df1ff887658658ca84390689f92ff1ee4cec4d Mon Sep 17 00:00:00 2001 From: Mischa The Evil Date: Wed, 27 Jan 2021 08:33:15 +0100 Subject: [PATCH 4/5] Disable the wiki module after deletion of a project wiki. By adding a (private) after_destroy :disable_wiki_module callback that disables the wiki module after deletion of a project wiki, we prevent the need to explicitly have to disable the wiki module first, before (re-)enabling the module would eventually create a new project wiki and reset the start_page. This fixes issue #34634. --- app/models/wiki.rb | 7 +++++++ test/functional/wikis_controller_test.rb | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/app/models/wiki.rb b/app/models/wiki.rb index 8173fb212..db7859af8 100644 --- a/app/models/wiki.rb +++ b/app/models/wiki.rb @@ -30,6 +30,7 @@ class Wiki < ActiveRecord::Base validates_length_of :start_page, maximum: 255 before_destroy :delete_redirects + after_destroy :disable_wiki_module safe_attributes 'start_page' @@ -78,6 +79,12 @@ class Wiki < ActiveRecord::Base WikiRedirect.where(:redirects_to_wiki_id => id).delete_all end + # Disables the wiki module after deletion of a project wiki + def disable_wiki_module + project.disable_module!(:wiki) + end + private :disable_wiki_module + # Finds a page by title # The given string can be of one of the forms: "title" or "project:title" # Examples: diff --git a/test/functional/wikis_controller_test.rb b/test/functional/wikis_controller_test.rb index c593d5200..de015c381 100644 --- a/test/functional/wikis_controller_test.rb +++ b/test/functional/wikis_controller_test.rb @@ -43,6 +43,14 @@ class WikisControllerTest < Redmine::ControllerTest :action => 'show', :id => 'ecookbook' assert_nil Project.find(1).wiki end + + def test_post_destroy_should_disable_wiki_module + set_tmp_attachments_directory + @request.session[:user_id] = 1 + assert Project.find(1).module_enabled?(:wiki) + post :destroy, :params => {:id => 1, :confirm => 1} + assert_not Project.find(1).module_enabled?(:wiki) + end def test_not_found @request.session[:user_id] = 1 -- 2.26.0.windows.1