summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2016-04-22 17:47:11 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2016-04-22 17:47:11 +0000
commitbda78a4679bc947dfd42ab92adfc043afd1d2f60 (patch)
tree39ad1356f3024f2dd9ee3a8710e8d9bd46334efc
parentb56f77322ac2f6a900ba011e767446e17401cf6f (diff)
downloadredmine-bda78a4679bc947dfd42ab92adfc043afd1d2f60.tar.gz
redmine-bda78a4679bc947dfd42ab92adfc043afd1d2f60.zip
Adds "New wiki page" link to create a new wiki page (#5536).
git-svn-id: http://svn.redmine.org/redmine/trunk@15346 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/wiki_controller.rb17
-rw-r--r--app/helpers/application_helper.rb10
-rw-r--r--app/views/wiki/_new_modal.html.erb21
-rw-r--r--app/views/wiki/date_index.html.erb3
-rw-r--r--app/views/wiki/index.html.erb3
-rw-r--r--app/views/wiki/new.html.erb17
-rw-r--r--app/views/wiki/new.js.erb2
-rw-r--r--app/views/wiki/show.html.erb3
-rw-r--r--config/locales/de.yml1
-rw-r--r--config/locales/en.yml1
-rw-r--r--config/locales/fr.yml1
-rw-r--r--config/routes.rb3
-rw-r--r--lib/redmine.rb2
-rw-r--r--test/functional/wiki_controller_test.rb49
-rw-r--r--test/integration/routing/wiki_test.rb3
15 files changed, 132 insertions, 4 deletions
diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb
index 46dec485c..2f174877f 100644
--- a/app/controllers/wiki_controller.rb
+++ b/app/controllers/wiki_controller.rb
@@ -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)
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 7edfbd534..7cdf5061a 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -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"
diff --git a/app/views/wiki/_new_modal.html.erb b/app/views/wiki/_new_modal.html.erb
new file mode 100644
index 000000000..52a87b751
--- /dev/null
+++ b/app/views/wiki/_new_modal.html.erb
@@ -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 %>
diff --git a/app/views/wiki/date_index.html.erb b/app/views/wiki/date_index.html.erb
index 74a5f45fb..c382ed6e7 100644
--- a/app/views/wiki/date_index.html.erb
+++ b/app/views/wiki/date_index.html.erb
@@ -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>
diff --git a/app/views/wiki/index.html.erb b/app/views/wiki/index.html.erb
index 333cc8531..0d6955da1 100644
--- a/app/views/wiki/index.html.erb
+++ b/app/views/wiki/index.html.erb
@@ -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>
diff --git a/app/views/wiki/new.html.erb b/app/views/wiki/new.html.erb
new file mode 100644
index 000000000..d0674202d
--- /dev/null
+++ b/app/views/wiki/new.html.erb
@@ -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 %>
diff --git a/app/views/wiki/new.js.erb b/app/views/wiki/new.js.erb
new file mode 100644
index 000000000..c12b35340
--- /dev/null
+++ b/app/views/wiki/new.js.erb
@@ -0,0 +1,2 @@
+$('#ajax-modal').html('<%= escape_javascript(render :partial => 'wiki/new_modal') %>');
+showModal('ajax-modal', '600px');
diff --git a/app/views/wiki/show.html.erb b/app/views/wiki/show.html.erb
index a9db7a0c4..41dd12d10 100644
--- a/app/views/wiki/show.html.erb
+++ b/app/views/wiki/show.html.erb
@@ -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)) %>
diff --git a/config/locales/de.yml b/config/locales/de.yml
index ced177ecf..cbfd7f97c 100644
--- a/config/locales/de.yml
+++ b/config/locales/de.yml
@@ -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
diff --git a/config/locales/en.yml b/config/locales/en.yml
index c19885191..98b3e351a 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -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
diff --git a/config/locales/fr.yml b/config/locales/fr.yml
index 1bb7bd48f..2d0f5114f 100644
--- a/config/locales/fr.yml
+++ b/config/locales/fr.yml
@@ -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
diff --git a/config/routes.rb b/config/routes.rb
index e80895207..06b500120 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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
diff --git a/lib/redmine.rb b/lib/redmine.rb
index 64c6a6946..540384071 100644
--- a/lib/redmine.rb
+++ b/lib/redmine.rb
@@ -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
diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb
index 82aca52d0..cd3bf0a76 100644
--- a/test/functional/wiki_controller_test.rb
+++ b/test/functional/wiki_controller_test.rb
@@ -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
diff --git a/test/integration/routing/wiki_test.rb b/test/integration/routing/wiki_test.rb
index 135bb3f1b..c1c176af1 100644
--- a/test/integration/routing/wiki_test.rb
+++ b/test/integration/routing/wiki_test.rb
@@ -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'