git-svn-id: http://svn.redmine.org/redmine/trunk@15346 e93f8b46-1217-0410-a6f0-8f06a7374b81tags/3.3.0
@@ -60,6 +60,23 @@ class WikiController < ApplicationController | |||
@pages_by_date = @pages.group_by {|p| p.updated_on.to_date} | |||
end | |||
def new | |||
@page = WikiPage.new(:wiki => @wiki, :title => params[:title]) | |||
unless User.current.allowed_to?(:edit_wiki_pages, @project) && editable? | |||
render_403 | |||
end | |||
if request.post? | |||
@page.validate | |||
if @page.errors[:title].blank? | |||
path = project_wiki_page_path(@project, @page.title) | |||
respond_to do |format| | |||
format.html { redirect_to path } | |||
format.js { render :js => "window.location = #{path.to_json}" } | |||
end | |||
end | |||
end | |||
end | |||
# display a page (in editing mode if it doesn't exist) | |||
def show | |||
if params[:version] && !User.current.allowed_to?(:view_wiki_edits, @project) |
@@ -1057,11 +1057,17 @@ module ApplicationHelper | |||
fields_for(*args, &proc) | |||
end | |||
# Render the error messages for the given objects | |||
def error_messages_for(*objects) | |||
html = "" | |||
objects = objects.map {|o| o.is_a?(String) ? instance_variable_get("@#{o}") : o}.compact | |||
errors = objects.map {|o| o.errors.full_messages}.flatten | |||
if errors.any? | |||
render_error_messages(errors) | |||
end | |||
# Renders a list of error messages | |||
def render_error_messages(errors) | |||
html = "" | |||
if errors.present? | |||
html << "<div id='errorExplanation'><ul>\n" | |||
errors.each do |error| | |||
html << "<li>#{h error}</li>\n" |
@@ -0,0 +1,21 @@ | |||
<h3 class="title"><%=l(:label_wiki_page_new)%></h3> | |||
<%= labelled_form_for :page, @page, | |||
:url => new_project_wiki_page_path(@project), | |||
:method => 'post', | |||
:remote => true do |f| %> | |||
<%= render_error_messages @page.errors.full_messages_for(:title) %> | |||
<div class="box tabular"> | |||
<p> | |||
<%= f.text_field :title, :name => 'title', :size => 60, :required => true %> | |||
<em class="info"><%= l(:text_unallowed_characters) %>: , . / ? ; : |</em> | |||
</p> | |||
</div> | |||
<p class="buttons"> | |||
<%= submit_tag l(:label_next), :name => nil %> | |||
<%= submit_tag l(:button_cancel), :name => nil, :onclick => "hideModal(this);", :type => 'button' %> | |||
</p> | |||
<% end %> |
@@ -1,4 +1,7 @@ | |||
<div class="contextual"> | |||
<% if User.current.allowed_to?(:edit_wiki_pages, @project) %> | |||
<%= link_to l(:label_wiki_page_new), new_project_wiki_page_path(@project), :remote => true, :class => 'icon icon-add' %> | |||
<% end %> | |||
<%= watcher_link(@wiki, User.current) %> | |||
</div> | |||
@@ -1,4 +1,7 @@ | |||
<div class="contextual"> | |||
<% if User.current.allowed_to?(:edit_wiki_pages, @project) %> | |||
<%= link_to l(:label_wiki_page_new), new_project_wiki_page_path(@project), :remote => true, :class => 'icon icon-add' %> | |||
<% end %> | |||
<%= watcher_link(@wiki, User.current) %> | |||
</div> | |||
@@ -0,0 +1,17 @@ | |||
<%= title l(:label_wiki_page_new) %> | |||
<%= labelled_form_for :page, @page, | |||
:url => new_project_wiki_page_path(@project) do |f| %> | |||
<%= render_error_messages @page.errors.full_messages_for(:title) %> | |||
<div class="box tabular"> | |||
<p> | |||
<%= f.text_field :title, :name => 'title', :size => 60, :required => true %> | |||
<em class="info"><%= l(:text_unallowed_characters) %>: , . / ? ; : |</em> | |||
</p> | |||
</div> | |||
<%= submit_tag(l(:label_next)) %> | |||
<% end %> |
@@ -0,0 +1,2 @@ | |||
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'wiki/new_modal') %>'); | |||
showModal('ajax-modal', '600px'); |
@@ -1,4 +1,7 @@ | |||
<div class="contextual"> | |||
<% if User.current.allowed_to?(:edit_wiki_pages, @project) %> | |||
<%= link_to l(:label_wiki_page_new), new_project_wiki_page_path(@project), :remote => true, :class => 'icon icon-add' %> | |||
<% end %> | |||
<% if @editable %> | |||
<% if @content.current_version? %> | |||
<%= link_to_if_authorized(l(:button_edit), {:action => 'edit', :id => @page.title}, :class => 'icon icon-edit', :accesskey => accesskey(:edit)) %> |
@@ -810,6 +810,7 @@ de: | |||
label_wiki_edit_plural: Wiki-Bearbeitungen | |||
label_wiki_page: Wiki-Seite | |||
label_wiki_page_plural: Wiki-Seiten | |||
label_wiki_page_new: Neue Wiki-Seite | |||
label_workflow: Workflow | |||
label_x_closed_issues_abbr: | |||
zero: 0 geschlossen |
@@ -764,6 +764,7 @@ en: | |||
label_wiki_edit_plural: Wiki edits | |||
label_wiki_page: Wiki page | |||
label_wiki_page_plural: Wiki pages | |||
label_wiki_page_new: New wiki page | |||
label_index_by_title: Index by title | |||
label_index_by_date: Index by date | |||
label_current_version: Current version |
@@ -776,6 +776,7 @@ fr: | |||
label_wiki_edit_plural: Révisions wiki | |||
label_wiki_page: Page wiki | |||
label_wiki_page_plural: Pages wiki | |||
label_wiki_page_new: Nouvelle page wiki | |||
label_index_by_title: Index par titre | |||
label_index_by_date: Index par date | |||
label_current_version: Version actuelle |
@@ -156,7 +156,7 @@ Rails.application.routes.draw do | |||
end | |||
match 'wiki/index', :controller => 'wiki', :action => 'index', :via => :get | |||
resources :wiki, :except => [:index, :new, :create], :as => 'wiki_page' do | |||
resources :wiki, :except => [:index, :create], :as => 'wiki_page' do | |||
member do | |||
get 'rename' | |||
post 'rename' | |||
@@ -169,6 +169,7 @@ Rails.application.routes.draw do | |||
collection do | |||
get 'export' | |||
get 'date_index' | |||
post 'new' | |||
end | |||
end | |||
match 'wiki', :controller => 'wiki', :action => 'show', :via => :get |
@@ -155,7 +155,7 @@ Redmine::AccessControl.map do |map| | |||
map.permission :view_wiki_pages, {:wiki => [:index, :show, :special, :date_index]}, :read => true | |||
map.permission :export_wiki_pages, {:wiki => [:export]}, :read => true | |||
map.permission :view_wiki_edits, {:wiki => [:history, :diff, :annotate]}, :read => true | |||
map.permission :edit_wiki_pages, :wiki => [:edit, :update, :preview, :add_attachment], :attachments => :upload | |||
map.permission :edit_wiki_pages, :wiki => [:new, :edit, :update, :preview, :add_attachment], :attachments => :upload | |||
map.permission :delete_wiki_pages_attachments, {} | |||
map.permission :protect_wiki_pages, {:wiki => :protect}, :require => :member | |||
end |
@@ -183,6 +183,55 @@ class WikiControllerTest < ActionController::TestCase | |||
assert_select 'textarea[name=?]', 'content[text]' | |||
end | |||
def test_get_new | |||
@request.session[:user_id] = 2 | |||
get :new, :project_id => 'ecookbook' | |||
assert_response :success | |||
assert_template 'new' | |||
end | |||
def test_get_new_xhr | |||
@request.session[:user_id] = 2 | |||
xhr :get, :new, :project_id => 'ecookbook' | |||
assert_response :success | |||
assert_template 'new' | |||
end | |||
def test_post_new_with_valid_title_should_redirect_to_edit | |||
@request.session[:user_id] = 2 | |||
post :new, :project_id => 'ecookbook', :title => 'New Page' | |||
assert_redirected_to '/projects/ecookbook/wiki/New_Page' | |||
end | |||
def test_post_new_xhr_with_valid_title_should_redirect_to_edit | |||
@request.session[:user_id] = 2 | |||
xhr :post, :new, :project_id => 'ecookbook', :title => 'New Page' | |||
assert_response :success | |||
assert_equal 'window.location = "/projects/ecookbook/wiki/New_Page"', response.body | |||
end | |||
def test_post_new_with_invalid_title_should_display_errors | |||
@request.session[:user_id] = 2 | |||
post :new, :project_id => 'ecookbook', :title => 'Another page' | |||
assert_response :success | |||
assert_template 'new' | |||
assert_select_error 'Title has already been taken' | |||
end | |||
def test_post_new_xhr_with_invalid_title_should_display_errors | |||
@request.session[:user_id] = 2 | |||
xhr :post, :new, :project_id => 'ecookbook', :title => 'Another page' | |||
assert_response :success | |||
assert_template 'new' | |||
assert_include 'Title has already been taken', response.body | |||
end | |||
def test_create_page | |||
@request.session[:user_id] = 2 | |||
assert_difference 'WikiPage.count' do |
@@ -30,6 +30,9 @@ class RoutingWikiTest < Redmine::RoutingTest | |||
should_route 'GET /projects/foo/wiki/page' => 'wiki#show', :project_id => 'foo', :id => 'page' | |||
should_route 'GET /projects/foo/wiki/page.pdf' => 'wiki#show', :project_id => 'foo', :id => 'page', :format => 'pdf' | |||
should_route 'GET /projects/foo/wiki/new' => 'wiki#new', :project_id => 'foo' | |||
should_route 'POST /projects/foo/wiki/new' => 'wiki#new', :project_id => 'foo' | |||
should_route 'GET /projects/foo/wiki/page/edit' => 'wiki#edit', :project_id => 'foo', :id => 'page' | |||
should_route 'PUT /projects/foo/wiki/page' => 'wiki#update', :project_id => 'foo', :id => 'page' | |||
should_route 'DELETE /projects/foo/wiki/page' => 'wiki#destroy', :project_id => 'foo', :id => 'page' |