Option to set parent automatically for new wiki pages (#3108).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8255 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2011-12-17 11:44:04 +00:00
parent c8066879db
commit dcce70095b
5 changed files with 55 additions and 16 deletions

View File

@ -95,7 +95,12 @@ class WikiController < ApplicationController
# edit an existing page or a new one
def edit
return render_403 unless editable?
@page.content = WikiContent.new(:page => @page) if @page.new_record?
if @page.new_record?
@page.content = WikiContent.new(:page => @page)
if params[:parent].present?
@page.parent = @page.wiki.find_page(params[:parent].to_s)
end
end
@content = @page.content_for_version(params[:version])
@content.text = initial_page_content(@page) if @content.text.blank?
@ -143,6 +148,9 @@ class WikiController < ApplicationController
@content.text = @text
end
@content.author = User.current
if @page.new_record? && params[:page]
@page.parent_id = params[:page][:parent_id]
end
# if page is new @page.save will also save content, but not if page isn't a new record
if (@page.new_record? ? @page.save : @content.save)
attachments = Attachment.attach_files(@page, params[:attachments])

View File

@ -596,7 +596,9 @@ module ApplicationHelper
when :anchor; "##{page.present? ? Wiki.titleize(page) : title}" + (anchor.present? ? "_#{anchor}" : '') # used for single-file wiki export
else
wiki_page_id = page.present? ? Wiki.titleize(page) : nil
url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project, :id => wiki_page_id, :anchor => anchor)
parent = wiki_page.nil? && obj.is_a?(WikiContent) && obj.page && project == link_project ? obj.page.title : nil
url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project,
:id => wiki_page_id, :anchor => anchor, :parent => parent)
end
end
link_to(title.present? ? title.html_safe : h(page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new')))

View File

@ -13,6 +13,10 @@
<div class="box tabular">
<%= text_area_tag 'content[text]', @text, :cols => 100, :rows => 25, :class => 'wiki-edit', :accesskey => accesskey(:edit) %>
<% if @page.new_record? && @page.parent %>
<p><label><%= check_box_tag 'page[parent_id]', @page.parent.id %> <%= l(:field_parent_title) %></label> <%=h @page.parent.pretty_title %></p>
<% end %>
<p><label><%= l(:field_comments) %></label><%= f.text_field :comments, :size => 120 %></p>
<p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
</div>

View File

@ -82,11 +82,6 @@ class WikiControllerTest < ActionController::TestCase
:content => /Side bar content for test_show_with_sidebar/
end
def test_show_unexistent_page_without_edit_right
get :show, :project_id => 1, :id => 'Unexistent page'
assert_response 404
end
def test_show_should_display_section_edit_links
@request.session[:user_id] = 2
get :show, :project_id => 1, :id => 'Page with sections'
@ -119,11 +114,25 @@ class WikiControllerTest < ActionController::TestCase
}
end
def test_show_unexistent_page_without_edit_right
get :show, :project_id => 1, :id => 'Unexistent page'
assert_response 404
end
def test_show_unexistent_page_with_edit_right
@request.session[:user_id] = 2
get :show, :project_id => 1, :id => 'Unexistent page'
assert_response :success
assert_template 'edit'
assert_no_tag 'input', :attributes => {:name => 'page[parent_id]'}
end
def test_show_unexistent_page_with_parent
@request.session[:user_id] = 2
get :show, :project_id => 1, :id => 'Unexistent page', :parent => 'Another_page'
assert_response :success
assert_template 'edit'
assert_tag 'input', :attributes => {:name => 'page[parent_id]', :value => '2'}
end
def test_show_should_not_show_history_without_permission
@ -135,15 +144,20 @@ class WikiControllerTest < ActionController::TestCase
def test_create_page
@request.session[:user_id] = 2
assert_difference 'WikiPage.count' do
assert_difference 'WikiContent.count' do
put :update, :project_id => 1,
:id => 'New page',
:content => {:comments => 'Created the page',
:text => "h1. New page\n\nThis is a new page",
:version => 0}
end
end
assert_redirected_to :action => 'show', :project_id => 'ecookbook', :id => 'New_page'
page = Project.find(1).wiki.find_page('New page')
assert !page.new_record?
assert_not_nil page.content
assert_nil page.parent
assert_equal 'Created the page', page.content.comments
end
@ -164,6 +178,17 @@ class WikiControllerTest < ActionController::TestCase
assert_equal 'testfile.txt', page.attachments.first.filename
end
def test_create_page_with_parent
@request.session[:user_id] = 2
assert_difference 'WikiPage.count' do
put :update, :project_id => 1, :id => 'New page',
:content => {:text => "h1. New page\n\nThis is a new page", :version => 0},
:page => {:parent_id => 2}
end
page = Project.find(1).wiki.find_page('New page')
assert_equal WikiPage.find(2), page.parent
end
def test_edit_page
@request.session[:user_id] = 2
get :edit, :project_id => 'ecookbook', :id => 'Another_page'

View File

@ -502,10 +502,10 @@ RAW
'[[Another page#anchor]]' => '<a href="#anchor" class="wiki-page">Another page</a>',
'[[Another page#anchor|Page]]' => '<a href="#anchor" class="wiki-page">Page</a>',
# page that doesn't exist
'[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
'[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>',
'[[Unknown page#anchor]]' => '<a href="/projects/ecookbook/wiki/Unknown_page#anchor" class="wiki-page new">Unknown page</a>',
'[[Unknown page#anchor|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page#anchor" class="wiki-page new">404</a>',
'[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page" class="wiki-page new">Unknown page</a>',
'[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page" class="wiki-page new">404</a>',
'[[Unknown page#anchor]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor" class="wiki-page new">Unknown page</a>',
'[[Unknown page#anchor|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page?parent=Another_page#anchor" class="wiki-page new">404</a>',
}
@project = Project.find(1)