Commit dee69566 authored by jplang's avatar jplang
Browse files

Adds a checkbox to set a page as the wiki start page (#26579).

git-svn-id: https://svn.redmine.org/redmine/trunk@16915 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent e7b02e02
......@@ -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)
......
......@@ -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 => '') +
......
......@@ -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|
......
......@@ -51,6 +51,7 @@ roles_001:
- :protect_wiki_pages
- :delete_wiki_pages
- :rename_wiki_pages
- :manage_wiki
- :view_messages
- :add_messages
- :edit_messages
......
......@@ -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'}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment