diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-07-30 07:38:48 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2017-07-30 07:38:48 +0000 |
commit | e930ee8e98acbe14438c9c314077a9f7ee198269 (patch) | |
tree | 2d2cac223b4dd0194c1930f30ac1f3809662cb96 | |
parent | 6bc9f3d10dfc22cf7dd1f0e1d0226d8dbec689e7 (diff) | |
download | redmine-e930ee8e98acbe14438c9c314077a9f7ee198269.tar.gz redmine-e930ee8e98acbe14438c9c314077a9f7ee198269.zip |
Adds a checkbox to set a page as the wiki start page (#26579).
git-svn-id: http://svn.redmine.org/redmine/trunk@16915 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/models/wiki_page.rb | 23 | ||||
-rw-r--r-- | app/views/wiki/rename.html.erb | 3 | ||||
-rw-r--r-- | lib/redmine.rb | 2 | ||||
-rw-r--r-- | test/fixtures/roles.yml | 1 | ||||
-rw-r--r-- | test/functional/wiki_controller_test.rb | 19 |
5 files changed, 46 insertions, 2 deletions
diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 9082859d3..48fbafe44 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -50,7 +50,7 @@ class WikiPage < ActiveRecord::Base validate :validate_parent_title before_destroy :delete_redirects - before_save :handle_rename_or_move + before_save :handle_rename_or_move, :update_wiki_start_page after_save :handle_children_move # eager load information about last updates, without loading text @@ -62,6 +62,9 @@ class WikiPage < ActiveRecord::Base safe_attributes 'parent_id', 'parent_title', 'title', 'redirect_existing_links', 'wiki_id', :if => lambda {|page, user| page.new_record? || user.allowed_to?(:rename_wiki_pages, page.project)} + safe_attributes 'is_start_page', + :if => lambda {|page, user| user.allowed_to?(:manage_wiki, page.project)} + def initialize(attributes=nil, *args) super if new_record? && DEFAULT_PROTECTED_PAGES.include?(title.to_s.downcase) @@ -212,6 +215,24 @@ class WikiPage < ActiveRecord::Base self.parent = parent_page end + def is_start_page + if @is_start_page.nil? + @is_start_page = wiki.try(:start_page) == title_was + end + @is_start_page + end + + def is_start_page=(arg) + @is_start_page = arg == '1' || arg == true + end + + def update_wiki_start_page + if is_start_page + wiki.update_attribute :start_page, title + end + end + private :update_wiki_start_page + # Saves the page and its content if text was changed # Return true if the page was saved def save_with_content(content) diff --git a/app/views/wiki/rename.html.erb b/app/views/wiki/rename.html.erb index ac88fd4bf..377e1717c 100644 --- a/app/views/wiki/rename.html.erb +++ b/app/views/wiki/rename.html.erb @@ -9,6 +9,9 @@ :html => { :method => :post } do |f| %> <div class="box tabular"> <p><%= f.text_field :title, :required => true, :size => 100 %></p> +<% if @page.safe_attribute? 'is_start_page' %> +<p><%= f.check_box :is_start_page, :label => :field_start_page, :disabled => @page.is_start_page %></p> +<% end %> <p><%= f.check_box :redirect_existing_links %></p> <p><%= f.select :parent_id, content_tag('option', '', :value => '') + diff --git a/lib/redmine.rb b/lib/redmine.rb index 29d96c2b0..1937ba8ee 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -155,7 +155,7 @@ Redmine::AccessControl.map do |map| map.permission :delete_wiki_pages, {:wiki => [:destroy, :destroy_version]}, :require => :member map.permission :delete_wiki_pages_attachments, {} map.permission :protect_wiki_pages, {:wiki => :protect}, :require => :member - map.permission :manage_wiki, {:wikis => [:edit, :destroy]}, :require => :member + map.permission :manage_wiki, {:wikis => [:edit, :destroy], :wiki => :rename}, :require => :member end map.project_module :repository do |map| diff --git a/test/fixtures/roles.yml b/test/fixtures/roles.yml index ce7e1b4e7..072440d31 100644 --- a/test/fixtures/roles.yml +++ b/test/fixtures/roles.yml @@ -51,6 +51,7 @@ roles_001: - :protect_wiki_pages - :delete_wiki_pages - :rename_wiki_pages + - :manage_wiki - :view_messages - :add_messages - :edit_messages diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index 7260d9094..314d46385 100644 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -843,6 +843,25 @@ class WikiControllerTest < Redmine::ControllerTest assert_equal project.wiki.id, page.wiki_id end + def test_rename_as_start_page + @request.session[:user_id] = 2 + + post :rename, :params => { + :project_id => 'ecookbook', + :id => 'Another_page', + :wiki_page => { + :wiki_id => '1', + :title => 'Another_page', + :redirect_existing_links => '1', + :is_start_page => '1' + } + } + assert_redirected_to '/projects/ecookbook/wiki/Another_page' + + wiki = Wiki.find(1) + assert_equal 'Another_page', wiki.start_page + end + def test_destroy_a_page_without_children_should_not_ask_confirmation @request.session[:user_id] = 2 delete :destroy, :params => {:project_id => 1, :id => 'Child_2'} |